Skip to content

Commit

Permalink
Rename PointerTemplate Conditional token to Condition (#1570)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Feb 12, 2025
1 parent f7abd4f commit 78f9c0a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ namespace sourcemeta::core {
template <typename PointerT> class GenericPointerTemplate {
public:
enum class Wildcard { Property, Item, Key };
struct Conditional {
auto operator==(const Conditional &) const noexcept -> bool = default;
auto operator<(const Conditional &) const noexcept -> bool { return false; }
struct Condition {
auto operator==(const Condition &) const noexcept -> bool = default;
auto operator<(const Condition &) const noexcept -> bool { return false; }
};
using Regex = typename PointerT::Value::String;
using Token = typename PointerT::Token;
using Container =
std::vector<std::variant<Wildcard, Conditional, Regex, Token>>;
std::vector<std::variant<Wildcard, Condition, Regex, Token>>;

/// This constructor creates an empty JSON Pointer template. For example:
///
Expand Down
3 changes: 1 addition & 2 deletions src/core/jsonpointer/stringify.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,7 @@ auto stringify(const PointerT &pointer,
const auto &value{std::get<typename PointerT::Regex>(token)};
stream.write(value.c_str(), static_cast<std::streamsize>(value.size()));
stream.put(internal::token_pointer_tilde<CharT>);
} else if (std::holds_alternative<typename PointerT::Conditional>(
token)) {
} else if (std::holds_alternative<typename PointerT::Condition>(token)) {
stream.put(internal::token_pointer_slash<CharT>);
stream.put(internal::token_pointer_tilde<CharT>);
stream.put('?');
Expand Down
20 changes: 10 additions & 10 deletions src/core/jsonschema/walker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ auto walk(const std::optional<sourcemeta::core::Pointer> &parent,
new_pointer.emplace_back(pair.first);
auto new_instance_location{instance_location};
new_instance_location.emplace_back(
sourcemeta::core::PointerTemplate::Conditional{});
sourcemeta::core::PointerTemplate::Condition{});
new_instance_location.emplace_back(
sourcemeta::core::PointerTemplate::Wildcard::Property);
walk(pointer, new_pointer, new_instance_location,
{sourcemeta::core::PointerTemplate::Conditional{},
{sourcemeta::core::PointerTemplate::Condition{},
sourcemeta::core::PointerTemplate::Wildcard::Property},
subschemas, pair.second, walker, resolver, new_dialect, type,
level + 1, orphan);
Expand Down Expand Up @@ -99,11 +99,11 @@ auto walk(const std::optional<sourcemeta::core::Pointer> &parent,
new_pointer.emplace_back(pair.first);
auto new_instance_location{instance_location};
new_instance_location.emplace_back(
sourcemeta::core::PointerTemplate::Conditional{});
sourcemeta::core::PointerTemplate::Condition{});
new_instance_location.emplace_back(
sourcemeta::core::PointerTemplate::Wildcard::Item);
walk(pointer, new_pointer, new_instance_location,
{sourcemeta::core::PointerTemplate::Conditional{},
{sourcemeta::core::PointerTemplate::Condition{},
sourcemeta::core::PointerTemplate::Wildcard::Item},
subschemas, pair.second, walker, resolver, new_dialect, type,
level + 1, orphan);
Expand Down Expand Up @@ -140,9 +140,9 @@ auto walk(const std::optional<sourcemeta::core::Pointer> &parent,
new_pointer.emplace_back(pair.first);
auto new_instance_location{instance_location};
new_instance_location.emplace_back(
sourcemeta::core::PointerTemplate::Conditional{});
sourcemeta::core::PointerTemplate::Condition{});
walk(pointer, new_pointer, new_instance_location,
{sourcemeta::core::PointerTemplate::Conditional{}}, subschemas,
{sourcemeta::core::PointerTemplate::Condition{}}, subschemas,
pair.second, walker, resolver, new_dialect, type, level + 1,
orphan);
} break;
Expand Down Expand Up @@ -185,9 +185,9 @@ auto walk(const std::optional<sourcemeta::core::Pointer> &parent,
new_pointer.emplace_back(index);
auto new_instance_location{instance_location};
new_instance_location.emplace_back(
sourcemeta::core::PointerTemplate::Conditional{});
sourcemeta::core::PointerTemplate::Condition{});
walk(pointer, new_pointer, new_instance_location,
{sourcemeta::core::PointerTemplate::Conditional{}}, subschemas,
{sourcemeta::core::PointerTemplate::Condition{}}, subschemas,
pair.second.at(index), walker, resolver, new_dialect, type,
level + 1, orphan);
}
Expand Down Expand Up @@ -256,9 +256,9 @@ auto walk(const std::optional<sourcemeta::core::Pointer> &parent,
new_pointer.emplace_back(subpair.first);
auto new_instance_location{instance_location};
new_instance_location.emplace_back(
sourcemeta::core::PointerTemplate::Conditional{});
sourcemeta::core::PointerTemplate::Condition{});
walk(pointer, new_pointer, new_instance_location,
{sourcemeta::core::PointerTemplate::Conditional{}}, subschemas,
{sourcemeta::core::PointerTemplate::Condition{}}, subschemas,
subpair.second, walker, resolver, new_dialect, type, level + 1,
orphan);
}
Expand Down
16 changes: 8 additions & 8 deletions test/jsonpointer/jsonpointer_template_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,32 +134,32 @@ TEST(JSONPointer_template, equality_with_key_wildcard_false) {
EXPECT_NE(left, right);
}

TEST(JSONPointer_template, equality_with_conditional_wildcard_true) {
TEST(JSONPointer_template, equality_with_condition_wildcard_true) {
const sourcemeta::core::Pointer prefix{"foo", "bar"};
const sourcemeta::core::Pointer suffix{"baz"};

sourcemeta::core::PointerTemplate left{prefix};
left.emplace_back(sourcemeta::core::PointerTemplate::Conditional{});
left.emplace_back(sourcemeta::core::PointerTemplate::Condition{});
left.push_back(suffix);

sourcemeta::core::PointerTemplate right{prefix};
right.emplace_back(sourcemeta::core::PointerTemplate::Conditional{});
right.emplace_back(sourcemeta::core::PointerTemplate::Condition{});
right.push_back(suffix);

EXPECT_EQ(left, right);
}

TEST(JSONPointer_template, equality_with_conditional_wildcard_false) {
TEST(JSONPointer_template, equality_with_condition_wildcard_false) {
const sourcemeta::core::Pointer prefix{"foo", "bar"};
const sourcemeta::core::Pointer suffix{"baz"};

sourcemeta::core::PointerTemplate left{prefix};
left.emplace_back(sourcemeta::core::PointerTemplate::Conditional{});
left.emplace_back(sourcemeta::core::PointerTemplate::Condition{});
left.push_back(suffix);

sourcemeta::core::PointerTemplate right{prefix};
right.push_back(suffix);
right.emplace_back(sourcemeta::core::PointerTemplate::Conditional{});
right.emplace_back(sourcemeta::core::PointerTemplate::Condition{});

EXPECT_NE(left, right);
}
Expand Down Expand Up @@ -232,11 +232,11 @@ TEST(JSONPointer_template, stringify_key_wildcard) {
EXPECT_EQ(stream.str(), "/foo/bar/~K~");
}

TEST(JSONPointer_template, stringify_conditional) {
TEST(JSONPointer_template, stringify_condition) {
const sourcemeta::core::Pointer prefix{"foo", "bar"};

sourcemeta::core::PointerTemplate pointer{prefix};
pointer.emplace_back(sourcemeta::core::PointerTemplate::Conditional{});
pointer.emplace_back(sourcemeta::core::PointerTemplate::Condition{});

std::ostringstream stream;
sourcemeta::core::stringify(pointer, stream);
Expand Down

0 comments on commit 78f9c0a

Please sign in to comment.