示例#1
0
		public void TestMatching()
		{
			Parser parser = new Parser(new ReportSettings());
			MockMatcher mockmatcher = new MockMatcher(null);

			string source = GetCodeFile();
			parser.Matchers.Clear();
			parser.Matchers.Add(mockmatcher);
			
			mockmatcher.InsertPointReturnValue = -1;
			string result = parser.ParseString(source);

			Assert.IsTrue(mockmatcher.InsertPointCalled);
			Assert.IsFalse(mockmatcher.MatchCalled);
			Assert.AreEqual(result, source);
			
			mockmatcher.InsertPointReturnValue = -2;
			mockmatcher.InsertPointCalled = false;

			result = parser.ParseString(source);

			Assert.IsTrue(mockmatcher.InsertPointCalled);
			Assert.IsTrue(mockmatcher.MatchCalled);
			Assert.AreEqual("foofoo", result);
		}
示例#2
0
        public void ShouldNotMatchWhenTheImplementationReturnsNull()
        {
            var tokenizer = new Mock <ITokenizableStreamBase <object> >();

            var mockMatcher = new MockMatcher(null);

            Assert.IsFalse(mockMatcher.IsMatch(tokenizer.Object));
        }
示例#3
0
        public void ShouldMatchWhenTheMatcherImplementationReturnsAToken()
        {
            var tokenizer = new Mock <ITokenizableStreamBase <object> >();

            var mockMatcher = new MockMatcher(new Token <object>(TokenType.Word));

            Assert.IsTrue(mockMatcher.IsMatch(tokenizer.Object));
        }
示例#4
0
        public void ShouldReturnNullWhenTheImplementationReturnsNull()
        {
            var tokenizer = new Mock <ITokenizableStreamBase <object> >();

            var mockMatcher = new MockMatcher(null);

            Assert.IsNull(mockMatcher.GetToken(tokenizer.Object));
            Assert.AreEqual(1, mockMatcher.ImplementationCalls);
        }
示例#5
0
        public void ShouldCallTakeSnapshotWhenTestingForAMatch()
        {
            var tokenizer = new Mock <ITokenizableStreamBase <object> >();

            var mockMatcher = new MockMatcher(null);

            mockMatcher.IsMatch(tokenizer.Object);

            tokenizer.Verify(t => t.TakeSnapshot(), Times.Once);
        }
示例#6
0
        public void ShouldCallGetTokenImplementationWhenTestingForAMatch()
        {
            var tokenizer = new Mock <ITokenizableStreamBase <object> >();

            var mockMatcher = new MockMatcher(null);

            mockMatcher.IsMatch(tokenizer.Object);

            Assert.AreEqual(1, mockMatcher.ImplementationCalls);
        }
示例#7
0
        public void ShouldReturnATokenWhenTheImplementationReturnsAToken()
        {
            var tokenizer = new Mock <ITokenizableStreamBase <object> >();

            var token       = new Token <object>(TokenType.Word);
            var mockMatcher = new MockMatcher(token);

            Assert.AreEqual(token, mockMatcher.GetToken(tokenizer.Object));
            Assert.AreEqual(1, mockMatcher.ImplementationCalls);
        }
示例#8
0
        public void ShouldNotCallCommitSnapshotWhenTestingForAMatch()
        {
            var tokenizer = new Mock <ITokenizableStreamBase <object> >();

            var mockMatcher = new MockMatcher(null);

            mockMatcher.IsMatch(tokenizer.Object);

            tokenizer.Verify(t => t.CommitSnapshot(), Times.Never);
        }
示例#9
0
        public void ShouldCallRollbackSnapshotWhenTheImplementationReturnsNull()
        {
            var tokenizer = new Mock <ITokenizableStreamBase <object> >();

            var mockMatcher = new MockMatcher(null);

            mockMatcher.GetToken(tokenizer.Object);

            tokenizer.Verify(t => t.RollbackSnapshot(), Times.Once);
            tokenizer.Verify(t => t.CommitSnapshot(), Times.Never);
        }
示例#10
0
        public void ShouldMatchWhenTheTokenizerHasPassedTheLastItem()
        {
            var tokenizer = new Mock <ITokenizableStreamBase <object> >();

            tokenizer.Setup(t => t.IsAtEnd()).Returns(true);

            var mockMatcher = new MockMatcher(null);

            var isMatch = mockMatcher.IsMatch(tokenizer.Object);

            Assert.IsTrue(isMatch);
            tokenizer.Verify(t => t.IsAtEnd(), Times.Once);
            Assert.AreEqual(0, mockMatcher.ImplementationCalls);
        }
示例#11
0
        public void ShouldReturnNullWhenTheTokenizerHasConsumedTheLastItem()
        {
            var tokenizer = new Mock <ITokenizableStreamBase <object> >();

            tokenizer.Setup(t => t.IsAtEnd()).Returns(true);

            var mockMatcher = new MockMatcher(null);

            var token = mockMatcher.GetToken(tokenizer.Object);

            Assert.IsNull(token);
            tokenizer.Verify(t => t.IsAtEnd(), Times.Once);
            Assert.AreEqual(0, mockMatcher.ImplementationCalls);
        }
示例#12
0
 public void SetUp()
 {
     arg           = new NamedObject("arg");
     stringMatcher = new MockMatcher();
     matcher       = new ToStringMatcher(stringMatcher);
 }