Exemplo n.º 1
0
        public void CreateInstance_TokensNotEmpty_IsNotAtEnd()
        {
            // Arrange

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

            // Assert
            Assert.IsFalse(target.IsEnd);
        }
Exemplo n.º 2
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
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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));
        }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
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);
        }