Skip to content

Commit 49920e4

Browse files
committed
Rename block to multiline
1 parent 9521a85 commit 49920e4

File tree

2 files changed

+67
-67
lines changed

2 files changed

+67
-67
lines changed

src/BlockScalars.jl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
module BlockScalars
22

3-
export @blk_str
3+
export @m_str
44

55
const ETX = '\x03' # ASCII control character: End of Text
66
const DEFAULT_STYLE = :folded
77
const DEFAULT_CHOMP = :strip
88

99
"""
10-
block(str, style=$(repr(DEFAULT_STYLE)), chomp=$(repr(DEFAULT_CHOMP))) -> AbstractString
10+
multiline(str, style=$(repr(DEFAULT_STYLE)), chomp=$(repr(DEFAULT_CHOMP))) -> AbstractString
1111
12-
Revise a multiline string according to the provided `style` and `chomp`. Works similarly to
12+
Create a multiline string according to the provided `style` and `chomp`. Works similarly to
1313
YAML multiline strings (also known as block scalars).
1414
1515
# Arguments
@@ -20,12 +20,12 @@ YAML multiline strings (also known as block scalars).
2020
- `chomp::Symbol`: No newlines at the end (`:strip`), single newline at the end (`:clip`),
2121
or keep all newlines from the end (`:keep`)
2222
"""
23-
function block(str::AbstractString; style=DEFAULT_STYLE, chomp=DEFAULT_CHOMP)
24-
block(str, style, chomp)
23+
function multiline(str::AbstractString; style=DEFAULT_STYLE, chomp=DEFAULT_CHOMP)
24+
multiline(str, style, chomp)
2525
end
2626

2727
"""
28-
block(str, indicators) -> AbstractString
28+
multiline(str, indicators) -> AbstractString
2929
3030
Revise a multiline string according to the provided style and chomp encoded in the
3131
`indicators` string.
@@ -42,7 +42,7 @@ Revise a multiline string according to the provided style and chomp encoded in t
4242
- "lc" / "|": literal and clip
4343
- "lk" / "|+": literal and keep
4444
"""
45-
function block(str::AbstractString, indicators::AbstractString)
45+
function multiline(str::AbstractString, indicators::AbstractString)
4646
indicators_len = length(indicators)
4747
indicators_len > 2 && throw(ArgumentError("Too many indicators provided"))
4848

@@ -75,7 +75,7 @@ function block(str::AbstractString, indicators::AbstractString)
7575
elseif style_char == '\0'
7676
DEFAULT_STYLE
7777
else
78-
throw(ArgumentError("Unknown block style indicator: $(repr(style_char))"))
78+
throw(ArgumentError("Unknown style indicator: $(repr(style_char))"))
7979
end
8080

8181
chomp = if chomp_char == 'c' || yaml_chomp
@@ -87,13 +87,13 @@ function block(str::AbstractString, indicators::AbstractString)
8787
elseif chomp_char == '\0'
8888
DEFAULT_CHOMP
8989
else
90-
throw(ArgumentError("Unknown block chomping indicator: $(repr(chomp_char))"))
90+
throw(ArgumentError("Unknown chomping indicator: $(repr(chomp_char))"))
9191
end
9292

93-
return block(str, style, chomp)
93+
return multiline(str, style, chomp)
9494
end
9595

96-
function block(str::AbstractString, style::Symbol, chomp::Symbol)
96+
function multiline(str::AbstractString, style::Symbol, chomp::Symbol)
9797
# Append an additional, non-space, character to force one more iteration of the style
9898
# loop
9999
str *= ETX
@@ -156,7 +156,7 @@ function block(str::AbstractString, style::Symbol, chomp::Symbol)
156156
curr = next
157157
end
158158
else
159-
throw(ArgumentError("Unknown block style indicator: $style"))
159+
throw(ArgumentError("Unknown style indicator: $style"))
160160
end
161161

162162
# Single newline at end (clip)
@@ -171,14 +171,14 @@ function block(str::AbstractString, style::Symbol, chomp::Symbol)
171171
elseif chomp === :keep
172172
write(out, "\n" ^ num_newlines)
173173
else
174-
throw(ArgumentError("Unknown block chomping indicator: $chomp"))
174+
throw(ArgumentError("Unknown chomping indicator: $chomp"))
175175
end
176176

177177
return String(take!(out))
178178
end
179179

180180
"""
181-
@blk_str -> String
181+
@m_str -> String
182182
183183
Construct a multiline string according to the indicators listed after the ending quote:
184184
@@ -191,17 +191,17 @@ Construct a multiline string according to the indicators listed after the ending
191191
Note string interpolation is still respected any newlines added from interpolation will be
192192
also be processed.
193193
"""
194-
macro blk_str(str::AbstractString, indicators::AbstractString="")
194+
macro m_str(str::AbstractString, indicators::AbstractString="")
195195
parsed = interpolate(str)
196196

197197
# When no string interpolation needs to take place we can just process the multiline
198198
# string during parse time. If string interpolation needs to take place we'll evaluate
199199
# the multiline string at runtime so that we can process after interpolation has taken
200200
# place.
201201
result = if parsed isa String
202-
block(unescape_string(parsed), indicators)
202+
multiline(unescape_string(parsed), indicators)
203203
else
204-
Expr(:call, :(BlockScalars.block), parsed, indicators)
204+
Expr(:call, :(MultilineStrings.multiline), parsed, indicators)
205205
end
206206

207207
return esc(result)

test/runtests.jl

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using BlockScalars: BlockScalars, @blk_str, block, interpolate
1+
using BlockScalars: BlockScalars, @m_str, multiline, interpolate
22
using Test
33
using YAML: YAML
44

@@ -9,9 +9,9 @@ function yaml_block(str, block_scalar)
99
YAML.load(yaml)["example"]
1010
end
1111

12-
# https://yaml-multiline.info/
1312
const TEST_STRINGS = [
14-
"paragraph" => """
13+
# Modified example from: https://yaml-multiline.info/
14+
"yaml-multiline" => """
1515
Several lines of text,
1616
with some "quotes" of various 'types'
1717
and also two blank lines:
@@ -31,7 +31,7 @@ for (test, str) in TEST_STRINGS
3131
end
3232

3333
@testset "BlockScalars.jl" begin
34-
@testset "block" begin
34+
@testset "multiline" begin
3535
@testset "string: $test" for (test, str) in TEST_STRINGS
3636
expected_lk = yaml_block(str, "|+")
3737
expected_lc = yaml_block(str, "|")
@@ -42,75 +42,75 @@ end
4242
expected_fs = yaml_block(str, ">-")
4343

4444
@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
4848

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
5252

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
5656

57-
@test block(str, "|+") == expected_lk
58-
@test block(str, "|-") == expected_ls
57+
@test multiline(str, "|+") == expected_lk
58+
@test multiline(str, "|-") == expected_ls
5959
end
6060

6161
@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
6565

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
6969

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
7373

74-
@test block(str, ">+") == expected_fk
75-
@test block(str, ">-") == expected_fs
74+
@test multiline(str, ">+") == expected_fk
75+
@test multiline(str, ">-") == expected_fs
7676
end
7777

7878
@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
8181

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
8484

85-
@test block(str, "|") == expected_lc
86-
@test block(str, ">") == expected_fc
85+
@test multiline(str, "|") == expected_lc
86+
@test multiline(str, ">") == expected_fc
8787
end
8888

8989
@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
9393

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
9797

98-
@test block(str, "+") == expected_fk
99-
@test block(str, "-") == expected_fs
98+
@test multiline(str, "+") == expected_fk
99+
@test multiline(str, "-") == expected_fs
100100
end
101101

102102
@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
105105
end
106106
end
107107

108108
@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
114114
end
115115
end
116116

@@ -129,17 +129,17 @@ end
129129
@test interpolate("\$(join([\"a\", \"b\"], \", \"))") == Expr(:string, :(join(["a", "b"], ", ")))
130130
end
131131

132-
@testset "@blk_str" begin
132+
@testset "@m_str" begin
133133
@testset "quoting" begin
134134
# Use of double-quotes could cause failure if not handled properly:
135135
# `syntax: incomplete: invalid string syntax`
136-
@test blk"\"\n\"" == "\" \""
136+
@test m"\"\n\"" == "\" \""
137137
end
138138

139139
@testset "string-interpolation" begin
140140
# If processing would accidentally take place in the interpolated code then
141141
# 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"
143143
end
144144
end
145145
end

0 commit comments

Comments
 (0)