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); }
public void ShouldNotMatchWhenTheImplementationReturnsNull() { var tokenizer = new Mock <ITokenizableStreamBase <object> >(); var mockMatcher = new MockMatcher(null); Assert.IsFalse(mockMatcher.IsMatch(tokenizer.Object)); }
public void ShouldMatchWhenTheMatcherImplementationReturnsAToken() { var tokenizer = new Mock <ITokenizableStreamBase <object> >(); var mockMatcher = new MockMatcher(new Token <object>(TokenType.Word)); Assert.IsTrue(mockMatcher.IsMatch(tokenizer.Object)); }
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); }
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); }
public void ShouldCallGetTokenImplementationWhenTestingForAMatch() { var tokenizer = new Mock <ITokenizableStreamBase <object> >(); var mockMatcher = new MockMatcher(null); mockMatcher.IsMatch(tokenizer.Object); Assert.AreEqual(1, mockMatcher.ImplementationCalls); }
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); }
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); }
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); }
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); }
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); }
public void SetUp() { arg = new NamedObject("arg"); stringMatcher = new MockMatcher(); matcher = new ToStringMatcher(stringMatcher); }