Skip to content

Commit b655f9e

Browse files
authored
Add const iterators to SchemaTransformer (#1837)
Fixes: #1836 Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent f00f364 commit b655f9e

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/core/jsonschema/include/sourcemeta/core/jsonschema_transform.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaTransformer {
242242
const std::optional<JSON::String> &default_id = std::nullopt) const
243243
-> bool;
244244

245+
auto begin() const -> auto { return this->rules.cbegin(); }
246+
auto end() const -> auto { return this->rules.cend(); }
247+
245248
private:
246249
// Exporting symbols that depends on the standard C++ library is considered
247250
// safe.

test/jsonschema/jsonschema_transformer_test.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <sourcemeta/core/json.h>
44
#include <sourcemeta/core/jsonschema.h>
55

6+
#include <set>
67
#include <string>
78
#include <tuple>
89
#include <vector>
@@ -1187,3 +1188,20 @@ TEST(JSONSchema_transformer, rereference_fixed_7) {
11871188

11881189
EXPECT_EQ(document, expected);
11891190
}
1191+
1192+
TEST(JSONSchema_transformer, iterators) {
1193+
sourcemeta::core::SchemaTransformer bundle;
1194+
bundle.add<ExampleRule1>();
1195+
bundle.add<ExampleRule2>();
1196+
bundle.add<ExampleRule3>();
1197+
1198+
std::set<std::string> rules;
1199+
for (const auto &entry : bundle) {
1200+
rules.insert(entry.first);
1201+
}
1202+
1203+
EXPECT_EQ(rules.size(), 3);
1204+
EXPECT_TRUE(rules.contains("example_rule_1"));
1205+
EXPECT_TRUE(rules.contains("example_rule_2"));
1206+
EXPECT_TRUE(rules.contains("example_rule_3"));
1207+
}

0 commit comments

Comments
 (0)