git subrepo clone --branch=0.2.5 https://github.com/yaml/libyaml.git deps/libyaml

subrepo:
  subdir:   "deps/libyaml"
  merged:   "2c891fc"
upstream:
  origin:   "https://github.com/yaml/libyaml.git"
  branch:   "0.2.5"
  commit:   "2c891fc"
git-subrepo:
  version:  "0.4.6"
  origin:   "???"
  commit:   "???"
This commit is contained in:
2024-03-05 22:38:36 -08:00
parent ca1fdb053d
commit 11e8fad44e
63 changed files with 18605 additions and 0 deletions

27
deps/libyaml/tests/CMakeLists.txt vendored Normal file
View File

@@ -0,0 +1,27 @@
function(add_yaml_executable name)
add_executable(${name} ${name}.c)
target_link_libraries(${name} yaml)
endfunction()
foreach(name IN ITEMS
example-deconstructor
example-deconstructor-alt
example-reformatter
example-reformatter-alt
run-dumper
run-emitter
run-emitter-test-suite
run-loader
run-parser
run-parser-test-suite
run-scanner
test-reader
test-version
)
add_yaml_executable(${name})
endforeach()
add_test(NAME version COMMAND test-version)
add_test(NAME reader COMMAND test-reader)

9
deps/libyaml/tests/Makefile.am vendored Normal file
View File

@@ -0,0 +1,9 @@
AM_CPPFLAGS = -I$(top_srcdir)/include -Wall
#AM_CFLAGS = -Wno-pointer-sign
LDADD = $(top_builddir)/src/libyaml.la
TESTS = test-version test-reader
check_PROGRAMS = test-version test-reader
noinst_PROGRAMS = run-scanner run-parser run-loader run-emitter run-dumper \
example-reformatter example-reformatter-alt \
example-deconstructor example-deconstructor-alt \
run-parser-test-suite run-emitter-test-suite

63
deps/libyaml/tests/ReadMe.md vendored Normal file
View File

@@ -0,0 +1,63 @@
# Testing the Parser and Emitter
There are several programs to test the parser and emitter.
## Parser
echo 'foo: bar' | ./tests/run-parser-test-suite
This will output the parsing events in yaml-test-suite format:
+STR
+DOC
+MAP
=VAL :foo
=VAL :bar
-MAP
-DOC
-STR
For flow style events, you have to enable it with the `--flow` option:
echo '{ foo: bar }' | ./tests/run-parser-test-suite --flow keep
...
+MAP {}
...
In the future, this will be the default.
You can also explicitly disable this style with `--flow off`, or output
flow style always, with `--flow on`.
## Emitter
run-emitter-test-suite takes yaml-test-suite event format and emits YAML.
./tests/run-parser-test-suite ... | ./tests/run-emitter-test-suite
## Options
* `--directive (1.1|1.2)`
Prints a version directive before every document.
* `--flow on`
Will emit the whole document in flow style.
* `--flow off`
Will emit the whole document in block style.
* `--flow keep`
Will emit block/flow style like in the original document.
Example:
```
% echo 'foo: [bar, {x: y}]' |
./tests/run-parser-test-suite --flow keep |
./tests/run-emitter-test-suite --flow keep
foo: [bar, {x: y}]
```

View File

@@ -0,0 +1,800 @@
#include <yaml.h>
#include <stdlib.h>
#include <stdio.h>
int
main(int argc, char *argv[])
{
int help = 0;
int canonical = 0;
int unicode = 0;
int k;
int done = 0;
yaml_parser_t parser;
yaml_emitter_t emitter;
yaml_event_t input_event;
yaml_document_t output_document;
int root;
/* Clear the objects. */
memset(&parser, 0, sizeof(parser));
memset(&emitter, 0, sizeof(emitter));
memset(&input_event, 0, sizeof(input_event));
memset(&output_document, 0, sizeof(output_document));
/* Analyze command line options. */
for (k = 1; k < argc; k ++)
{
if (strcmp(argv[k], "-h") == 0
|| strcmp(argv[k], "--help") == 0) {
help = 1;
}
else if (strcmp(argv[k], "-c") == 0
|| strcmp(argv[k], "--canonical") == 0) {
canonical = 1;
}
else if (strcmp(argv[k], "-u") == 0
|| strcmp(argv[k], "--unicode") == 0) {
unicode = 1;
}
else {
fprintf(stderr, "Unrecognized option: %s\n"
"Try `%s --help` for more information.\n",
argv[k], argv[0]);
return 1;
}
}
/* Display the help string. */
if (help)
{
printf("%s <input\n"
"or\n%s -h | --help\nDeconstruct a YAML stream\n\nOptions:\n"
"-h, --help\t\tdisplay this help and exit\n"
"-c, --canonical\t\toutput in the canonical YAML format\n"
"-u, --unicode\t\toutput unescaped non-ASCII characters\n",
argv[0], argv[0]);
return 0;
}
/* Initialize the parser and emitter objects. */
if (!yaml_parser_initialize(&parser)) {
fprintf(stderr, "Could not initialize the parser object\n");
return 1;
}
if (!yaml_emitter_initialize(&emitter)) {
yaml_parser_delete(&parser);
fprintf(stderr, "Could not inialize the emitter object\n");
return 1;
}
/* Set the parser parameters. */
yaml_parser_set_input_file(&parser, stdin);
/* Set the emitter parameters. */
yaml_emitter_set_output_file(&emitter, stdout);
yaml_emitter_set_canonical(&emitter, canonical);
yaml_emitter_set_unicode(&emitter, unicode);
/* Create and emit the STREAM-START event. */
if (!yaml_emitter_open(&emitter))
goto emitter_error;
/* Create a output_document object. */
if (!yaml_document_initialize(&output_document, NULL, NULL, NULL, 0, 0))
goto document_error;
/* Create the root sequence. */
root = yaml_document_add_sequence(&output_document, NULL,
YAML_BLOCK_SEQUENCE_STYLE);
if (!root) goto document_error;
/* Loop through the input events. */
while (!done)
{
int properties, key, value, map, seq;
/* Get the next event. */
if (!yaml_parser_parse(&parser, &input_event))
goto parser_error;
/* Check if this is the stream end. */
if (input_event.type == YAML_STREAM_END_EVENT) {
done = 1;
}
/* Create a mapping node and attach it to the root sequence. */
properties = yaml_document_add_mapping(&output_document, NULL,
YAML_BLOCK_MAPPING_STYLE);
if (!properties) goto document_error;
if (!yaml_document_append_sequence_item(&output_document,
root, properties)) goto document_error;
/* Analyze the event. */
switch (input_event.type)
{
case YAML_STREAM_START_EVENT:
/* Add 'type': 'STREAM-START'. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"type", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"STREAM-START", -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
/* Add 'encoding': <encoding>. */
if (input_event.data.stream_start.encoding)
{
yaml_encoding_t encoding
= input_event.data.stream_start.encoding;
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"encoding", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)(encoding == YAML_UTF8_ENCODING ? "utf-8" :
encoding == YAML_UTF16LE_ENCODING ? "utf-16-le" :
encoding == YAML_UTF16BE_ENCODING ? "utf-16-be" :
"unknown"), -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
}
break;
case YAML_STREAM_END_EVENT:
/* Add 'type': 'STREAM-END'. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"type", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"STREAM-END", -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
break;
case YAML_DOCUMENT_START_EVENT:
/* Add 'type': 'DOCUMENT-START'. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"type", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"DOCUMENT-START", -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
/* Display the output_document version numbers. */
if (input_event.data.document_start.version_directive)
{
yaml_version_directive_t *version
= input_event.data.document_start.version_directive;
char number[64];
/* Add 'version': {}. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"version", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
map = yaml_document_add_mapping(&output_document, NULL,
YAML_FLOW_MAPPING_STYLE);
if (!map) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, map)) goto document_error;
/* Add 'major': <number>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"major", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
sprintf(number, "%d", version->major);
value = yaml_document_add_scalar(&output_document, (yaml_char_t *)YAML_INT_TAG,
(yaml_char_t *)number, -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
map, key, value)) goto document_error;
/* Add 'minor': <number>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"minor", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
sprintf(number, "%d", version->minor);
value = yaml_document_add_scalar(&output_document, (yaml_char_t *)YAML_INT_TAG,
(yaml_char_t *)number, -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
map, key, value)) goto document_error;
}
/* Display the output_document tag directives. */
if (input_event.data.document_start.tag_directives.start
!= input_event.data.document_start.tag_directives.end)
{
yaml_tag_directive_t *tag;
/* Add 'tags': []. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"tags", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
seq = yaml_document_add_sequence(&output_document, NULL,
YAML_BLOCK_SEQUENCE_STYLE);
if (!seq) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, seq)) goto document_error;
for (tag = input_event.data.document_start.tag_directives.start;
tag != input_event.data.document_start.tag_directives.end;
tag ++)
{
/* Add {}. */
map = yaml_document_add_mapping(&output_document, NULL,
YAML_FLOW_MAPPING_STYLE);
if (!map) goto document_error;
if (!yaml_document_append_sequence_item(&output_document,
seq, map)) goto document_error;
/* Add 'handle': <handle>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"handle", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
tag->handle, -1, YAML_DOUBLE_QUOTED_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
map, key, value)) goto document_error;
/* Add 'prefix': <prefix>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"prefix", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
tag->prefix, -1, YAML_DOUBLE_QUOTED_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
map, key, value)) goto document_error;
}
}
/* Add 'implicit': <flag>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"implicit", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, (yaml_char_t *)YAML_BOOL_TAG,
(yaml_char_t *)(input_event.data.document_start.implicit ?
"true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
break;
case YAML_DOCUMENT_END_EVENT:
/* Add 'type': 'DOCUMENT-END'. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"type", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"DOCUMENT-END", -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
/* Add 'implicit': <flag>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"implicit", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, (yaml_char_t *)YAML_BOOL_TAG,
(yaml_char_t *)(input_event.data.document_end.implicit ?
"true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
break;
case YAML_ALIAS_EVENT:
/* Add 'type': 'ALIAS'. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"type", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"ALIAS", -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
/* Add 'anchor': <anchor>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"anchor", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
input_event.data.alias.anchor, -1,
YAML_DOUBLE_QUOTED_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
break;
case YAML_SCALAR_EVENT:
/* Add 'type': 'SCALAR'. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"type", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"SCALAR", -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
/* Add 'anchor': <anchor>. */
if (input_event.data.scalar.anchor)
{
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"anchor", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
input_event.data.scalar.anchor, -1,
YAML_DOUBLE_QUOTED_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
}
/* Add 'tag': <tag>. */
if (input_event.data.scalar.tag)
{
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"tag", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
input_event.data.scalar.tag, -1,
YAML_DOUBLE_QUOTED_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
}
/* Add 'value': <value>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"value", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
input_event.data.scalar.value,
input_event.data.scalar.length,
YAML_DOUBLE_QUOTED_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
/* Display if the scalar tag is implicit. */
/* Add 'implicit': {} */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"version", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
map = yaml_document_add_mapping(&output_document, NULL,
YAML_FLOW_MAPPING_STYLE);
if (!map) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, map)) goto document_error;
/* Add 'plain': <flag>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"plain", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, (yaml_char_t *)YAML_BOOL_TAG,
(yaml_char_t *)(input_event.data.scalar.plain_implicit ?
"true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
map, key, value)) goto document_error;
/* Add 'quoted': <flag>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"quoted", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, (yaml_char_t *)YAML_BOOL_TAG,
(yaml_char_t *)(input_event.data.scalar.quoted_implicit ?
"true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
map, key, value)) goto document_error;
/* Display the style information. */
if (input_event.data.scalar.style)
{
yaml_scalar_style_t style = input_event.data.scalar.style;
/* Add 'style': <style>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"style", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)(style == YAML_PLAIN_SCALAR_STYLE ? "plain" :
style == YAML_SINGLE_QUOTED_SCALAR_STYLE ?
"single-quoted" :
style == YAML_DOUBLE_QUOTED_SCALAR_STYLE ?
"double-quoted" :
style == YAML_LITERAL_SCALAR_STYLE ? "literal" :
style == YAML_FOLDED_SCALAR_STYLE ? "folded" :
"unknown"), -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
}
break;
case YAML_SEQUENCE_START_EVENT:
/* Add 'type': 'SEQUENCE-START'. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"type", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"SEQUENCE-START", -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
/* Add 'anchor': <anchor>. */
if (input_event.data.sequence_start.anchor)
{
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"anchor", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
input_event.data.sequence_start.anchor, -1,
YAML_DOUBLE_QUOTED_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
}
/* Add 'tag': <tag>. */
if (input_event.data.sequence_start.tag)
{
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"tag", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
input_event.data.sequence_start.tag, -1,
YAML_DOUBLE_QUOTED_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
}
/* Add 'implicit': <flag>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"implicit", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, (yaml_char_t *)YAML_BOOL_TAG,
(yaml_char_t *)(input_event.data.sequence_start.implicit ?
"true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
/* Display the style information. */
if (input_event.data.sequence_start.style)
{
yaml_sequence_style_t style
= input_event.data.sequence_start.style;
/* Add 'style': <style>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"style", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)(style == YAML_BLOCK_SEQUENCE_STYLE ? "block" :
style == YAML_FLOW_SEQUENCE_STYLE ? "flow" :
"unknown"), -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
}
break;
case YAML_SEQUENCE_END_EVENT:
/* Add 'type': 'SEQUENCE-END'. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"type", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"SEQUENCE-END", -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
break;
case YAML_MAPPING_START_EVENT:
/* Add 'type': 'MAPPING-START'. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"type", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"MAPPING-START", -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
/* Add 'anchor': <anchor>. */
if (input_event.data.mapping_start.anchor)
{
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"anchor", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
input_event.data.mapping_start.anchor, -1,
YAML_DOUBLE_QUOTED_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
}
/* Add 'tag': <tag>. */
if (input_event.data.mapping_start.tag)
{
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"tag", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
input_event.data.mapping_start.tag, -1,
YAML_DOUBLE_QUOTED_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
}
/* Add 'implicit': <flag>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"implicit", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, (yaml_char_t *)YAML_BOOL_TAG,
(yaml_char_t *)(input_event.data.mapping_start.implicit ?
"true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
/* Display the style information. */
if (input_event.data.mapping_start.style)
{
yaml_mapping_style_t style
= input_event.data.mapping_start.style;
/* Add 'style': <style>. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"style", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)(style == YAML_BLOCK_MAPPING_STYLE ? "block" :
style == YAML_FLOW_MAPPING_STYLE ? "flow" :
"unknown"), -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
}
break;
case YAML_MAPPING_END_EVENT:
/* Add 'type': 'MAPPING-END'. */
key = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"type", -1, YAML_PLAIN_SCALAR_STYLE);
if (!key) goto document_error;
value = yaml_document_add_scalar(&output_document, NULL,
(yaml_char_t *)"MAPPING-END", -1, YAML_PLAIN_SCALAR_STYLE);
if (!value) goto document_error;
if (!yaml_document_append_mapping_pair(&output_document,
properties, key, value)) goto document_error;
break;
default:
/* It couldn't really happen. */
break;
}
/* Delete the event object. */
yaml_event_delete(&input_event);
}
if (!yaml_emitter_dump(&emitter, &output_document))
goto emitter_error;
if (!yaml_emitter_close(&emitter))
goto emitter_error;
yaml_parser_delete(&parser);
yaml_emitter_delete(&emitter);
return 0;
parser_error:
/* Display a parser error message. */
switch (parser.error)
{
case YAML_MEMORY_ERROR:
fprintf(stderr, "Memory error: Not enough memory for parsing\n");
break;
case YAML_READER_ERROR:
if (parser.problem_value != -1) {
fprintf(stderr, "Reader error: %s: #%X at %zd\n", parser.problem,
parser.problem_value, parser.problem_offset);
}
else {
fprintf(stderr, "Reader error: %s at %zd\n", parser.problem,
parser.problem_offset);
}
break;
case YAML_SCANNER_ERROR:
if (parser.context) {
fprintf(stderr, "Scanner error: %s at line %lu, column %lu\n"
"%s at line %lu, column %lu\n", parser.context,
parser.context_mark.line+1, parser.context_mark.column+1,
parser.problem, parser.problem_mark.line+1,
parser.problem_mark.column+1);
}
else {
fprintf(stderr, "Scanner error: %s at line %lu, column %lu\n",
parser.problem, parser.problem_mark.line+1,
parser.problem_mark.column+1);
}
break;
case YAML_PARSER_ERROR:
if (parser.context) {
fprintf(stderr, "Parser error: %s at line %lu, column %lu\n"
"%s at line %lu, column %lu\n", parser.context,
parser.context_mark.line+1, parser.context_mark.column+1,
parser.problem, parser.problem_mark.line+1,
parser.problem_mark.column+1);
}
else {
fprintf(stderr, "Parser error: %s at line %lu, column %lu\n",
parser.problem, parser.problem_mark.line+1,
parser.problem_mark.column+1);
}
break;
default:
/* Couldn't happen. */
fprintf(stderr, "Internal error\n");
break;
}
yaml_event_delete(&input_event);
yaml_document_delete(&output_document);
yaml_parser_delete(&parser);
yaml_emitter_delete(&emitter);
return 1;
emitter_error:
/* Display an emitter error message. */
switch (emitter.error)
{
case YAML_MEMORY_ERROR:
fprintf(stderr, "Memory error: Not enough memory for emitting\n");
break;
case YAML_WRITER_ERROR:
fprintf(stderr, "Writer error: %s\n", emitter.problem);
break;
case YAML_EMITTER_ERROR:
fprintf(stderr, "Emitter error: %s\n", emitter.problem);
break;
default:
/* Couldn't happen. */
fprintf(stderr, "Internal error\n");
break;
}
yaml_event_delete(&input_event);
yaml_document_delete(&output_document);
yaml_parser_delete(&parser);
yaml_emitter_delete(&emitter);
return 1;
document_error:
fprintf(stderr, "Memory error: Not enough memory for creating a document\n");
yaml_event_delete(&input_event);
yaml_document_delete(&output_document);
yaml_parser_delete(&parser);
yaml_emitter_delete(&emitter);
return 1;
}

1127
deps/libyaml/tests/example-deconstructor.c vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,217 @@
#include <yaml.h>
#include <stdlib.h>
#include <stdio.h>
int
main(int argc, char *argv[])
{
int help = 0;
int canonical = 0;
int unicode = 0;
int k;
int done = 0;
yaml_parser_t parser;
yaml_emitter_t emitter;
yaml_document_t document;
/* Clear the objects. */
memset(&parser, 0, sizeof(parser));
memset(&emitter, 0, sizeof(emitter));
memset(&document, 0, sizeof(document));
/* Analyze command line options. */
for (k = 1; k < argc; k ++)
{
if (strcmp(argv[k], "-h") == 0
|| strcmp(argv[k], "--help") == 0) {
help = 1;
}
else if (strcmp(argv[k], "-c") == 0
|| strcmp(argv[k], "--canonical") == 0) {
canonical = 1;
}
else if (strcmp(argv[k], "-u") == 0
|| strcmp(argv[k], "--unicode") == 0) {
unicode = 1;
}
else {
fprintf(stderr, "Unrecognized option: %s\n"
"Try `%s --help` for more information.\n",
argv[k], argv[0]);
return 1;
}
}
/* Display the help string. */
if (help)
{
printf("%s [--canonical] [--unicode] <input >output\n"
"or\n%s -h | --help\nReformat a YAML stream\n\nOptions:\n"
"-h, --help\t\tdisplay this help and exit\n"
"-c, --canonical\t\toutput in the canonical YAML format\n"
"-u, --unicode\t\toutput unescaped non-ASCII characters\n",
argv[0], argv[0]);
return 0;
}
/* Initialize the parser and emitter objects. */
if (!yaml_parser_initialize(&parser))
goto parser_error;
if (!yaml_emitter_initialize(&emitter))
goto emitter_error;
/* Set the parser parameters. */
yaml_parser_set_input_file(&parser, stdin);
/* Set the emitter parameters. */
yaml_emitter_set_output_file(&emitter, stdout);
yaml_emitter_set_canonical(&emitter, canonical);
yaml_emitter_set_unicode(&emitter, unicode);
/* The main loop. */
while (!done)
{
/* Get the next event. */
if (!yaml_parser_load(&parser, &document))
goto parser_error;
/* Check if this is the stream end. */
if (!yaml_document_get_root_node(&document)) {
done = 1;
}
/* Emit the event. */
if (!yaml_emitter_dump(&emitter, &document))
goto emitter_error;
}
yaml_parser_delete(&parser);
yaml_emitter_delete(&emitter);
return 0;
parser_error:
/* Display a parser error message. */
switch (parser.error)
{
case YAML_MEMORY_ERROR:
fprintf(stderr, "Memory error: Not enough memory for parsing\n");
break;
case YAML_READER_ERROR:
if (parser.problem_value != -1) {
fprintf(stderr, "Reader error: %s: #%X at %zd\n", parser.problem,
parser.problem_value, parser.problem_offset);
}
else {
fprintf(stderr, "Reader error: %s at %lu\n", parser.problem,
parser.problem_offset);
}
break;
case YAML_SCANNER_ERROR:
if (parser.context) {
fprintf(stderr, "Scanner error: %s at line %lu, column %lu\n"
"%s at line %lu, column %lu\n", parser.context,
parser.context_mark.line+1, parser.context_mark.column+1,
parser.problem, parser.problem_mark.line+1,
parser.problem_mark.column+1);
}
else {
fprintf(stderr, "Scanner error: %s at line %lu, column %lu\n",
parser.problem, parser.problem_mark.line+1,
parser.problem_mark.column+1);
}
break;
case YAML_PARSER_ERROR:
if (parser.context) {
fprintf(stderr, "Parser error: %s at line %lu, column %lu\n"
"%s at line %lu, column %lu\n", parser.context,
parser.context_mark.line+1, parser.context_mark.column+1,
parser.problem, parser.problem_mark.line+1,
parser.problem_mark.column+1);
}
else {
fprintf(stderr, "Parser error: %s at line %lu, column %lu\n",
parser.problem, parser.problem_mark.line+1,
parser.problem_mark.column+1);
}
break;
case YAML_COMPOSER_ERROR:
if (parser.context) {
fprintf(stderr, "Composer error: %s at line %lu, column %lu\n"
"%s at line %lu, column %lu\n", parser.context,
parser.context_mark.line+1, parser.context_mark.column+1,
parser.problem, parser.problem_mark.line+1,
parser.problem_mark.column+1);
}
else {
fprintf(stderr, "Composer error: %s at line %lu, column %lu\n",
parser.problem, parser.problem_mark.line+1,
parser.problem_mark.column+1);
}
break;
default:
/* Couldn't happen. */
fprintf(stderr, "Internal error\n");
break;
}
yaml_parser_delete(&parser);
yaml_emitter_delete(&emitter);
return 1;
emitter_error:
/* Display an emitter error message. */
switch (emitter.error)
{
case YAML_MEMORY_ERROR:
fprintf(stderr, "Memory error: Not enough memory for emitting\n");
break;
case YAML_WRITER_ERROR:
fprintf(stderr, "Writer error: %s\n", emitter.problem);
break;
case YAML_EMITTER_ERROR:
fprintf(stderr, "Emitter error: %s\n", emitter.problem);
break;
default:
/* Couldn't happen. */
fprintf(stderr, "Internal error\n");
break;
}
yaml_parser_delete(&parser);
yaml_emitter_delete(&emitter);
return 1;
}

202
deps/libyaml/tests/example-reformatter.c vendored Normal file
View File

@@ -0,0 +1,202 @@
#include <yaml.h>
#include <stdlib.h>
#include <stdio.h>
int
main(int argc, char *argv[])
{
int help = 0;
int canonical = 0;
int unicode = 0;
int k;
int done = 0;
yaml_parser_t parser;
yaml_emitter_t emitter;
yaml_event_t event;
/* Clear the objects. */
memset(&parser, 0, sizeof(parser));
memset(&emitter, 0, sizeof(emitter));
memset(&event, 0, sizeof(event));
/* Analyze command line options. */
for (k = 1; k < argc; k ++)
{
if (strcmp(argv[k], "-h") == 0
|| strcmp(argv[k], "--help") == 0) {
help = 1;
}
else if (strcmp(argv[k], "-c") == 0
|| strcmp(argv[k], "--canonical") == 0) {
canonical = 1;
}
else if (strcmp(argv[k], "-u") == 0
|| strcmp(argv[k], "--unicode") == 0) {
unicode = 1;
}
else {
fprintf(stderr, "Unrecognized option: %s\n"
"Try `%s --help` for more information.\n",
argv[k], argv[0]);
return 1;
}
}
/* Display the help string. */
if (help)
{
printf("%s [--canonical] [--unicode] <input >output\n"
"or\n%s -h | --help\nReformat a YAML stream\n\nOptions:\n"
"-h, --help\t\tdisplay this help and exit\n"
"-c, --canonical\t\toutput in the canonical YAML format\n"
"-u, --unicode\t\toutput unescaped non-ASCII characters\n",
argv[0], argv[0]);
return 0;
}
/* Initialize the parser and emitter objects. */
if (!yaml_parser_initialize(&parser))
goto parser_error;
if (!yaml_emitter_initialize(&emitter))
goto emitter_error;
/* Set the parser parameters. */
yaml_parser_set_input_file(&parser, stdin);
/* Set the emitter parameters. */
yaml_emitter_set_output_file(&emitter, stdout);
yaml_emitter_set_canonical(&emitter, canonical);
yaml_emitter_set_unicode(&emitter, unicode);
/* The main loop. */
while (!done)
{
/* Get the next event. */
if (!yaml_parser_parse(&parser, &event))
goto parser_error;
/* Check if this is the stream end. */
if (event.type == YAML_STREAM_END_EVENT) {
done = 1;
}
/* Emit the event. */
if (!yaml_emitter_emit(&emitter, &event))
goto emitter_error;
}
yaml_parser_delete(&parser);
yaml_emitter_delete(&emitter);
return 0;
parser_error:
/* Display a parser error message. */
switch (parser.error)
{
case YAML_MEMORY_ERROR:
fprintf(stderr, "Memory error: Not enough memory for parsing\n");
break;
case YAML_READER_ERROR:
if (parser.problem_value != -1) {
fprintf(stderr, "Reader error: %s: #%X at %ld\n", parser.problem,
parser.problem_value, (long)parser.problem_offset);
}
else {
fprintf(stderr, "Reader error: %s at %ld\n", parser.problem,
(long)parser.problem_offset);
}
break;
case YAML_SCANNER_ERROR:
if (parser.context) {
fprintf(stderr, "Scanner error: %s at line %d, column %d\n"
"%s at line %d, column %d\n", parser.context,
(int)parser.context_mark.line+1, (int)parser.context_mark.column+1,
parser.problem, (int)parser.problem_mark.line+1,
(int)parser.problem_mark.column+1);
}
else {
fprintf(stderr, "Scanner error: %s at line %d, column %d\n",
parser.problem, (int)parser.problem_mark.line+1,
(int)parser.problem_mark.column+1);
}
break;
case YAML_PARSER_ERROR:
if (parser.context) {
fprintf(stderr, "Parser error: %s at line %d, column %d\n"
"%s at line %d, column %d\n", parser.context,
(int)parser.context_mark.line+1, (int)parser.context_mark.column+1,
parser.problem, (int)parser.problem_mark.line+1,
(int)parser.problem_mark.column+1);
}
else {
fprintf(stderr, "Parser error: %s at line %d, column %d\n",
parser.problem, (int)parser.problem_mark.line+1,
(int)parser.problem_mark.column+1);
}
break;
default:
/* Couldn't happen. */
fprintf(stderr, "Internal error\n");
break;
}
yaml_parser_delete(&parser);
yaml_emitter_delete(&emitter);
return 1;
emitter_error:
/* Display an emitter error message. */
switch (emitter.error)
{
case YAML_MEMORY_ERROR:
fprintf(stderr, "Memory error: Not enough memory for emitting\n");
break;
case YAML_WRITER_ERROR:
fprintf(stderr, "Writer error: %s\n", emitter.problem);
break;
case YAML_EMITTER_ERROR:
fprintf(stderr, "Emitter error: %s\n", emitter.problem);
break;
default:
/* Couldn't happen. */
fprintf(stderr, "Internal error\n");
break;
}
yaml_parser_delete(&parser);
yaml_emitter_delete(&emitter);
return 1;
}

29
deps/libyaml/tests/run-all-tests.sh vendored Executable file
View File

@@ -0,0 +1,29 @@
#!/bin/sh
set -e
main() {
# Autoconf based in-source build and tests
clean
./bootstrap
./configure
make test-all
# CMake based in-source build and tests
clean
cmake .
make
make test
clean
}
clean() {
git clean -d -x -f
rm -fr tests/run-test-suite
git worktree prune
}
main "$@"

314
deps/libyaml/tests/run-dumper.c vendored Normal file
View File

@@ -0,0 +1,314 @@
#include <yaml.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef NDEBUG
#undef NDEBUG
#endif
#include <assert.h>
#define BUFFER_SIZE 65536
#define MAX_DOCUMENTS 16
int copy_document(yaml_document_t *document_to, yaml_document_t *document_from)
{
yaml_node_t *node;
yaml_node_item_t *item;
yaml_node_pair_t *pair;
if (!yaml_document_initialize(document_to, document_from->version_directive,
document_from->tag_directives.start,
document_from->tag_directives.end,
document_from->start_implicit, document_from->end_implicit))
return 0;
for (node = document_from->nodes.start;
node < document_from->nodes.top; node ++) {
switch (node->type) {
case YAML_SCALAR_NODE:
if (!yaml_document_add_scalar(document_to, node->tag,
node->data.scalar.value, node->data.scalar.length,
node->data.scalar.style)) goto error;
break;
case YAML_SEQUENCE_NODE:
if (!yaml_document_add_sequence(document_to, node->tag,
node->data.sequence.style)) goto error;
break;
case YAML_MAPPING_NODE:
if (!yaml_document_add_mapping(document_to, node->tag,
node->data.mapping.style)) goto error;
break;
default:
assert(0);
break;
}
}
for (node = document_from->nodes.start;
node < document_from->nodes.top; node ++) {
switch (node->type) {
case YAML_SEQUENCE_NODE:
for (item = node->data.sequence.items.start;
item < node->data.sequence.items.top; item ++) {
if (!yaml_document_append_sequence_item(document_to,
node - document_from->nodes.start + 1,
*item)) goto error;
}
break;
case YAML_MAPPING_NODE:
for (pair = node->data.mapping.pairs.start;
pair < node->data.mapping.pairs.top; pair ++) {
if (!yaml_document_append_mapping_pair(document_to,
node - document_from->nodes.start + 1,
pair->key, pair->value)) goto error;
}
break;
default:
break;
}
}
return 1;
error:
yaml_document_delete(document_to);
return 0;
}
int compare_nodes(yaml_document_t *document1, int index1,
yaml_document_t *document2, int index2, int level)
{
int k;
yaml_node_t *node1;
yaml_node_t *node2;
if (level++ > 1000) return 0;
node1 = yaml_document_get_node(document1, index1);
node2 = yaml_document_get_node(document2, index2);
assert(node1);
assert(node2);
if (node1->type != node2->type)
return 0;
if (strcmp((char *)node1->tag, (char *)node2->tag) != 0) return 0;
switch (node1->type) {
case YAML_SCALAR_NODE:
if (node1->data.scalar.length != node2->data.scalar.length)
return 0;
if (strncmp((char *)node1->data.scalar.value, (char *)node2->data.scalar.value,
node1->data.scalar.length) != 0) return 0;
break;
case YAML_SEQUENCE_NODE:
if ((node1->data.sequence.items.top - node1->data.sequence.items.start) !=
(node2->data.sequence.items.top - node2->data.sequence.items.start))
return 0;
for (k = 0; k < (node1->data.sequence.items.top - node1->data.sequence.items.start); k ++) {
if (!compare_nodes(document1, node1->data.sequence.items.start[k],
document2, node2->data.sequence.items.start[k], level)) return 0;
}
break;
case YAML_MAPPING_NODE:
if ((node1->data.mapping.pairs.top - node1->data.mapping.pairs.start) !=
(node2->data.mapping.pairs.top - node2->data.mapping.pairs.start))
return 0;
for (k = 0; k < (node1->data.mapping.pairs.top - node1->data.mapping.pairs.start); k ++) {
if (!compare_nodes(document1, node1->data.mapping.pairs.start[k].key,
document2, node2->data.mapping.pairs.start[k].key, level)) return 0;
if (!compare_nodes(document1, node1->data.mapping.pairs.start[k].value,
document2, node2->data.mapping.pairs.start[k].value, level)) return 0;
}
break;
default:
assert(0);
break;
}
return 1;
}
int compare_documents(yaml_document_t *document1, yaml_document_t *document2)
{
int k;
if ((document1->version_directive && !document2->version_directive)
|| (!document1->version_directive && document2->version_directive)
|| (document1->version_directive && document2->version_directive
&& (document1->version_directive->major != document2->version_directive->major
|| document1->version_directive->minor != document2->version_directive->minor)))
return 0;
if ((document1->tag_directives.end - document1->tag_directives.start) !=
(document2->tag_directives.end - document2->tag_directives.start))
return 0;
for (k = 0; k < (document1->tag_directives.end - document1->tag_directives.start); k ++) {
if ((strcmp((char *)document1->tag_directives.start[k].handle,
(char *)document2->tag_directives.start[k].handle) != 0)
|| (strcmp((char *)document1->tag_directives.start[k].prefix,
(char *)document2->tag_directives.start[k].prefix) != 0))
return 0;
}
if ((document1->nodes.top - document1->nodes.start) !=
(document2->nodes.top - document2->nodes.start))
return 0;
if (document1->nodes.top != document1->nodes.start) {
if (!compare_nodes(document1, 1, document2, 1, 0))
return 0;
}
return 1;
}
int print_output(char *name, unsigned char *buffer, size_t size, int count)
{
FILE *file;
char data[BUFFER_SIZE];
size_t data_size = 1;
size_t total_size = 0;
if (count >= 0) {
printf("FAILED (at the document #%d)\nSOURCE:\n", count+1);
}
file = fopen(name, "rb");
assert(file);
while (data_size > 0) {
data_size = fread(data, 1, BUFFER_SIZE, file);
assert(!ferror(file));
if (!data_size) break;
assert(fwrite(data, 1, data_size, stdout) == data_size);
total_size += data_size;
if (feof(file)) break;
}
fclose(file);
printf("#### (length: %ld)\n", (long)total_size);
printf("OUTPUT:\n%s#### (length: %ld)\n", buffer, (long)size);
return 0;
}
int
main(int argc, char *argv[])
{
int number;
int canonical = 0;
int unicode = 0;
number = 1;
while (number < argc) {
if (strcmp(argv[number], "-c") == 0) {
canonical = 1;
}
else if (strcmp(argv[number], "-u") == 0) {
unicode = 1;
}
else if (argv[number][0] == '-') {
printf("Unknown option: '%s'\n", argv[number]);
return 0;
}
if (argv[number][0] == '-') {
if (number < argc-1) {
memmove(argv+number, argv+number+1, (argc-number-1)*sizeof(char *));
}
argc --;
}
else {
number ++;
}
}
if (argc < 2) {
printf("Usage: %s [-c] [-u] file1.yaml ...\n", argv[0]);
return 0;
}
for (number = 1; number < argc; number ++)
{
FILE *file;
yaml_parser_t parser;
yaml_emitter_t emitter;
yaml_document_t document;
unsigned char buffer[BUFFER_SIZE+1];
size_t written = 0;
yaml_document_t documents[MAX_DOCUMENTS];
size_t document_number = 0;
int done = 0;
int count = 0;
int error = 0;
int k;
memset(buffer, 0, BUFFER_SIZE+1);
memset(documents, 0, MAX_DOCUMENTS*sizeof(yaml_document_t));
printf("[%d] Loading, dumping, and loading again '%s': ", number, argv[number]);
fflush(stdout);
file = fopen(argv[number], "rb");
assert(file);
assert(yaml_parser_initialize(&parser));
yaml_parser_set_input_file(&parser, file);
assert(yaml_emitter_initialize(&emitter));
if (canonical) {
yaml_emitter_set_canonical(&emitter, 1);
}
if (unicode) {
yaml_emitter_set_unicode(&emitter, 1);
}
yaml_emitter_set_output_string(&emitter, buffer, BUFFER_SIZE, &written);
yaml_emitter_open(&emitter);
while (!done)
{
if (!yaml_parser_load(&parser, &document)) {
error = 1;
break;
}
done = (!yaml_document_get_root_node(&document));
if (!done) {
assert(document_number < MAX_DOCUMENTS);
assert(copy_document(&(documents[document_number++]), &document));
assert(yaml_emitter_dump(&emitter, &document) ||
(yaml_emitter_flush(&emitter) && print_output(argv[number], buffer, written, count)));
count ++;
}
else {
yaml_document_delete(&document);
}
}
yaml_parser_delete(&parser);
assert(!fclose(file));
yaml_emitter_close(&emitter);
yaml_emitter_delete(&emitter);
if (!error)
{
count = done = 0;
assert(yaml_parser_initialize(&parser));
yaml_parser_set_input_string(&parser, buffer, written);
while (!done)
{
assert(yaml_parser_load(&parser, &document) || print_output(argv[number], buffer, written, count));
done = (!yaml_document_get_root_node(&document));
if (!done) {
assert(compare_documents(documents+count, &document) || print_output(argv[number], buffer, written, count));
count ++;
}
yaml_document_delete(&document);
}
yaml_parser_delete(&parser);
}
for (k = 0; k < document_number; k ++) {
yaml_document_delete(documents+k);
}
printf("PASSED (length: %ld)\n", (long)written);
print_output(argv[number], buffer, written, -1);
}
return 0;
}

View File

@@ -0,0 +1,290 @@
#include <yaml.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "../src/yaml_private.h"
int get_line(FILE * input, char *line);
char *get_anchor(char sigil, char *line, char *anchor);
char *get_tag(char *line, char *tag);
void get_value(char *line, char *value, int *style);
int usage(int ret);
int main(int argc, char *argv[])
{
FILE *input;
yaml_emitter_t emitter;
yaml_event_t event;
yaml_version_directive_t *version_directive = NULL;
int canonical = 0;
int unicode = 0;
char line[1024];
int foundfile = 0;
int i = 0;
int minor = 0;
int flow = -1; /** default no flow style collections */
for (i = 1; i < argc; i++) {
if (strncmp(argv[i], "--help", 6) == 0)
return usage(0);
if (strncmp(argv[i], "-h", 2) == 0)
return usage(0);
if (strncmp(argv[i], "--flow", 6) == 0) {
if (i+1 == argc)
return usage(1);
i++;
if (strncmp(argv[i], "keep", 4) == 0)
flow = 0;
else if (strncmp(argv[i], "on", 2) == 0)
flow = 1;
else if (strncmp(argv[i], "off", 3) == 0)
flow = -1;
else
return usage(1);
}
else if (strncmp(argv[i], "--directive", 11) == 0) {
if (i+1 == argc)
return usage(1);
i++;
if (strncmp(argv[i], "1.1", 3) == 0)
minor = 1;
else if (strncmp(argv[i], "1.2", 3) == 0)
minor = 2;
else
return usage(1);
}
else if (!foundfile) {
input = fopen(argv[i], "rb");
foundfile = 1;
}
}
if (minor) {
version_directive = YAML_MALLOC_STATIC(yaml_version_directive_t);
version_directive->major = 1;
version_directive->minor = minor;
}
if (!foundfile)
input = stdin;
assert(input);
if (!yaml_emitter_initialize(&emitter)) {
fprintf(stderr, "Could not initalize the emitter object\n");
return 1;
}
yaml_emitter_set_output_file(&emitter, stdout);
yaml_emitter_set_canonical(&emitter, canonical);
yaml_emitter_set_unicode(&emitter, unicode);
while (get_line(input, line)) {
int ok;
char anchor[256];
char tag[256];
int implicit;
int style;
if (strncmp(line, "+STR", 4) == 0) {
ok = yaml_stream_start_event_initialize(&event, YAML_UTF8_ENCODING);
}
else if (strncmp(line, "-STR", 4) == 0) {
ok = yaml_stream_end_event_initialize(&event);
}
else if (strncmp(line, "+DOC", 4) == 0) {
implicit = strncmp(line+4, " ---", 4) != 0;
ok = yaml_document_start_event_initialize(&event, version_directive, NULL, NULL, implicit);
}
else if (strncmp(line, "-DOC", 4) == 0) {
implicit = strncmp(line+4, " ...", 4) != 0;
ok = yaml_document_end_event_initialize(&event, implicit);
}
else if (strncmp(line, "+MAP", 4) == 0) {
style = YAML_BLOCK_MAPPING_STYLE;
if (flow == 1)
style = YAML_FLOW_MAPPING_STYLE;
else if (flow == 0 && strncmp(line+5, "{}", 2) == 0)
style = YAML_FLOW_MAPPING_STYLE;
ok = yaml_mapping_start_event_initialize(&event, (yaml_char_t *)
get_anchor('&', line, anchor), (yaml_char_t *)
get_tag(line, tag), 0, style);
}
else if (strncmp(line, "-MAP", 4) == 0) {
ok = yaml_mapping_end_event_initialize(&event);
}
else if (strncmp(line, "+SEQ", 4) == 0) {
style = YAML_BLOCK_SEQUENCE_STYLE;
if (flow == 1)
style = YAML_FLOW_MAPPING_STYLE;
else if (flow == 0 && strncmp(line+5, "[]", 2) == 0)
style = YAML_FLOW_SEQUENCE_STYLE;
ok = yaml_sequence_start_event_initialize(&event, (yaml_char_t *)
get_anchor('&', line, anchor), (yaml_char_t *)
get_tag(line, tag), 0, style);
}
else if (strncmp(line, "-SEQ", 4) == 0) {
ok = yaml_sequence_end_event_initialize(&event);
}
else if (strncmp(line, "=VAL", 4) == 0) {
char value[1024];
int style;
get_value(line, value, &style);
implicit = (get_tag(line, tag) == NULL);
ok = yaml_scalar_event_initialize(&event, (yaml_char_t *)
get_anchor('&', line, anchor), (yaml_char_t *) get_tag(line, tag), (yaml_char_t *) value, -1, implicit, implicit, style);
}
else if (strncmp(line, "=ALI", 4) == 0) {
ok = yaml_alias_event_initialize(&event, (yaml_char_t *)
get_anchor('*', line, anchor)
);
}
else {
fprintf(stderr, "Unknown event: '%s'\n", line);
fflush(stdout);
return 1;
}
if (!ok)
goto event_error;
if (!yaml_emitter_emit(&emitter, &event))
goto emitter_error;
}
assert(!fclose(input));
yaml_emitter_delete(&emitter);
fflush(stdout);
return 0;
emitter_error:
switch (emitter.error) {
case YAML_MEMORY_ERROR:
fprintf(stderr, "Memory error: Not enough memory for emitting\n");
break;
case YAML_WRITER_ERROR:
fprintf(stderr, "Writer error: %s\n", emitter.problem);
break;
case YAML_EMITTER_ERROR:
fprintf(stderr, "Emitter error: %s\n", emitter.problem);
break;
default:
/*
* Couldn't happen.
*/
fprintf(stderr, "Internal error\n");
break;
}
yaml_emitter_delete(&emitter);
return 1;
event_error:
fprintf(stderr, "Memory error: Not enough memory for creating an event\n");
yaml_emitter_delete(&emitter);
return 1;
}
int get_line(FILE * input, char *line)
{
char *newline;
if (!fgets(line, 1024 - 1, input))
return 0;
if ((newline = strchr(line, '\n')) == NULL) {
fprintf(stderr, "Line too long: '%s'", line);
abort();
}
*newline = '\0';
return 1;
}
char *get_anchor(char sigil, char *line, char *anchor)
{
char *start;
char *end;
if ((start = strchr(line, sigil)) == NULL)
return NULL;
start++;
if ((end = strchr(start, ' ')) == NULL)
end = line + strlen(line);
memcpy(anchor, start, end - start);
anchor[end - start] = '\0';
return anchor;
}
char *get_tag(char *line, char *tag)
{
char *start;
char *end;
if ((start = strchr(line, '<')) == NULL)
return NULL;
if ((end = strchr(line, '>')) == NULL)
return NULL;
memcpy(tag, start + 1, end - start - 1);
tag[end - start - 1] = '\0';
return tag;
}
void get_value(char *line, char *value, int *style)
{
int i = 0;
char *c;
char *start = NULL;
char *end = line + strlen(line);
for (c = line + 4; c < end; c++) {
if (*c == ' ') {
start = c + 1;
if (*start == ':')
*style = YAML_PLAIN_SCALAR_STYLE;
else if (*start == '\'')
*style = YAML_SINGLE_QUOTED_SCALAR_STYLE;
else if (*start == '"')
*style = YAML_DOUBLE_QUOTED_SCALAR_STYLE;
else if (*start == '|')
*style = YAML_LITERAL_SCALAR_STYLE;
else if (*start == '>')
*style = YAML_FOLDED_SCALAR_STYLE;
else {
start = NULL;
continue;
}
start++;
break;
}
}
if (!start)
abort();
for (c = start; c < end; c++) {
if (*c == '\\') {
if (*++c == '\\')
value[i++] = '\\';
else if (*c == '0')
value[i++] = '\0';
else if (*c == 'b')
value[i++] = '\b';
else if (*c == 'n')
value[i++] = '\n';
else if (*c == 'r')
value[i++] = '\r';
else if (*c == 't')
value[i++] = '\t';
else
abort();
}
else
value[i++] = *c;
}
value[i] = '\0';
}
int usage(int ret) {
fprintf(stderr, "Usage: run-emitter-test-suite [--directive (1.1|1.2)] [--flow (on|off|keep)] [<input-file>]\n");
return ret;
}

327
deps/libyaml/tests/run-emitter.c vendored Normal file
View File

@@ -0,0 +1,327 @@
#include <yaml.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef NDEBUG
#undef NDEBUG
#endif
#include <assert.h>
#define BUFFER_SIZE 65536
#define MAX_EVENTS 1024
int copy_event(yaml_event_t *event_to, yaml_event_t *event_from)
{
switch (event_from->type)
{
case YAML_STREAM_START_EVENT:
return yaml_stream_start_event_initialize(event_to,
event_from->data.stream_start.encoding);
case YAML_STREAM_END_EVENT:
return yaml_stream_end_event_initialize(event_to);
case YAML_DOCUMENT_START_EVENT:
return yaml_document_start_event_initialize(event_to,
event_from->data.document_start.version_directive,
event_from->data.document_start.tag_directives.start,
event_from->data.document_start.tag_directives.end,
event_from->data.document_start.implicit);
case YAML_DOCUMENT_END_EVENT:
return yaml_document_end_event_initialize(event_to,
event_from->data.document_end.implicit);
case YAML_ALIAS_EVENT:
return yaml_alias_event_initialize(event_to,
event_from->data.alias.anchor);
case YAML_SCALAR_EVENT:
return yaml_scalar_event_initialize(event_to,
event_from->data.scalar.anchor,
event_from->data.scalar.tag,
event_from->data.scalar.value,
event_from->data.scalar.length,
event_from->data.scalar.plain_implicit,
event_from->data.scalar.quoted_implicit,
event_from->data.scalar.style);
case YAML_SEQUENCE_START_EVENT:
return yaml_sequence_start_event_initialize(event_to,
event_from->data.sequence_start.anchor,
event_from->data.sequence_start.tag,
event_from->data.sequence_start.implicit,
event_from->data.sequence_start.style);
case YAML_SEQUENCE_END_EVENT:
return yaml_sequence_end_event_initialize(event_to);
case YAML_MAPPING_START_EVENT:
return yaml_mapping_start_event_initialize(event_to,
event_from->data.mapping_start.anchor,
event_from->data.mapping_start.tag,
event_from->data.mapping_start.implicit,
event_from->data.mapping_start.style);
case YAML_MAPPING_END_EVENT:
return yaml_mapping_end_event_initialize(event_to);
default:
assert(1);
}
return 0;
}
int compare_events(yaml_event_t *event1, yaml_event_t *event2)
{
int k;
if (event1->type != event2->type)
return 0;
switch (event1->type)
{
case YAML_STREAM_START_EVENT:
return 1;
/* return (event1->data.stream_start.encoding ==
event2->data.stream_start.encoding); */
case YAML_DOCUMENT_START_EVENT:
if ((event1->data.document_start.version_directive && !event2->data.document_start.version_directive)
|| (!event1->data.document_start.version_directive && event2->data.document_start.version_directive)
|| (event1->data.document_start.version_directive && event2->data.document_start.version_directive
&& (event1->data.document_start.version_directive->major != event2->data.document_start.version_directive->major
|| event1->data.document_start.version_directive->minor != event2->data.document_start.version_directive->minor)))
return 0;
if ((event1->data.document_start.tag_directives.end - event1->data.document_start.tag_directives.start) !=
(event2->data.document_start.tag_directives.end - event2->data.document_start.tag_directives.start))
return 0;
for (k = 0; k < (event1->data.document_start.tag_directives.end - event1->data.document_start.tag_directives.start); k ++) {
if ((strcmp((char *)event1->data.document_start.tag_directives.start[k].handle,
(char *)event2->data.document_start.tag_directives.start[k].handle) != 0)
|| (strcmp((char *)event1->data.document_start.tag_directives.start[k].prefix,
(char *)event2->data.document_start.tag_directives.start[k].prefix) != 0))
return 0;
}
/* if (event1->data.document_start.implicit != event2->data.document_start.implicit)
return 0; */
return 1;
case YAML_DOCUMENT_END_EVENT:
return 1;
/* return (event1->data.document_end.implicit ==
event2->data.document_end.implicit); */
case YAML_ALIAS_EVENT:
return (strcmp((char *)event1->data.alias.anchor,
(char *)event2->data.alias.anchor) == 0);
case YAML_SCALAR_EVENT:
if ((event1->data.scalar.anchor && !event2->data.scalar.anchor)
|| (!event1->data.scalar.anchor && event2->data.scalar.anchor)
|| (event1->data.scalar.anchor && event2->data.scalar.anchor
&& strcmp((char *)event1->data.scalar.anchor,
(char *)event2->data.scalar.anchor) != 0))
return 0;
if ((event1->data.scalar.tag && !event2->data.scalar.tag
&& strcmp((char *)event1->data.scalar.tag, "!") != 0)
|| (!event1->data.scalar.tag && event2->data.scalar.tag
&& strcmp((char *)event2->data.scalar.tag, "!") != 0)
|| (event1->data.scalar.tag && event2->data.scalar.tag
&& strcmp((char *)event1->data.scalar.tag,
(char *)event2->data.scalar.tag) != 0))
return 0;
if ((event1->data.scalar.length != event2->data.scalar.length)
|| memcmp(event1->data.scalar.value, event2->data.scalar.value,
event1->data.scalar.length) != 0)
return 0;
if ((event1->data.scalar.plain_implicit != event2->data.scalar.plain_implicit)
|| (event1->data.scalar.quoted_implicit != event2->data.scalar.quoted_implicit)
/* || (event2->data.scalar.style != event2->data.scalar.style) */)
return 0;
return 1;
case YAML_SEQUENCE_START_EVENT:
if ((event1->data.sequence_start.anchor && !event2->data.sequence_start.anchor)
|| (!event1->data.sequence_start.anchor && event2->data.sequence_start.anchor)
|| (event1->data.sequence_start.anchor && event2->data.sequence_start.anchor
&& strcmp((char *)event1->data.sequence_start.anchor,
(char *)event2->data.sequence_start.anchor) != 0))
return 0;
if ((event1->data.sequence_start.tag && !event2->data.sequence_start.tag)
|| (!event1->data.sequence_start.tag && event2->data.sequence_start.tag)
|| (event1->data.sequence_start.tag && event2->data.sequence_start.tag
&& strcmp((char *)event1->data.sequence_start.tag,
(char *)event2->data.sequence_start.tag) != 0))
return 0;
if ((event1->data.sequence_start.implicit != event2->data.sequence_start.implicit)
/* || (event2->data.sequence_start.style != event2->data.sequence_start.style) */)
return 0;
return 1;
case YAML_MAPPING_START_EVENT:
if ((event1->data.mapping_start.anchor && !event2->data.mapping_start.anchor)
|| (!event1->data.mapping_start.anchor && event2->data.mapping_start.anchor)
|| (event1->data.mapping_start.anchor && event2->data.mapping_start.anchor
&& strcmp((char *)event1->data.mapping_start.anchor,
(char *)event2->data.mapping_start.anchor) != 0))
return 0;
if ((event1->data.mapping_start.tag && !event2->data.mapping_start.tag)
|| (!event1->data.mapping_start.tag && event2->data.mapping_start.tag)
|| (event1->data.mapping_start.tag && event2->data.mapping_start.tag
&& strcmp((char *)event1->data.mapping_start.tag,
(char *)event2->data.mapping_start.tag) != 0))
return 0;
if ((event1->data.mapping_start.implicit != event2->data.mapping_start.implicit)
/* || (event2->data.mapping_start.style != event2->data.mapping_start.style) */)
return 0;
return 1;
default:
return 1;
}
}
int print_output(char *name, unsigned char *buffer, size_t size, int count)
{
FILE *file;
char data[BUFFER_SIZE];
size_t data_size = 1;
size_t total_size = 0;
if (count >= 0) {
printf("FAILED (at the event #%d)\nSOURCE:\n", count+1);
}
file = fopen(name, "rb");
assert(file);
while (data_size > 0) {
data_size = fread(data, 1, BUFFER_SIZE, file);
assert(!ferror(file));
if (!data_size) break;
assert(fwrite(data, 1, data_size, stdout) == data_size);
total_size += data_size;
if (feof(file)) break;
}
fclose(file);
printf("#### (length: %ld)\n", (long)total_size);
printf("OUTPUT:\n%s#### (length: %ld)\n", buffer, (long)size);
return 0;
}
int
main(int argc, char *argv[])
{
int number;
int canonical = 0;
int unicode = 0;
number = 1;
while (number < argc) {
if (strcmp(argv[number], "-c") == 0) {
canonical = 1;
}
else if (strcmp(argv[number], "-u") == 0) {
unicode = 1;
}
else if (argv[number][0] == '-') {
printf("Unknown option: '%s'\n", argv[number]);
return 0;
}
if (argv[number][0] == '-') {
if (number < argc-1) {
memmove(argv+number, argv+number+1, (argc-number-1)*sizeof(char *));
}
argc --;
}
else {
number ++;
}
}
if (argc < 2) {
printf("Usage: %s [-c] [-u] file1.yaml ...\n", argv[0]);
return 0;
}
for (number = 1; number < argc; number ++)
{
FILE *file;
yaml_parser_t parser;
yaml_emitter_t emitter;
yaml_event_t event;
unsigned char buffer[BUFFER_SIZE+1];
size_t written = 0;
yaml_event_t events[MAX_EVENTS];
size_t event_number = 0;
int done = 0;
int count = 0;
int error = 0;
int k;
memset(buffer, 0, BUFFER_SIZE+1);
memset(events, 0, MAX_EVENTS*sizeof(yaml_event_t));
printf("[%d] Parsing, emitting, and parsing again '%s': ", number, argv[number]);
fflush(stdout);
file = fopen(argv[number], "rb");
assert(file);
assert(yaml_parser_initialize(&parser));
yaml_parser_set_input_file(&parser, file);
assert(yaml_emitter_initialize(&emitter));
if (canonical) {
yaml_emitter_set_canonical(&emitter, 1);
}
if (unicode) {
yaml_emitter_set_unicode(&emitter, 1);
}
yaml_emitter_set_output_string(&emitter, buffer, BUFFER_SIZE, &written);
while (!done)
{
if (!yaml_parser_parse(&parser, &event)) {
error = 1;
break;
}
done = (event.type == YAML_STREAM_END_EVENT);
assert(event_number < MAX_EVENTS);
assert(copy_event(&(events[event_number++]), &event));
assert(yaml_emitter_emit(&emitter, &event) ||
print_output(argv[number], buffer, written, count));
count ++;
}
yaml_parser_delete(&parser);
assert(!fclose(file));
yaml_emitter_delete(&emitter);
if (!error)
{
count = done = 0;
assert(yaml_parser_initialize(&parser));
yaml_parser_set_input_string(&parser, buffer, written);
while (!done)
{
assert(yaml_parser_parse(&parser, &event) || print_output(argv[number], buffer, written, count));
done = (event.type == YAML_STREAM_END_EVENT);
assert(compare_events(events+count, &event) || print_output(argv[number], buffer, written, count));
yaml_event_delete(&event);
count ++;
}
yaml_parser_delete(&parser);
}
for (k = 0; k < event_number; k ++) {
yaml_event_delete(events+k);
}
printf("PASSED (length: %ld)\n", (long)written);
print_output(argv[number], buffer, written, -1);
}
return 0;
}

63
deps/libyaml/tests/run-loader.c vendored Normal file
View File

@@ -0,0 +1,63 @@
#include <yaml.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef NDEBUG
#undef NDEBUG
#endif
#include <assert.h>
int
main(int argc, char *argv[])
{
int number;
if (argc < 2) {
printf("Usage: %s file1.yaml ...\n", argv[0]);
return 0;
}
for (number = 1; number < argc; number ++)
{
FILE *file;
yaml_parser_t parser;
yaml_document_t document;
int done = 0;
int count = 0;
int error = 0;
printf("[%d] Loading '%s': ", number, argv[number]);
fflush(stdout);
file = fopen(argv[number], "rb");
assert(file);
assert(yaml_parser_initialize(&parser));
yaml_parser_set_input_file(&parser, file);
while (!done)
{
if (!yaml_parser_load(&parser, &document)) {
error = 1;
break;
}
done = (!yaml_document_get_root_node(&document));
yaml_document_delete(&document);
if (!done) count ++;
}
yaml_parser_delete(&parser);
assert(!fclose(file));
printf("%s (%d documents)\n", (error ? "FAILURE" : "SUCCESS"), count);
}
return 0;
}

View File

@@ -0,0 +1,189 @@
#include <yaml.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
void print_escaped(yaml_char_t * str, size_t length);
int usage(int ret);
int main(int argc, char *argv[])
{
FILE *input;
yaml_parser_t parser;
yaml_event_t event;
int flow = -1; /** default no flow style collections */
int i = 0;
int foundfile = 0;
for (i = 1; i < argc; i++) {
if (strncmp(argv[i], "--flow", 6) == 0) {
if (i+1 == argc)
return usage(1);
i++;
if (strncmp(argv[i], "keep", 4) == 0)
flow = 0;
else if (strncmp(argv[i], "on", 2) == 0)
flow = 1;
else if (strncmp(argv[i], "off", 3) == 0)
flow = -1;
else
return usage(1);
}
else if (strncmp(argv[i], "--help", 6) == 0)
return usage(0);
else if (strncmp(argv[i], "-h", 2) == 0)
return usage(0);
else if (!foundfile) {
input = fopen(argv[i], "rb");
foundfile = 1;
}
else
return usage(1);
}
if (!foundfile) {
input = stdin;
}
assert(input);
if (!yaml_parser_initialize(&parser)) {
fprintf(stderr, "Could not initialize the parser object\n");
return 1;
}
yaml_parser_set_input_file(&parser, input);
while (1) {
yaml_event_type_t type;
if (!yaml_parser_parse(&parser, &event)) {
if ( parser.problem_mark.line || parser.problem_mark.column ) {
fprintf(stderr, "Parse error: %s\nLine: %lu Column: %lu\n",
parser.problem,
(unsigned long)parser.problem_mark.line + 1,
(unsigned long)parser.problem_mark.column + 1);
}
else {
fprintf(stderr, "Parse error: %s\n", parser.problem);
}
return 1;
}
type = event.type;
if (type == YAML_NO_EVENT)
printf("???\n");
else if (type == YAML_STREAM_START_EVENT)
printf("+STR\n");
else if (type == YAML_STREAM_END_EVENT)
printf("-STR\n");
else if (type == YAML_DOCUMENT_START_EVENT) {
printf("+DOC");
if (!event.data.document_start.implicit)
printf(" ---");
printf("\n");
}
else if (type == YAML_DOCUMENT_END_EVENT) {
printf("-DOC");
if (!event.data.document_end.implicit)
printf(" ...");
printf("\n");
}
else if (type == YAML_MAPPING_START_EVENT) {
printf("+MAP");
if (flow == 0 && event.data.mapping_start.style == YAML_FLOW_MAPPING_STYLE)
printf(" {}");
else if (flow == 1)
printf(" {}");
if (event.data.mapping_start.anchor)
printf(" &%s", event.data.mapping_start.anchor);
if (event.data.mapping_start.tag)
printf(" <%s>", event.data.mapping_start.tag);
printf("\n");
}
else if (type == YAML_MAPPING_END_EVENT)
printf("-MAP\n");
else if (type == YAML_SEQUENCE_START_EVENT) {
printf("+SEQ");
if (flow == 0 && event.data.sequence_start.style == YAML_FLOW_SEQUENCE_STYLE)
printf(" []");
else if (flow == 1)
printf(" []");
if (event.data.sequence_start.anchor)
printf(" &%s", event.data.sequence_start.anchor);
if (event.data.sequence_start.tag)
printf(" <%s>", event.data.sequence_start.tag);
printf("\n");
}
else if (type == YAML_SEQUENCE_END_EVENT)
printf("-SEQ\n");
else if (type == YAML_SCALAR_EVENT) {
printf("=VAL");
if (event.data.scalar.anchor)
printf(" &%s", event.data.scalar.anchor);
if (event.data.scalar.tag)
printf(" <%s>", event.data.scalar.tag);
switch (event.data.scalar.style) {
case YAML_PLAIN_SCALAR_STYLE:
printf(" :");
break;
case YAML_SINGLE_QUOTED_SCALAR_STYLE:
printf(" '");
break;
case YAML_DOUBLE_QUOTED_SCALAR_STYLE:
printf(" \"");
break;
case YAML_LITERAL_SCALAR_STYLE:
printf(" |");
break;
case YAML_FOLDED_SCALAR_STYLE:
printf(" >");
break;
case YAML_ANY_SCALAR_STYLE:
abort();
}
print_escaped(event.data.scalar.value, event.data.scalar.length);
printf("\n");
}
else if (type == YAML_ALIAS_EVENT)
printf("=ALI *%s\n", event.data.alias.anchor);
else
abort();
yaml_event_delete(&event);
if (type == YAML_STREAM_END_EVENT)
break;
}
assert(!fclose(input));
yaml_parser_delete(&parser);
fflush(stdout);
return 0;
}
void print_escaped(yaml_char_t * str, size_t length)
{
int i;
char c;
for (i = 0; i < length; i++) {
c = *(str + i);
if (c == '\\')
printf("\\\\");
else if (c == '\0')
printf("\\0");
else if (c == '\b')
printf("\\b");
else if (c == '\n')
printf("\\n");
else if (c == '\r')
printf("\\r");
else if (c == '\t')
printf("\\t");
else
printf("%c", c);
}
}
int usage(int ret) {
fprintf(stderr, "Usage: libyaml-parser [--flow (on|off|keep)] [<input-file>]\n");
return ret;
}

63
deps/libyaml/tests/run-parser.c vendored Normal file
View File

@@ -0,0 +1,63 @@
#include <yaml.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef NDEBUG
#undef NDEBUG
#endif
#include <assert.h>
int
main(int argc, char *argv[])
{
int number;
if (argc < 2) {
printf("Usage: %s file1.yaml ...\n", argv[0]);
return 0;
}
for (number = 1; number < argc; number ++)
{
FILE *file;
yaml_parser_t parser;
yaml_event_t event;
int done = 0;
int count = 0;
int error = 0;
printf("[%d] Parsing '%s': ", number, argv[number]);
fflush(stdout);
file = fopen(argv[number], "rb");
assert(file);
assert(yaml_parser_initialize(&parser));
yaml_parser_set_input_file(&parser, file);
while (!done)
{
if (!yaml_parser_parse(&parser, &event)) {
error = 1;
break;
}
done = (event.type == YAML_STREAM_END_EVENT);
yaml_event_delete(&event);
count ++;
}
yaml_parser_delete(&parser);
assert(!fclose(file));
printf("%s (%d events)\n", (error ? "FAILURE" : "SUCCESS"), count);
}
return 0;
}

63
deps/libyaml/tests/run-scanner.c vendored Normal file
View File

@@ -0,0 +1,63 @@
#include <yaml.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef NDEBUG
#undef NDEBUG
#endif
#include <assert.h>
int
main(int argc, char *argv[])
{
int number;
if (argc < 2) {
printf("Usage: %s file1.yaml ...\n", argv[0]);
return 0;
}
for (number = 1; number < argc; number ++)
{
FILE *file;
yaml_parser_t parser;
yaml_token_t token;
int done = 0;
int count = 0;
int error = 0;
printf("[%d] Scanning '%s': ", number, argv[number]);
fflush(stdout);
file = fopen(argv[number], "rb");
assert(file);
assert(yaml_parser_initialize(&parser));
yaml_parser_set_input_file(&parser, file);
while (!done)
{
if (!yaml_parser_scan(&parser, &token)) {
error = 1;
break;
}
done = (token.type == YAML_STREAM_END_TOKEN);
yaml_token_delete(&token);
count ++;
}
yaml_parser_delete(&parser);
assert(!fclose(file));
printf("%s (%d tokens)\n", (error ? "FAILURE" : "SUCCESS"), count);
}
return 0;
}

354
deps/libyaml/tests/test-reader.c vendored Normal file
View File

@@ -0,0 +1,354 @@
#include <yaml.h>
YAML_DECLARE(int)
yaml_parser_update_buffer(yaml_parser_t *parser, size_t length);
#include <stdlib.h>
#include <stdio.h>
#ifdef NDEBUG
#undef NDEBUG
#endif
#include <assert.h>
/*
* Test cases are stolen from
* http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt
*/
typedef struct {
char *title;
char *test;
int result;
} test_case;
test_case utf8_sequences[] = {
/* {"title", "test 1|test 2|...|test N!", (0 or 1)}, */
{"a simple test", "'test' is '\xd0\xbf\xd1\x80\xd0\xbe\xd0\xb2\xd0\xb5\xd1\x80\xd0\xba\xd0\xb0' in Russian!", 1},
{"an empty line", "!", 1},
{"u-0 is a control character", "\x00!", 0},
{"u-80 is a control character", "\xc2\x80!", 0},
{"u-800 is valid", "\xe0\xa0\x80!", 1},
{"u-10000 is valid", "\xf0\x90\x80\x80!", 1},
{"5 bytes sequences are not allowed", "\xf8\x88\x80\x80\x80!", 0},
{"6 bytes sequences are not allowed", "\xfc\x84\x80\x80\x80\x80!", 0},
{"u-7f is a control character", "\x7f!", 0},
{"u-7FF is valid", "\xdf\xbf!", 1},
{"u-FFFF is a control character", "\xef\xbf\xbf!", 0},
{"u-1FFFFF is too large", "\xf7\xbf\xbf\xbf!", 0},
{"u-3FFFFFF is 5 bytes", "\xfb\xbf\xbf\xbf\xbf!", 0},
{"u-7FFFFFFF is 6 bytes", "\xfd\xbf\xbf\xbf\xbf\xbf!", 0},
{"u-D7FF", "\xed\x9f\xbf!", 1},
{"u-E000", "\xee\x80\x80!", 1},
{"u-FFFD", "\xef\xbf\xbd!", 1},
{"u-10FFFF", "\xf4\x8f\xbf\xbf!", 1},
{"u-110000", "\xf4\x90\x80\x80!", 0},
{"first continuation byte", "\x80!", 0},
{"last continuation byte", "\xbf!", 0},
{"2 continuation bytes", "\x80\xbf!", 0},
{"3 continuation bytes", "\x80\xbf\x80!", 0},
{"4 continuation bytes", "\x80\xbf\x80\xbf!", 0},
{"5 continuation bytes", "\x80\xbf\x80\xbf\x80!", 0},
{"6 continuation bytes", "\x80\xbf\x80\xbf\x80\xbf!", 0},
{"7 continuation bytes", "\x80\xbf\x80\xbf\x80\xbf\x80!", 0},
{"sequence of all 64 possible continuation bytes",
"\x80|\x81|\x82|\x83|\x84|\x85|\x86|\x87|\x88|\x89|\x8a|\x8b|\x8c|\x8d|\x8e|\x8f|"
"\x90|\x91|\x92|\x93|\x94|\x95|\x96|\x97|\x98|\x99|\x9a|\x9b|\x9c|\x9d|\x9e|\x9f|"
"\xa0|\xa1|\xa2|\xa3|\xa4|\xa5|\xa6|\xa7|\xa8|\xa9|\xaa|\xab|\xac|\xad|\xae|\xaf|"
"\xb0|\xb1|\xb2|\xb3|\xb4|\xb5|\xb6|\xb7|\xb8|\xb9|\xba|\xbb|\xbc|\xbd|\xbe|\xbf!", 0},
{"32 first bytes of 2-byte sequences {0xc0-0xdf}",
"\xc0 |\xc1 |\xc2 |\xc3 |\xc4 |\xc5 |\xc6 |\xc7 |\xc8 |\xc9 |\xca |\xcb |\xcc |\xcd |\xce |\xcf |"
"\xd0 |\xd1 |\xd2 |\xd3 |\xd4 |\xd5 |\xd6 |\xd7 |\xd8 |\xd9 |\xda |\xdb |\xdc |\xdd |\xde |\xdf !", 0},
{"16 first bytes of 3-byte sequences {0xe0-0xef}",
"\xe0 |\xe1 |\xe2 |\xe3 |\xe4 |\xe5 |\xe6 |\xe7 |\xe8 |\xe9 |\xea |\xeb |\xec |\xed |\xee |\xef !", 0},
{"8 first bytes of 4-byte sequences {0xf0-0xf7}", "\xf0 |\xf1 |\xf2 |\xf3 |\xf4 |\xf5 |\xf6 |\xf7 !", 0},
{"4 first bytes of 5-byte sequences {0xf8-0xfb}", "\xf8 |\xf9 |\xfa |\xfb !", 0},
{"2 first bytes of 6-byte sequences {0xfc-0xfd}", "\xfc |\xfd !", 0},
{"sequences with last byte missing {u-0}",
"\xc0|\xe0\x80|\xf0\x80\x80|\xf8\x80\x80\x80|\xfc\x80\x80\x80\x80!", 0},
{"sequences with last byte missing {u-...FF}",
"\xdf|\xef\xbf|\xf7\xbf\xbf|\xfb\xbf\xbf\xbf|\xfd\xbf\xbf\xbf\xbf!", 0},
{"impossible bytes", "\xfe|\xff|\xfe\xfe\xff\xff!", 0},
{"overlong sequences {u-2f}",
"\xc0\xaf|\xe0\x80\xaf|\xf0\x80\x80\xaf|\xf8\x80\x80\x80\xaf|\xfc\x80\x80\x80\x80\xaf!", 0},
{"maximum overlong sequences",
"\xc1\xbf|\xe0\x9f\xbf|\xf0\x8f\xbf\xbf|\xf8\x87\xbf\xbf\xbf|\xfc\x83\xbf\xbf\xbf\xbf!", 0},
{"overlong representation of the NUL character",
"\xc0\x80|\xe0\x80\x80|\xf0\x80\x80\x80|\xf8\x80\x80\x80\x80|\xfc\x80\x80\x80\x80\x80!", 0},
{"single UTF-16 surrogates",
"\xed\xa0\x80|\xed\xad\xbf|\xed\xae\x80|\xed\xaf\xbf|\xed\xb0\x80|\xed\xbe\x80|\xed\xbf\xbf!", 0},
{"paired UTF-16 surrogates",
"\xed\xa0\x80\xed\xb0\x80|\xed\xa0\x80\xed\xbf\xbf|\xed\xad\xbf\xed\xb0\x80|"
"\xed\xad\xbf\xed\xbf\xbf|\xed\xae\x80\xed\xb0\x80|\xed\xae\x80\xed\xbf\xbf|"
"\xed\xaf\xbf\xed\xb0\x80|\xed\xaf\xbf\xed\xbf\xbf!", 0},
{"other illegal code positions", "\xef\xbf\xbe|\xef\xbf\xbf!", 0},
{NULL, NULL, 0}
};
test_case boms[] = {
/* {"title", "test!", lenth}, */
{"no bom (utf-8)", "Hi is \xd0\x9f\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82!", 13},
{"bom (utf-8)", "\xef\xbb\xbfHi is \xd0\x9f\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82!", 13},
{"bom (utf-16-le)", "\xff\xfeH\x00i\x00 \x00i\x00s\x00 \x00\x1f\x04@\x04""8\x04""2\x04""5\x04""B\x04!", 13},
{"bom (utf-16-be)", "\xfe\xff\x00H\x00i\x00 \x00i\x00s\x00 \x04\x1f\x04@\x04""8\x04""2\x04""5\x04""B!", 13},
{NULL, NULL, 0}
};
char *bom_original = "Hi is \xd0\x9f\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82";
int check_utf8_sequences(void)
{
yaml_parser_t parser;
int failed = 0;
int k;
printf("checking utf-8 sequences...\n");
for (k = 0; utf8_sequences[k].test; k++) {
char *title = utf8_sequences[k].title;
int check = utf8_sequences[k].result;
int result;
char *start = utf8_sequences[k].test;
char *end = start;
printf("\t%s:\n", title);
while(1) {
while (*end != '|' && *end != '!') end++;
yaml_parser_initialize(&parser);
yaml_parser_set_input_string(&parser, (unsigned char *)start, end-start);
result = yaml_parser_update_buffer(&parser, end-start);
if (result != check) {
printf("\t\t- ");
failed ++;
}
else {
printf("\t\t+ ");
}
if (!parser.error) {
printf("(no error)\n");
}
else if (parser.error == YAML_READER_ERROR) {
if (parser.problem_value != -1) {
printf("(reader error: %s: #%X at %ld)\n",
parser.problem, parser.problem_value, (long)parser.problem_offset);
}
else {
printf("(reader error: %s at %ld)\n",
parser.problem, (long)parser.problem_offset);
}
}
if (*end == '!') break;
start = ++end;
yaml_parser_delete(&parser);
};
printf("\n");
}
printf("checking utf-8 sequences: %d fail(s)\n", failed);
return failed;
}
int check_boms(void)
{
yaml_parser_t parser;
int failed = 0;
int k;
printf("checking boms...\n");
for (k = 0; boms[k].test; k++) {
char *title = boms[k].title;
int check = boms[k].result;
int result;
char *start = boms[k].test;
char *end = start;
while (*end != '!') end++;
printf("\t%s: ", title);
yaml_parser_initialize(&parser);
yaml_parser_set_input_string(&parser, (unsigned char *)start, end-start);
result = yaml_parser_update_buffer(&parser, end-start);
if (!result) {
printf("- (reader error: %s at %ld)\n", parser.problem, (long)parser.problem_offset);
failed++;
}
else {
if (parser.unread != check) {
printf("- (length=%ld while expected length=%d)\n", (long)parser.unread, check);
failed++;
}
else if (memcmp(parser.buffer.start, bom_original, check) != 0) {
printf("- (value '%s' does not equal to the original value '%s')\n", parser.buffer.start, bom_original);
failed++;
}
else {
printf("+\n");
}
}
yaml_parser_delete(&parser);
}
printf("checking boms: %d fail(s)\n", failed);
return failed;
}
#define LONG 100000
int check_long_utf8(void)
{
yaml_parser_t parser;
int k = 0;
int j;
int failed = 0;
unsigned char ch0, ch1;
unsigned char *buffer = (unsigned char *)malloc(3+LONG*2);
assert(buffer);
printf("checking a long utf8 sequence...\n");
buffer[k++] = '\xef';
buffer[k++] = '\xbb';
buffer[k++] = '\xbf';
for (j = 0; j < LONG; j ++) {
if (j % 2) {
buffer[k++] = '\xd0';
buffer[k++] = '\x90';
}
else {
buffer[k++] = '\xd0';
buffer[k++] = '\xaf';
}
}
yaml_parser_initialize(&parser);
yaml_parser_set_input_string(&parser, buffer, 3+LONG*2);
for (k = 0; k < LONG; k++) {
if (!parser.unread) {
if (!yaml_parser_update_buffer(&parser, 1)) {
printf("\treader error: %s at %ld\n", parser.problem, (long)parser.problem_offset);
failed = 1;
break;
}
}
if (!parser.unread) {
printf("\tnot enough characters at %d\n", k);
failed = 1;
break;
}
if (k % 2) {
ch0 = '\xd0';
ch1 = '\x90';
}
else {
ch0 = '\xd0';
ch1 = '\xaf';
}
if (parser.buffer.pointer[0] != ch0 || parser.buffer.pointer[1] != ch1) {
printf("\tincorrect UTF-8 sequence: %X %X instead of %X %X\n",
(int)parser.buffer.pointer[0], (int)parser.buffer.pointer[1],
(int)ch0, (int)ch1);
failed = 1;
break;
}
parser.buffer.pointer += 2;
parser.unread -= 1;
}
if (!failed) {
if (!yaml_parser_update_buffer(&parser, 1)) {
printf("\treader error: %s at %ld\n", parser.problem, (long)parser.problem_offset);
failed = 1;
}
else if (parser.buffer.pointer[0] != '\0') {
printf("\texpected NUL, found %X (eof=%d, unread=%ld)\n", (int)parser.buffer.pointer[0], parser.eof, (long)parser.unread);
failed = 1;
}
}
yaml_parser_delete(&parser);
free(buffer);
printf("checking a long utf8 sequence: %d fail(s)\n", failed);
return failed;
}
int check_long_utf16(void)
{
yaml_parser_t parser;
int k = 0;
int j;
int failed = 0;
unsigned char ch0, ch1;
unsigned char *buffer = (unsigned char *)malloc(2+LONG*2);
assert(buffer);
printf("checking a long utf16 sequence...\n");
buffer[k++] = '\xff';
buffer[k++] = '\xfe';
for (j = 0; j < LONG; j ++) {
if (j % 2) {
buffer[k++] = '\x10';
buffer[k++] = '\x04';
}
else {
buffer[k++] = '/';
buffer[k++] = '\x04';
}
}
yaml_parser_initialize(&parser);
yaml_parser_set_input_string(&parser, buffer, 2+LONG*2);
for (k = 0; k < LONG; k++) {
if (!parser.unread) {
if (!yaml_parser_update_buffer(&parser, 1)) {
printf("\treader error: %s at %ld\n", parser.problem, (long)parser.problem_offset);
failed = 1;
break;
}
}
if (!parser.unread) {
printf("\tnot enough characters at %d\n", k);
failed = 1;
break;
}
if (k % 2) {
ch0 = '\xd0';
ch1 = '\x90';
}
else {
ch0 = '\xd0';
ch1 = '\xaf';
}
if (parser.buffer.pointer[0] != ch0 || parser.buffer.pointer[1] != ch1) {
printf("\tincorrect UTF-8 sequence: %X %X instead of %X %X\n",
(int)parser.buffer.pointer[0], (int)parser.buffer.pointer[1],
(int)ch0, (int)ch1);
failed = 1;
break;
}
parser.buffer.pointer += 2;
parser.unread -= 1;
}
if (!failed) {
if (!yaml_parser_update_buffer(&parser, 1)) {
printf("\treader error: %s at %ld\n", parser.problem, (long)parser.problem_offset);
failed = 1;
}
else if (parser.buffer.pointer[0] != '\0') {
printf("\texpected NUL, found %X (eof=%d, unread=%ld)\n", (int)parser.buffer.pointer[0], parser.eof, (long)parser.unread);
failed = 1;
}
}
yaml_parser_delete(&parser);
free(buffer);
printf("checking a long utf16 sequence: %d fail(s)\n", failed);
return failed;
}
int
main(void)
{
return check_utf8_sequences() + check_boms() + check_long_utf8() + check_long_utf16();
}

29
deps/libyaml/tests/test-version.c vendored Normal file
View File

@@ -0,0 +1,29 @@
#include <yaml.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef NDEBUG
#undef NDEBUG
#endif
#include <assert.h>
int
main(void)
{
int major = -1;
int minor = -1;
int patch = -1;
char buf[64];
yaml_get_version(&major, &minor, &patch);
sprintf(buf, "%d.%d.%d", major, minor, patch);
assert(strcmp(buf, yaml_get_version_string()) == 0);
/* Print structure sizes. */
printf("sizeof(token) = %ld\n", (long)sizeof(yaml_token_t));
printf("sizeof(event) = %ld\n", (long)sizeof(yaml_event_t));
printf("sizeof(parser) = %ld\n", (long)sizeof(yaml_parser_t));
return 0;
}