/// <summary> /// Загрузить содержимое файла с исходным кодом и получить набор единиц кода /// </summary> /// <returns></returns> public CCodeUnitsCollection Load() { if (File.Exists(m_args.GetPath())) { using (FileStream f_stream = new FileStream(m_args.GetPath(), FileMode.Open)) { using (StreamReader sreader = new StreamReader(f_stream, m_args.GetEncoding())) { CCodeUnitsCollection collection = new CCodeUnitsCollection(); string source_str = null; long line_number = CElementPosition.LINE_NUMBER_LOW_BOUND; while ((source_str = sreader.ReadLine()) != null) { CCodeUnit unit = new CCodeUnit(new CElementPosition(line_number, CElementPosition.INDEX_NUMBER_LOW_BOUND, line_number, source_str.Length), source_str); collection.Add(new CExtendedCodeUnit(unit, m_args.GetFileID().SourceFileID)); ++line_number; } return(collection); } } } else { throw new FileNotFoundException("File not found", m_args.GetPath()); } }
public void GetHashCodeTest() { string text = "))))dsfg dfgsdfhigndfkgsdfkgl sdfgjhsdfkgskl dfgsdfgjsdlf gsdflg"; CCodeUnit target = new CCodeUnit(new CElementPosition(12, 12), text); Assert.AreEqual(text.GetHashCode(), target.GetHashCode()); }
public void CCodeUnitConstructorTest2() { CCodeUnit target = new CCodeUnit(new CElementPosition(12, 12), string.Empty); Assert.IsNotNull(target); Assert.AreEqual(target.Text, string.Empty); }
public void TextTest3() { CCodeUnit target = new CCodeUnit(new CElementPosition(12, 12), ")"); target.Text = string.Empty; Assert.AreEqual(target.Text, string.Empty); }
public static CExtendedCodeUnit FromToken(Token token, CTokenizerParms args) { CElementPosition pos = new CElementPosition(token.line, token.col, token.line, token.col + token.val.Length); CCodeUnit simple_unit = new CCodeUnit(pos, token.val); CExtendedCodeUnit unit = new CExtendedCodeUnit(simple_unit, args.GetFileID().SourceFileID); return(unit); }
public void TextTest1() { CCodeUnit target = new CCodeUnit(new CElementPosition(12, 12), ")"); string text = "))))dsfg dfgsdfhigndfkgsdfkgl sdfgjhsdfkgskl dfgsdfgjsdlf gsdflg"; target.Text = text; Assert.AreEqual(target.Text, text); }
public void CCodeUnitConstructorTest() { string expected = ")"; CCodeUnit other = new CCodeUnit(new CElementPosition(12, 12), expected); CCodeUnit target = new CCodeUnit(other); other.Text = "("; Assert.AreEqual(target.Text, expected); }
public static ISourceFileContentLoader Create(CTokenizerParms args, ICloneExtension ext) { if (CCodeUnit.IsUseTokens()) { return(new CTokenSourceFileContentLoader(args, ext)); } else { return(new CEntireRowSourceFileContentLoader(args)); } }
/// <summary> /// /// </summary> /// <param name="_Path"></param> /// <param name="_Encoding"></param> /// <returns></returns> public static ISourceFileContentSaver Create(string _Path, Encoding _Encoding) { if (CCodeUnit.IsUseTokens()) { throw new NotImplementedException(); } else { return(new CEntireRowSourceFileContentSaver(_Path, _Encoding)); } }
public void CloneTest() { CCodeUnit target = new CCodeUnit(new CElementPosition(12, 12), ")"); object actual = target.Clone(); Assert.IsNotNull(actual); Assert.IsFalse(target == actual); Assert.IsTrue(actual.Equals(target)); Assert.IsTrue(target.EqualsObject(actual)); Assert.AreEqual(target, actual); }
public void EqualsObjectTest2() { CCodeUnit first = new CCodeUnit(new CElementPosition(12, 12), ")"); object second = new CCodeUnit(new CElementPosition(12, 12), ")"); Assert.IsFalse(first.EqualsObject(null)); Assert.IsTrue(first.EqualsObject(first as object)); Assert.IsTrue(first.EqualsObject(second)); Assert.AreEqual(first.EqualsObject(second), second.Equals(first)); second = new CCodeUnit(new CElementPosition(12, 12), "else"); Assert.IsFalse(first.EqualsObject(second)); }
public void EqualsTest() { CCodeUnit first = new CCodeUnit(new CElementPosition(12, 12), ")"); CCodeUnit second = new CCodeUnit(new CElementPosition(12, 12), ")"); Assert.IsFalse(first.Equals(null)); Assert.IsTrue(first.Equals(first)); Assert.IsTrue(first.Equals(second)); Assert.AreEqual(first.Equals(second), second.Equals(first)); second = new CCodeUnit(new CElementPosition(12, 12), "else"); Assert.IsFalse(first.Equals(second)); second = new CCodeUnit(new CElementPosition(1, 34), ")"); Assert.IsTrue(second.Equals(first)); }
public void CompareToTest() { CCodeUnit first = new CCodeUnit(new CElementPosition(12, 12), ")"); Assert.AreEqual(0, first.CompareTo(first)); CCodeUnit second = new CCodeUnit(new CElementPosition(12, 12), ")"); Assert.AreEqual(0, first.CompareTo(second)); Assert.AreEqual(0, second.CompareTo(first)); CCodeUnit third = new CCodeUnit(new CElementPosition(12, 12), ")"); Assert.AreEqual(0, first.CompareTo(third)); Assert.AreEqual(0, second.CompareTo(third)); second = new CCodeUnit(new CElementPosition(12, 12), ")!"); Assert.AreEqual(-1, first.CompareTo(second)); Assert.AreEqual(1, second.CompareTo(first)); second = new CCodeUnit(new CElementPosition(12, 12, 15, 1234), ")"); Assert.AreEqual(-1, first.CompareTo(second)); Assert.AreEqual(1, second.CompareTo(first)); }
public void CCodeUnitConstructorTest3() { CCodeUnit target = new CCodeUnit(new CElementPosition(12, 12), null); }
public void TextTest2() { CCodeUnit target = new CCodeUnit(new CElementPosition(12, 12), ")"); target.Text = null; }
public void CCodeUnitConstructorTest1() { CCodeUnit target = new CCodeUnit(new CElementPosition(12, 12), ")"); Assert.IsNotNull(target); }