Beispiel #1
0
        public void CreateInstance_TokensEmpty_IsAtEnd()
        {
            // Arrange

            // Act
            var target = new FragmentTokenSource(new FragmentToken[0]);

            // Assert
            Assert.IsTrue(target.IsEnd);
        }
Beispiel #2
0
        public void CreateInstance_TokensNotEmpty_IsNotAtEnd()
        {
            // Arrange

            // Act
            var target = new FragmentTokenSource(new[] { FragmentTokenSourceTests.CreateFragmentToken("E") });

            // Assert
            Assert.IsFalse(target.IsEnd);
        }
Beispiel #3
0
        public void CreateInstance_TokensNotEmpty_TokenThrows()
        {
            // Arrange
            var tokens = new[] { FragmentTokenSourceTests.CreateFragmentToken("A"), FragmentTokenSourceTests.CreateFragmentToken("B") };
            var target = new FragmentTokenSource(tokens);

            // Act
            var t = target.Token;

            // Assert
        }
Beispiel #4
0
        public void MoveNext_FirstCall_IsEndIsFalse()
        {
            // Arrange
            var tokens = new[] { FragmentTokenSourceTests.CreateFragmentToken("A"), FragmentTokenSourceTests.CreateFragmentToken("B") };
            var target = new FragmentTokenSource(tokens);

            // Act
            target.MoveNext();

            // Assert
            Assert.IsFalse(target.IsEnd);
        }
Beispiel #5
0
        public void MoveNext_FirstCall_TokenIsFirstToken()
        {
            // Arrange
            var tokens = new[] { FragmentTokenSourceTests.CreateFragmentToken("A"), FragmentTokenSourceTests.CreateFragmentToken("B") };
            var target = new FragmentTokenSource(tokens);

            // Act
            target.MoveNext();

            // Assert
            Assert.AreEqual(tokens[0], target.Token);
        }
Beispiel #6
0
        public void CreateInstance_LookAhead_ContainsAllTokens()
        {
            // Arrange
            var tokens = new[] { FragmentTokenSourceTests.CreateFragmentToken("A"), FragmentTokenSourceTests.CreateFragmentToken("B") };
            var target = new FragmentTokenSource(tokens);

            // Act
            var lookAhead = target.LookAhead.ToArray();

            // Assert
            Assert.IsTrue(tokens.SequenceEqual(lookAhead));
        }
Beispiel #7
0
        public void MoveNext_FirstCall_LookAheadSkipsFirstToken()
        {
            // Arrange
            var tokens = new[] { FragmentTokenSourceTests.CreateFragmentToken("A"), FragmentTokenSourceTests.CreateFragmentToken("B") };
            var target = new FragmentTokenSource(tokens);

            // Act
            target.MoveNext();
            var lookAhead = target.LookAhead.ToArray();

            // Assert
            Assert.IsTrue(tokens.Skip(1).SequenceEqual(lookAhead));
        }
Beispiel #8
0
        public void FragmentTokenSource_IntegrationTest_BehavesAsExpected()
        {
            // Arrange
            var tokens = new[]
            {
                FragmentTokenSourceTests.CreateFragmentToken("A"),
                FragmentTokenSourceTests.CreateFragmentToken("B"),
                FragmentTokenSourceTests.CreateFragmentToken("C"),
                FragmentTokenSourceTests.CreateFragmentToken("D")
            };
            var target = new FragmentTokenSource(tokens);

            // Integration
            Assert.IsFalse(target.IsEnd);
            Assert.AreEqual(tokens.Length, target.LookAhead.Count());

            Assert.IsTrue(target.MoveNext());
            Assert.IsFalse(target.IsEnd);
            Assert.AreEqual(tokens[0], target.Token);
            Assert.AreEqual(tokens.Length - 1, target.LookAhead.Count());

            Assert.IsTrue(target.MoveNext());
            Assert.IsFalse(target.IsEnd);
            Assert.AreEqual(tokens[1], target.Token);
            Assert.AreEqual(tokens.Length - 2, target.LookAhead.Count());

            Assert.IsTrue(target.MoveNext());
            Assert.IsFalse(target.IsEnd);
            Assert.AreEqual(tokens[2], target.Token);
            Assert.AreEqual(tokens.Length - 3, target.LookAhead.Count());

            Assert.IsTrue(target.MoveNext());
            Assert.IsFalse(target.IsEnd);
            Assert.AreEqual(tokens[3], target.Token);
            Assert.AreEqual(tokens.Length - 4, target.LookAhead.Count());

            Assert.IsFalse(target.MoveNext());
            Assert.IsTrue(target.IsEnd);
        }