Move testsuite to plain EUnit

References #15.
This commit is contained in:
Jean-Sébastien Pédron 2016-11-10 09:23:35 +01:00
parent 18fe0651df
commit 31e0453f04
No known key found for this signature in database
GPG Key ID: 39E99761A5FD94CC
495 changed files with 12153 additions and 13966 deletions

1
.gitignore vendored
View File

@ -24,7 +24,6 @@ debian/files
/.rebar/
/rebar
/deps/
/test/
/ebin/yamerl.app
/rebar.lock

View File

@ -0,0 +1,49 @@
-module(alias).
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
setup() ->
application:start(yamerl).
simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[
"Duplicate",
"Duplicate"
]
],
yamerl_constr:file(?FILENAME, [{detailed_constr, false}])
)
]
}.
detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,
{yamerl_seq,yamerl_node_seq, "tag:yaml.org,2002:seq",
[{line,1},{column,1}],
[
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,1},{column,11}],
"Duplicate"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,1},{column,11}],
"Duplicate"}
],
2}
}
],
yamerl_constr:file(?FILENAME, [{detailed_constr, true}])
)
]
}.

377
test/construction/bool.erl Normal file
View File

@ -0,0 +1,377 @@
-module(bool).
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
setup() ->
application:start(yamerl).
schema_failsafe_simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[
"true", "True", "TRUE",
"y", "Y",
"yes", "Yes", "YES",
"on", "On", "ON",
"false", "False", "FALSE",
"n", "N",
"no", "No", "NO",
"off", "Off", "OFF",
"Not a bool"
]
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, false}, {schema, failsafe}])
)
]
}.
schema_json_simple_test_() ->
{setup,
fun setup/0,
[
?_assertThrow(
{yamerl_exception, [
{yamerl_parsing_error,error, "Invalid string", 2, 3, not_a_string,
{yamerl_scalar, 2, 3,
{yamerl_tag, 2, 3, {non_specific, "?"}},
flow, plain, "True"},
[]}]},
yamerl_constr:file(?FILENAME,
[{detailed_constr, false}, {schema, json}])
)
]
}.
schema_core_simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[
true, true, true,
"y", "Y",
"yes", "Yes", "YES",
"on", "On", "ON",
false, false, false,
"n", "N",
"no", "No", "NO",
"off", "Off", "OFF",
"Not a bool"
]
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, false}, {schema, core}])
)
]
}.
schema_failsafe_bool_ext_simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[
true, true, true,
true, true,
true, true, true,
true, true, true,
false, false, false,
false, false,
false, false, false,
false, false, false,
"Not a bool"
]
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, false}, {schema, failsafe},
{node_mods, [yamerl_node_bool_ext]}])
)
]
}.
schema_failsafe_detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,1},{column,1}],
[{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,1},{column,3}],
"true"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,2},{column,3}],
"True"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,3},{column,3}],
"TRUE"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,4},{column,3}],
"y"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,5},{column,3}],
"Y"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,6},{column,3}],
"yes"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,7},{column,3}],
"Yes"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,8},{column,3}],
"YES"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,9},{column,3}],
"on"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,10},{column,3}],
"On"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,11},{column,3}],
"ON"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,13},{column,3}],
"false"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,14},{column,3}],
"False"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,15},{column,3}],
"FALSE"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,16},{column,3}],
"n"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,17},{column,3}],
"N"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,18},{column,3}],
"no"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,19},{column,3}],
"No"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,20},{column,3}],
"NO"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,21},{column,3}],
"off"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,22},{column,3}],
"Off"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,23},{column,3}],
"OFF"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,25},{column,3}],
"Not a bool"}],
23}
}
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, true}, {schema, failsafe}])
)
]
}.
schema_json_detailed_test_() ->
{setup,
fun setup/0,
[
?_assertThrow(
{yamerl_exception, [
{yamerl_parsing_error,error, "Invalid string", 2, 3, not_a_string,
{yamerl_scalar, 2, 3,
{yamerl_tag, 2, 3, {non_specific, "?"}},
flow, plain, "True"},
[]}]},
yamerl_constr:file(?FILENAME,
[{detailed_constr, true}, {schema, json}])
)
]
}.
schema_core_detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,1},{column,1}],
[{yamerl_bool,yamerl_node_bool,"tag:yaml.org,2002:bool",
[{line,1},{column,3}],
true},
{yamerl_bool,yamerl_node_bool,"tag:yaml.org,2002:bool",
[{line,2},{column,3}],
true},
{yamerl_bool,yamerl_node_bool,"tag:yaml.org,2002:bool",
[{line,3},{column,3}],
true},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,4},{column,3}],
"y"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,5},{column,3}],
"Y"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,6},{column,3}],
"yes"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,7},{column,3}],
"Yes"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,8},{column,3}],
"YES"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,9},{column,3}],
"on"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,10},{column,3}],
"On"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,11},{column,3}],
"ON"},
{yamerl_bool,yamerl_node_bool,"tag:yaml.org,2002:bool",
[{line,13},{column,3}],
false},
{yamerl_bool,yamerl_node_bool,"tag:yaml.org,2002:bool",
[{line,14},{column,3}],
false},
{yamerl_bool,yamerl_node_bool,"tag:yaml.org,2002:bool",
[{line,15},{column,3}],
false},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,16},{column,3}],
"n"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,17},{column,3}],
"N"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,18},{column,3}],
"no"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,19},{column,3}],
"No"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,20},{column,3}],
"NO"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,21},{column,3}],
"off"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,22},{column,3}],
"Off"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,23},{column,3}],
"OFF"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,25},{column,3}],
"Not a bool"}],
23}
}
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, true}, {schema, core}])
)
]
}.
schema_failsafe_bool_ext_detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,1},{column,1}],
[{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
[{line,1},{column,3}],
true},
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
[{line,2},{column,3}],
true},
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
[{line,3},{column,3}],
true},
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
[{line,4},{column,3}],
true},
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
[{line,5},{column,3}],
true},
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
[{line,6},{column,3}],
true},
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
[{line,7},{column,3}],
true},
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
[{line,8},{column,3}],
true},
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
[{line,9},{column,3}],
true},
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
[{line,10},{column,3}],
true},
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
[{line,11},{column,3}],
true},
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
[{line,13},{column,3}],
false},
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
[{line,14},{column,3}],
false},
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
[{line,15},{column,3}],
false},
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
[{line,16},{column,3}],
false},
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
[{line,17},{column,3}],
false},
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
[{line,18},{column,3}],
false},
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
[{line,19},{column,3}],
false},
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
[{line,20},{column,3}],
false},
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
[{line,21},{column,3}],
false},
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
[{line,22},{column,3}],
false},
{yamerl_bool,yamerl_node_bool_ext,"tag:yaml.org,2002:bool",
[{line,23},{column,3}],
false},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,25},{column,3}],
"Not a bool"}],
23}
}
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, true}, {schema, failsafe},
{node_mods, [yamerl_node_bool_ext]}])
)
]
}.

View File

@ -0,0 +1,51 @@
-module(bool_json).
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
setup() ->
application:start(yamerl).
simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[
true,
false
]
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, false}, {schema, json}])
)
]
}.
detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,1},{column,1}],
[{yamerl_bool,yamerl_node_bool_json,
"tag:yaml.org,2002:bool",
[{line,1},{column,3}],
true},
{yamerl_bool,yamerl_node_bool_json,
"tag:yaml.org,2002:bool",
[{line,2},{column,3}],
false}],
2}
}
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, true}, {schema, json}])
)
]
}.

View File

@ -0,0 +1,30 @@
-module(empty).
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
setup() ->
application:start(yamerl).
simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[],
yamerl_constr:file(?FILENAME, [{detailed_constr, false}])
)
]
}.
detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[],
yamerl_constr:file(?FILENAME, [{detailed_constr, true}])
)
]
}.

View File

@ -0,0 +1,147 @@
-module(erlang_atom).
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
setup() ->
application:start(yamerl),
yamerl_app:set_param(node_mods, [yamerl_node_erlang_atom]).
simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[
atom,
'atom requiring quoting!',
"atom",
"node@domain",
"not an atom",
"NotAnAtom",
"Not an atom",
"Not an atom"
]
],
yamerl_constr:file(?FILENAME, [{detailed_constr, false}])
)
]
}.
autodetection_simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[
atom,
'atom requiring quoting!',
atom,
node@domain,
"not an atom",
"NotAnAtom",
"Not an atom",
"Not an atom"
]
],
yamerl_constr:file(?FILENAME, [
{detailed_constr, false},
{erlang_atom_autodetection, true}
])
)
]
}.
detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,1},{column,1}],
[
{yamerl_erlang_atom,yamerl_node_erlang_atom,
"tag:yamerl,2012:atom",
[{line,1},{column,27}],
atom},
{yamerl_erlang_atom,yamerl_node_erlang_atom,
"tag:yamerl,2012:atom",
[{line,2},{column,27}],
'atom requiring quoting!'},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,4},{column,3}],
"atom"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,5},{column,3}],
"node@domain"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,7},{column,3}],
"not an atom"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,8},{column,3}],
"NotAnAtom"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,9},{column,3}],
"Not an atom"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,10},{column,3}],
"Not an atom"}],
8}}
],
yamerl_constr:file(?FILENAME, [{detailed_constr, true}])
)
]
}.
autodetection_detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,1},{column,1}],
[
{yamerl_erlang_atom,yamerl_node_erlang_atom,
"tag:yamerl,2012:atom",
[{line,1},{column,27}],
atom},
{yamerl_erlang_atom,yamerl_node_erlang_atom,
"tag:yamerl,2012:atom",
[{line,2},{column,27}],
'atom requiring quoting!'},
{yamerl_erlang_atom,yamerl_node_erlang_atom,
"tag:yamerl,2012:atom",
[{line,4},{column,3}],
atom},
{yamerl_erlang_atom,yamerl_node_erlang_atom,
"tag:yamerl,2012:atom",
[{line,5},{column,3}],
node@domain},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,7},{column,3}],
"not an atom"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,8},{column,3}],
"NotAnAtom"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,9},{column,3}],
"Not an atom"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,10},{column,3}],
"Not an atom"}],
8}}
],
yamerl_constr:file(?FILENAME, [
{detailed_constr, true},
{erlang_atom_autodetection, true}
])
)
]
}.

View File

@ -0,0 +1,59 @@
-module(erlang_atom_if_exist).
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
setup() ->
application:start(yamerl),
yamerl_app:set_param(node_mods, [yamerl_node_erlang_atom]).
simple_test_() ->
{setup,
fun setup/0,
[
?_assertThrow(
{yamerl_exception,
[{yamerl_parsing_error, error,
"Non-existing Erlang atom",
1, 27,
non_existing_erlang_atom,
{yamerl_scalar, 1, 27,
{yamerl_tag, 1, 3, "tag:yamerl,2012:atom"},
flow, plain, "inexistent_atom"
},
[]
}]
},
yamerl_constr:file(?FILENAME, [
{detailed_constr, false},
{erlang_atom_only_if_exist, true}
])
)
]
}.
detailed_test_() ->
{setup,
fun setup/0,
[
?_assertThrow(
{yamerl_exception,
[{yamerl_parsing_error, error,
"Non-existing Erlang atom",
1, 27,
non_existing_erlang_atom,
{yamerl_scalar, 1, 27,
{yamerl_tag, 1, 3, "tag:yamerl,2012:atom"},
flow, plain, "inexistent_atom"
},
[]
}]
},
yamerl_constr:file(?FILENAME, [
{detailed_constr, true},
{erlang_atom_only_if_exist, true}
])
)
]
}.

View File

@ -0,0 +1,47 @@
-module(erlang_atom_if_exist_auto).
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
setup() ->
application:start(yamerl),
yamerl_app:set_param(node_mods, [yamerl_node_erlang_atom]).
simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
"inexistent_atom"
],
yamerl_constr:file(?FILENAME, [
{detailed_constr, false},
{erlang_atom_autodetection, true},
{erlang_atom_only_if_exist, true}
])
)
]
}.
detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,1},{column,1}],
"inexistent_atom"}
}
],
yamerl_constr:file(?FILENAME, [
{detailed_constr, true},
{erlang_atom_autodetection, true},
{erlang_atom_only_if_exist, true}
])
)
]
}.

View File

@ -0,0 +1,47 @@
-module(erlang_fun).
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
setup() ->
application:start(yamerl),
yamerl_app:set_param(node_mods, [yamerl_node_erlang_fun]).
simple_test_() ->
{setup,
fun setup/0,
[
{generator,
fun() ->
[Erlang_Fun_Simple] = yamerl_constr:file(?FILENAME,
[{detailed_constr, false}]),
?_assertMatch(
"Hello World!",
Erlang_Fun_Simple()
)
end}
]
}.
detailed_test_() ->
{setup,
fun setup/0,
[
{generator,
fun() ->
[{yamerl_doc,
{yamerl_erlang_fun,yamerl_node_erlang_fun,
"tag:yamerl,2012:fun",
[{line,1},{column,24}],
Erlang_Fun_Normal,
"fun() -> \"Hello World!\" end.\n"}}
] = yamerl_constr:file(?FILENAME,
[{detailed_constr, true}]),
?_assertMatch(
"Hello World!",
Erlang_Fun_Normal()
)
end}
]
}.

695
test/construction/float.erl Normal file
View File

@ -0,0 +1,695 @@
-module(float).
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
setup() ->
application:start(yamerl).
schema_failsafe_simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[
"0", "+0", "-0",
"123", "+123", "-123",
"12.34", "+12.34", "-12.34",
"12e10", "+12e10", "-12e10",
"1.2e11", "1.2e+11", "1.2e-11",
"1.0e10", "1.0E10",
".", ".1", ".e+3", "1.", "1.e+3",
"190:20:30.15", "+190:20:30.15", "-190:20:30.15",
".inf", "+.inf", "-.inf", ".nan",
".Inf", ".INF", ".iNF",
".NaN", ".NAN", ".Nan", ".nAN",
"Not a float.0e+10", "+Not a float.0e+10", "-Not a float.0e+10"
]
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, false}, {schema, failsafe}]) %% No float parsing
)
]
}.
schema_failsafe_float_json_simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[
0.0, "+0", 0.0,
123.0, "+123", -123.0,
12.34, "+12.34", -12.34,
1.2e+11, "+12e10", -1.2e+11,
1.2e+11, 1.2e+11, 1.2e-11,
1.0e+10, 1.0e+10,
".", ".1", ".e+3", 1.0, 1000.0,
"190:20:30.15", "+190:20:30.15", "-190:20:30.15",
'+inf', "+.inf", '-inf', 'nan',
".Inf", ".INF", ".iNF",
".NaN", ".NAN", ".Nan", ".nAN",
"Not a float.0e+10", "+Not a float.0e+10", "-Not a float.0e+10"
]
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, false}, {schema, failsafe},
{node_mods, [yamerl_node_float_json]}])
)
]
}.
schema_failsafe_float_simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[
0.0, 0.0, 0.0,
123.0, 123.0, -123.0,
12.34, 12.34, -12.34,
1.2e+11, 1.2e+11, -1.2e+11,
1.2e+11, 1.2e+11, 1.2e-11,
1.0e+10, 1.0e+10,
".", 0.1, ".e+3", 1.0, 1000.0,
"190:20:30.15", "+190:20:30.15", "-190:20:30.15",
'+inf', '+inf', '-inf', 'nan',
'+inf', '+inf', ".iNF",
'nan', 'nan', ".Nan", ".nAN",
"Not a float.0e+10", "+Not a float.0e+10", "-Not a float.0e+10"
]
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, false}, {schema, failsafe},
{node_mods, [yamerl_node_float]}])
)
]
}.
schema_failsafe_float_ext_simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[
0.0, 0.0, 0.0,
"123", "+123", "-123",
12.34, 12.34, -12.34,
"12e10", "+12e10", "-12e10",
"1.2e11", 1.2e+11, 1.2e-11,
"1.0e10", "1.0E10",
".", 0.1, 0.0, 1.0, 1000.0,
685230.15, 685230.15, -685230.15,
'+inf', '+inf', '-inf', 'nan',
'+inf', '+inf', ".iNF",
'nan', 'nan', ".Nan", ".nAN",
"Not a float.0e+10", "+Not a float.0e+10", "-Not a float.0e+10"
]
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, false}, {schema, failsafe},
{node_mods, [yamerl_node_float_ext]}])
)
]
}.
schema_failsafe_detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[{yamerl_doc,
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,1},{column,1}],
[
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,1},{column,4}],
"0"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,2},{column,3}],
"+0"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,3},{column,3}],
"-0"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,5},{column,4}],
"123"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,6},{column,3}],
"+123"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,7},{column,3}],
"-123"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,9},{column,4}],
"12.34"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,10},{column,3}],
"+12.34"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,11},{column,3}],
"-12.34"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,13},{column,4}],
"12e10"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,14},{column,3}],
"+12e10"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,15},{column,3}],
"-12e10"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,17},{column,3}],
"1.2e11"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,18},{column,3}],
"1.2e+11"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,19},{column,3}],
"1.2e-11"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,21},{column,3}],
"1.0e10"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,22},{column,3}],
"1.0E10"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,24},{column,4}],
"."},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,25},{column,4}],
".1"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,26},{column,4}],
".e+3"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,27},{column,3}],
"1."},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,28},{column,3}],
"1.e+3"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,30},{column,4}],
"190:20:30.15"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,31},{column,3}],
"+190:20:30.15"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,32},{column,3}],
"-190:20:30.15"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,34},{column,4}],
".inf"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,35},{column,3}],
"+.inf"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,36},{column,3}],
"-.inf"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,37},{column,4}],
".nan"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,39},{column,3}],
".Inf"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,40},{column,3}],
".INF"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,41},{column,3}],
".iNF"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,43},{column,3}],
".NaN"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,44},{column,3}],
".NAN"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,45},{column,3}],
".Nan"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,46},{column,3}],
".nAN"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,48},{column,4}],
"Not a float.0e+10"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,49},{column,3}],
"+Not a float.0e+10"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,50},{column,3}],
"-Not a float.0e+10"}],
39}}],
yamerl_constr:file(?FILENAME,
[{detailed_constr, true}, {schema, failsafe}]) %% No float parsing
)
]
}.
schema_failsafe_float_json_detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[{yamerl_doc,
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,1},{column,1}],
[
{yamerl_float,yamerl_node_float_json,
"tag:yaml.org,2002:float",
[{line,1},{column,4}],
0.0},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,2},{column,3}],
"+0"},
{yamerl_float,yamerl_node_float_json,
"tag:yaml.org,2002:float",
[{line,3},{column,3}],
0.0},
{yamerl_float,yamerl_node_float_json,
"tag:yaml.org,2002:float",
[{line,5},{column,4}],
123.0},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,6},{column,3}],
"+123"},
{yamerl_float,yamerl_node_float_json,
"tag:yaml.org,2002:float",
[{line,7},{column,3}],
-123.0},
{yamerl_float,yamerl_node_float_json,
"tag:yaml.org,2002:float",
[{line,9},{column,4}],
12.34},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,10},{column,3}],
"+12.34"},
{yamerl_float,yamerl_node_float_json,
"tag:yaml.org,2002:float",
[{line,11},{column,3}],
-12.34},
{yamerl_float,yamerl_node_float_json,
"tag:yaml.org,2002:float",
[{line,13},{column,4}],
1.2e11},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,14},{column,3}],
"+12e10"},
{yamerl_float,yamerl_node_float_json,
"tag:yaml.org,2002:float",
[{line,15},{column,3}],
-1.2e11},
{yamerl_float,yamerl_node_float_json,
"tag:yaml.org,2002:float",
[{line,17},{column,3}],
1.2e11},
{yamerl_float,yamerl_node_float_json,
"tag:yaml.org,2002:float",
[{line,18},{column,3}],
1.2e11},
{yamerl_float,yamerl_node_float_json,
"tag:yaml.org,2002:float",
[{line,19},{column,3}],
1.2e-11},
{yamerl_float,yamerl_node_float_json,
"tag:yaml.org,2002:float",
[{line,21},{column,3}],
1.0e10},
{yamerl_float,yamerl_node_float_json,
"tag:yaml.org,2002:float",
[{line,22},{column,3}],
1.0e10},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,24},{column,4}],
"."},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,25},{column,4}],
".1"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,26},{column,4}],
".e+3"},
{yamerl_float,yamerl_node_float_json,
"tag:yaml.org,2002:float",
[{line,27},{column,3}],
1.0},
{yamerl_float,yamerl_node_float_json,
"tag:yaml.org,2002:float",
[{line,28},{column,3}],
1000.0},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,30},{column,4}],
"190:20:30.15"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,31},{column,3}],
"+190:20:30.15"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,32},{column,3}],
"-190:20:30.15"},
{yamerl_float,yamerl_node_float_json,
"tag:yaml.org,2002:float",
[{line,34},{column,4}],
'+inf'},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,35},{column,3}],
"+.inf"},
{yamerl_float,yamerl_node_float_json,
"tag:yaml.org,2002:float",
[{line,36},{column,3}],
'-inf'},
{yamerl_float,yamerl_node_float_json,
"tag:yaml.org,2002:float",
[{line,37},{column,4}],
nan},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,39},{column,3}],
".Inf"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,40},{column,3}],
".INF"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,41},{column,3}],
".iNF"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,43},{column,3}],
".NaN"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,44},{column,3}],
".NAN"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,45},{column,3}],
".Nan"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,46},{column,3}],
".nAN"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,48},{column,4}],
"Not a float.0e+10"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,49},{column,3}],
"+Not a float.0e+10"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,50},{column,3}],
"-Not a float.0e+10"}],
39}}],
yamerl_constr:file(?FILENAME,
[{detailed_constr, true}, {schema, failsafe},
{node_mods, [yamerl_node_float_json]}])
)
]
}.
schema_failsafe_float_detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[{yamerl_doc,
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,1},{column,1}],
[
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,1},{column,4}],
0.0},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,2},{column,3}],
0.0},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,3},{column,3}],
0.0},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,5},{column,4}],
123.0},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,6},{column,3}],
123.0},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,7},{column,3}],
-123.0},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,9},{column,4}],
12.34},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,10},{column,3}],
12.34},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,11},{column,3}],
-12.34},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,13},{column,4}],
1.2e11},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,14},{column,3}],
1.2e11},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,15},{column,3}],
-1.2e11},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,17},{column,3}],
1.2e11},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,18},{column,3}],
1.2e11},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,19},{column,3}],
1.2e-11},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,21},{column,3}],
1.0e10},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,22},{column,3}],
1.0e10},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,24},{column,4}],
"."},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,25},{column,4}],
0.1},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,26},{column,4}],
".e+3"},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,27},{column,3}],
1.0},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,28},{column,3}],
1000.0},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,30},{column,4}],
"190:20:30.15"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,31},{column,3}],
"+190:20:30.15"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,32},{column,3}],
"-190:20:30.15"},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,34},{column,4}],
'+inf'},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,35},{column,3}],
'+inf'},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,36},{column,3}],
'-inf'},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,37},{column,4}],
nan},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,39},{column,3}],
'+inf'},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,40},{column,3}],
'+inf'},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,41},{column,3}],
".iNF"},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,43},{column,3}],
nan},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,44},{column,3}],
nan},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,45},{column,3}],
".Nan"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,46},{column,3}],
".nAN"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,48},{column,4}],
"Not a float.0e+10"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,49},{column,3}],
"+Not a float.0e+10"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,50},{column,3}],
"-Not a float.0e+10"}],
39}}],
yamerl_constr:file(?FILENAME,
[{detailed_constr, true}, {schema, failsafe},
{node_mods, [yamerl_node_float]}])
)
]
}.
schema_failsafe_float_ext_detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[{yamerl_doc,
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,1},{column,1}],
[
{yamerl_float,yamerl_node_float_ext,
"tag:yaml.org,2002:float",
[{line,1},{column,4}],
0.0},
{yamerl_float,yamerl_node_float_ext,
"tag:yaml.org,2002:float",
[{line,2},{column,3}],
0.0},
{yamerl_float,yamerl_node_float_ext,
"tag:yaml.org,2002:float",
[{line,3},{column,3}],
0.0},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,5},{column,4}],
"123"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,6},{column,3}],
"+123"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,7},{column,3}],
"-123"},
{yamerl_float,yamerl_node_float_ext,
"tag:yaml.org,2002:float",
[{line,9},{column,4}],
12.34},
{yamerl_float,yamerl_node_float_ext,
"tag:yaml.org,2002:float",
[{line,10},{column,3}],
12.34},
{yamerl_float,yamerl_node_float_ext,
"tag:yaml.org,2002:float",
[{line,11},{column,3}],
-12.34},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,13},{column,4}],
"12e10"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,14},{column,3}],
"+12e10"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,15},{column,3}],
"-12e10"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,17},{column,3}],
"1.2e11"},
{yamerl_float,yamerl_node_float_ext,
"tag:yaml.org,2002:float",
[{line,18},{column,3}],
1.2e11},
{yamerl_float,yamerl_node_float_ext,
"tag:yaml.org,2002:float",
[{line,19},{column,3}],
1.2e-11},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,21},{column,3}],
"1.0e10"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,22},{column,3}],
"1.0E10"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,24},{column,4}],
"."},
{yamerl_float,yamerl_node_float_ext,
"tag:yaml.org,2002:float",
[{line,25},{column,4}],
0.1},
{yamerl_float,yamerl_node_float_ext,
"tag:yaml.org,2002:float",
[{line,26},{column,4}],
0.0},
{yamerl_float,yamerl_node_float_ext,
"tag:yaml.org,2002:float",
[{line,27},{column,3}],
1.0},
{yamerl_float,yamerl_node_float_ext,
"tag:yaml.org,2002:float",
[{line,28},{column,3}],
1000.0},
{yamerl_float,yamerl_node_float_ext,
"tag:yaml.org,2002:float",
[{line,30},{column,4}],
685230.15},
{yamerl_float,yamerl_node_float_ext,
"tag:yaml.org,2002:float",
[{line,31},{column,3}],
685230.15},
{yamerl_float,yamerl_node_float_ext,
"tag:yaml.org,2002:float",
[{line,32},{column,3}],
-685230.15},
{yamerl_float,yamerl_node_float_ext,
"tag:yaml.org,2002:float",
[{line,34},{column,4}],
'+inf'},
{yamerl_float,yamerl_node_float_ext,
"tag:yaml.org,2002:float",
[{line,35},{column,3}],
'+inf'},
{yamerl_float,yamerl_node_float_ext,
"tag:yaml.org,2002:float",
[{line,36},{column,3}],
'-inf'},
{yamerl_float,yamerl_node_float_ext,
"tag:yaml.org,2002:float",
[{line,37},{column,4}],
nan},
{yamerl_float,yamerl_node_float_ext,
"tag:yaml.org,2002:float",
[{line,39},{column,3}],
'+inf'},
{yamerl_float,yamerl_node_float_ext,
"tag:yaml.org,2002:float",
[{line,40},{column,3}],
'+inf'},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,41},{column,3}],
".iNF"},
{yamerl_float,yamerl_node_float_ext,
"tag:yaml.org,2002:float",
[{line,43},{column,3}],
nan},
{yamerl_float,yamerl_node_float_ext,
"tag:yaml.org,2002:float",
[{line,44},{column,3}],
nan},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,45},{column,3}],
".Nan"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,46},{column,3}],
".nAN"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,48},{column,4}],
"Not a float.0e+10"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,49},{column,3}],
"+Not a float.0e+10"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,50},{column,3}],
"-Not a float.0e+10"}],
39}}],
yamerl_constr:file(?FILENAME,
[{detailed_constr, true}, {schema, failsafe},
{node_mods, [yamerl_node_float_ext]}])
)
]
}.

546
test/construction/int.erl Normal file
View File

@ -0,0 +1,546 @@
-module(int).
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
setup() ->
application:start(yamerl).
schema_failsafe_simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[
"0", "+0", "-0",
"123", "+123", "-123",
"0b101", "+0b101", "-0b101",
"0o123", "+0o123", "-0o123",
"0123", "+0123", "-0123",
"0x1aB", "+0x1aB", "-0x1aB",
"123:1:23", "+123:1:23", "-123:1:23",
"1_234", "0b10_10", "0o12_34", "012_34", "0xc3_A9", "1_234:56:8",
"Not an int", "+Not an int", "-Not an int"
]
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, false}, {schema, failsafe}]) %% No integer parsing
)
]
}.
schema_failsafe_int_json_simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[
0, "+0", 0,
123, "+123", -123,
"0b101", "+0b101", "-0b101",
"0o123", "+0o123", "-0o123",
"0123", "+0123", "-0123",
"0x1aB", "+0x1aB", "-0x1aB",
"123:1:23", "+123:1:23", "-123:1:23",
"1_234", "0b10_10", "0o12_34", "012_34", "0xc3_A9", "1_234:56:8",
"Not an int", "+Not an int", "-Not an int"
]
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, false}, {schema, failsafe},
{node_mods, [yamerl_node_int_json]}])
)
]
}.
schema_failsafe_int_simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[
0, 0, 0,
123, 123, -123,
"0b101", "+0b101", "-0b101",
83, 83, -83,
123, 123, -123,
427, 427, -427,
"123:1:23", "+123:1:23", "-123:1:23",
"1_234", "0b10_10", "0o12_34", "012_34", "0xc3_A9", "1_234:56:8",
"Not an int", "+Not an int", "-Not an int"
]
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, false}, {schema, failsafe},
{node_mods, [yamerl_node_int]}])
)
]
}.
schema_failsafe_int_ext_simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[
0, 0, 0,
123, 123, -123,
5, 5, -5,
"0o123", "+0o123", "-0o123",
83, 83, -83,
427, 427, -427,
442883, 442883, -442883,
1234, 10, "0o12_34", 668, 50089, 4445768,
"Not an int", "+Not an int", "-Not an int"
]
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, false}, {schema, failsafe},
{node_mods, [yamerl_node_int_ext]}])
)
]
}.
schema_failsafe_detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,1},{column,1}],
[{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,1},{column,4}],
"0"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,2},{column,3}],
"+0"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,3},{column,3}],
"-0"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,5},{column,4}],
"123"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,6},{column,3}],
"+123"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,7},{column,3}],
"-123"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,9},{column,4}],
"0b101"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,10},{column,3}],
"+0b101"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,11},{column,3}],
"-0b101"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,13},{column,4}],
"0o123"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,14},{column,3}],
"+0o123"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,15},{column,3}],
"-0o123"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,17},{column,4}],
"0123"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,18},{column,3}],
"+0123"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,19},{column,3}],
"-0123"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,21},{column,4}],
"0x1aB"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,22},{column,3}],
"+0x1aB"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,23},{column,3}],
"-0x1aB"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,25},{column,4}],
"123:1:23"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,26},{column,3}],
"+123:1:23"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,27},{column,3}],
"-123:1:23"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,29},{column,3}],
"1_234"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,30},{column,3}],
"0b10_10"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,31},{column,3}],
"0o12_34"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,32},{column,3}],
"012_34"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,33},{column,3}],
"0xc3_A9"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,34},{column,3}],
"1_234:56:8"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,36},{column,4}],
"Not an int"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,37},{column,3}],
"+Not an int"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,38},{column,3}],
"-Not an int"}],
30}
}
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, true}, {schema, failsafe}]) %% No integer parsing
)
]
}.
schema_failsafe_int_json_detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,1},{column,1}],
[{yamerl_int,yamerl_node_int_json,
"tag:yaml.org,2002:int",
[{line,1},{column,4}],
0},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,2},{column,3}],
"+0"},
{yamerl_int,yamerl_node_int_json,
"tag:yaml.org,2002:int",
[{line,3},{column,3}],
0},
{yamerl_int,yamerl_node_int_json,
"tag:yaml.org,2002:int",
[{line,5},{column,4}],
123},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,6},{column,3}],
"+123"},
{yamerl_int,yamerl_node_int_json,
"tag:yaml.org,2002:int",
[{line,7},{column,3}],
-123},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,9},{column,4}],
"0b101"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,10},{column,3}],
"+0b101"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,11},{column,3}],
"-0b101"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,13},{column,4}],
"0o123"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,14},{column,3}],
"+0o123"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,15},{column,3}],
"-0o123"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,17},{column,4}],
"0123"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,18},{column,3}],
"+0123"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,19},{column,3}],
"-0123"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,21},{column,4}],
"0x1aB"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,22},{column,3}],
"+0x1aB"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,23},{column,3}],
"-0x1aB"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,25},{column,4}],
"123:1:23"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,26},{column,3}],
"+123:1:23"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,27},{column,3}],
"-123:1:23"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,29},{column,3}],
"1_234"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,30},{column,3}],
"0b10_10"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,31},{column,3}],
"0o12_34"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,32},{column,3}],
"012_34"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,33},{column,3}],
"0xc3_A9"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,34},{column,3}],
"1_234:56:8"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,36},{column,4}],
"Not an int"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,37},{column,3}],
"+Not an int"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,38},{column,3}],
"-Not an int"}],
30}
}
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, true}, {schema, failsafe},
{node_mods, [yamerl_node_int_json]}])
)
]
}.
schema_failsafe_int_detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,1},{column,1}],
[{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
[{line,1},{column,4}],
0},
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
[{line,2},{column,3}],
0},
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
[{line,3},{column,3}],
0},
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
[{line,5},{column,4}],
123},
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
[{line,6},{column,3}],
123},
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
[{line,7},{column,3}],
-123},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,9},{column,4}],
"0b101"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,10},{column,3}],
"+0b101"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,11},{column,3}],
"-0b101"},
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
[{line,13},{column,4}],
83},
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
[{line,14},{column,3}],
83},
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
[{line,15},{column,3}],
-83},
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
[{line,17},{column,4}],
123},
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
[{line,18},{column,3}],
123},
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
[{line,19},{column,3}],
-123},
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
[{line,21},{column,4}],
427},
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
[{line,22},{column,3}],
427},
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
[{line,23},{column,3}],
-427},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,25},{column,4}],
"123:1:23"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,26},{column,3}],
"+123:1:23"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,27},{column,3}],
"-123:1:23"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,29},{column,3}],
"1_234"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,30},{column,3}],
"0b10_10"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,31},{column,3}],
"0o12_34"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,32},{column,3}],
"012_34"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,33},{column,3}],
"0xc3_A9"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,34},{column,3}],
"1_234:56:8"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,36},{column,4}],
"Not an int"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,37},{column,3}],
"+Not an int"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,38},{column,3}],
"-Not an int"}],
30}
}
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, true}, {schema, failsafe},
{node_mods, [yamerl_node_int]}])
)
]
}.
schema_failsafe_int_ext_detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,1},{column,1}],
[{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
[{line,1},{column,4}],
0},
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
[{line,2},{column,3}],
0},
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
[{line,3},{column,3}],
0},
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
[{line,5},{column,4}],
123},
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
[{line,6},{column,3}],
123},
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
[{line,7},{column,3}],
-123},
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
[{line,9},{column,4}],
5},
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
[{line,10},{column,3}],
5},
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
[{line,11},{column,3}],
-5},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,13},{column,4}],
"0o123"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,14},{column,3}],
"+0o123"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,15},{column,3}],
"-0o123"},
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
[{line,17},{column,4}],
83},
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
[{line,18},{column,3}],
83},
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
[{line,19},{column,3}],
-83},
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
[{line,21},{column,4}],
427},
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
[{line,22},{column,3}],
427},
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
[{line,23},{column,3}],
-427},
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
[{line,25},{column,4}],
442883},
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
[{line,26},{column,3}],
442883},
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
[{line,27},{column,3}],
-442883},
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
[{line,29},{column,3}],
1234},
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
[{line,30},{column,3}],
10},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,31},{column,3}],
"0o12_34"},
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
[{line,32},{column,3}],
668},
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
[{line,33},{column,3}],
50089},
{yamerl_int,yamerl_node_int_ext,"tag:yaml.org,2002:int",
[{line,34},{column,3}],
4445768},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,36},{column,4}],
"Not an int"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,37},{column,3}],
"+Not an int"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,38},{column,3}],
"-Not an int"}],
30}
}
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, true}, {schema, failsafe},
{node_mods, [yamerl_node_int_ext]}])
)
]
}.

View File

@ -0,0 +1,77 @@
-module(ipaddr).
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
setup() ->
application:start(yamerl),
yamerl_app:set_param(node_mods, [yamerl_node_ipaddr]).
simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[
{192, 168, 1, 10},
{{192, 168, 1, 10}, 24},
{{192, 168, 1, 10}, {192, 168, 1, 20}},
{8193,16848,1,28696,0,0,1,2},
{{8193,16848,1,28696,0,0,1,0},64},
{{8193,16848,1,28696,0,0,1,2},{8193,16848,1,28696,0,0,1,5}},
"Not an IP address"
]
],
yamerl_constr:file(?FILENAME, [{detailed_constr, false}])
)
]
}.
detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,1},{column,1}],
[{yamerl_ip_addr,yamerl_node_ipaddr,
"tag:yamerl,2012:ipaddr",
[{line,1},{column,3}],
{192,168,1,10}},
{yamerl_ip_netmask,yamerl_node_ipaddr,
"tag:yamerl,2012:ipaddr",
[{line,2},{column,3}],
{192,168,1,10},
24},
{yamerl_ip_range,yamerl_node_ipaddr,
"tag:yamerl,2012:ipaddr",
[{line,3},{column,3}],
{192,168,1,10},
{192,168,1,20}},
{yamerl_ip_addr,yamerl_node_ipaddr,
"tag:yamerl,2012:ipaddr",
[{line,5},{column,3}],
{8193,16848,1,28696,0,0,1,2}},
{yamerl_ip_netmask,yamerl_node_ipaddr,
"tag:yamerl,2012:ipaddr",
[{line,6},{column,3}],
{8193,16848,1,28696,0,0,1,0},
64},
{yamerl_ip_range,yamerl_node_ipaddr,
"tag:yamerl,2012:ipaddr",
[{line,7},{column,3}],
{8193,16848,1,28696,0,0,1,2},
{8193,16848,1,28696,0,0,1,5}},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,9},{column,3}],
"Not an IP address"}],
7}}
],
yamerl_constr:file(?FILENAME, [{detailed_constr, true}])
)
]
}.

65
test/construction/map.erl Normal file
View File

@ -0,0 +1,65 @@
-module(map).
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
setup() ->
application:start(yamerl).
simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[
{"first", [{"item", 1}]},
{"second", [{"item", 2}]}
]
],
yamerl_constr:file(?FILENAME, [{detailed_constr, false}])
)
]
}.
detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,
{yamerl_map,yamerl_node_map,"tag:yaml.org,2002:map",
[{line,1},{column,1}],
[{{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,1},{column,1}],
"first"},
{yamerl_map,yamerl_node_map,"tag:yaml.org,2002:map",
[{line,1},{column,9}],
[{{yamerl_str,yamerl_node_str,
"tag:yaml.org,2002:str",
[{line,1},{column,11}],
"item"},
{yamerl_int,yamerl_node_int,
"tag:yaml.org,2002:int",
[{line,1},{column,17}],
1}}]}},
{{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,2},{column,1}],
"second"},
{yamerl_map,yamerl_node_map,"tag:yaml.org,2002:map",
[{line,2},{column,9}],
[{{yamerl_str,yamerl_node_str,
"tag:yaml.org,2002:str",
[{line,2},{column,11}],
"item"},
{yamerl_int,yamerl_node_int,
"tag:yaml.org,2002:int",
[{line,2},{column,17}],
2}}]}}]}}
],
yamerl_constr:file(?FILENAME, [{detailed_constr, true}])
)
]
}.

135
test/construction/null.erl Normal file
View File

@ -0,0 +1,135 @@
-module(null).
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
setup() ->
application:start(yamerl).
schema_failsafe_simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
["~", "null", "Null", "NULL", "", "Not a null"]
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, false}, {schema, failsafe}])
)
]
}.
schema_json_simple_test_() ->
{setup,
fun setup/0,
[
?_assertThrow(
{yamerl_exception, [
{yamerl_parsing_error,error, "Invalid string", 1, 3, not_a_string,
{yamerl_scalar, 1, 3,
{yamerl_tag, 1, 3, {non_specific, "?"}},
flow, plain, "~"},
[]}]},
yamerl_constr:file(?FILENAME,
[{detailed_constr, false}, {schema, json}])
)
]
}.
schema_core_simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[null, null, null, null, null, "Not a null"]
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, false}, {schema, core}])
)
]
}.
schema_failsafe_detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,1},{column,1}],
[{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,1},{column,3}],
"~"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,2},{column,3}],
"null"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,3},{column,3}],
"Null"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,4},{column,3}],
"NULL"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,5},{column,1}],
""},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,7},{column,3}],
"Not a null"}],
6}}
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, true}, {schema, failsafe}])
)
]
}.
schema_json_detailed_test_() ->
{setup,
fun setup/0,
[
?_assertThrow(
{yamerl_exception, [
{yamerl_parsing_error,error, "Invalid string", 1, 3, not_a_string,
{yamerl_scalar, 1, 3,
{yamerl_tag, 1, 3, {non_specific, "?"}},
flow, plain, "~"},
[]}]},
yamerl_constr:file(?FILENAME,
[{detailed_constr, true}, {schema, json}])
)
]
}.
schema_core_detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,1},{column,1}],
[{yamerl_null,yamerl_node_null,"tag:yaml.org,2002:null",
[{line,1},{column,3}]},
{yamerl_null,yamerl_node_null,"tag:yaml.org,2002:null",
[{line,2},{column,3}]},
{yamerl_null,yamerl_node_null,"tag:yaml.org,2002:null",
[{line,3},{column,3}]},
{yamerl_null,yamerl_node_null,"tag:yaml.org,2002:null",
[{line,4},{column,3}]},
{yamerl_null,yamerl_node_null,"tag:yaml.org,2002:null",
[{line,5},{column,1}]},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,7},{column,3}],
"Not a null"}],
6}}
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, true}, {schema, core}])
)
]
}.

View File

@ -0,0 +1,42 @@
-module(null_json).
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
setup() ->
application:start(yamerl).
simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[null]
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, false}, {schema, json}])
)
]
}.
detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,1},{column,1}],
[{yamerl_null,yamerl_node_null_json,
"tag:yaml.org,2002:null",
[{line,1},{column,3}]}],
1}}
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, true}, {schema, json}])
)
]
}.

63
test/construction/seq.erl Normal file
View File

@ -0,0 +1,63 @@
-module(seq).
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
setup() ->
application:start(yamerl).
simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[
[ "item", 1 ],
[ "item", 2 ]
]
],
yamerl_constr:file(?FILENAME, [{detailed_constr, false}])
)
]
}.
detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,1},{column,1}],
[{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,1},{column,3}],
[{yamerl_str,yamerl_node_str,
"tag:yaml.org,2002:str",
[{line,1},{column,5}],
"item"},
{yamerl_int,yamerl_node_int,
"tag:yaml.org,2002:int",
[{line,1},{column,11}],
1}],
2},
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,2},{column,3}],
[{yamerl_str,yamerl_node_str,
"tag:yaml.org,2002:str",
[{line,2},{column,5}],
"item"},
{yamerl_int,yamerl_node_int,
"tag:yaml.org,2002:int",
[{line,2},{column,11}],
2}],
2}],
2}
}
],
yamerl_constr:file(?FILENAME, [{detailed_constr, true}])
)
]
}.

View File

@ -0,0 +1,69 @@
-module(size).
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
setup() ->
application:start(yamerl),
yamerl_app:set_param(node_mods, [yamerl_node_size]).
simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[
2000, 2000000, 2000000000, 2000000000000,
2048, 2097152, 2147483648, 2199023255552,
"Not a size"
]
],
yamerl_constr:file(?FILENAME, [{detailed_constr, false}])
)
]
}.
detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,1},{column,1}],
[{yamerl_int,yamerl_node_size,"tag:yamerl,2012:size",
[{line,1},{column,3}],
2000},
{yamerl_int,yamerl_node_size,"tag:yamerl,2012:size",
[{line,2},{column,3}],
2000000},
{yamerl_int,yamerl_node_size,"tag:yamerl,2012:size",
[{line,3},{column,3}],
2000000000},
{yamerl_int,yamerl_node_size,"tag:yamerl,2012:size",
[{line,4},{column,3}],
2000000000000},
{yamerl_int,yamerl_node_size,"tag:yamerl,2012:size",
[{line,6},{column,3}],
2048},
{yamerl_int,yamerl_node_size,"tag:yamerl,2012:size",
[{line,7},{column,3}],
2097152},
{yamerl_int,yamerl_node_size,"tag:yamerl,2012:size",
[{line,8},{column,3}],
2147483648},
{yamerl_int,yamerl_node_size,"tag:yamerl,2012:size",
[{line,9},{column,3}],
2199023255552},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,11},{column,3}],
"Not a size"}],
9}}
],
yamerl_constr:file(?FILENAME, [{detailed_constr, true}])
)
]
}.

110
test/construction/str.erl Normal file
View File

@ -0,0 +1,110 @@
-module(str).
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
setup() ->
application:start(yamerl).
list_simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[$2, $\s, 8364] % "2 €"
],
yamerl_constr:file(?FILENAME, [{detailed_constr, false}])
)
]
}.
list_detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,1},{column,1}],
[$2, $\s, 8364]} % "2 €"
}
],
yamerl_constr:file(?FILENAME, [{detailed_constr, true}])
)
]
}.
binary_simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
<<50,32,226,130,172>> % "2 €"
],
yamerl_constr:file(?FILENAME, [
{detailed_constr, false},
str_node_as_binary
])
)
]
}.
binary_detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,1},{column,1}],
<<50,32,226,130,172>>} % "2 €"
}
],
yamerl_constr:file(?FILENAME, [
{detailed_constr, true},
str_node_as_binary
])
)
]
}.
binary_utf32be_simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
<<0,0,0,50, 0,0,0,32, 0,0,32,172>> % "2 €"
],
yamerl_constr:file(?FILENAME, [
{detailed_constr, false},
{str_node_as_binary, {utf32, big}}
])
)
]
}.
binary_utf32be_simple_detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,1},{column,1}],
<<0,0,0,50, 0,0,0,32, 0,0,32,172>>} % "2 €"
}
],
yamerl_constr:file(?FILENAME, [
{detailed_constr, true},
{str_node_as_binary, {utf32, big}}
])
)
]
}.

View File

@ -0,0 +1,54 @@
-module(stream).
-include_lib("eunit/include/eunit.hrl").
setup() ->
application:start(yamerl).
simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
["Hello!"],
begin
Stream_St1 = yamerl_constr:new("<stdin>"),
{continue, Stream_St2} = yamerl_constr:next_chunk(Stream_St1,
<<"He">>),
{continue, Stream_St3} = yamerl_constr:next_chunk(Stream_St2,
<<"ll">>),
yamerl_constr:last_chunk(Stream_St3, <<"o!">>)
end
)
]
}.
detailed_test_() ->
{setup,
fun setup/0,
[
?_assertThrow(
{yamerl_exception,
[
{yamerl_parsing_error, error,
"Unexpected end-of-stream while parsing flow scalar",
1, 8,
unexpected_eos,
{yamerl_scalar, 1, 1, {yamerl_tag, 1, 1, {non_specific, "!"}},
flow, single_quoted,
"Hello!"},
[]
}
]
},
begin
Stream_St1 = yamerl_constr:new("<stdin>"),
{continue, Stream_St2} = yamerl_constr:next_chunk(Stream_St1,
<<"'He">>),
{continue, Stream_St3} = yamerl_constr:next_chunk(Stream_St2,
<<"ll">>),
yamerl_constr:last_chunk(Stream_St3, <<"o!">>)
end
)
]
}.

View File

@ -0,0 +1,80 @@
-module(timestamp).
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
setup() ->
application:start(yamerl),
Node_Mods = yamerl_app:get_param(node_mods),
yamerl_app:set_param(node_mods, [yamerl_node_timestamp]),
Node_Mods.
teardown(Node_Mods) ->
yamerl_app:set_param(node_mods, Node_Mods).
simple_test_() ->
{setup,
fun setup/0,
fun teardown/1,
[
?_assertMatch(
[
[
{{2011, 5, 26}, undefined},
{undefined, {14,58,3}},
{{2011, 5, 26}, {14,58,3}},
{{2011, 5, 26}, {14,58,3}},
{{2011, 5, 26}, {14,58,3}},
"Not a timestamp"
]
],
yamerl_constr:file(?FILENAME, [{detailed_constr, false}])
)
]
}.
detailed_test_() ->
{setup,
fun setup/0,
fun teardown/1,
[
?_assertMatch(
[
{yamerl_doc,
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,1},{column,1}],
[{yamerl_timestamp,yamerl_node_timestamp,
"tag:yamerl,2012:timestamp",
[{line,1},{column,3}],
2011,5,26,undefined,undefined,undefined,
0,0},
{yamerl_timestamp,yamerl_node_timestamp,
"tag:yamerl,2012:timestamp",
[{line,2},{column,3}],
undefined,undefined,undefined,14,58,3,
0,0},
{yamerl_timestamp,yamerl_node_timestamp,
"tag:yamerl,2012:timestamp",
[{line,3},{column,3}],
2011,5,26,14,58,3,
0,0},
{yamerl_timestamp,yamerl_node_timestamp,
"tag:yamerl,2012:timestamp",
[{line,4},{column,3}],
2011,5,26,14,58,3,
0,0},
{yamerl_timestamp,yamerl_node_timestamp,
"tag:yamerl,2012:timestamp",
[{line,5},{column,3}],
2011,5,26,14,58,3,
0,0},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,7},{column,3}],
"Not a timestamp"}],
6}}
],
yamerl_constr:file(?FILENAME, [{detailed_constr, true}])
)
]
}.

View File

@ -0,0 +1,110 @@
-module(unicode_string).
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
setup() ->
application:start(yamerl).
schema_failsafe_simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[[12356, 12429, 12399]]
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, false}, {schema, failsafe}])
)
]
}.
schema_json_simple_test_() ->
{setup,
fun setup/0,
[
?_assertThrow(
{yamerl_exception, [
{yamerl_parsing_error,error, "Invalid string", 1, 3, not_a_string,
{yamerl_scalar, 1, 3,
{yamerl_tag, 1, 3, {non_specific, "?"}},
flow, plain, [12356, 12429, 12399]},
[]}]},
yamerl_constr:file(?FILENAME,
[{detailed_constr, false}, {schema, json}])
)
]
}.
schema_core_simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[[12356, 12429, 12399]]
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, false}, {schema, core}])
)
]
}.
schema_failsafe_detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,1},{column,1}],
[{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,1},{column,3}],
[12356, 12429, 12399]}],
1}}
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, true}, {schema, failsafe}])
)
]
}.
schema_json_detailed_test_() ->
{setup,
fun setup/0,
[
?_assertThrow(
{yamerl_exception, [
{yamerl_parsing_error,error, "Invalid string", 1, 3, not_a_string,
{yamerl_scalar, 1, 3,
{yamerl_tag, 1, 3, {non_specific, "?"}},
flow, plain, [12356, 12429, 12399]},
[]}]},
yamerl_constr:file(?FILENAME,
[{detailed_constr, true}, {schema, json}])
)
]
}.
schema_core_detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,1},{column,1}],
[{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,1},{column,3}],
[12356, 12429, 12399]}],
1}}
],
yamerl_constr:file(?FILENAME,
[{detailed_constr, true}, {schema, core}])
)
]
}.

View File

@ -0,0 +1,44 @@
-module(unknown_alias).
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").
setup() ->
application:start(yamerl).
simple_test_() ->
{setup,
fun setup/0,
[
?_assertThrow(
{yamerl_exception,
[{yamerl_parsing_error,error,
"No anchor corresponds to alias \"anchor\"",
2,3,no_matching_anchor,
{yamerl_alias,2,3,"anchor"},
[]}
]
},
yamerl_constr:file(?FILENAME, [{detailed_constr, false}])
)
]
}.
detailed_test_() ->
{setup,
fun setup/0,
[
?_assertThrow(
{yamerl_exception,
[{yamerl_parsing_error,error,
"No anchor corresponds to alias \"anchor\"",
2,3,no_matching_anchor,
{yamerl_alias,2,3,"anchor"},
[]}
]
},
yamerl_constr:file(?FILENAME, [{detailed_constr, true}])
)
]
}.

296
test/examples/invoice.erl Normal file
View File

@ -0,0 +1,296 @@
-module(invoice).
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/examples/" ?MODULE_STRING ".yaml").
setup() ->
application:start(yamerl).
simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[
{"invoice",34843},
{"date","2001-01-23"},
{"bill-to",
[
{"given","Chris"},
{"family","Dumars"},
{"address",
[
{"lines","458 Walkman Dr.\nSuite #292\n"},
{"city","Royal Oak"},
{"state","MI"},
{"postal",48046}]}]},
{"ship-to",
[
{"given","Chris"},
{"family","Dumars"},
{"address",
[
{"lines","458 Walkman Dr.\nSuite #292\n"},
{"city","Royal Oak"},
{"state","MI"},
{"postal",48046}]}]},
{"product",
[
[
{"sku","BL394D"},
{"quantity",4},
{"description","Basketball"},
{"price",450.0}],
[
{"sku","BL4438H"},
{"quantity",1},
{"description","Super Hoop"},
{"price",2392.0}]]},
{"tax",251.42},
{"total",4443.52},
{"comments",
"Late afternoon is best. "
"Backup contact is Nancy Billsmer @ 338-4338."}]
],
yamerl_constr:file(?FILENAME, [{detailed_constr, false}])
)
]
}.
detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,{yamerl_map,yamerl_node_map,
"tag:yaml.org,2002:map",
[{line,2},{column,1}],
[
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,2},{column,1}],
"invoice"},
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
[{line,2},{column,10}],
34843}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,3},{column,1}],
"date"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,3},{column,10}],
"2001-01-23"}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,4},{column,1}],
"bill-to"},
{yamerl_map,yamerl_node_map,"tag:yaml.org,2002:map",
[{line,5},{column,5}],
[
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,5},{column,5}],
"given"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,5},{column,14}],
"Chris"}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,6},{column,5}],
"family"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,6},{column,14}],
"Dumars"}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,7},{column,5}],
"address"},
{yamerl_map,yamerl_node_map,"tag:yaml.org,2002:map",
[{line,8},{column,9}],
[
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,8},{column,9}],
"lines"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,8},{column,16}],
"458 Walkman Dr.\nSuite #292\n"}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,11},{column,9}],
"city"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,11},{column,19}],
"Royal Oak"}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,12},{column,9}],
"state"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,12},{column,19}],
"MI"}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,13},{column,9}],
"postal"},
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
[{line,13},{column,19}],
48046}}]}}]}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,14},{column,1}],
"ship-to"},
{yamerl_map,yamerl_node_map,"tag:yaml.org,2002:map",
[{line,5},{column,5}],
[
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,5},{column,5}],
"given"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,5},{column,14}],
"Chris"}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,6},{column,5}],
"family"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,6},{column,14}],
"Dumars"}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,7},{column,5}],
"address"},
{yamerl_map,yamerl_node_map,"tag:yaml.org,2002:map",
[{line,8},{column,9}],
[
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,8},{column,9}],
"lines"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,8},{column,16}],
"458 Walkman Dr.\nSuite #292\n"}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,11},{column,9}],
"city"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,11},{column,19}],
"Royal Oak"}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,12},{column,9}],
"state"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,12},{column,19}],
"MI"}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,13},{column,9}],
"postal"},
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
[{line,13},{column,19}],
48046}}]}}]}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,15},{column,1}],
"product"},
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,16},{column,5}],
[
{yamerl_map,yamerl_node_map,"tag:yaml.org,2002:map",
[{line,16},{column,7}],
[
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,16},{column,7}],
"sku"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,16},{column,21}],
"BL394D"}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,17},{column,7}],
"quantity"},
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
[{line,17},{column,21}],
4}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,18},{column,7}],
"description"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,18},{column,21}],
"Basketball"}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,19},{column,7}],
"price"},
{yamerl_float,yamerl_node_float,
"tag:yaml.org,2002:float",
[{line,19},{column,21}],
450.0}}]},
{yamerl_map,yamerl_node_map,"tag:yaml.org,2002:map",
[{line,20},{column,7}],
[
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,20},{column,7}],
"sku"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,20},{column,21}],
"BL4438H"}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,21},{column,7}],
"quantity"},
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
[{line,21},{column,21}],
1}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,22},{column,7}],
"description"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,22},{column,21}],
"Super Hoop"}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,23},{column,7}],
"price"},
{yamerl_float,yamerl_node_float,
"tag:yaml.org,2002:float",
[{line,23},{column,21}],
2392.0}}]}],
2}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,24},{column,1}],
"tax"},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,24},{column,8}],
251.42}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,25},{column,1}],
"total"},
{yamerl_float,yamerl_node_float,"tag:yaml.org,2002:float",
[{line,25},{column,8}],
4443.52}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,26},{column,1}],
"comments"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,27},{column,5}],
"Late afternoon is best. "
"Backup contact is Nancy Billsmer @ 338-4338."}}]}}
],
yamerl_constr:file(?FILENAME, [{detailed_constr, true}])
)
]
}.

184
test/examples/logfile.erl Normal file
View File

@ -0,0 +1,184 @@
-module(logfile).
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/examples/" ?MODULE_STRING ".yaml").
setup() ->
application:start(yamerl).
simple_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
[
{"Time","2001-11-23 15:01:42 -5"},
{"User","ed"},
{"Warning","This is an error message for the log file"}],
[
{"Time","2001-11-23 15:02:31 -5"},
{"User","ed"},
{"Warning","A slightly different error message."}],
[
{"Date","2001-11-23 15:03:17 -5"},
{"User","ed"},
{"Fatal","Unknown variable \"bar\""},
{"Stack",
[
[
{"file","TopClass.py"},
{"line",23},
{"code","x = MoreObject(\"345\\n\")\n"}],
[
{"file","MoreClass.py"},
{"line",58},
{"code","foo = bar"}]]}]],
yamerl_constr:file(?FILENAME, [{detailed_constr, false}])
)
]
}.
detailed_test_() ->
{setup,
fun setup/0,
[
?_assertMatch(
[
{yamerl_doc,{yamerl_map,yamerl_node_map,
"tag:yaml.org,2002:map",
[{line,2},{column,1}],
[
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,2},{column,1}],
"Time"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,2},{column,7}],
"2001-11-23 15:01:42 -5"}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,3},{column,1}],
"User"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,3},{column,7}],
"ed"}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,4},{column,1}],
"Warning"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,5},{column,3}],
"This is an error message for the log file"}}]}},
{yamerl_doc,{yamerl_map,yamerl_node_map,
"tag:yaml.org,2002:map",
[{line,8},{column,1}],
[
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,8},{column,1}],
"Time"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,8},{column,7}],
"2001-11-23 15:02:31 -5"}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,9},{column,1}],
"User"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,9},{column,7}],
"ed"}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,10},{column,1}],
"Warning"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,11},{column,3}],
"A slightly different error message."}}]}},
{yamerl_doc,{yamerl_map,yamerl_node_map,
"tag:yaml.org,2002:map",
[{line,14},{column,1}],
[
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,14},{column,1}],
"Date"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,14},{column,7}],
"2001-11-23 15:03:17 -5"}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,15},{column,1}],
"User"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,15},{column,7}],
"ed"}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,16},{column,1}],
"Fatal"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,17},{column,3}],
"Unknown variable \"bar\""}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,18},{column,1}],
"Stack"},
{yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
[{line,19},{column,3}],
[
{yamerl_map,yamerl_node_map,"tag:yaml.org,2002:map",
[{line,19},{column,5}],
[
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,19},{column,5}],
"file"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,19},{column,11}],
"TopClass.py"}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,20},{column,5}],
"line"},
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
[{line,20},{column,11}],
23}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,21},{column,5}],
"code"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,21},{column,11}],
"x = MoreObject(\"345\\n\")\n"}}]},
{yamerl_map,yamerl_node_map,"tag:yaml.org,2002:map",
[{line,23},{column,5}],
[
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,23},{column,5}],
"file"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,23},{column,11}],
"MoreClass.py"}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,24},{column,5}],
"line"},
{yamerl_int,yamerl_node_int,"tag:yaml.org,2002:int",
[{line,24},{column,11}],
58}},
{
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,25},{column,5}],
"code"},
{yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
[{line,25},{column,11}],
"foo = bar"}}]}],
2}}]}}
],
yamerl_constr:file(?FILENAME, [{detailed_constr, true}])
)
]
}.

View File

@ -0,0 +1,66 @@
-module('block_mapping_noeol').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[{io_blocksize, 1}],
<<>>,
24,
true,
[],
0,
25,
2,
5,
false,
2,
5,
utf8,
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
11,
10,
undefined,
undefined,
_,
false,
[],
[
{yamerl_stream_end,2,5},
{yamerl_doc_end,2,5},
{yamerl_collection_end,2,5,block,mapping},
{yamerl_scalar,2,4,
{yamerl_tag,2,4,{non_specific,"?"}},
flow,plain,[]},
{yamerl_mapping_value,2,4},
{yamerl_scalar,2,1,
{yamerl_tag,2,1,{non_specific,"?"}},
flow,plain,"key"},
{yamerl_mapping_key,2,1},
{yamerl_collection_start,2,1,
{yamerl_tag,2,1,{non_specific,"?"}},
block,mapping},
{yamerl_doc_start,2,1,{1,2}, _},
{yamerl_stream_start,1,1,utf8}
]
},
yamerl_parser:file(?FILENAME, [{io_blocksize, 1}])
).

View File

@ -0,0 +1,62 @@
-module('bom_between_docs').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[{io_blocksize, 1}],
<<>>,
55,
true,
[],
0,
51,
6,
1,
false,
5,
11,
utf8,
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
9,
8,
undefined,
undefined,
_,
false,
[],
[
{yamerl_stream_end,5,11},
{yamerl_doc_end,5,11},
{yamerl_scalar,5,1,
{yamerl_tag,5,1,{non_specific,"?"}},
flow,plain,"Document 2"},
{yamerl_doc_start,5,1,{1,2},_},
{yamerl_doc_end,3,1},
{yamerl_scalar,2,1,
{yamerl_tag,2,1,{non_specific,"?"}},
flow,plain,"Document 1"},
{yamerl_doc_start,2,1,{1,2},_},
{yamerl_stream_start,1,1,utf8}
]
},
yamerl_parser:file(?FILENAME, [{io_blocksize, 1}])
).

View File

@ -0,0 +1,66 @@
-module('dos_newlines').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[{io_blocksize, 1}],
<<>>,
70,
true,
[],
0,
71,
7,
1,
false,
6,
10,
utf8,
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
11,
10,
undefined,
undefined,
_,
false,
[],
[
{yamerl_stream_end,6,10},
{yamerl_doc_end,6,10},
{yamerl_collection_end,6,10,block,sequence},
{yamerl_scalar,5,3,
{yamerl_tag,5,3,{non_specific,"!"}},
flow,double_quoted,"Hello World"},
{yamerl_sequence_entry,5,1},
{yamerl_scalar,2,3,
{yamerl_tag,2,3,{non_specific,"!"}},
block,folded,"Hello World\n"},
{yamerl_sequence_entry,2,1},
{yamerl_collection_start,2,1,
{yamerl_tag,2,1,{non_specific,"?"}},
block,sequence},
{yamerl_doc_start,2,1,{1,2},_},
{yamerl_stream_start,1,1,utf8}
]
},
yamerl_parser:file(?FILENAME, [{io_blocksize, 1}])
).

52
test/parsing/empty.erl Normal file
View File

@ -0,0 +1,52 @@
-module('empty').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[],
<<>>,
0,
true,
[],
0,
1,
1,
1,
false,
1,
1,
utf8,
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
3,
2,
undefined,
undefined,
_,
false,
[],
[
{yamerl_stream_end,1,1},
{yamerl_stream_start,1,1,utf8}
]
},
yamerl_parser:file(?FILENAME)
).

View File

@ -0,0 +1,17 @@
-module('enc_invalid_unicode').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertThrow(
{yamerl_exception, [
{yamerl_parsing_error,error,
"Invalid Unicode character at byte #4",
undefined,undefined,invalid_unicode,undefined,
[{byte,4}]}
]
},
yamerl_parser:file(?FILENAME, [{io_blocksize, 1}])
).

View File

@ -0,0 +1,52 @@
-module('enc_utf16be_bom').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[{io_blocksize, 1}],
<<>>,
52,
true,
[],
0,
26,
2,
1,
false,
1,
25,
{utf16,big},
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
3,
2,
undefined,
undefined,
_,
false,
[],
[
{yamerl_stream_end,1,25},
{yamerl_stream_start,1,1,{utf16,big}}
]
},
yamerl_parser:file(?FILENAME, [{io_blocksize, 1}])
).

View File

@ -0,0 +1,52 @@
-module('enc_utf16be_char').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[{io_blocksize, 1}],
<<>>,
40,
true,
[],
0,
21,
2,
1,
false,
1,
20,
{utf16,big},
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
3,
2,
undefined,
undefined,
_,
false,
[],
[
{yamerl_stream_end,1,20},
{yamerl_stream_start,1,1,{utf16,big}}
]
},
yamerl_parser:file(?FILENAME, [{io_blocksize, 1}])
).

View File

@ -0,0 +1,52 @@
-module('enc_utf16le_bom').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[{io_blocksize, 1}],
<<>>,
52,
true,
[],
0,
26,
2,
1,
false,
1,
25,
{utf16,little},
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
3,
2,
undefined,
undefined,
_,
false,
[],
[
{yamerl_stream_end,1,25},
{yamerl_stream_start,1,1,{utf16,little}}
]
},
yamerl_parser:file(?FILENAME, [{io_blocksize, 1}])
).

View File

@ -0,0 +1,52 @@
-module('enc_utf16le_char').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[{io_blocksize, 1}],
<<>>,
40,
true,
[],
0,
21,
2,
1,
false,
1,
20,
{utf16,little},
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
3,
2,
undefined,
undefined,
_,
false,
[],
[
{yamerl_stream_end,1,20},
{yamerl_stream_start,1,1,{utf16,little}}
]
},
yamerl_parser:file(?FILENAME, [{io_blocksize, 1}])
).

View File

@ -0,0 +1,52 @@
-module('enc_utf32be_bom').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[{io_blocksize, 1}],
<<>>,
104,
true,
[],
0,
26,
2,
1,
false,
1,
25,
{utf32,big},
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
3,
2,
undefined,
undefined,
_,
false,
[],
[
{yamerl_stream_end,1,25},
{yamerl_stream_start,1,1,{utf32,big}}
]
},
yamerl_parser:file(?FILENAME, [{io_blocksize, 1}])
).

View File

@ -0,0 +1,52 @@
-module('enc_utf32be_char').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[{io_blocksize, 1}],
<<>>,
80,
true,
[],
0,
21,
2,
1,
false,
1,
20,
{utf32,big},
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
3,
2,
undefined,
undefined,
_,
false,
[],
[
{yamerl_stream_end,1,20},
{yamerl_stream_start,1,1,{utf32,big}}
]
},
yamerl_parser:file(?FILENAME, [{io_blocksize, 1}])
).

View File

@ -0,0 +1,52 @@
-module('enc_utf32le_bom').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[{io_blocksize, 1}],
<<>>,
104,
true,
[],
0,
26,
2,
1,
false,
1,
25,
{utf32,little},
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
3,
2,
undefined,
undefined,
_,
false,
[],
[
{yamerl_stream_end,1,25},
{yamerl_stream_start,1,1,{utf32,little}}
]
},
yamerl_parser:file(?FILENAME, [{io_blocksize, 1}])
).

View File

@ -0,0 +1,52 @@
-module('enc_utf32le_char').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[{io_blocksize, 1}],
<<>>,
80,
true,
[],
0,
21,
2,
1,
false,
1,
20,
{utf32,little},
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
3,
2,
undefined,
undefined,
_,
false,
[],
[
{yamerl_stream_end,1,20},
{yamerl_stream_start,1,1,{utf32,little}}
]
},
yamerl_parser:file(?FILENAME, [{io_blocksize, 1}])
).

View File

@ -0,0 +1,52 @@
-module('enc_utf8_bom').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[{io_blocksize, 1}],
<<>>,
25,
true,
[],
0,
23,
2,
1,
false,
1,
22,
utf8,
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
3,
2,
undefined,
undefined,
_,
false,
[],
[
{yamerl_stream_end,1,22},
{yamerl_stream_start,1,1,utf8}
]
},
yamerl_parser:file(?FILENAME, [{io_blocksize, 1}])
).

View File

@ -0,0 +1,52 @@
-module('enc_utf8_char').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[{io_blocksize, 1}],
<<>>,
17,
true,
[],
0,
18,
2,
1,
false,
1,
17,
utf8,
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
3,
2,
undefined,
undefined,
_,
false,
[],
[
{yamerl_stream_end,1,17},
{yamerl_stream_start,1,1,utf8}
]
},
yamerl_parser:file(?FILENAME, [{io_blocksize, 1}])
).

View File

@ -0,0 +1,83 @@
-module('ex_5.10_reserved_indicators').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[],
<<>>,
41,
true,
[],
0,
42,
3,
1,
false,
2,
20,
utf8,
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
15,
14,
undefined,
undefined,
_,
false,
[
{yamerl_parsing_error,warning,
"The reserved indicator \"`\" is not allowed at the beginning of a plain scalar",
2,15,reserved_indicator,
undefined,[]},
{yamerl_parsing_error,warning,
"The reserved indicator \"@\" is not allowed at the beginning of a plain scalar",
1,16,reserved_indicator,
undefined,[]}
],
[
{yamerl_stream_end,2,20},
{yamerl_doc_end,2,20},
{yamerl_collection_end,2,20,block,mapping},
{yamerl_scalar,2,15,
{yamerl_tag,2,15,{non_specific,"?"}},
flow,plain,"`text"},
{yamerl_mapping_value,2,13},
{yamerl_scalar,2,1,
{yamerl_tag,2,1,{non_specific,"?"}},
flow,plain,"grave-accent"},
{yamerl_mapping_key,2,1},
{yamerl_scalar,1,16,
{yamerl_tag,1,16,{non_specific,"?"}},
flow,plain,"@text"},
{yamerl_mapping_value,1,14},
{yamerl_scalar,1,1,
{yamerl_tag,1,1,{non_specific,"?"}},
flow,plain,"commercial-at"},
{yamerl_mapping_key,1,1},
{yamerl_collection_start,1,1,
{yamerl_tag,1,1,{non_specific,"?"}},
block,mapping},
{yamerl_doc_start,1,1,{1,2},_},
{yamerl_stream_start,1,1,utf8}
]
},
yamerl_parser:file(?FILENAME)
).

View File

@ -0,0 +1,74 @@
-module('ex_5.12_tabs_and_spaces').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[],
<<>>,
96,
true,
[],
0,
97,
7,
1,
false,
7,
1,
utf8,
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
15,
14,
undefined,
undefined,
_,
false,
[],
[
{yamerl_stream_end,7,1},
{yamerl_doc_end,7,1},
{yamerl_collection_end,7,1,block,mapping},
{yamerl_scalar,3,8,
{yamerl_tag,3,8,{non_specific,"!"}},
block,literal,"void main() {\n\tprintf(\"Hello, world!\\n\");\n}\n"},
{yamerl_mapping_value,3,6},
{yamerl_scalar,3,1,
{yamerl_tag,3,1,{non_specific,"?"}},
flow,plain,"block"},
{yamerl_mapping_key,3,1},
{yamerl_scalar,2,9,
{yamerl_tag,2,9,{non_specific,"!"}},
flow,double_quoted,"Quoted \t"},
{yamerl_mapping_value,2,7},
{yamerl_scalar,2,1,
{yamerl_tag,2,1,{non_specific,"?"}},
flow,plain,"quoted"},
{yamerl_mapping_key,2,1},
{yamerl_collection_start,2,1,
{yamerl_tag,2,1,{non_specific,"?"}},
block,mapping},
{yamerl_doc_start,2,1,{1,2},_},
{yamerl_stream_start,1,1,utf8}
]
},
yamerl_parser:file(?FILENAME)
).

View File

@ -0,0 +1,57 @@
-module('ex_5.13_escaped_characters').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[],
<<>>,
88,
true,
[],
0,
89,
6,
1,
false,
5,
24,
utf8,
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
6,
5,
undefined,
undefined,
_,
false,
[],
[
{yamerl_stream_end,5,24},
{yamerl_doc_end,5,24},
{yamerl_scalar,1,1,
{yamerl_tag,1,1,{non_specific,"!"}},
flow,double_quoted,"Fun with \x5C \x22 \x07 \x08 \x1B \x0C \x0A \x0D \x09 \x0B \x00 \x20 \xA0 \x85 \x{2028} \x{2029} A A A"},
{yamerl_doc_start,1,1,{1,2},_},
{yamerl_stream_start,1,1,utf8}
]
},
yamerl_parser:file(?FILENAME)
).

View File

@ -0,0 +1,77 @@
-module('ex_5.14_invalid_escaped_characters').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[],
<<>>,
27,
true,
[],
0,
28,
4,
1,
false,
3,
8,
utf8,
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
11,
10,
undefined,
undefined,
_,
false,
[
{yamerl_parsing_error,warning,
"Invalid escaped character",
3,3,invalid_escaped_character,
{yamerl_scalar,2,3,{yamerl_tag,2,3,{non_specific,"!"}},flow,double_quoted,"c "},
[]},
{yamerl_parsing_error,warning,
"Invalid escaped character",
2,4,invalid_escaped_character,
{yamerl_scalar,2,3,{yamerl_tag,2,3,{non_specific,"!"}},flow,double_quoted,""},
[]}
],
[
{yamerl_stream_end,3,8},
{yamerl_doc_end,3,8},
{yamerl_collection_end,3,8,block,mapping},
{yamerl_scalar,2,3,
{yamerl_tag,2,3,{non_specific,"!"}},
flow,double_quoted,"c xq-"},
{yamerl_mapping_value,1,12},
{yamerl_scalar,1,1,
{yamerl_tag,1,1,{non_specific,"?"}},
flow,plain,"Bad escapes"},
{yamerl_mapping_key,1,1},
{yamerl_collection_start,1,1,
{yamerl_tag,1,1,{non_specific,"?"}},
block,mapping},
{yamerl_doc_start,1,1,{1,2},_},
{yamerl_stream_start,1,1,utf8}
]
},
yamerl_parser:file(?FILENAME)
).

View File

@ -0,0 +1,70 @@
-module('ex_5.2_invalid_bom').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[],
<<>>,
90,
true,
[],
0,
45,
4,
1,
false,
3,
21,
{utf16,big},
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
11,
10,
undefined,
undefined,
_,
false,
[
{yamerl_parsing_error,warning,
_,
2,1,bom_after_doc_start,undefined,[]}
],
[
{yamerl_stream_end,3,21},
{yamerl_doc_end,3,21},
{yamerl_collection_end,3,21,block,sequence},
{yamerl_scalar,3,3,
{yamerl_tag,3,3,{non_specific,"?"}},
flow,plain,"Inside a document."},
{yamerl_sequence_entry,3,1},
{yamerl_scalar,1,3,
{yamerl_tag,1,3,{non_specific,"?"}},
flow,plain,"Invalid use of BOM"},
{yamerl_sequence_entry,1,1},
{yamerl_collection_start,1,1,
{yamerl_tag,1,1,{non_specific,"?"}},
block,sequence},
{yamerl_doc_start,1,1,{1,2},_},
{yamerl_stream_start,1,1,{utf16,big}}
]
},
yamerl_parser:file(?FILENAME)
).

View File

@ -0,0 +1,100 @@
-module('ex_5.3_block_structure_indicators').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[],
<<>>,
62,
true,
[],
0,
63,
8,
1,
false,
7,
14,
utf8,
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
29,
28,
undefined,
undefined,
_,
false,
[],
[
{yamerl_stream_end,7,14},
{yamerl_doc_end,7,14},
{yamerl_collection_end,7,14,block,mapping},
{yamerl_collection_end,7,14,block,mapping},
{yamerl_scalar,7,9,
{yamerl_tag,7,9,{non_specific,"?"}},
flow,plain,"green"},
{yamerl_mapping_value,7,7},
{yamerl_scalar,7,3,
{yamerl_tag,7,3,{non_specific,"?"}},
flow,plain,"sea"},
{yamerl_mapping_key,7,3},
{yamerl_scalar,6,5,
{yamerl_tag,6,5,{non_specific,"?"}},
flow,plain,"blue"},
{yamerl_mapping_value,6,3},
{yamerl_scalar,5,5,
{yamerl_tag,5,5,{non_specific,"?"}},
flow,plain,"sky"},
{yamerl_mapping_key,5,3},
{yamerl_collection_start,5,3,
{yamerl_tag,5,3,{non_specific,"?"}},
block,mapping},
{yamerl_mapping_value,4,8},
{yamerl_scalar,4,1,
{yamerl_tag,4,1,{non_specific,"?"}},
flow,plain,"mapping"},
{yamerl_mapping_key,4,1},
{yamerl_collection_end,3,6,block,sequence},
{yamerl_scalar,3,3,
{yamerl_tag,3,3,{non_specific,"?"}},
flow,plain,"two"},
{yamerl_sequence_entry,3,1},
{yamerl_scalar,2,3,
{yamerl_tag,2,3,{non_specific,"?"}},
flow,plain,"one"},
{yamerl_sequence_entry,2,1},
{yamerl_collection_start,2,1,
{yamerl_tag,2,1,{non_specific,"?"}},
block,sequence},
{yamerl_mapping_value,1,9},
{yamerl_scalar,1,1,
{yamerl_tag,1,1,{non_specific,"?"}},
flow,plain,"sequence"},
{yamerl_mapping_key,1,1},
{yamerl_collection_start,1,1,
{yamerl_tag,1,1,{non_specific,"?"}},
block,mapping},
{yamerl_doc_start,1,1,{1,2},_},
{yamerl_stream_start,1,1,utf8}
]
},
yamerl_parser:file(?FILENAME)
).

View File

@ -0,0 +1,100 @@
-module('ex_5.4_flow_collection_indicators').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[],
<<>>,
59,
true,
[],
0,
60,
3,
1,
false,
2,
35,
utf8,
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
29,
28,
undefined,
undefined,
_,
false,
[],
[
{yamerl_stream_end,2,35},
{yamerl_doc_end,2,35},
{yamerl_collection_end,2,35,block,mapping},
{yamerl_collection_end,2,34,flow,mapping},
{yamerl_scalar,2,28,
{yamerl_tag,2,28,{non_specific,"?"}},
flow,plain,"green"},
{yamerl_mapping_value,2,26},
{yamerl_scalar,2,23,
{yamerl_tag,2,23,{non_specific,"?"}},
flow,plain,"sea"},
{yamerl_mapping_key,2,23},
{yamerl_scalar,2,17,
{yamerl_tag,2,17,{non_specific,"?"}},
flow,plain,"blue"},
{yamerl_mapping_value,2,15},
{yamerl_scalar,2,12,
{yamerl_tag,2,12,{non_specific,"?"}},
flow,plain,"sky"},
{yamerl_mapping_key,2,12},
{yamerl_collection_start,2,10,
{yamerl_tag,2,10,{non_specific,"?"}},
flow,mapping},
{yamerl_mapping_value,2,8},
{yamerl_scalar,2,1,
{yamerl_tag,2,1,{non_specific,"?"}},
flow,plain,"mapping"},
{yamerl_mapping_key,2,1},
{yamerl_collection_end,1,23,flow,sequence},
{yamerl_scalar,1,18,
{yamerl_tag,1,18,{non_specific,"?"}},
flow,plain,"two"},
{yamerl_sequence_entry,1,18},
{yamerl_scalar,1,13,
{yamerl_tag,1,13,{non_specific,"?"}},
flow,plain,"one"},
{yamerl_sequence_entry,1,13},
{yamerl_collection_start,1,11,
{yamerl_tag,1,11,{non_specific,"?"}},
flow,sequence},
{yamerl_mapping_value,1,9},
{yamerl_scalar,1,1,
{yamerl_tag,1,1,{non_specific,"?"}},
flow,plain,"sequence"},
{yamerl_mapping_key,1,1},
{yamerl_collection_start,1,1,
{yamerl_tag,1,1,{non_specific,"?"}},
block,mapping},
{yamerl_doc_start,1,1,{1,2},_},
{yamerl_stream_start,1,1,utf8}
]
},
yamerl_parser:file(?FILENAME)
).

View File

@ -0,0 +1,73 @@
-module('ex_5.6_node_property_indicators').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[],
<<>>,
46,
true,
[],
0,
47,
3,
1,
false,
2,
15,
utf8,
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
17,
15,
undefined,
undefined,
_,
false,
[],
[
{yamerl_stream_end,2,15},
{yamerl_doc_end,2,15},
{yamerl_collection_end,2,15,block,mapping},
{yamerl_alias,2,8,"anchor"},
{yamerl_mapping_value,2,6},
{yamerl_scalar,2,1,
{yamerl_tag,2,1,{non_specific,"?"}},
flow,plain,"alias"},
{yamerl_mapping_key,2,1},
{yamerl_scalar,1,26,
{yamerl_tag,1,11,"!local"},
flow,plain,"value"},
{yamerl_anchor,1,18,"anchor"},
{yamerl_mapping_value,1,9},
{yamerl_scalar,1,1,
{yamerl_tag,1,1,{non_specific,"?"}},
flow,plain,"anchored"},
{yamerl_mapping_key,1,1},
{yamerl_collection_start,1,1,
{yamerl_tag,1,1,{non_specific,"?"}},
block,mapping},
{yamerl_doc_start,1,1,{1,2},_},
{yamerl_stream_start,1,1,utf8}
]
},
yamerl_parser:file(?FILENAME)
).

View File

@ -0,0 +1,74 @@
-module('ex_5.7_block_scalar_indicators').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[],
<<>>,
49,
true,
[],
0,
50,
7,
1,
false,
7,
1,
utf8,
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
15,
14,
undefined,
undefined,
_,
false,
[],
[
{yamerl_stream_end,7,1},
{yamerl_doc_end,7,1},
{yamerl_collection_end,7,1,block,mapping},
{yamerl_scalar,4,9,
{yamerl_tag,4,9,{non_specific,"!"}},
block,folded,"some text\n"},
{yamerl_mapping_value,4,7},
{yamerl_scalar,4,1,
{yamerl_tag,4,1,{non_specific,"?"}},
flow,plain,"folded"},
{yamerl_mapping_key,4,1},
{yamerl_scalar,1,10,
{yamerl_tag,1,10,{non_specific,"!"}},
block,literal,"some\ntext\n"},
{yamerl_mapping_value,1,8},
{yamerl_scalar,1,1,
{yamerl_tag,1,1,{non_specific,"?"}},
flow,plain,"literal"},
{yamerl_mapping_key,1,1},
{yamerl_collection_start,1,1,
{yamerl_tag,1,1,{non_specific,"?"}},
block,mapping},
{yamerl_doc_start,1,1,{1,2},_},
{yamerl_stream_start,1,1,utf8}
]
},
yamerl_parser:file(?FILENAME)
).

View File

@ -0,0 +1,74 @@
-module('ex_5.8_quoted_scalar_indicators').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[],
<<>>,
30,
true,
[],
0,
31,
3,
1,
false,
2,
15,
utf8,
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
15,
14,
undefined,
undefined,
_,
false,
[],
[
{yamerl_stream_end,2,15},
{yamerl_doc_end,2,15},
{yamerl_collection_end,2,15,block,mapping},
{yamerl_scalar,2,9,
{yamerl_tag,2,9,{non_specific,"!"}},
flow,double_quoted,"text"},
{yamerl_mapping_value,2,7},
{yamerl_scalar,2,1,
{yamerl_tag,2,1,{non_specific,"?"}},
flow,plain,"double"},
{yamerl_mapping_key,2,1},
{yamerl_scalar,1,9,
{yamerl_tag,1,9,{non_specific,"!"}},
flow,single_quoted,"text"},
{yamerl_mapping_value,1,7},
{yamerl_scalar,1,1,
{yamerl_tag,1,1,{non_specific,"?"}},
flow,plain,"single"},
{yamerl_mapping_key,1,1},
{yamerl_collection_start,1,1,
{yamerl_tag,1,1,{non_specific,"?"}},
block,mapping},
{yamerl_doc_start,1,1,{1,2},_},
{yamerl_stream_start,1,1,utf8}
]
},
yamerl_parser:file(?FILENAME)
).

View File

@ -0,0 +1,58 @@
-module('ex_5.9_directive_indicator').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[],
<<>>,
19,
true,
[],
0,
20,
3,
1,
false,
2,
9,
utf8,
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
7,
6,
undefined,
undefined,
_,
false,
[],
[
{yamerl_stream_end,2,9},
{yamerl_doc_end,2,9},
{yamerl_scalar,2,5,
{yamerl_tag,2,5,{non_specific,"?"}},
flow,plain,"text"},
{yamerl_doc_start,2,1,{1,2},_},
{yamerl_yaml_directive,1,1,{1,2}},
{yamerl_stream_start,1,1,utf8}
]
},
yamerl_parser:file(?FILENAME)
).

View File

@ -0,0 +1,66 @@
-module('ex_6.11_multiline_comments').
-include_lib("eunit/include/eunit.hrl").
-define(FILENAME, "test/parsing/" ?MODULE_STRING ".yaml").
single_test_() ->
?_assertMatch(
{yamerl_parser,
{file,?FILENAME},
[],
<<>>,
43,
true,
[],
0,
44,
5,
1,
false,
3,
8,
utf8,
false,
undefined,
_,
_,
[],
{bcoll,root,0,-1,1,1,-1,1,1},
false,
false,
false,
[{impl_key,false,undefined,undefined,undefined,undefined,undefined}],
false,
false,
_,
[],
0,
11,
10,
undefined,
undefined,
_,
false,
[],
[
{yamerl_stream_end,3,8},
{yamerl_doc_end,3,8},
{yamerl_collection_end,3,8,block,mapping},
{yamerl_scalar,3,3,
{yamerl_tag,3,3,{non_specific,"?"}},
flow,plain,"value"},
{yamerl_mapping_value,1,4},
{yamerl_scalar,1,1,
{yamerl_tag,1,1,{non_specific,"?"}},
flow,plain,"key"},
{yamerl_mapping_key,1,1},
{yamerl_collection_start,1,1,
{yamerl_tag,1,1,{non_specific,"?"}},
block,mapping},
{yamerl_doc_start,1,1,{1,2},_},
{yamerl_stream_start,1,1,utf8}
]
},
yamerl_parser:file(?FILENAME)
).

Some files were not shown because too many files have changed in this diff Show More