Skip to content

Commit

Permalink
test: additional roundtrip tests for sarif
Browse files Browse the repository at this point in the history
  • Loading branch information
frabert committed Jul 25, 2024
1 parent d7f75a0 commit 858179c
Showing 1 changed file with 68 additions and 2 deletions.
70 changes: 68 additions & 2 deletions test/sarif/definitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <gap/sarif/definitions.hpp>

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,
Expand Down Expand Up @@ -73,6 +73,72 @@ 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") {
using namespace nlohmann::literals;

Check failure on line 80 in test/sarif/definitions.cpp

View workflow job for this annotation

GitHub Actions / build

‘literals’ is not a namespace-name
auto j = 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
}
]
}
]
})"_json;

root_struct root = j;

nlohmann::json j2 = root;

CHECK_EQ(j, j2);
}
}

0 comments on commit 858179c

Please sign in to comment.