Пример #1
0
        public void FewLinesPositionTest()
        {
            string source = "1\n22\n\n4";

            iOrigin = CreateOriginTest(source);
            iReader = iOrigin.GetReader();
            OriginPosition pos;

            iReader.MoveNext();
            pos = iReader.CurrentLocation.GetOriginPosition();
            Assert.IsTrue((pos.LineNumber == 1) && (pos.CharNumber == 1));

            iReader.MoveNext();
            pos = iReader.CurrentLocation.GetOriginPosition();
            Assert.IsTrue((pos.LineNumber == 2) && (pos.CharNumber == 0));

            iReader.MoveNext();
            iReader.MoveNext();
            pos = iReader.CurrentLocation.GetOriginPosition();
            Assert.IsTrue((pos.LineNumber == 2) && (pos.CharNumber == 2));

            iReader.MoveNext();
            pos = iReader.CurrentLocation.GetOriginPosition();
            Assert.IsTrue((pos.LineNumber == 3) && (pos.CharNumber == 0));

            iReader.MoveNext();
            pos = iReader.CurrentLocation.GetOriginPosition();
            Assert.IsTrue((pos.LineNumber == 4) && (pos.CharNumber == 0));

            iReader.MoveNext();
            pos = iReader.CurrentLocation.GetOriginPosition();
            Assert.IsTrue((pos.LineNumber == 4) && (pos.CharNumber == 1));
        }
Пример #2
0
        public void FewLinesFragmentPositionsTest()
        {
            string source = "1\n22\n\n4";

            iOrigin = CreateOriginTest(source);
            iReader = iOrigin.GetReader();

            iReader.MoveNext();
            ILocation loc1 = iReader.CurrentLocation;

            iReader.MoveNext();
            iReader.MoveNext();
            ILocation loc2 = iReader.CurrentLocation;

            iReader.MoveNext();

            IFragment fr = iOrigin.MakeFragment(loc1, loc2);

            Assert.AreEqual(fr.GetBeginOriginPosition(), loc1.GetOriginPosition());
            Assert.AreEqual(fr.GetEndOriginPosition(), loc2.GetOriginPosition());

            iReader.MoveNext();
            iReader.MoveNext();
            ILocation loc3 = iReader.CurrentLocation;

            IFragment fr2 = iOrigin.MakeFragment(loc2, loc3);

            Assert.AreEqual(fr2.GetBeginOriginPosition(), loc2.GetOriginPosition());
            Assert.AreEqual(fr2.GetEndOriginPosition(), loc3.GetOriginPosition());
        }
Пример #3
0
        public void FewLinesFragmentTextTest()
        {
            string source = "1\n22\n\n4";

            iOrigin = CreateOriginTest(source);
            iReader = iOrigin.GetReader();

            iReader.MoveNext(); // after '1'
            ILocation loc1 = iReader.CurrentLocation;

            iReader.MoveNext(); // after '\n'
            iReader.MoveNext(); // after '2'
            ILocation loc2 = iReader.CurrentLocation;

            iReader.MoveNext(); // after '2'

            Assert.AreEqual(iOrigin.MakeFragment(loc1, loc2).GetOriginText(), "\n2");

            ILocation loc3 = iReader.CurrentLocation;

            iReader.MoveNext(); // after '\n'
            iReader.MoveNext(); // after '\n'
            ILocation loc4 = iReader.CurrentLocation;

            Assert.AreEqual(iOrigin.MakeFragment(loc3, loc4).GetOriginText(), "\n\n");

            iReader.MoveNext(); // after '4'
            ILocation loc5 = iReader.CurrentLocation;

            Assert.AreEqual(iOrigin.MakeFragment(loc4, loc5).GetOriginText(), "4");
        }
Пример #4
0
        public void SettingLocationsTest()
        {
            string source = "012";

            iOrigin = CreateOriginTest(source);
            iReader = iOrigin.GetReader();

            iReader.MoveNext(); // point to first character
            char      char1 = iReader.CurrentCharacter;
            ILocation loc1  = iReader.CurrentLocation;

            iReader.MoveNext(); // second character
            char      char2 = iReader.CurrentCharacter;
            ILocation loc2  = iReader.CurrentLocation;

            iReader.MoveNext(); // third character
            char      char3 = iReader.CurrentCharacter;
            ILocation loc3  = iReader.CurrentLocation;

            // check if setting location works

            iReader.CurrentLocation = loc1; // restore first character
            Assert.AreEqual(char1, iReader.CurrentCharacter);

            iReader.MoveNext(); // go to the second
            Assert.AreEqual(char2, iReader.CurrentCharacter);

            iReader.CurrentLocation = loc3; // restore third
            Assert.AreEqual(char3, iReader.CurrentCharacter);

            Assert.IsFalse(iReader.MoveNext());

            iReader.CurrentLocation = loc2; // restore second character
            Assert.AreEqual(char2, iReader.CurrentCharacter);
        }
Пример #5
0
        public void InitialReaderLocationTest()
        {
            string source = "";

            iOrigin = CreateOriginTest(source);
            iReader = iOrigin.GetReader();
            Assert.AreEqual(iOrigin.Begin, iReader.CurrentLocation);
        }
Пример #6
0
        public void EmptySourceTest()
        {
            string source = "";

            iOrigin = CreateOriginTest(source);
            iReader = iOrigin.GetReader();
            Assert.IsFalse(iReader.MoveNext());
        }
Пример #7
0
        private ILocation _lastAcceptingLocation;                // Memento equivalent

        public LexerState(IOrigin origin)
        {
            _sourceReader          = origin.GetReader();
            _currentLocation       = _sourceReader.CurrentLocation;
            _lastAcceptedLocation  = _sourceReader.CurrentLocation;
            _lastAcceptingLocation = _lastAcceptedLocation;
            _tokens = new List <Tuple <IFragment, int> >();
        }
Пример #8
0
        public void OneCharacterSourceTest()
        {
            string source = "X";

            iOrigin = CreateOriginTest(source);
            iReader = iOrigin.GetReader();
            Assert.IsTrue(iReader.MoveNext());
            Assert.AreEqual('X', iReader.CurrentCharacter);
            Assert.IsFalse(iReader.MoveNext());
        }
Пример #9
0
        public void SetBeginLocationTest()
        {
            string source = "XyZ";

            iOrigin = CreateOriginTest(source);
            iReader = iOrigin.GetReader();
            iReader.MoveNext();
            iReader.MoveNext();
            iReader.CurrentLocation = iOrigin.Begin; // set reader before first character
            iReader.MoveNext();
            Assert.AreEqual('X', iReader.CurrentCharacter);
        }
Пример #10
0
        public void NotEqualLocationsTest()
        {
            string source = "XXX";

            iOrigin = CreateOriginTest(source);
            iReader = iOrigin.GetReader();

            iReader.MoveNext(); // point to first character
            ILocation loc1 = iReader.CurrentLocation;

            iReader.MoveNext(); // second character
            Assert.AreNotEqual(loc1, iReader.CurrentLocation);
        }
Пример #11
0
        public void SetOneLocationTest()
        {
            string source = "XyZ";

            iOrigin = CreateOriginTest(source);
            iReader = iOrigin.GetReader();

            iReader.MoveNext(); // point to first character
            Assert.AreEqual('X', iReader.CurrentCharacter);
            ILocation loc1 = iReader.CurrentLocation;

            iReader.CurrentLocation = loc1;
            Assert.AreEqual('X', iReader.CurrentCharacter);
        }
Пример #12
0
        public void FalseMoveNextCallsTest()
        {
            string source = "I like reading sources!\nEspecially in tests.";

            iOrigin = CreateOriginTest(source);
            iReader = iOrigin.GetReader();

            while (iReader.MoveNext())
            {
                ;
            }
            Assert.IsFalse(iReader.MoveNext());
            Assert.IsFalse(iReader.MoveNext());
            Assert.IsFalse(iReader.MoveNext());
        }
Пример #13
0
        public void EmptySourcePositionTest()
        {
            string source = "";

            iOrigin = CreateOriginTest(source);
            iReader = iOrigin.GetReader();

            OriginPosition pos = iReader.CurrentLocation.GetOriginPosition();

            Assert.IsTrue((pos.LineNumber == 1) && (pos.CharNumber == 0));

            Assert.IsFalse(iReader.MoveNext());
            pos = iReader.CurrentLocation.GetOriginPosition();
            Assert.IsTrue((pos.LineNumber == 1) && (pos.CharNumber == 0));
        }
Пример #14
0
        public void ReadSourceWithEmptyLinesTest()
        {
            string source = "I \n\nlike reading \nsources!\n\n\nEspecially\nin\n tests.";

            iOrigin = CreateOriginTest(source);
            iReader = iOrigin.GetReader();

            StringBuilder readString = new StringBuilder();

            while (iReader.MoveNext())
            {
                readString.Append(iReader.CurrentCharacter);
            }
            Assert.AreEqual(source, readString.ToString());
        }
Пример #15
0
        public void ReadTheWholeSourceTest()
        {
            string source = "I like reading sources!\nEspecially in tests.";

            iOrigin = CreateOriginTest(source);
            iReader = iOrigin.GetReader();

            StringBuilder readString = new StringBuilder();

            while (iReader.MoveNext())
            {
                readString.Append(iReader.CurrentCharacter);
            }
            Assert.AreEqual(source, readString.ToString());
        }
Пример #16
0
        public void OneLineEndPositionTest()
        {
            string source = "1234";

            iOrigin = CreateOriginTest(source);
            iReader = iOrigin.GetReader();

            while (iReader.MoveNext())
            {
                ;
            }

            OriginPosition pos = iReader.CurrentLocation.GetOriginPosition();

            Assert.IsTrue((pos.LineNumber == 1) && (pos.CharNumber == 4));
        }
Пример #17
0
        public void GetLocationOriginTest()
        {
            string source = "XyZ";

            iOrigin = CreateOriginTest(source);
            iReader = iOrigin.GetReader();

            iReader.MoveNext(); // point to first character
            ILocation loc1 = iReader.CurrentLocation;

            iReader.MoveNext();
            ILocation loc2 = iReader.CurrentLocation;

            Assert.AreSame(loc1.Origin, iOrigin);
            Assert.AreSame(loc2.Origin, iOrigin);
        }
Пример #18
0
        public void EmptySourceFragmentTextTest()
        {
            string source = "";

            iOrigin = CreateOriginTest(source);
            iReader = iOrigin.GetReader();

            ILocation loc1 = iReader.CurrentLocation;

            iReader.MoveNext();
            ILocation loc2 = iReader.CurrentLocation;

            IFragment fr = iOrigin.MakeFragment(loc1, loc2);

            Assert.AreEqual(fr.GetOriginText(), "");
        }
Пример #19
0
        public void FalseMoveNextDoesntAffectLocationTest()
        {
            string source = "XXX";

            iOrigin = CreateOriginTest(source);
            iReader = iOrigin.GetReader();

            while (iReader.MoveNext())
            {
                ;                        // move to the end of the origin
            }
            ILocation endLocation = iReader.CurrentLocation;

            iReader.MoveNext();
            iReader.MoveNext();
            Assert.AreEqual(endLocation, iReader.CurrentLocation);
        }
Пример #20
0
        public void WholeSourceFragmentTextTest()
        {
            string source = "I like reading sources!\nEspecially in tests.";

            iOrigin = CreateOriginTest(source);
            iReader = iOrigin.GetReader();

            ILocation locBeg = iReader.CurrentLocation;

            while (iReader.MoveNext())
            {
                ;                        // move to the end of source
            }
            ILocation locEnd = iReader.CurrentLocation;

            IFragment frAll = iOrigin.MakeFragment(locBeg, locEnd);

            Assert.AreEqual(frAll.GetOriginText(), source);
        }