public void PatternParser_ParseInvalidPattern_ThrowsException(string pattern, int errorPosition, TokenType errorToken) { // arrange var parser = new NumberPatternParser(); // act var exception = Assert.ThrowsException <NumberPatternParseException>(() => parser.Parse(pattern)); // assert Assert.AreEqual(errorPosition, exception.Position); Assert.AreEqual(errorToken, exception.TokenType); }
public void PatternParser_SimpleParse_ReturnTags(string pattern, string tags) { // arrange var parser = new NumberPatternParser(); var expected = tags.Split(","); // act var result = parser.Parse(pattern); // assert CollectionAssert.AreEqual(expected, result.Tokens.OfType <TagToken>().Select(x => x.Name).ToArray()); }
public void PatternParser_Parse_ReturnTokens_1() { // arrange var parser = new NumberPatternParser(); // act var result = parser.Parse("P-{Company}-{Number:5}/{Year:4}"); // assert Assert.AreEqual(6, result.Tokens.Count); AssertTextToken(result.Tokens[0], "P-"); AssertTagToken(result.Tokens[1], "Company", new string[0]); AssertTextToken(result.Tokens[2], "-"); AssertTagToken(result.Tokens[3], "Number", new[] { "5" }); AssertTextToken(result.Tokens[4], "/"); AssertTagToken(result.Tokens[5], "Year", new[] { "4" }); }