diff --git a/src/command_compile.cc b/src/command_compile.cc index 02099c4e..54f72431 100644 --- a/src/command_compile.cc +++ b/src/command_compile.cc @@ -87,32 +87,41 @@ auto sourcemeta::jsonschema::compile(const sourcemeta::core::Options &options) sourcemeta::core::stringify(template_json, json_stream); const auto json_data{std::move(json_stream).str()}; - constexpr auto BYTES_PER_LINE{16}; + constexpr auto BYTES_PER_LINE{12}; std::cout << "#ifndef SOURCEMETA_JSONSCHEMA_INCLUDE_" << name << "_H_\n"; std::cout << "#define SOURCEMETA_JSONSCHEMA_INCLUDE_" << name << "_H_\n"; std::cout << "\n"; std::cout << "#ifdef __cplusplus\n"; + std::cout << "#include \n"; std::cout << "#include \n"; std::cout << "#endif\n"; std::cout << "\n"; - std::cout << "static const char " << name << "_DATA[] ="; + std::cout << "static const char " << name << "_DATA[] = {"; for (std::size_t index = 0; index < json_data.size(); ++index) { if (index % BYTES_PER_LINE == 0) { - std::cout << "\n \""; + std::cout << "\n "; } - std::cout << "\\x" << std::hex << std::setw(2) << std::setfill('0') + std::cout << "0x" << std::hex << std::setw(2) << std::setfill('0') << (static_cast( static_cast(json_data[index]))); - if ((index + 1) % BYTES_PER_LINE == 0 || index + 1 == json_data.size()) { - std::cout << "\""; + std::cout << ","; + if ((index + 1) % BYTES_PER_LINE != 0) { + std::cout << " "; } } - std::cout << ";\n"; + if (json_data.size() % BYTES_PER_LINE != 0) { + std::cout << "0x00"; + } else { + std::cout << "\n 0x00"; + } + + std::cout << "\n};\n"; + std::cout << "\n"; std::cout << std::dec; std::cout << "static const unsigned int " << name << "_LENGTH = " << json_data.size() << ";\n"; diff --git a/test/ci/fail_bundle_http_non_schema.sh b/test/ci/fail_bundle_http_non_schema.sh index baa5ee23..7389df62 100755 --- a/test/ci/fail_bundle_http_non_schema.sh +++ b/test/ci/fail_bundle_http_non_schema.sh @@ -12,7 +12,7 @@ cat << 'EOF' > "$TMP/schema.json" "$schema": "http://json-schema.org/draft-07/schema#", "title": "Test", "description": "Test schema", - "allOf": [ { "$ref": "https://schemas.sourcemeta.com/self/api/schemas/stats/jsonschema/2020-12/schema" } ] + "allOf": [ { "$ref": "https://schemas.sourcemeta.com/self/v1/api/schemas/stats/jsonschema/2020-12/schema" } ] } EOF @@ -22,7 +22,7 @@ test "$CODE" = "1" || exit 1 cat << EOF > "$TMP/expected.txt" error: The JSON document is not a valid JSON Schema - at identifier https://schemas.sourcemeta.com/self/api/schemas/stats/jsonschema/2020-12/schema + at identifier https://schemas.sourcemeta.com/self/v1/api/schemas/stats/jsonschema/2020-12/schema at file path $(realpath "$TMP")/schema.json at location "/allOf/0/\$ref" EOF diff --git a/test/ci/fail_bundle_http_non_schema_verbose.sh b/test/ci/fail_bundle_http_non_schema_verbose.sh index 24ba4028..536a5334 100755 --- a/test/ci/fail_bundle_http_non_schema_verbose.sh +++ b/test/ci/fail_bundle_http_non_schema_verbose.sh @@ -12,7 +12,7 @@ cat << 'EOF' > "$TMP/schema.json" "$schema": "http://json-schema.org/draft-07/schema#", "title": "Test", "description": "Test schema", - "allOf": [ { "$ref": "https://schemas.sourcemeta.com/self/api/schemas/stats/jsonschema/2020-12/schema" } ] + "allOf": [ { "$ref": "https://schemas.sourcemeta.com/self/v1/api/schemas/stats/jsonschema/2020-12/schema" } ] } EOF @@ -21,9 +21,9 @@ EOF test "$CODE" = "1" || exit 1 cat << EOF > "$TMP/expected.txt" -Resolving over HTTP: https://schemas.sourcemeta.com/self/api/schemas/stats/jsonschema/2020-12/schema +Resolving over HTTP: https://schemas.sourcemeta.com/self/v1/api/schemas/stats/jsonschema/2020-12/schema error: The JSON document is not a valid JSON Schema - at identifier https://schemas.sourcemeta.com/self/api/schemas/stats/jsonschema/2020-12/schema + at identifier https://schemas.sourcemeta.com/self/v1/api/schemas/stats/jsonschema/2020-12/schema at file path $(realpath "$TMP")/schema.json at location "/allOf/0/\$ref" EOF diff --git a/test/ci/fail_validate_http_non_schema.sh b/test/ci/fail_validate_http_non_schema.sh index a412bc71..6e116865 100755 --- a/test/ci/fail_validate_http_non_schema.sh +++ b/test/ci/fail_validate_http_non_schema.sh @@ -12,7 +12,7 @@ cat << 'EOF' > "$TMP/schema.json" "$schema": "http://json-schema.org/draft-07/schema#", "title": "Test", "description": "Test schema", - "allOf": [ { "$ref": "https://schemas.sourcemeta.com/self/api/schemas/stats/jsonschema/2020-12/schema" } ] + "allOf": [ { "$ref": "https://schemas.sourcemeta.com/self/v1/api/schemas/stats/jsonschema/2020-12/schema" } ] } EOF @@ -26,7 +26,7 @@ test "$CODE" = "1" || exit 1 cat << EOF > "$TMP/expected.txt" error: The JSON document is not a valid JSON Schema - at identifier https://schemas.sourcemeta.com/self/api/schemas/stats/jsonschema/2020-12/schema + at identifier https://schemas.sourcemeta.com/self/v1/api/schemas/stats/jsonschema/2020-12/schema at file path $(realpath "$TMP")/schema.json at location "/allOf/0/\$ref" EOF diff --git a/test/ci/fail_validate_http_non_schema_verbose.sh b/test/ci/fail_validate_http_non_schema_verbose.sh index 4af7ebdf..038450b6 100755 --- a/test/ci/fail_validate_http_non_schema_verbose.sh +++ b/test/ci/fail_validate_http_non_schema_verbose.sh @@ -12,7 +12,7 @@ cat << 'EOF' > "$TMP/schema.json" "$schema": "http://json-schema.org/draft-07/schema#", "title": "Test", "description": "Test schema", - "allOf": [ { "$ref": "https://schemas.sourcemeta.com/self/api/schemas/stats/jsonschema/2020-12/schema" } ] + "allOf": [ { "$ref": "https://schemas.sourcemeta.com/self/v1/api/schemas/stats/jsonschema/2020-12/schema" } ] } EOF @@ -25,9 +25,9 @@ EOF test "$CODE" = "1" || exit 1 cat << EOF > "$TMP/expected.txt" -Resolving over HTTP: https://schemas.sourcemeta.com/self/api/schemas/stats/jsonschema/2020-12/schema +Resolving over HTTP: https://schemas.sourcemeta.com/self/v1/api/schemas/stats/jsonschema/2020-12/schema error: The JSON document is not a valid JSON Schema - at identifier https://schemas.sourcemeta.com/self/api/schemas/stats/jsonschema/2020-12/schema + at identifier https://schemas.sourcemeta.com/self/v1/api/schemas/stats/jsonschema/2020-12/schema at file path $(realpath "$TMP")/schema.json at location "/allOf/0/\$ref" EOF diff --git a/test/compile/pass_include.sh b/test/compile/pass_include.sh index 2d5e548f..76b1c4ac 100755 --- a/test/compile/pass_include.sh +++ b/test/compile/pass_include.sh @@ -22,15 +22,20 @@ cat << 'EOF' > "$TMP/expected.h" #define SOURCEMETA_JSONSCHEMA_INCLUDE_TEST_SCHEMA_H_ #ifdef __cplusplus +#include #include #endif -static const char TEST_SCHEMA_DATA[] = - "\x5b\x66\x61\x6c\x73\x65\x2c\x74\x72\x75\x65\x2c\x5b\x22\x22\x2c" - "\x22\x68\x74\x74\x70\x73\x3a\x2f\x2f\x65\x78\x61\x6d\x70\x6c\x65" - "\x2e\x63\x6f\x6d\x22\x5d\x2c\x5b\x5b\x31\x31\x2c\x22\x2f\x74\x79" - "\x70\x65\x22\x2c\x22\x22\x2c\x22\x23\x2f\x74\x79\x70\x65\x22\x2c" - "\x32\x2c\x5b\x38\x2c\x34\x5d\x5d\x5d\x5d"; +static const char TEST_SCHEMA_DATA[] = { + 0x5b, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x74, 0x72, 0x75, 0x65, 0x2c, + 0x5b, 0x22, 0x22, 0x2c, 0x22, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, + 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, + 0x22, 0x5d, 0x2c, 0x5b, 0x5b, 0x31, 0x31, 0x2c, 0x22, 0x2f, 0x74, 0x79, + 0x70, 0x65, 0x22, 0x2c, 0x22, 0x22, 0x2c, 0x22, 0x23, 0x2f, 0x74, 0x79, + 0x70, 0x65, 0x22, 0x2c, 0x32, 0x2c, 0x5b, 0x38, 0x2c, 0x34, 0x5d, 0x5d, + 0x5d, 0x5d, 0x00 +}; + static const unsigned int TEST_SCHEMA_LENGTH = 74; #ifdef __cplusplus diff --git a/test/compile/pass_include_lowercase.sh b/test/compile/pass_include_lowercase.sh index 9fa6024f..e2b2e8a5 100755 --- a/test/compile/pass_include_lowercase.sh +++ b/test/compile/pass_include_lowercase.sh @@ -22,15 +22,20 @@ cat << 'EOF' > "$TMP/expected.h" #define SOURCEMETA_JSONSCHEMA_INCLUDE_TEST_SCHEMA_H_ #ifdef __cplusplus +#include #include #endif -static const char TEST_SCHEMA_DATA[] = - "\x5b\x66\x61\x6c\x73\x65\x2c\x74\x72\x75\x65\x2c\x5b\x22\x22\x2c" - "\x22\x68\x74\x74\x70\x73\x3a\x2f\x2f\x65\x78\x61\x6d\x70\x6c\x65" - "\x2e\x63\x6f\x6d\x22\x5d\x2c\x5b\x5b\x31\x31\x2c\x22\x2f\x74\x79" - "\x70\x65\x22\x2c\x22\x22\x2c\x22\x23\x2f\x74\x79\x70\x65\x22\x2c" - "\x32\x2c\x5b\x38\x2c\x34\x5d\x5d\x5d\x5d"; +static const char TEST_SCHEMA_DATA[] = { + 0x5b, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x74, 0x72, 0x75, 0x65, 0x2c, + 0x5b, 0x22, 0x22, 0x2c, 0x22, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, + 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, + 0x22, 0x5d, 0x2c, 0x5b, 0x5b, 0x31, 0x31, 0x2c, 0x22, 0x2f, 0x74, 0x79, + 0x70, 0x65, 0x22, 0x2c, 0x22, 0x22, 0x2c, 0x22, 0x23, 0x2f, 0x74, 0x79, + 0x70, 0x65, 0x22, 0x2c, 0x32, 0x2c, 0x5b, 0x38, 0x2c, 0x34, 0x5d, 0x5d, + 0x5d, 0x5d, 0x00 +}; + static const unsigned int TEST_SCHEMA_LENGTH = 74; #ifdef __cplusplus diff --git a/test/compile/pass_include_short.sh b/test/compile/pass_include_short.sh index 530dce14..617822c7 100755 --- a/test/compile/pass_include_short.sh +++ b/test/compile/pass_include_short.sh @@ -23,15 +23,20 @@ cat << 'EOF' > "$TMP/expected.h" #define SOURCEMETA_JSONSCHEMA_INCLUDE_TEST_SCHEMA_H_ #ifdef __cplusplus +#include #include #endif -static const char TEST_SCHEMA_DATA[] = - "\x5b\x66\x61\x6c\x73\x65\x2c\x74\x72\x75\x65\x2c\x5b\x22\x22\x2c" - "\x22\x68\x74\x74\x70\x73\x3a\x2f\x2f\x65\x78\x61\x6d\x70\x6c\x65" - "\x2e\x63\x6f\x6d\x22\x5d\x2c\x5b\x5b\x31\x31\x2c\x22\x2f\x74\x79" - "\x70\x65\x22\x2c\x22\x22\x2c\x22\x23\x2f\x74\x79\x70\x65\x22\x2c" - "\x32\x2c\x5b\x38\x2c\x34\x5d\x5d\x5d\x5d"; +static const char TEST_SCHEMA_DATA[] = { + 0x5b, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x74, 0x72, 0x75, 0x65, 0x2c, + 0x5b, 0x22, 0x22, 0x2c, 0x22, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, + 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, + 0x22, 0x5d, 0x2c, 0x5b, 0x5b, 0x31, 0x31, 0x2c, 0x22, 0x2f, 0x74, 0x79, + 0x70, 0x65, 0x22, 0x2c, 0x22, 0x22, 0x2c, 0x22, 0x23, 0x2f, 0x74, 0x79, + 0x70, 0x65, 0x22, 0x2c, 0x32, 0x2c, 0x5b, 0x38, 0x2c, 0x34, 0x5d, 0x5d, + 0x5d, 0x5d, 0x00 +}; + static const unsigned int TEST_SCHEMA_LENGTH = 74; #ifdef __cplusplus