Repository navigation
Expand file tree
/
Copy pathfail_safe_spec.cr
More file actions
82 lines (73 loc) · 2.28 KB
/
Copy pathfail_safe_spec.cr
File metadata and controls
82 lines (73 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
require "spec"
require "yaml"
private def it_parses(string, expected, file = __FILE__, line = __LINE__)
it "parses #{string.inspect}", file, line do
YAML::Schema::FailSafe.parse(string).should eq(expected)
end
end
private def it_raises_on_parse(string, message, file = __FILE__, line = __LINE__)
it "raises on parse #{string.inspect}", file, line do
expect_raises(YAML::ParseException, message) do
YAML::Schema::FailSafe.parse(string)
end
end
end
private def it_parses_all(string, expected, file = __FILE__, line = __LINE__)
it "parses all #{string.inspect}", file, line do
YAML::Schema::FailSafe.parse_all(string).should eq(expected)
end
end
private def it_raises_on_parse_all(string, message, file = __FILE__, line = __LINE__)
it "raises on parse all #{string.inspect}", file, line do
expect_raises(YAML::ParseException, message) do
YAML::Schema::FailSafe.parse_all(string)
end
end
end
private def yaml(value)
YAML::Any.new(value)
end
describe YAML::Schema::FailSafe do
# parse
it_parses "123", "123"
it_parses %(
context:
replace_me: "Yes please!"
), {yaml("context") => {yaml("replace_me") => "Yes please!"}}
it_parses %(
first:
document:
second:
document:
), {
yaml("first") => {
yaml("document") => "",
},
yaml("second") => {
yaml("document") => "",
},
}
it_raises_on_parse %(
this: "gives"
an: "error"
), "did not find expected key at line 3, column 7, while parsing a block mapping at line 2, column 5"
it_raises_on_parse ":", "did not find expected key at line 1, column 1, while parsing a block mapping at line 1, column 1"
# parse_all
it_parses "321", "321"
it_parses_all %(
context:
replace_me: "Yes please!"
), [{yaml("context") => {yaml("replace_me") => "Yes please!"}}]
it_parses_all %(
foo:
bar: 123
bar:
foo: 321
), [{yaml("foo") => {yaml("bar") => "123"}, yaml("bar") => {yaml("foo") => "321"}}]
it_raises_on_parse_all %(
this: "raises"
an: "yaml"
parse: "exception"
), "did not find expected key at line 3, column 7, while parsing a block mapping at line 2, column 5"
it_raises_on_parse_all ":", "did not find expected key at line 1, column 1, while parsing a block mapping at line 1, column 1"
end