Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use json-specs/sql_token_examples.json test input #1852

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions test/Elastic.Apm.Tests/DbSpanNameTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Elastic.Apm.Libraries.Newtonsoft.Json;
using Elastic.Apm.Libraries.Newtonsoft.Json.Linq;
using Elastic.Apm.Model;
using Elastic.Apm.Tests.Utilities;
using FluentAssertions;
using Xunit;

Expand Down Expand Up @@ -51,4 +52,44 @@ public static IEnumerable<object[]> SqlSignatureExamplesTestData
}
}
}

public class SqlTokenTestData
{
public string Name;
public string Comment;
public string Input;
public List<SqlToken> Tokens = new();
}

public struct SqlToken
{
public string Kind;
public string Text;
}

[Theory]
[JsonFileData("./TestResources/json-specs/sql_token_examples.json", typeof(SqlTokenTestData))]
public void TestSqlTokenParsing(SqlTokenTestData data)
{
var parsedTokens = Helper_ParseSql(data.Input);
parsedTokens.Count.Should().Be(data.Tokens.Count);
for (var i = 0; i < parsedTokens.Count; i++)
parsedTokens[i].ToString().Should().BeEquivalentTo(data.Tokens[i].Kind);
}

private static List<Scanner.Token> Helper_ParseSql(string sql)
{
var scanner = new Scanner();
scanner.SetQuery(sql);
var tokens = new List<Scanner.Token>();
while (true)
{
var token = scanner.Scan();
if (token == Scanner.Token.Eof)
break;
tokens.Add(token);
}

return tokens;
}
}