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 e5cb1ad
Showing 1 changed file with 67 additions and 2 deletions.
69 changes: 67 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,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);
}
}

0 comments on commit e5cb1ad

Please sign in to comment.