Skip to content

Commit

Permalink
rename ExpectError::do_check() to ExpectError::check_error()
Browse files Browse the repository at this point in the history
  • Loading branch information
biojppm committed Aug 12, 2024
1 parent 5b15b85 commit 38f616b
Show file tree
Hide file tree
Showing 20 changed files with 167 additions and 167 deletions.
64 changes: 32 additions & 32 deletions test/test_emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,14 @@ void test_emits(Tree const& t, id_type id, std::string const& expected, std::str
if(max_depth > 1)
{
EmitOptions opts = EmitOptions{}.max_depth(0);
ExpectError::do_check(&t, [&]{ return emit2buf([&](substr buf){ return emit_yaml(t, id, opts, buf); }); });
ExpectError::do_check(&t, [&]{ return emit2buf([&](substr buf){ return emit_json(t, id, opts, buf); }); });
ExpectError::do_check(&t, [&]{ return emit2file([&](FILE *f){ return emit_yaml(t, id, opts, f); }); });
ExpectError::do_check(&t, [&]{ return emit2file([&](FILE *f){ return emit_json(t, id, opts, f); }); });
ExpectError::do_check(&t, [&]{ return emit2stream([&](std::ostringstream &oss){ oss << as_yaml(t, id, opts); }); });
ExpectError::do_check(&t, [&]{ return emit2stream([&](std::ostringstream &oss){ oss << as_json(t, id, opts); }); });
ExpectError::do_check(&t, [&]{ return emitrs_yaml<std::string>(t, id, opts); });
ExpectError::do_check(&t, [&]{ return emitrs_json<std::string>(t, id, opts); });
ExpectError::check_error(&t, [&]{ return emit2buf([&](substr buf){ return emit_yaml(t, id, opts, buf); }); });
ExpectError::check_error(&t, [&]{ return emit2buf([&](substr buf){ return emit_json(t, id, opts, buf); }); });
ExpectError::check_error(&t, [&]{ return emit2file([&](FILE *f){ return emit_yaml(t, id, opts, f); }); });
ExpectError::check_error(&t, [&]{ return emit2file([&](FILE *f){ return emit_json(t, id, opts, f); }); });
ExpectError::check_error(&t, [&]{ return emit2stream([&](std::ostringstream &oss){ oss << as_yaml(t, id, opts); }); });
ExpectError::check_error(&t, [&]{ return emit2stream([&](std::ostringstream &oss){ oss << as_json(t, id, opts); }); });
ExpectError::check_error(&t, [&]{ return emitrs_yaml<std::string>(t, id, opts); });
ExpectError::check_error(&t, [&]{ return emitrs_json<std::string>(t, id, opts); });
}
}

Expand Down Expand Up @@ -264,14 +264,14 @@ void test_emits(Tree const& t, std::string const& expected, std::string const& e
if(max_depth > 1)
{
EmitOptions opts = EmitOptions{}.max_depth(0);
ExpectError::do_check(&t, [&]{ return emit2buf([&](substr buf){ return emit_yaml(t, opts, buf); }); });
ExpectError::do_check(&t, [&]{ return emit2buf([&](substr buf){ return emit_json(t, opts, buf); }); });
ExpectError::do_check(&t, [&]{ return emit2file([&](FILE *f){ return emit_yaml(t, opts, f); }); });
ExpectError::do_check(&t, [&]{ return emit2file([&](FILE *f){ return emit_json(t, opts, f); }); });
ExpectError::do_check(&t, [&]{ return emit2stream([&](std::ostringstream &oss){ oss << as_yaml(ConstNodeRef(&t), opts); }); });
ExpectError::do_check(&t, [&]{ return emit2stream([&](std::ostringstream &oss){ oss << as_json(ConstNodeRef(&t), opts); }); });
ExpectError::do_check(&t, [&]{ return emitrs_yaml<std::string>(t, opts); });
ExpectError::do_check(&t, [&]{ return emitrs_json<std::string>(t, opts); });
ExpectError::check_error(&t, [&]{ return emit2buf([&](substr buf){ return emit_yaml(t, opts, buf); }); });
ExpectError::check_error(&t, [&]{ return emit2buf([&](substr buf){ return emit_json(t, opts, buf); }); });
ExpectError::check_error(&t, [&]{ return emit2file([&](FILE *f){ return emit_yaml(t, opts, f); }); });
ExpectError::check_error(&t, [&]{ return emit2file([&](FILE *f){ return emit_json(t, opts, f); }); });
ExpectError::check_error(&t, [&]{ return emit2stream([&](std::ostringstream &oss){ oss << as_yaml(ConstNodeRef(&t), opts); }); });
ExpectError::check_error(&t, [&]{ return emit2stream([&](std::ostringstream &oss){ oss << as_json(ConstNodeRef(&t), opts); }); });
ExpectError::check_error(&t, [&]{ return emitrs_yaml<std::string>(t, opts); });
ExpectError::check_error(&t, [&]{ return emitrs_json<std::string>(t, opts); });
}
}

Expand Down Expand Up @@ -312,18 +312,18 @@ void test_emits(ConstNodeRef n, std::string const& expected, std::string const&
if(max_depth > 1)
{
EmitOptions opts = EmitOptions{}.max_depth(0);
ExpectError::do_check(n.tree(), [&]{
ExpectError::check_error(n.tree(), [&]{
return emit2buf([&](substr buf){
return emit_yaml(n, opts, buf);
});
});
ExpectError::do_check(n.tree(), [&]{ return emit2buf([&](substr buf){ return emit_json(n, opts, buf); }); });
ExpectError::do_check(n.tree(), [&]{ return emit2file([&](FILE *f){ return emit_yaml(n, opts, f); }); });
ExpectError::do_check(n.tree(), [&]{ return emit2file([&](FILE *f){ return emit_json(n, opts, f); }); });
ExpectError::do_check(n.tree(), [&]{ return emit2stream([&](std::ostringstream &oss){ oss << as_yaml(n, opts); }); });
ExpectError::do_check(n.tree(), [&]{ return emit2stream([&](std::ostringstream &oss){ oss << as_json(n, opts); }); });
ExpectError::do_check(n.tree(), [&]{ return emitrs_yaml<std::string>(n, opts); });
ExpectError::do_check(n.tree(), [&]{ return emitrs_json<std::string>(n, opts); });
ExpectError::check_error(n.tree(), [&]{ return emit2buf([&](substr buf){ return emit_json(n, opts, buf); }); });
ExpectError::check_error(n.tree(), [&]{ return emit2file([&](FILE *f){ return emit_yaml(n, opts, f); }); });
ExpectError::check_error(n.tree(), [&]{ return emit2file([&](FILE *f){ return emit_json(n, opts, f); }); });
ExpectError::check_error(n.tree(), [&]{ return emit2stream([&](std::ostringstream &oss){ oss << as_yaml(n, opts); }); });
ExpectError::check_error(n.tree(), [&]{ return emit2stream([&](std::ostringstream &oss){ oss << as_json(n, opts); }); });
ExpectError::check_error(n.tree(), [&]{ return emitrs_yaml<std::string>(n, opts); });
ExpectError::check_error(n.tree(), [&]{ return emitrs_json<std::string>(n, opts); });
}
}
}
Expand Down Expand Up @@ -954,10 +954,10 @@ TEST(emit, error_on_emit_yaml_to_short_buffer)
const Tree tree = parse_in_arena(yaml);
{
char too_small[2];
ExpectError::do_check([&]{
ExpectError::check_error([&]{
emit_yaml(tree, too_small);
});
ExpectError::do_check([&]{
ExpectError::check_error([&]{
emit_yaml(tree, too_small, /*error_on_excess*/true);
});
substr required = emit_yaml(tree, too_small, /*error_on_excess*/false);
Expand All @@ -968,10 +968,10 @@ TEST(emit, error_on_emit_yaml_to_short_buffer)
substr nothing;
EXPECT_EQ(nothing.str, nullptr);
EXPECT_EQ(nothing.len, 0u);
ExpectError::do_check([&]{
ExpectError::check_error([&]{
emit_yaml(tree, nothing);
});
ExpectError::do_check([&]{
ExpectError::check_error([&]{
emit_yaml(tree, nothing, /*error_on_excess*/true);
});
substr required = emit_yaml(tree, nothing, /*error_on_excess*/false);
Expand All @@ -986,10 +986,10 @@ TEST(emit, error_on_emit_json_to_short_buffer)
const Tree tree = parse_in_arena(json);
{
char too_small[2];
ExpectError::do_check([&]{
ExpectError::check_error([&]{
emit_json(tree, too_small);
});
ExpectError::do_check([&]{
ExpectError::check_error([&]{
emit_json(tree, too_small, /*error_on_excess*/true);
});
substr required = emit_json(tree, too_small, /*error_on_excess*/false);
Expand All @@ -1000,10 +1000,10 @@ TEST(emit, error_on_emit_json_to_short_buffer)
substr nothing;
EXPECT_EQ(nothing.str, nullptr);
EXPECT_EQ(nothing.len, 0u);
ExpectError::do_check([&]{
ExpectError::check_error([&]{
emit_json(tree, nothing);
});
ExpectError::do_check([&]{
ExpectError::check_error([&]{
emit_json(tree, nothing, /*error_on_excess*/true);
});
substr required = emit_json(tree, nothing, /*error_on_excess*/false);
Expand Down
34 changes: 17 additions & 17 deletions test/test_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,119 +490,119 @@ quntity2: 95000000)");

TEST(parse_json, error_on_missing_seq_val)
{
ExpectError::do_check([]{
ExpectError::check_error([]{
Tree tree = parse_json_in_arena("[foo, , ]");
});
}

TEST(parse_json, error_on_double_seq_val)
{
ExpectError::do_check([]{
ExpectError::check_error([]{
Tree tree = parse_json_in_arena("[0 1, ]");
});
}

TEST(parse_json, error_on_double_seq_val_quoted)
{
ExpectError::do_check([]{
ExpectError::check_error([]{
Tree tree = parse_json_in_arena("[\"0\" 1, ]");
});
}

TEST(parse_json, error_on_double_seq_val_quoted_2)
{
ExpectError::do_check([]{
ExpectError::check_error([]{
Tree tree = parse_json_in_arena("[\"0\" \"1\", ]");
});
}

TEST(parse_json, error_on_double_seq_val_quoted_3)
{
ExpectError::do_check([]{
ExpectError::check_error([]{
Tree tree = parse_json_in_arena("[0 \"1\", ]");
});
}

TEST(parse_json, error_on_double_map_val)
{
ExpectError::do_check([]{
ExpectError::check_error([]{
Tree tree = parse_json_in_arena("{\"key\": 0 1}");
});
}

TEST(parse_json, error_on_double_map_val_quoted)
{
ExpectError::do_check([]{
ExpectError::check_error([]{
Tree tree = parse_json_in_arena("{\"key\": 0 \"1\"}");
});
}

TEST(parse_json, error_on_double_map_val_quoted_2)
{
ExpectError::do_check([]{
ExpectError::check_error([]{
Tree tree = parse_json_in_arena("{\"key\": \"0\" 1}");
});
}

TEST(parse_json, error_on_double_map_val_quoted_3)
{
ExpectError::do_check([]{
ExpectError::check_error([]{
Tree tree = parse_json_in_arena("{\"key\": \"0\" \"1\"}");
});
}

TEST(parse_json, error_on_missing_seq_term)
{
ExpectError::do_check([]{
ExpectError::check_error([]{
Tree tree = parse_json_in_arena("[foo, ");
});
}

TEST(parse_json, error_on_missing_map_val)
{
ExpectError::do_check([]{
ExpectError::check_error([]{
Tree tree = parse_json_in_arena("{\"foo\": }");
});
}

TEST(parse_json, error_on_missing_map_term)
{
ExpectError::do_check([]{
ExpectError::check_error([]{
Tree tree = parse_json_in_arena("{\"foo\": 0");
});
}

TEST(parse_json, error_on_missing_map_colon)
{
ExpectError::do_check([]{
ExpectError::check_error([]{
Tree tree = parse_json_in_arena("{\"foo\" }");
});
}

TEST(parse_json, error_on_bad_map_val)
{
ExpectError::do_check([]{
ExpectError::check_error([]{
Tree tree = parse_json_in_arena("{\"foo\": , }");
});
}

TEST(parse_json, error_on_wrong_key_character)
{
ExpectError::do_check([]{
ExpectError::check_error([]{
Tree tree = parse_json_in_arena("{'foo': 1}");
});
}

TEST(parse_json, error_on_unquoted_key_character)
{
ExpectError::do_check([]{
ExpectError::check_error([]{
Tree tree = parse_json_in_arena("{foo: 1}");
});
}

TEST(parse_json, error_on_bare_keyval)
{
ExpectError::do_check([]{
ExpectError::check_error([]{
Tree tree = parse_json_in_arena("\"fails\": true");
});
}
Expand Down
8 changes: 4 additions & 4 deletions test/test_lib/test_case.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,12 @@ void ExpectError::check_success(Tree *tree, std::function<void()> fn)
EXPECT_FALSE(context.m_got_an_error);
}

void ExpectError::do_check(Tree const* tree, std::function<void()> fn, Location expected_location)
void ExpectError::check_error(Tree const* tree, std::function<void()> fn, Location expected_location)
{
do_check(const_cast<Tree*>(tree), fn, expected_location);
check_error(const_cast<Tree*>(tree), fn, expected_location);
}

void ExpectError::do_check(Tree *tree, std::function<void()> fn, Location expected_location)
void ExpectError::check_error(Tree *tree, std::function<void()> fn, Location expected_location)
{
auto context = ExpectError(tree, expected_location);
C4_IF_EXCEPTIONS_(try, if(setjmp(s_jmp_env_expect_error) == 0))
Expand Down Expand Up @@ -311,7 +311,7 @@ void ExpectError::do_check(Tree *tree, std::function<void()> fn, Location expect
void ExpectError::check_assertion(Tree *tree, std::function<void()> fn, Location expected_location)
{
#if RYML_USE_ASSERT
ExpectError::do_check(tree, fn, expected_location);
ExpectError::check_error(tree, fn, expected_location);
#else
C4_UNUSED(tree);
C4_UNUSED(fn);
Expand Down
6 changes: 3 additions & 3 deletions test/test_lib/test_case.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ struct ExpectError
ExpectError(Tree *tree, Location loc={});
~ExpectError();

static void do_check( std::function<void()> fn, Location expected={}) { do_check((const Tree*)nullptr, fn, expected); }
static void do_check(Tree *tree, std::function<void()> fn, Location expected={});
static void do_check(Tree const *tree, std::function<void()> fn, Location expected={});
static void check_error( std::function<void()> fn, Location expected={}) { check_error((const Tree*)nullptr, fn, expected); }
static void check_error(Tree *tree, std::function<void()> fn, Location expected={});
static void check_error(Tree const *tree, std::function<void()> fn, Location expected={});
static void check_assertion( std::function<void()> fn, Location expected={}) { check_assertion(nullptr, fn, expected); }
static void check_assertion(Tree *tree, std::function<void()> fn, Location expected={});
static void check_success( std::function<void()> fn) { check_success(nullptr, fn); };
Expand Down
4 changes: 2 additions & 2 deletions test/test_lib/test_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ std::vector<std::string> inject_comments(std::string const& src_)

void test_expected_error_events_from_yaml(std::string const& parsed_yaml, Location const& expected_error_location)
{
ExpectError::do_check([&]{
ExpectError::check_error([&]{
EventHandlerYamlStd::EventSink sink;
EventHandlerYamlStd handler(&sink);
handler.reset();
Expand All @@ -53,7 +53,7 @@ void test_expected_error_events_from_yaml(std::string const& parsed_yaml, Locati
void test_expected_error_tree_from_yaml(std::string const& parsed_yaml, Location const& expected_error_location)
{
Tree tree = {};
ExpectError::do_check(&tree, [&]{
ExpectError::check_error(&tree, [&]{
EventHandlerTree handler(&tree, tree.root_id());
ASSERT_EQ(&tree, handler.m_tree);
ParseEngine<EventHandlerTree> parser(&handler);
Expand Down
2 changes: 1 addition & 1 deletion test/test_lib/test_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ C4_NO_INLINE void test_new_parser_tree_from_events(ReferenceYaml const& yaml)
{
if(yaml.test_case_flags & HAS_CONTAINER_KEYS)
{
ExpectError::do_check([&]{
ExpectError::check_error([&]{
Tree tree = {};
EventHandlerTree handler(&tree, tree.root_id());
EventProducerFn<EventHandlerTree> event_producer;
Expand Down
2 changes: 1 addition & 1 deletion test/test_lib/test_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void YmlTestCase::_test_parse_using_ryml(CaseDataLineEndings *cd)
if(c->flags & EXPECT_PARSE_ERROR)
{
auto flags = c->flags;
ExpectError::do_check(&cd->parsed_tree, [this, cd, flags](){
ExpectError::check_error(&cd->parsed_tree, [this, cd, flags](){
parse_in_place(c->fileline, cd->src, &cd->parsed_tree);
if(flags & RESOLVE_REFS)
cd->parsed_tree.resolve();
Expand Down
2 changes: 1 addition & 1 deletion test/test_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ TEST(locations, default_is_no_location)
TEST(locations, error_is_triggered_querying_with_locations_disabled)
{
bool parsed_ok = false;
ExpectError::do_check([&]{
ExpectError::check_error([&]{
Parser::handler_type evt_handler = {};
Parser parser(&evt_handler, ParserOptions().locations(false));
Tree t = parse_in_arena(&parser, "test", "foo: bar");
Expand Down
8 changes: 4 additions & 4 deletions test/test_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ TEST(simple_map, test_suite_UT92_0)
TEST(simple_map, test_suite_UT92_1)
{
Tree tree;
ExpectError::do_check(&tree, [&]{
ExpectError::check_error(&tree, [&]{
csubstr yaml = R"(
- { matches
% : 20 }
Expand All @@ -294,7 +294,7 @@ TEST(simple_map, test_suite_UT92_1)
TEST(simple_map, two_nested_flow_maps_not_accepted_because_of_container_key)
{
Tree tree;
ExpectError::do_check(&tree, [&]{
ExpectError::check_error(&tree, [&]{
parse_in_arena("{{}}", &tree);
});
}
Expand All @@ -309,7 +309,7 @@ TEST(simple_map, many_unmatched_brackets)
for(size_t i = src.size(); i < num_brackets; ++i)
src += '{';
Tree tree;
ExpectError::do_check(&tree, [&]{
ExpectError::check_error(&tree, [&]{
parse_in_place(to_substr(src), &tree);
});
}
Expand Down Expand Up @@ -413,7 +413,7 @@ void verify_error_is_reported(csubstr case_name, csubstr yaml, LineCol lc={})
Location loc = {};
loc.line = lc.line;
loc.col = lc.col;
ExpectError::do_check(&tree, [&](){
ExpectError::check_error(&tree, [&](){
parse_in_arena(yaml, &tree);
}, loc);
}
Expand Down
Loading

0 comments on commit 38f616b

Please sign in to comment.