Esempio n. 1
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);
        }
Esempio n. 2
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));
        }
Esempio n. 3
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());
        }
Esempio n. 4
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");
        }
Esempio n. 5
0
 public Synchronizer(IOriginReader originReader, IDestinationWriter destinationWriter, IQueuingTaskManager taskManager, ILogger <Synchronizer>?logger)
 {
     _originReader      = originReader ?? throw new ArgumentNullException(nameof(originReader));
     _destinationWriter = destinationWriter ?? throw new ArgumentNullException(nameof(destinationWriter));
     _taskManager       = taskManager ?? throw new ArgumentNullException(nameof(taskManager));
     _logger            = logger;
 }
Esempio n. 6
0
        public void InitialReaderLocationTest()
        {
            string source = "";

            iOrigin = CreateOriginTest(source);
            iReader = iOrigin.GetReader();
            Assert.AreEqual(iOrigin.Begin, iReader.CurrentLocation);
        }
 private ISynchronizer Create(string name, IOriginReader originReader, IDestinationWriter destinationWriter, IQueuingTaskManager taskManager)
 => new TimedSynchronizer(
     new RobustSynchronizer(
         new TracingSynchronizer(
             new Synchronizer(originReader, destinationWriter, taskManager, _synchronizerLogger),
             _syncLogger,
             name)),
     _syncTimeHolderResolver.Resolve(name));
Esempio n. 8
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> >();
        }
Esempio n. 9
0
        public void EmptySourceTest()
        {
            string source = "";

            iOrigin = CreateOriginTest(source);
            iReader = iOrigin.GetReader();
            Assert.IsFalse(iReader.MoveNext());
        }
Esempio n. 10
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());
        }
Esempio n. 11
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);
        }
Esempio n. 12
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);
        }
Esempio n. 13
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);
        }
Esempio n. 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());
        }
Esempio n. 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());
        }
Esempio n. 16
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());
        }
Esempio n. 17
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));
        }
Esempio n. 18
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));
        }
Esempio n. 19
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(), "");
        }
Esempio n. 20
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);
        }
Esempio n. 21
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);
        }
Esempio n. 22
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);
        }