Esempio n. 1
0
        public void ShouldReturnNullWhenAtTheEndOfTheTokenizer()
        {
            var stringTokenizer  = new StringTokenizer(string.Empty);
            var mockMatchKeyword = new MockMatchKeyword(TokenType.Word, "key");

            var token = mockMatchKeyword.CallImplementation(stringTokenizer);

            Assert.IsNull(token);
        }
Esempio n. 2
0
        public void ShouldSetTheValueOfTheToken()
        {
            var stringTokenizer  = new StringTokenizer("key");
            var mockMatchKeyword = new MockMatchKeyword(TokenType.Word, "key");

            var token = mockMatchKeyword.CallImplementation(stringTokenizer);

            Assert.AreEqual("key", token.TokenValue);
        }
Esempio n. 3
0
        public void ShouldReturnNullWhenTheKeywordIsNotFound()
        {
            var stringTokenizer  = new StringTokenizer("kee");
            var mockMatchKeyword = new MockMatchKeyword(TokenType.Word, "key");

            var token = mockMatchKeyword.CallImplementation(stringTokenizer);

            Assert.IsNull(token);
        }
Esempio n. 4
0
        public void ShouldMatchAWordAtTheEndOfTheTokenizerWhenAllowAsSubstringIsFalse()
        {
            var stringTokenizer = new StringTokenizer("key");

            var mockMatchKeyword = new MockMatchKeyword(TokenType.Word, "key");

            mockMatchKeyword.AllowAsSubString = false;

            var token = mockMatchKeyword.CallImplementation(stringTokenizer);

            Assert.IsNotNull(token);
        }
Esempio n. 5
0
        public void ShouldMatchASubstringWhenAllowAsSubstringIsTrue()
        {
            var stringTokenizer = new StringTokenizer("keyword");

            var mockMatchKeyword = new MockMatchKeyword(TokenType.Word, "key");

            mockMatchKeyword.AllowAsSubString = true;

            var token = mockMatchKeyword.CallImplementation(stringTokenizer);

            Assert.IsNotNull(token);
        }
Esempio n. 6
0
        public void ShouldCaptureCurrentTheLocation()
        {
            var stringTokenizer = new Mock <StringTokenizer>("key")
            {
                CallBase = true
            };

            var mockMatchKeyword = new MockMatchKeyword(TokenType.Word, "key");

            mockMatchKeyword.CallImplementation(stringTokenizer.Object);

            stringTokenizer.Verify(t => t.GetCurrentLocation(), Times.Once);
        }
Esempio n. 7
0
        public void ShouldMatchAWordTerminatedByASpecialCharacterWhenAllowAsSubstringIsFalse()
        {
            var stringTokenizer = new StringTokenizer("key, word");

            var mockMatchKeyword = new MockMatchKeyword(TokenType.Word, "key");

            mockMatchKeyword.AllowAsSubString  = false;
            mockMatchKeyword.SpecialCharacters = new List <MatchKeyword> {
                new MatchKeyword(TokenType.Word, ",")
            };

            var token = mockMatchKeyword.CallImplementation(stringTokenizer);

            Assert.IsNotNull(token);
        }
Esempio n. 8
0
        public void ShouldCreateATokenFromCurrentTheLoction()
        {
            var tokenLocation   = new Mock <ITokenLocation>(MockBehavior.Default);
            var stringTokenizer = new Mock <StringTokenizer>("key")
            {
                CallBase = true
            };

            stringTokenizer.Setup(t => t.GetCurrentLocation()).Returns(tokenLocation.Object);

            var mockMatchKeyword = new MockMatchKeyword(TokenType.Word, "key");

            mockMatchKeyword.CallImplementation(stringTokenizer.Object);

            tokenLocation.Verify(l => l.CreateToken(It.IsAny <TokenType>(), It.IsAny <string>()), Times.Once);
        }