public void Parse_InputIsEmpty() { //Act var target = new TextTokenParser("{", "}"); var actual = target.Parse("").ToList(); //Assert actual.Should().BeEmpty(); }
public void Parse_StartDelimiterAtEndOfInput() { //Arrange var input = "Begin <"; var target = new TextTokenParser("<", ">"); var expected = new TextTokenInfo[] { new TextTokenInfo(TextTokenKind.Text, "Begin <", 0) }; //Act var actual = target.Parse(input).ToList(); //Assert actual.Should().ContainInOrder(expected); }
public void Parse_EndDelimiterWithNoStart() { //Arrange var input = "Begin first> End"; var target = new TextTokenParser("<", ">"); var expected = new TextTokenInfo[] { new TextTokenInfo(TextTokenKind.Text, input, 0) }; //Act var actual = target.Parse(input).ToList(); //Assert actual.Should().ContainInOrder(expected); }
public void Parse_NoDelimitedText() { //Arrange var input = "Some text"; var expected = new TextTokenInfo[] { new TextTokenInfo(TextTokenKind.Text, "Some text", 0) }; var target = new TextTokenParser("{", "}"); //Act var actual = target.Parse(input).ToList(); //Assert actual.Should().ContainInOrder(expected); }
public void Parse_DelimiterHasMultipleCharacters() { //Arrange var input = "Begin <!-- comment -->"; var target = new TextTokenParser("<!--", "-->"); var expected = new TextTokenInfo[] { new TextTokenInfo(TextTokenKind.Text, "Begin ", 0), new TextTokenInfo(TextTokenKind.DelimitedText, " comment ", 6) }; //Act var actual = target.Parse(input).ToList(); //Assert actual.Should().ContainInOrder(expected); }
public void Parse_DelimiterAtStart() { //Arrange var input = "<first> End"; var target = new TextTokenParser("<", ">"); var expected = new TextTokenInfo[] { new TextTokenInfo(TextTokenKind.DelimitedText, "first", 0), new TextTokenInfo(TextTokenKind.Text, " End", 7) }; //Act var actual = target.Parse(input).ToList(); //Assert actual.Should().ContainInOrder(expected); }
public void Parse_SpacesAtFront() { //Arrange var input = " Begin <target> End"; var target = new TextTokenParser("<", ">"); var expected = new TextTokenInfo[] { new TextTokenInfo(TextTokenKind.Text, " Begin ", 0), new TextTokenInfo(TextTokenKind.DelimitedText, "target", 10), new TextTokenInfo(TextTokenKind.Text, " End", 18) }; //Act var actual = target.Parse(input).ToList(); //Assert actual.Should().ContainInOrder(expected); }
public void Parse_TooManyEndDelimiters() { //Arrange var input = "Begin <4 > 5> End"; var target = new TextTokenParser("<", ">"); var expected = new TextTokenInfo[] { new TextTokenInfo(TextTokenKind.Text, "Begin ", 0), new TextTokenInfo(TextTokenKind.DelimitedText, "4 ", 6), new TextTokenInfo(TextTokenKind.Text, " 5> End", 10) }; //Act var actual = target.Parse(input).ToList(); //Assert actual.Should().ContainInOrder(expected); }
public void Parse_DelimitersSideBySide() { //Arrange var input = "Begin <first><second> End"; var target = new TextTokenParser("<", ">"); var expected = new TextTokenInfo[] { new TextTokenInfo(TextTokenKind.Text, "Begin ", 0), new TextTokenInfo(TextTokenKind.DelimitedText, "first", 6), new TextTokenInfo(TextTokenKind.DelimitedText, "second", 13), new TextTokenInfo(TextTokenKind.Text, " End", 21) }; //Act var actual = target.Parse(input).ToList(); //Assert actual.Should().ContainInOrder(expected); }
/// <summary>Processes the inputValue string and returns the string with the substitution rules applied.</summary> /// <param name="inputValue">The string to process.</param> /// <returns>The processed string.</returns> /// <remarks> /// If <paramref name="inputValue"/> is <see langword="null"/> or empty then an empty string is returned. /// </remarks> /// <example>Refer to <see cref="TextSubstitutionEngine"/> for an example.</example> public string Process(string inputValue) { if (String.IsNullOrWhiteSpace(inputValue)) { return(""); } var context = new TextSubstitutionProcessContext(m_options, inputValue); BeginProcess(context); //Enumerate the tokens var parser = new TextTokenParser(StartDelimiter, EndDelimiter); foreach (var tokenInfo in parser.Parse(inputValue)) { ProcessToken(context, tokenInfo); } ; return(EndProcess(context)); }