@@ -12,7 +12,7 @@ static auto transformer_callback_error(const sourcemeta::core::Pointer &,
1212 throw std::runtime_error (" The transform callback must not be called" );
1313}
1414
15- TEST (Linter, valid_examples_error_message ) {
15+ TEST (Linter, valid_examples_error_message_without_id_nested ) {
1616 sourcemeta::core::SchemaTransformer bundle;
1717 bundle.add <sourcemeta::blaze::ValidExamples>(
1818 sourcemeta::blaze::default_schema_compiler);
@@ -55,6 +55,127 @@ TEST(Linter, valid_examples_error_message) {
5555)TXT" );
5656}
5757
58+ TEST (Linter, valid_examples_error_message_without_id_flat) {
59+ sourcemeta::core::SchemaTransformer bundle;
60+ bundle.add <sourcemeta::blaze::ValidExamples>(
61+ sourcemeta::blaze::default_schema_compiler);
62+
63+ const auto schema{sourcemeta::core::parse_json (R"JSON( {
64+ "$schema": "https://json-schema.org/draft/2020-12/schema",
65+ "examples": [ 1 ],
66+ "type": "string"
67+ })JSON" )};
68+
69+ std::vector<std::tuple<sourcemeta::core::Pointer, std::string, std::string,
70+ std::string>>
71+ entries;
72+ const bool result =
73+ bundle.check (schema, sourcemeta::core::schema_official_walker,
74+ sourcemeta::core::schema_official_resolver,
75+ [&entries](const auto &pointer, const auto &name,
76+ const auto &message, const auto &description) {
77+ entries.emplace_back (pointer, name, message, description);
78+ });
79+
80+ EXPECT_FALSE (result);
81+ EXPECT_EQ (entries.size (), 1 );
82+
83+ EXPECT_EQ (std::get<0 >(entries.at (0 )), sourcemeta::core::Pointer ({}));
84+ EXPECT_EQ (std::get<1 >(entries.at (0 )), " blaze/valid_examples" );
85+ EXPECT_EQ (std::get<2 >(entries.at (0 )),
86+ " Only include instances in the `examples` array that validate "
87+ " against the schema" );
88+ EXPECT_EQ (std::get<3 >(entries.at (0 )),
89+ R"TXT( Invalid example instance at index 0
90+ The value was expected to be of type string but it was of type integer
91+ at instance location ""
92+ at evaluate path "/type"
93+ )TXT" );
94+ }
95+
96+ TEST (Linter, valid_examples_error_message_with_id_nested) {
97+ sourcemeta::core::SchemaTransformer bundle;
98+ bundle.add <sourcemeta::blaze::ValidExamples>(
99+ sourcemeta::blaze::default_schema_compiler);
100+
101+ const auto schema{sourcemeta::core::parse_json (R"JSON( {
102+ "$schema": "https://json-schema.org/draft/2020-12/schema",
103+ "$id": "https://example.com",
104+ "properties": {
105+ "foo": {
106+ "examples": [ 1 ],
107+ "type": "string"
108+ }
109+ }
110+ })JSON" )};
111+
112+ std::vector<std::tuple<sourcemeta::core::Pointer, std::string, std::string,
113+ std::string>>
114+ entries;
115+ const bool result =
116+ bundle.check (schema, sourcemeta::core::schema_official_walker,
117+ sourcemeta::core::schema_official_resolver,
118+ [&entries](const auto &pointer, const auto &name,
119+ const auto &message, const auto &description) {
120+ entries.emplace_back (pointer, name, message, description);
121+ });
122+
123+ EXPECT_FALSE (result);
124+ EXPECT_EQ (entries.size (), 1 );
125+
126+ EXPECT_EQ (std::get<0 >(entries.at (0 )),
127+ sourcemeta::core::Pointer ({" properties" , " foo" }));
128+ EXPECT_EQ (std::get<1 >(entries.at (0 )), " blaze/valid_examples" );
129+ EXPECT_EQ (std::get<2 >(entries.at (0 )),
130+ " Only include instances in the `examples` array that validate "
131+ " against the schema" );
132+ EXPECT_EQ (std::get<3 >(entries.at (0 )),
133+ R"TXT( Invalid example instance at index 0
134+ The value was expected to be of type string but it was of type integer
135+ at instance location ""
136+ at evaluate path "/type"
137+ )TXT" );
138+ }
139+
140+ TEST (Linter, valid_examples_error_message_with_id_flat) {
141+ sourcemeta::core::SchemaTransformer bundle;
142+ bundle.add <sourcemeta::blaze::ValidExamples>(
143+ sourcemeta::blaze::default_schema_compiler);
144+
145+ const auto schema{sourcemeta::core::parse_json (R"JSON( {
146+ "$schema": "https://json-schema.org/draft/2020-12/schema",
147+ "$id": "https://example.com",
148+ "examples": [ 1 ],
149+ "type": "string"
150+ })JSON" )};
151+
152+ std::vector<std::tuple<sourcemeta::core::Pointer, std::string, std::string,
153+ std::string>>
154+ entries;
155+ const bool result =
156+ bundle.check (schema, sourcemeta::core::schema_official_walker,
157+ sourcemeta::core::schema_official_resolver,
158+ [&entries](const auto &pointer, const auto &name,
159+ const auto &message, const auto &description) {
160+ entries.emplace_back (pointer, name, message, description);
161+ });
162+
163+ EXPECT_FALSE (result);
164+ EXPECT_EQ (entries.size (), 1 );
165+
166+ EXPECT_EQ (std::get<0 >(entries.at (0 )), sourcemeta::core::Pointer ({}));
167+ EXPECT_EQ (std::get<1 >(entries.at (0 )), " blaze/valid_examples" );
168+ EXPECT_EQ (std::get<2 >(entries.at (0 )),
169+ " Only include instances in the `examples` array that validate "
170+ " against the schema" );
171+ EXPECT_EQ (std::get<3 >(entries.at (0 )),
172+ R"TXT( Invalid example instance at index 0
173+ The value was expected to be of type string but it was of type integer
174+ at instance location ""
175+ at evaluate path "/type"
176+ )TXT" );
177+ }
178+
58179TEST (Linter, valid_examples_1) {
59180 sourcemeta::core::SchemaTransformer bundle;
60181 bundle.add <sourcemeta::blaze::ValidExamples>(
0 commit comments