From e5cb1ad13a706e3d1f0c5d2a7bc7fc20f84fc434 Mon Sep 17 00:00:00 2001 From: Francesco Bertolaccini Date: Thu, 25 Jul 2024 17:42:22 +0200 Subject: [PATCH] test: additional roundtrip tests for sarif --- test/sarif/definitions.cpp | 69 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/test/sarif/definitions.cpp b/test/sarif/definitions.cpp index 43122e6..cb351ad 100644 --- a/test/sarif/definitions.cpp +++ b/test/sarif/definitions.cpp @@ -4,7 +4,7 @@ #include namespace gap::sarif::definitions { - TEST_CASE("Roundtrip") { + TEST_CASE("Struct to JSON roundtrip") { // Sample SARIF output from https://github.com/microsoft/sarif-tutorials/blob/main/docs/1-Introduction.md root_struct root{ .version = version_enum::k2_1_0, @@ -73,6 +73,71 @@ namespace gap::sarif::definitions { root_struct deser = root; nlohmann::json deser_json = deser; - CHECK(root_json == deser_json); + CHECK_EQ(root_json, deser_json); + } + + TEST_CASE("JSON to struct roundtrip") { + auto j = nlohmann::json::parse(R"({ + "version": "2.1.0", + "runs": [ + { + "tool": { + "driver": { + "name": "ESLint", + "informationUri": "https://eslint.org", + "rules": [ + { + "id": "no-unused-vars", + "shortDescription": { + "text": "disallow unused variables" + }, + "helpUri": "https://eslint.org/docs/rules/no-unused-vars", + "properties": { + "category": "Variables" + } + } + ] + } + }, + "artifacts": [ + { + "location": { + "uri": "file:///C:/dev/sarif/sarif-tutorials/samples/Introduction/simple-example.js" + } + } + ], + "results": [ + { + "level": "error", + "message": { + "text": "'x' is assigned a value but never used." + }, + "locations": [ + { + "physicalLocation": { + "artifactLocation": { + "uri": "file:///C:/dev/sarif/sarif-tutorials/samples/Introduction/simple-example.js", + "index": 0 + }, + "region": { + "startLine": 1, + "startColumn": 5 + } + } + } + ], + "ruleId": "no-unused-vars", + "ruleIndex": 0 + } + ] + } + ] +})"); + + root_struct root = j; + + nlohmann::json j2 = root; + + CHECK_EQ(j, j2); } } \ No newline at end of file