Skip to content

Commit

Permalink
Merge pull request #67 from biojppm/suite.
Browse files Browse the repository at this point in the history
Parsing improvements: can now successfully parse most of the tests from YAML. Some exceptions are temporarily disabled. It should be noted that for now the test suite tests are only testing that the parsing is successful, and not whether it is fully correct. Here's the full list of temporarily disabled tests ([from the suite.cpp file](https://github.com/biojppm/rapidyaml/pull/67/files#diff-5296eeacbcb55d466601f07772e50312R81)):

```c++
    _("3UYS", CPART_IN_YAML, "no need to escape the slash in \"a\\/b\""),
    // malformed json
    _("7Z25", CPART_IN_JSON, "malformed JSON from multiple documents"),
    _("35KP", CPART_IN_JSON|CPART_IN_YAML, "malformed JSON from multiple documents|TODO[hard]: \"d e\" plain scalar continuing on the next line with the same indentation]"),
    _("6XDY", CPART_IN_JSON, "malformed JSON from multiple documents"),
    _("6ZKB", CPART_IN_JSON|CPART_IN_YAML, "malformed JSON from multiple documents|TODO[next]: document handling"),
    _("9KAX", CPART_IN_JSON, "malformed JSON from multiple documents"),
    _("9DXL", CPART_IN_JSON|CPART_IN_YAML, "malformed JSON from multiple documents|TODO[next]: document handling"),
    _("W4TN", CPART_IN_JSON|CPART_IN_YAML, "malformed JSON from multiple documents|TODO[next]: document handling"),
    // complex keys
    _("4FJ6", CPART_ALL, "only string keys allowed (keys cannot be maps or seqs)"),
    _("6BFJ", CPART_ALL, "only string keys allowed (keys cannot be maps or seqs)"),
    _("6PBE", CPART_ALL, "only string keys allowed (keys cannot be maps or seqs)"),
    _("KK5P", CPART_ALL, "only string keys allowed (keys cannot be maps or seqs)"),
    _("LX3P", CPART_ALL, "only string keys allowed (keys cannot be maps or seqs)"),
    _("M5DY", CPART_ALL, "only string keys allowed (keys cannot be maps or seqs)"),
    _("Q9WF", CPART_ALL, "only string keys allowed (keys cannot be maps or seqs)"),
    _("XW4D", CPART_ALL, "only string keys allowed (keys cannot be maps or seqs)"),

    // TODO
    _("5MUD", CPART_IN_YAML, "TODO[hard]"),
    _("9WXW", CPART_ALL, "TODO[next]: document handling"),
    _("M7A3", CPART_ALL, "TODO[next]: document handling/special tags in .tml file with test specs"),
    _("735Y", CPART_IN_YAML, "TODO[next]: plain scalar parsing"),
    _("7T8X", CPART_IN_YAML|CPART_OUT_YAML, "TODO[next]: scalar block parsing"),
    _("RZP5", CPART_IN_YAML|CPART_OUT_YAML, "TODO[next]: plain scalar block parsing, anchors"),
    _("FH7J", CPART_ALL, "TODO[next]: implicit keys"),
    _("7W2P", CPART_IN_YAML, "TODO[next]: implicit key/explicit key"),
    _("PW8X", CPART_ALL, "TODO[next]: anchors with implicit key"),
    _("CN3R", CPART_ALL, "TODO[next]: anchors + maps nested in seqs"),
    _("6BCT", CPART_IN_YAML, "TODO[hard]: allow tabs after - or :"),
    _("7ZZ5", CPART_ALL, "TODO[next]: nested sequences"),
    _("G5U8", CPART_ALL, "TODO[next]: sequences with -"),
    _("K858", CPART_OUT_YAML|CPART_IN_JSON, "TODO[next]: emitting block scalars is not idempotent"),
    _("NAT4", CPART_IN_YAML|CPART_IN_JSON, "TODO[next]: emitting block scalars is not idempotent"),

    _("82AN", CPART_ALL, "temporarily disabled pending further investigation"),
    _("87E4", CPART_ALL, "temporarily disabled pending further investigation"),
    _("8UDB", CPART_ALL, "temporarily disabled pending further investigation"),
    _("9MMW", CPART_ALL, "temporarily disabled pending further investigation"),
    _("9YRD", CPART_ALL, "temporarily disabled pending further investigation"),
    _("C2DT", CPART_ALL, "temporarily disabled pending further investigation"),
    _("CT4Q", CPART_ALL, "temporarily disabled pending further investigation"),
    _("DC7X", CPART_ALL, "temporarily disabled pending further investigation"),
    _("EX5H", CPART_ALL, "temporarily disabled pending further investigation"),
    _("EXG3", CPART_ALL, "temporarily disabled pending further investigation"),
    _("F6MC", CPART_ALL, "temporarily disabled pending further investigation"),
    _("F8F9", CPART_ALL, "temporarily disabled pending further investigation"),
    _("HS5T", CPART_ALL, "temporarily disabled pending further investigation"),
    _("JHB9", CPART_ALL, "temporarily disabled pending further investigation"),
    _("K3WX", CPART_ALL, "temporarily disabled pending further investigation"),
    _("KSS4", CPART_ALL, "temporarily disabled pending further investigation"),
    _("KZN9", CPART_ALL, "temporarily disabled pending further investigation"),
    _("L94M", CPART_ALL, "temporarily disabled pending further investigation"),
    _("L9U5", CPART_ALL, "temporarily disabled pending further investigation"),
    _("LQZ7", CPART_ALL, "temporarily disabled pending further investigation"),
    _("QF4Y", CPART_ALL, "temporarily disabled pending further investigation"),
    _("RZT7", CPART_ALL, "temporarily disabled pending further investigation"),
    _("SBG9", CPART_ALL, "temporarily disabled pending further investigation"),
    _("TS54", CPART_ALL, "temporarily disabled pending further investigation"),
    _("U9NS", CPART_ALL, "temporarily disabled pending further investigation"),
    _("UGM3", CPART_ALL, "temporarily disabled pending further investigation"),
    _("WZ62", CPART_ALL, "temporarily disabled pending further investigation"),
    _("X38W", CPART_ALL, "temporarily disabled pending further investigation"),
    _("XLQ9", CPART_ALL, "temporarily disabled pending further investigation"),
    _("ZWK4", CPART_ALL, "temporarily disabled pending further investigation"),
```
  • Loading branch information
biojppm authored May 19, 2020
2 parents cf69b15 + 442919d commit f4364df
Show file tree
Hide file tree
Showing 16 changed files with 1,293 additions and 466 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ script:
- ryml_cfg_test 64 dynamic
- ryml_run_test 64 dynamic

- echo "Running tests again, with the test suite enabled (~1300 tests)"
- addcmflags TEST_SUITE=ON ; ryml_cfg_test 64 static ; ryml_run_test 64 static
- addcmflags TEST_SUITE=ON ; ryml_cfg_test 32 static ; ryml_run_test 32 static

- echo "Success!"

after_success:
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1141,10 +1141,16 @@ appear some cases which ryml fails to parse. So we welcome your

### Known limitations

* ryml does not handle complex elements as mapping keys: keys must be simple
ryml does not follow the standard in the following situations:

* complex elements as mapping keys: keys must be simple
values and cannot themselves be mappings or sequences. Yaml test suite
cases:
* [KK5P](https://github.com/yaml/yaml-test-suite/tree/master/test/KK5P.tml)
* these directives have no effect and are ignored:
* `%YAML`
* `%TAG`
* any other directives found at document level which start with the `%` character


------
Expand Down
7 changes: 3 additions & 4 deletions src/c4/yml/emit.def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ void Emitter<Writer>::_write(NodeScalar const& sc, NodeType flags, size_t ilevel
}

const bool has_newlines = sc.scalar.first_of('\n') != npos;
if(!has_newlines)
if(!has_newlines || (sc.scalar.triml(" \t") != sc.scalar))
{
_write_scalar(sc.scalar);
}
Expand Down Expand Up @@ -327,7 +327,7 @@ void Emitter<Writer>::_write_scalar(csubstr s)
(
(s != s.trim(" \t\n\r")) // has leading or trailing whitespace
||
s.first_of("#:-,\n{}[]'\"") != npos // has special chars
s.first_of("#:-?,\n{}[]'\"") != npos // has special chars
)
);

Expand Down Expand Up @@ -364,8 +364,7 @@ void Emitter<Writer>::_write_scalar(csubstr s)
this->Writer::_do_write('\'');
for(size_t i = 0; i < s.len; ++i)
{
RYML_ASSERT(s[i] != '\n');
if(s[i] == '\'')
if(s[i] == '\'' || s[i] == '\n')
{
csubstr sub = s.range(pos, i);
pos = i;
Expand Down
Loading

0 comments on commit f4364df

Please sign in to comment.