1
- using BlockScalars: BlockScalars, @blk_str , block , interpolate
1
+ using BlockScalars: BlockScalars, @m_str , multiline , interpolate
2
2
using Test
3
3
using YAML: YAML
4
4
@@ -9,9 +9,9 @@ function yaml_block(str, block_scalar)
9
9
YAML. load (yaml)[" example" ]
10
10
end
11
11
12
- # https://yaml-multiline.info/
13
12
const TEST_STRINGS = [
14
- " paragraph" => """
13
+ # Modified example from: https://yaml-multiline.info/
14
+ " yaml-multiline" => """
15
15
Several lines of text,
16
16
with some "quotes" of various 'types'
17
17
and also two blank lines:
@@ -31,7 +31,7 @@ for (test, str) in TEST_STRINGS
31
31
end
32
32
33
33
@testset " BlockScalars.jl" begin
34
- @testset " block " begin
34
+ @testset " multiline " begin
35
35
@testset " string: $test " for (test, str) in TEST_STRINGS
36
36
expected_lk = yaml_block (str, " |+" )
37
37
expected_lc = yaml_block (str, " |" )
42
42
expected_fs = yaml_block (str, " >-" )
43
43
44
44
@testset " literal" begin
45
- @test block (str, :literal , :keep ) == expected_lk
46
- @test block (str, :literal , :clip ) == expected_lc
47
- @test block (str, :literal , :strip ) == expected_ls
45
+ @test multiline (str, :literal , :keep ) == expected_lk
46
+ @test multiline (str, :literal , :clip ) == expected_lc
47
+ @test multiline (str, :literal , :strip ) == expected_ls
48
48
49
- @test block (str, style= :literal , chomp= :keep ) == expected_lk
50
- @test block (str, style= :literal , chomp= :clip ) == expected_lc
51
- @test block (str, style= :literal , chomp= :strip ) == expected_ls
49
+ @test multiline (str, style= :literal , chomp= :keep ) == expected_lk
50
+ @test multiline (str, style= :literal , chomp= :clip ) == expected_lc
51
+ @test multiline (str, style= :literal , chomp= :strip ) == expected_ls
52
52
53
- @test block (str, " lk" ) == expected_lk
54
- @test block (str, " lc" ) == expected_lc
55
- @test block (str, " ls" ) == expected_ls
53
+ @test multiline (str, " lk" ) == expected_lk
54
+ @test multiline (str, " lc" ) == expected_lc
55
+ @test multiline (str, " ls" ) == expected_ls
56
56
57
- @test block (str, " |+" ) == expected_lk
58
- @test block (str, " |-" ) == expected_ls
57
+ @test multiline (str, " |+" ) == expected_lk
58
+ @test multiline (str, " |-" ) == expected_ls
59
59
end
60
60
61
61
@testset " folding" begin
62
- @test block (str, :folded , :keep ) == expected_fk
63
- @test block (str, :folded , :clip ) == expected_fc
64
- @test block (str, :folded , :strip ) == expected_fs
62
+ @test multiline (str, :folded , :keep ) == expected_fk
63
+ @test multiline (str, :folded , :clip ) == expected_fc
64
+ @test multiline (str, :folded , :strip ) == expected_fs
65
65
66
- @test block (str, style= :folded , chomp= :keep ) == expected_fk
67
- @test block (str, style= :folded , chomp= :clip ) == expected_fc
68
- @test block (str, style= :folded , chomp= :strip ) == expected_fs
66
+ @test multiline (str, style= :folded , chomp= :keep ) == expected_fk
67
+ @test multiline (str, style= :folded , chomp= :clip ) == expected_fc
68
+ @test multiline (str, style= :folded , chomp= :strip ) == expected_fs
69
69
70
- @test block (str, " fk" ) == expected_fk
71
- @test block (str, " fc" ) == expected_fc
72
- @test block (str, " fs" ) == expected_fs
70
+ @test multiline (str, " fk" ) == expected_fk
71
+ @test multiline (str, " fc" ) == expected_fc
72
+ @test multiline (str, " fs" ) == expected_fs
73
73
74
- @test block (str, " >+" ) == expected_fk
75
- @test block (str, " >-" ) == expected_fs
74
+ @test multiline (str, " >+" ) == expected_fk
75
+ @test multiline (str, " >-" ) == expected_fs
76
76
end
77
77
78
78
@testset " default chomp" begin
79
- @test block (str, style= :literal ) == expected_ls
80
- @test block (str, style= :folded ) == expected_fs
79
+ @test multiline (str, style= :literal ) == expected_ls
80
+ @test multiline (str, style= :folded ) == expected_fs
81
81
82
- @test block (str, " l" ) == expected_ls
83
- @test block (str, " f" ) == expected_fs
82
+ @test multiline (str, " l" ) == expected_ls
83
+ @test multiline (str, " f" ) == expected_fs
84
84
85
- @test block (str, " |" ) == expected_lc
86
- @test block (str, " >" ) == expected_fc
85
+ @test multiline (str, " |" ) == expected_lc
86
+ @test multiline (str, " >" ) == expected_fc
87
87
end
88
88
89
89
@testset " default style" begin
90
- @test block (str, chomp= :keep ) == expected_fk
91
- @test block (str, chomp= :clip ) == expected_fc
92
- @test block (str, chomp= :strip ) == expected_fs
90
+ @test multiline (str, chomp= :keep ) == expected_fk
91
+ @test multiline (str, chomp= :clip ) == expected_fc
92
+ @test multiline (str, chomp= :strip ) == expected_fs
93
93
94
- @test block (str, " k" ) == expected_fk
95
- @test block (str, " c" ) == expected_fc
96
- @test block (str, " s" ) == expected_fs
94
+ @test multiline (str, " k" ) == expected_fk
95
+ @test multiline (str, " c" ) == expected_fc
96
+ @test multiline (str, " s" ) == expected_fs
97
97
98
- @test block (str, " +" ) == expected_fk
99
- @test block (str, " -" ) == expected_fs
98
+ @test multiline (str, " +" ) == expected_fk
99
+ @test multiline (str, " -" ) == expected_fs
100
100
end
101
101
102
102
@testset " default style/chomp" begin
103
- @test block (str) == expected_fs
104
- @test block (str, " " ) == expected_fs
103
+ @test multiline (str) == expected_fs
104
+ @test multiline (str, " " ) == expected_fs
105
105
end
106
106
end
107
107
108
108
@testset " invalid indicators" begin
109
- @test_throws ArgumentError block (" " , " fs_" ) # Too many indicators
110
- @test_throws ArgumentError block (" " , " sf" ) # Order matters
111
- @test_throws ArgumentError block (" " , " _s" ) # Invalid style
112
- @test_throws ArgumentError block (" " , " f_" ) # Invalid chomp
113
- @test_throws ArgumentError block (" " , " _" ) # Invalid style/chomp
109
+ @test_throws ArgumentError multiline (" " , " fs_" ) # Too many indicators
110
+ @test_throws ArgumentError multiline (" " , " sf" ) # Order matters
111
+ @test_throws ArgumentError multiline (" " , " _s" ) # Invalid style
112
+ @test_throws ArgumentError multiline (" " , " f_" ) # Invalid chomp
113
+ @test_throws ArgumentError multiline (" " , " _" ) # Invalid style/chomp
114
114
end
115
115
end
116
116
@@ -129,17 +129,17 @@ end
129
129
@test interpolate (" \$ (join([\" a\" , \" b\" ], \" , \" ))" ) == Expr (:string , :(join ([" a" , " b" ], " , " )))
130
130
end
131
131
132
- @testset " @blk_str " begin
132
+ @testset " @m_str " begin
133
133
@testset " quoting" begin
134
134
# Use of double-quotes could cause failure if not handled properly:
135
135
# `syntax: incomplete: invalid string syntax`
136
- @test blk "\"\n\" " == " \" \" "
136
+ @test m "\"\n\" " == " \" \" "
137
137
end
138
138
139
139
@testset " string-interpolation" begin
140
140
# If processing would accidentally take place in the interpolated code then
141
141
# we could see "a b " as the result.
142
- @test blk """ $(join(("a", "b") .* "\n ", ""))""" fc == " a b\n "
142
+ @test m """ $(join(("a", "b") .* "\n ", ""))""" fc == " a b\n "
143
143
end
144
144
end
145
145
end
0 commit comments