static T TestParse <T>(string source, ICfgNode expected, TokenListParser <ScriptToken, T> parser) where T : ICfgNode { var tokens = ScriptTokenizer.Tokenize(source); if (!tokens.HasValue) { throw new InvalidOperationException( $"Tokenization failure: {tokens.ErrorMessage} at {tokens.ErrorPosition}"); } var filtered = ScriptParser.FilterTokens(tokens.Value); var parsed = parser.TryParse(filtered); if (!parsed.HasValue) { throw new InvalidOperationException($"Parse failure: {parsed}"); } Assert.Equal(expected, parsed.Value); return(parsed.Value); }