コード例 #1
0
 /// <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());
     }
 }
コード例 #2
0
        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());
        }
コード例 #3
0
        public void CCodeUnitConstructorTest2()
        {
            CCodeUnit target = new CCodeUnit(new CElementPosition(12, 12), string.Empty);

            Assert.IsNotNull(target);
            Assert.AreEqual(target.Text, string.Empty);
        }
コード例 #4
0
        public void TextTest3()
        {
            CCodeUnit target = new CCodeUnit(new CElementPosition(12, 12), ")");

            target.Text = string.Empty;
            Assert.AreEqual(target.Text, string.Empty);
        }
コード例 #5
0
ファイル: Utils.cs プロジェクト: mfvanek/i-clone
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
 public static ISourceFileContentLoader Create(CTokenizerParms args, ICloneExtension ext)
 {
     if (CCodeUnit.IsUseTokens())
     {
         return(new CTokenSourceFileContentLoader(args, ext));
     }
     else
     {
         return(new CEntireRowSourceFileContentLoader(args));
     }
 }
コード例 #9
0
 /// <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));
     }
 }
コード例 #10
0
        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);
        }
コード例 #11
0
        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));
        }
コード例 #12
0
        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));
        }
コード例 #13
0
        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));
        }
コード例 #14
0
 public void CCodeUnitConstructorTest3()
 {
     CCodeUnit target = new CCodeUnit(new CElementPosition(12, 12), null);
 }
コード例 #15
0
        public void TextTest2()
        {
            CCodeUnit target = new CCodeUnit(new CElementPosition(12, 12), ")");

            target.Text = null;
        }
コード例 #16
0
        public void CCodeUnitConstructorTest1()
        {
            CCodeUnit target = new CCodeUnit(new CElementPosition(12, 12), ")");

            Assert.IsNotNull(target);
        }