Fixing grammar indentation to be consistent throughout file.

This commit is contained in:
Clint Herron 2024-06-21 23:00:31 -04:00
parent 3bdf7c3021
commit 5d15dc832e

View file

@ -428,10 +428,11 @@ static void test_quantifiers() {
static void test_failure_missing_root() { static void test_failure_missing_root() {
fprintf(stderr, "⚫ Testing missing root node:\n"); fprintf(stderr, "⚫ Testing missing root node:\n");
// Test case for a grammar that is missing a root rule // Test case for a grammar that is missing a root rule
const std::string grammar_str = R"""(rot ::= expr const std::string grammar_str = R"""(
expr ::= term ("+" term)* rot ::= expr
term ::= number expr ::= term ("+" term)*
number ::= [0-9]+)"""; term ::= number
number ::= [0-9]+)""";
grammar_parser::parse_state parsed_grammar = grammar_parser::parse(grammar_str.c_str()); grammar_parser::parse_state parsed_grammar = grammar_parser::parse(grammar_str.c_str());
@ -448,10 +449,10 @@ static void test_failure_missing_reference() {
// Test case for a grammar that is missing a referenced rule // Test case for a grammar that is missing a referenced rule
const std::string grammar_str = const std::string grammar_str =
R"""(root ::= expr R"""(root ::= expr
expr ::= term ("+" term)* expr ::= term ("+" term)*
term ::= numero term ::= numero
number ::= [0-9]+)"""; number ::= [0-9]+)""";
fprintf(stderr, " Expected error: "); fprintf(stderr, " Expected error: ");
@ -473,24 +474,24 @@ static void test_failure_left_recursion() {
// Test more complicated left recursion detection // Test more complicated left recursion detection
const std::string medium_str = R"""( const std::string medium_str = R"""(
root ::= asdf root ::= asdf
asdf ::= "a" | asdf "a" asdf ::= "a" | asdf "a"
)"""; )""";
assert(test_build_grammar_fails(medium_str)); assert(test_build_grammar_fails(medium_str));
// Test even more complicated left recursion detection // Test even more complicated left recursion detection
const std::string hard_str = R"""( const std::string hard_str = R"""(
root ::= asdf root ::= asdf
asdf ::= "a" | foo "b" asdf ::= "a" | foo "b"
foo ::= "c" | asdf "d" | "e")"""; foo ::= "c" | asdf "d" | "e")""";
assert(test_build_grammar_fails(hard_str)); assert(test_build_grammar_fails(hard_str));
// Test yet even more complicated left recursion detection // Test yet even more complicated left recursion detection
const std::string hardest_str = R"""( const std::string hardest_str = R"""(
root ::= asdf root ::= asdf
asdf ::= "a" | foo "b" asdf ::= "a" | foo "b"
foo ::= "c" | empty asdf "d" | "e" foo ::= "c" | empty asdf "d" | "e"
empty ::= "blah" | )"""; empty ::= "blah" | )""";
assert(test_build_grammar_fails(hardest_str)); assert(test_build_grammar_fails(hardest_str));
fprintf(stderr, " ✅︎ Passed\n"); fprintf(stderr, " ✅︎ Passed\n");
@ -505,7 +506,7 @@ static void test_json_schema() {
"empty schema (object)", "empty schema (object)",
// Schema // Schema
R"""( R"""(
{} {}
)""", )""",
// Passing strings // Passing strings
{ {
@ -526,14 +527,14 @@ static void test_json_schema() {
"exotic formats (list)", "exotic formats (list)",
// Schema // Schema
R"""( R"""(
{ {
"items": [ "items": [
{ "format": "date" }, { "format": "date" },
{ "format": "uuid" }, { "format": "uuid" },
{ "format": "time" }, { "format": "time" },
{ "format": "date-time" } { "format": "date-time" }
] ]
} }
)""", )""",
// Passing strings // Passing strings
{ {
@ -554,9 +555,9 @@ static void test_json_schema() {
"string", "string",
// Schema // Schema
R"""( R"""(
{ {
"type": "string" "type": "string"
} }
)""", )""",
// Passing strings // Passing strings
{ {
@ -575,10 +576,10 @@ static void test_json_schema() {
"string w/ min length 1", "string w/ min length 1",
// Schema // Schema
R"""( R"""(
{ {
"type": "string", "type": "string",
"minLength": 1 "minLength": 1
} }
)""", )""",
// Passing strings // Passing strings
{ {
@ -597,10 +598,10 @@ static void test_json_schema() {
"string w/ min length 3", "string w/ min length 3",
// Schema // Schema
R"""( R"""(
{ {
"type": "string", "type": "string",
"minLength": 3 "minLength": 3
} }
)""", )""",
// Passing strings // Passing strings
{ {
@ -620,10 +621,10 @@ static void test_json_schema() {
"string w/ max length", "string w/ max length",
// Schema // Schema
R"""( R"""(
{ {
"type": "string", "type": "string",
"maxLength": 3 "maxLength": 3
} }
)""", )""",
// Passing strings // Passing strings
{ {
@ -643,11 +644,11 @@ static void test_json_schema() {
"string w/ min & max length", "string w/ min & max length",
// Schema // Schema
R"""( R"""(
{ {
"type": "string", "type": "string",
"minLength": 1, "minLength": 1,
"maxLength": 4 "maxLength": 4
} }
)""", )""",
// Passing strings // Passing strings
{ {
@ -668,9 +669,9 @@ static void test_json_schema() {
"boolean", "boolean",
// Schema // Schema
R"""( R"""(
{ {
"type": "boolean" "type": "boolean"
} }
)""", )""",
// Passing strings // Passing strings
{ {
@ -690,9 +691,9 @@ static void test_json_schema() {
"integer", "integer",
// Schema // Schema
R"""( R"""(
{ {
"type": "integer" "type": "integer"
} }
)""", )""",
// Passing strings // Passing strings
{ {
@ -713,9 +714,9 @@ static void test_json_schema() {
"string const", "string const",
// Schema // Schema
R"""( R"""(
{ {
"const": "foo" "const": "foo"
} }
)""", )""",
// Passing strings // Passing strings
{ {
@ -732,9 +733,9 @@ static void test_json_schema() {
"non-string const", "non-string const",
// Schema // Schema
R"""( R"""(
{ {
"const": true "const": true
} }
)""", )""",
// Passing strings // Passing strings
{ {
@ -752,9 +753,9 @@ static void test_json_schema() {
"non-string const", "non-string const",
// Schema // Schema
R"""( R"""(
{ {
"enum": ["red", "amber", "green", null, 42, ["foo"]] "enum": ["red", "amber", "green", null, 42, ["foo"]]
} }
)""", )""",
// Passing strings // Passing strings
{ {
@ -777,13 +778,13 @@ static void test_json_schema() {
"min+max items", "min+max items",
// Schema // Schema
R"""( R"""(
{ {
"items": { "items": {
"type": ["number", "integer"] "type": ["number", "integer"]
}, },
"minItems": 3, "minItems": 3,
"maxItems": 5 "maxItems": 5
} }
)""", )""",
// Passing strings // Passing strings
{ {
@ -804,14 +805,14 @@ static void test_json_schema() {
"object properties", "object properties",
// Schema // Schema
R"""( R"""(
{ {
"type": "object", "type": "object",
"properties": { "properties": {
"number": { "type": "number" }, "number": { "type": "number" },
"street_name": { "type": "string" }, "street_name": { "type": "string" },
"street_type": { "enum": ["Street", "Avenue", "Boulevard"] } "street_type": { "enum": ["Street", "Avenue", "Boulevard"] }
} }
} }
)""", )""",
// Passing strings // Passing strings
{ {
@ -846,15 +847,15 @@ static void test_json_schema() {
"object properties, additionalProperties: true", "object properties, additionalProperties: true",
// Schema // Schema
R"""( R"""(
{ {
"type": "object", "type": "object",
"properties": { "properties": {
"number": { "type": "number" }, "number": { "type": "number" },
"street_name": { "type": "string" }, "street_name": { "type": "string" },
"street_type": { "enum": ["Street", "Avenue", "Boulevard"] } "street_type": { "enum": ["Street", "Avenue", "Boulevard"] }
}, },
"additionalProperties": true "additionalProperties": true
} }
)""", )""",
// Passing strings // Passing strings
{ {
@ -889,15 +890,15 @@ static void test_json_schema() {
"required + optional props each in original order", "required + optional props each in original order",
// Schema // Schema
R"""( R"""(
{ {
"type": "object", "type": "object",
"properties": { "properties": {
"number": { "type": "number" }, "number": { "type": "number" },
"street_name": { "type": "string" }, "street_name": { "type": "string" },
"street_type": { "enum": ["Street", "Avenue", "Boulevard"] } "street_type": { "enum": ["Street", "Avenue", "Boulevard"] }
}, },
"additionalProperties": false "additionalProperties": false
} }
)""", )""",
// Passing strings // Passing strings
{ {
@ -923,16 +924,16 @@ static void test_json_schema() {
"required + optional props each in original order", "required + optional props each in original order",
// Schema // Schema
R"""( R"""(
{ {
"properties": { "properties": {
"b": {"type": "string"}, "b": {"type": "string"},
"a": {"type": "string"}, "a": {"type": "string"},
"d": {"type": "string"}, "d": {"type": "string"},
"c": {"type": "string"} "c": {"type": "string"}
}, },
"required": ["a", "b"], "required": ["a", "b"],
"additionalProperties": false "additionalProperties": false
} }
)""", )""",
// Passing strings // Passing strings
{ {
@ -954,53 +955,53 @@ static void test_json_schema() {
"required props", "required props",
// Schema // Schema
R"""( R"""(
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/product.schema.json", "$id": "https://example.com/product.schema.json",
"title": "Product", "title": "Product",
"description": "A product from Acme's catalog", "description": "A product from Acme's catalog",
"type": "object", "type": "object",
"properties": { "properties": {
"productId": { "productId": {
"description": "The unique identifier for a product", "description": "The unique identifier for a product",
"type": "integer" "type": "integer"
}, },
"productName": { "productName": {
"description": "Name of the product", "description": "Name of the product",
"type": "string" "type": "string"
}, },
"price": { "price": {
"description": "The price of the product", "description": "The price of the product",
"type": "number", "type": "number",
"exclusiveMinimum": 0 "exclusiveMinimum": 0
}, },
"tags": { "tags": {
"description": "Tags for the product", "description": "Tags for the product",
"type": "array", "type": "array",
"items": { "items": {
"type": "string" "type": "string"
}, },
"minItems": 1, "minItems": 1,
"uniqueItems": true "uniqueItems": true
}, },
"dimensions": { "dimensions": {
"type": "object", "type": "object",
"properties": { "properties": {
"length": { "length": {
"type": "number" "type": "number"
}, },
"width": { "width": {
"type": "number" "type": "number"
}, },
"height": { "height": {
"type": "number" "type": "number"
} }
}, },
"required": [ "length", "width", "height" ] "required": [ "length", "width", "height" ]
} }
}, },
"required": [ "productId", "productName", "price" ] "required": [ "productId", "productName", "price" ]
} }
)""", )""",
// Passing strings // Passing strings
{ {