Skip to content

Commit

Permalink
Merge pull request #178 from biojppm/fix/test_suite
Browse files Browse the repository at this point in the history
[chore] update test suite format
  • Loading branch information
biojppm committed Dec 26, 2021
2 parents c39bdd8 + 24914b7 commit 7fb3d51
Show file tree
Hide file tree
Showing 11 changed files with 245 additions and 209 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/emscripten.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ on:
env:
PROJ_PFX_TARGET: ryml-
PROJ_PFX_CMAKE: RYML_
CMAKE_FLAGS:
CMAKE_FLAGS: '-DRYML_TEST_SUITE=OFF'
NUM_JOBS_BUILD: # 4
EMSCRIPTEN_CACHE_FOLDER: 'emsdk-cache'

Expand Down
14 changes: 14 additions & 0 deletions changelog/current.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@
### Fixes
- Take block literal indentation as relative to current indentation level, rather than as an absolute indentation level ([PR #178](https://github.com/biojppm/rapidyaml/pull/178)):
```yaml
foo:
- |
child0
- |2
child2 # indentation is 4, not 2
```
- Fix parsing when seq member maps start without a key ([PR #178](https://github.com/biojppm/rapidyaml/pull/178)):
```yaml
# previously this resulted in a parse error
- - : empty key
- - : another empty key
```
- Prefer passing `substr` and `csubstr` by value instead of const reference ([PR #171](https://github.com/biojppm/rapidyaml/pull/171))
- Fix [#173](https://github.com/biojppm/rapidyaml/issues/173): add alias target `ryml::ryml` ([PR #174](https://github.com/biojppm/rapidyaml/pull/174))
- Speedup compilation of tests by removing linking with yaml-cpp and libyaml. ([PR #177](https://github.com/biojppm/rapidyaml/pull/177))
54 changes: 31 additions & 23 deletions src/c4/yml/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,22 +881,38 @@ bool Parser::_handle_seq_impl()
/* pathological case:
* - &key : val
* - &key :
* - : val
*/
else if((!has_all(SSCL)) &&
(!m_val_anchor.empty() || !m_val_tag.empty()) &&
(rem.begins_with(": ") || rem.left_of(rem.find("#")).trimr("\t") == ":"))
{
_c4dbgp("val is a child map + this key is empty");
addrem_flags(RNXT, RVAL); // before _push_level!
_move_val_tag_to_key_tag();
_move_val_anchor_to_key_anchor();
_push_level();
_start_map();
_store_scalar({}, /*is_quoted*/false);
addrem_flags(RVAL, RKEY);
RYML_CHECK(_maybe_set_indentation_from_anchor_or_tag()); // one of them must exist
_line_progressed(rem.begins_with(": ") ? 2u : 1u);
return true;
if(!m_val_anchor.empty() || !m_val_tag.empty())
{
_c4dbgp("val is a child map + this key is empty, with anchors or tags");
addrem_flags(RNXT, RVAL); // before _push_level!
_move_val_tag_to_key_tag();
_move_val_anchor_to_key_anchor();
_push_level();
_start_map();
_store_scalar({}, /*is_quoted*/false);
addrem_flags(RVAL, RKEY);
RYML_CHECK(_maybe_set_indentation_from_anchor_or_tag()); // one of them must exist
_line_progressed(rem.begins_with(": ") ? 2u : 1u);
return true;
}
else
{
_c4dbgp("val is a child map + this key is empty, no anchors or tags");
addrem_flags(RNXT, RVAL); // before _push_level!
_push_level();
_start_map();
_store_scalar({}, /*is_quoted*/false);
addrem_flags(RVAL, RKEY);
_c4dbgpf("set indentation from map anchor: %zu", m_state->indref + 2);
_set_indentation(m_state->indref + 2); // this is the column where the map starts
_line_progressed(rem.begins_with(": ") ? 2u : 1u);
return true;
}
}
else
{
Expand Down Expand Up @@ -3562,15 +3578,14 @@ csubstr Parser::_scan_block()
else
t = t.first(pos);
}

// from here to the end, only digits are considered
digits = t.left_of(t.first_not_of("0123456789"));
if( ! digits.empty())
{
if( ! _read_decimal(digits, &indentation))
{
if( ! c4::atou(digits, &indentation))
_c4err("parse error: could not read decimal");
}
_c4dbgpf("scanning block: indentation specified: %zu. add %zu from curr state -> %zu", indentation, m_state->indref, indentation+m_state->indref);
indentation += m_state->indref;
}
}

Expand Down Expand Up @@ -4142,13 +4157,6 @@ csubstr Parser::_filter_block_scalar(substr s, BlockStyle_e style, BlockChomp_e
return r;
}

//-----------------------------------------------------------------------------
bool Parser::_read_decimal(csubstr const& str, size_t *decimal)
{
RYML_ASSERT(str.len >= 1);
return c4::atou(str, decimal);
}

//-----------------------------------------------------------------------------
size_t Parser::_count_nlines(csubstr src)
{
Expand Down
1 change: 0 additions & 1 deletion src/c4/yml/parse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ class RYML_EXPORT Parser

private:

static bool _read_decimal(csubstr const& str, size_t *decimal);
static size_t _count_nlines(csubstr src);

private:
Expand Down
12 changes: 8 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ if(RYML_TEST_SUITE)
set(tsdir ${ed}/yaml-test-suite)
c4_download_remote_proj(yaml-test-suite tsdir
GIT_REPOSITORY https://github.com/yaml/yaml-test-suite
GIT_TAG ed99dd31187f00d729fe160a7658f6f29c08f80b) #master)
set(suite_dir ${tsdir}/test)
GIT_TAG bcd49a2d4919c1b1ac3b9d6e5ebe6b140b5089e3) #master)
set(suite_dir ${tsdir}/src)
if(NOT EXISTS ${suite_dir})
c4_err("cannot find yaml-test-suite at ${suite_dir} -- was there an error downloading the project?")
endif()
Expand All @@ -157,7 +157,11 @@ if(RYML_TEST_SUITE)
FOLDER test)
add_dependencies(ryml-test-build ryml-test-suite)

set(tgt $<TARGET_FILE:ryml-test-suite>)
if(CMAKE_CROSSCOMPILING)
set(tgt ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:ryml-test-suite>)
else()
set(tgt $<TARGET_FILE:ryml-test-suite>)
endif()
function(ryml_add_test_from_suite tml_file)
get_filename_component(name ${tml_file} NAME_WE)
add_test(NAME ryml-test-suite-${name}-in_yaml COMMAND ${tgt} --gtest_filter=*/in_yaml* ${suite_dir}/${tml_file})
Expand All @@ -170,7 +174,7 @@ if(RYML_TEST_SUITE)
add_test(NAME ryml-test-suite-${name}-in_json COMMAND ${tgt} --gtest_filter=*/in_json* ${suite_dir}/${tml_file})
endfunction()

file(GLOB suite_cases RELATIVE "${suite_dir}" "${suite_dir}/*.tml")
file(GLOB suite_cases RELATIVE "${suite_dir}" "${suite_dir}/*.yaml")
foreach(case ${suite_cases})
ryml_add_test_from_suite(${case})
endforeach()
Expand Down
10 changes: 7 additions & 3 deletions test/test_block_folded.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ TEST(block_folded, test_suite_4QFQ)
EXPECT_EQ(t[1].val(), csubstr(" child2\n"));
EXPECT_EQ(t[2].val(), csubstr(" child2\n"));
});
yaml = R"(---
}

TEST(block_folded, test_suite_4QFQ_pt2)
{
csubstr yaml = R"(---
- |
child0
- >
Expand All @@ -160,8 +164,8 @@ TEST(block_folded, test_suite_4QFQ)
# child1
- |3
child2
- |2
child2
- >
child3
)";
Expand Down
25 changes: 24 additions & 1 deletion test/test_block_literal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ TEST(block_literal, emit_does_not_add_lines_to_multi_at_end)
"block literal as map val, explicit indentation 9",\
"block literal with empty unindented lines, without quotes",\
"block literal with empty unindented lines, with double quotes",\
"block literal with empty unindented lines, with single quotes"
"block literal with empty unindented lines, with single quotes",\
"block literal with same indentation level 0",\
"block literal with same indentation level 1"


CASE_GROUP(BLOCK_LITERAL)
Expand Down Expand Up @@ -465,6 +467,27 @@ C("block literal with empty unindented lines, with single quotes",
N("tpl", L{N(QV, "src", "#include '{{hdr.filename}}'\n\n{{src.gencode}}\n")})
}
),

C("block literal with same indentation level 0",
R"(
aaa: |2
xxx
bbb: |
xxx
)",
L{N(QV, "aaa", "xxx\n"), N(QV, "bbb", "xxx\n")}
),

C("block literal with same indentation level 1",
R"(
- aaa: |2
xxx
bbb: |
xxx
)",
L{N(L{N(QV, "aaa", "xxx\n"), N(QV, "bbb", "xxx\n")})}
),

)
}

Expand Down
4 changes: 2 additions & 2 deletions test/test_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,13 @@ void YmlTestCase::_test_recreate_from_ref(CaseDataLineEndings *cd)
}

//-----------------------------------------------------------------------------
TEST_P(YmlTestCase, parse_unix_using_ryml)
TEST_P(YmlTestCase, parse_unix)
{
SCOPED_TRACE("unix style");
_test_parse_using_ryml(&d->unix_style);
}

TEST_P(YmlTestCase, parse_windows_using_ryml)
TEST_P(YmlTestCase, parse_windows)
{
SCOPED_TRACE("windows style");
_test_parse_using_ryml(&d->windows_style);
Expand Down
Loading

0 comments on commit 7fb3d51

Please sign in to comment.