void TestTokenPrinter(string expresion, TokenPrinter.FixType fixType, string expectedOutput) { var expr = Parser.ParseExpression(expresion); expr.Should().NotBeNull($"parsing '{expresion}' should succeed."); expr.Accept(new TokenPrinter(fixType)).Trim().Should().Be(expectedOutput.Trim(), $"output should match with {fixType}"); }
public static string Print(this IToken token, TokenPrinter.FixType fixType = TokenPrinter.DefaultFixType) => token.Accept(new TokenPrinter(fixType));
public static void CompareParseTree(string input, string expectedParseString = null, TokenPrinter.FixType fixType = TokenPrinter.FixType.Postfix) { IToken rawToken = null; try { rawToken = Parser.ParseExpression(input); } catch (ParseException) { if (string.IsNullOrWhiteSpace(expectedParseString)) { return; } } // If expectedTokenStr is null, then we expect the parse to fail. // No need to check anything else after that if (string.IsNullOrWhiteSpace(expectedParseString)) { rawToken.Should().BeNull(); return; } rawToken.Should().NotBeNull("the token should parse correctly"); var parseText = rawToken.Print(fixType).Trim(); parseText.Should().BeEquivalentTo(expectedParseString.Trim()); }