@@ -35,6 +35,87 @@ static auto test_resolver(std::string_view identifier)
3535 }
3636}
3737
38+ TEST (JSONSchema_vocabulary_2019_09, parse_vocabularies_with_vocabulary) {
39+ const sourcemeta::core::JSON document = sourcemeta::core::parse_json (R"JSON( {
40+ "$schema": "https://json-schema.org/draft/2019-09/schema",
41+ "$vocabulary": {
42+ "https://json-schema.org/draft/2019-09/vocab/core": true,
43+ "https://json-schema.org/draft/2019-09/vocab/applicator": true,
44+ "https://json-schema.org/draft/2019-09/vocab/validation": false
45+ }
46+ })JSON" );
47+
48+ const auto result{
49+ sourcemeta::core::parse_vocabularies (document, test_resolver)};
50+ EXPECT_TRUE (result.has_value ());
51+ EXPECT_EQ (result->size (), 3 );
52+ EXPECT_VOCABULARY_REQUIRED (*result, JSON_Schema_2019_09_Core);
53+ EXPECT_VOCABULARY_REQUIRED (*result, JSON_Schema_2019_09_Applicator);
54+ EXPECT_VOCABULARY_OPTIONAL (*result, JSON_Schema_2019_09_Validation);
55+ }
56+
57+ TEST (JSONSchema_vocabulary_2019_09, parse_vocabularies_without_vocabulary) {
58+ const sourcemeta::core::JSON document = sourcemeta::core::parse_json (R"JSON( {
59+ "$schema": "https://json-schema.org/draft/2019-09/schema",
60+ "type": "object"
61+ })JSON" );
62+
63+ const auto result{
64+ sourcemeta::core::parse_vocabularies (document, test_resolver)};
65+ EXPECT_FALSE (result.has_value ());
66+ }
67+
68+ TEST (JSONSchema_vocabulary_2019_09, parse_vocabularies_boolean_schema) {
69+ const sourcemeta::core::JSON document{true };
70+ const auto result{sourcemeta::core::parse_vocabularies (
71+ document, test_resolver, " https://json-schema.org/draft/2019-09/schema" )};
72+ EXPECT_FALSE (result.has_value ());
73+ }
74+
75+ TEST (JSONSchema_vocabulary_2019_09,
76+ parse_vocabularies_with_base_dialect_with_vocabulary) {
77+ const sourcemeta::core::JSON document = sourcemeta::core::parse_json (R"JSON( {
78+ "$vocabulary": {
79+ "https://json-schema.org/draft/2019-09/vocab/core": true,
80+ "https://json-schema.org/draft/2019-09/vocab/applicator": true
81+ }
82+ })JSON" );
83+
84+ const auto result{sourcemeta::core::parse_vocabularies (
85+ document, sourcemeta::core::SchemaBaseDialect::JSON_Schema_2019_09)};
86+ EXPECT_TRUE (result.has_value ());
87+ EXPECT_EQ (result->size (), 2 );
88+ EXPECT_VOCABULARY_REQUIRED (*result, JSON_Schema_2019_09_Core);
89+ EXPECT_VOCABULARY_REQUIRED (*result, JSON_Schema_2019_09_Applicator);
90+ }
91+
92+ TEST (JSONSchema_vocabulary_2019_09,
93+ parse_vocabularies_with_base_dialect_without_vocabulary) {
94+ const sourcemeta::core::JSON document = sourcemeta::core::parse_json (R"JSON( {
95+ "type": "object"
96+ })JSON" );
97+
98+ const auto result{sourcemeta::core::parse_vocabularies (
99+ document, sourcemeta::core::SchemaBaseDialect::JSON_Schema_2019_09)};
100+ EXPECT_FALSE (result.has_value ());
101+ }
102+
103+ TEST (JSONSchema_vocabulary_2019_09,
104+ parse_vocabularies_with_base_dialect_hyper) {
105+ const sourcemeta::core::JSON document = sourcemeta::core::parse_json (R"JSON( {
106+ "$vocabulary": {
107+ "https://json-schema.org/draft/2019-09/vocab/core": true
108+ }
109+ })JSON" );
110+
111+ const auto result{sourcemeta::core::parse_vocabularies (
112+ document,
113+ sourcemeta::core::SchemaBaseDialect::JSON_Schema_2019_09_Hyper)};
114+ EXPECT_TRUE (result.has_value ());
115+ EXPECT_EQ (result->size (), 1 );
116+ EXPECT_VOCABULARY_REQUIRED (*result, JSON_Schema_2019_09_Core);
117+ }
118+
38119TEST (JSONSchema_vocabulary_2019_09, no_vocabularies) {
39120 const sourcemeta::core::JSON document = sourcemeta::core::parse_json (R"JSON( {
40121 "$schema": "https://sourcemeta.com/2019-09-no-vocabularies"
0 commit comments