Skip to content

Commit 1045b9f

Browse files
byroothsbt
authored andcommitted
[ruby/json] Modernize heredocs
ruby/json@fb25e94aea
1 parent bfdf02e commit 1045b9f

File tree

4 files changed

+112
-112
lines changed

4 files changed

+112
-112
lines changed

ext/json/lib/json.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -378,13 +378,13 @@
378378
# json1 = JSON.generate(ruby)
379379
# ruby1 = JSON.parse(json1, create_additions: true)
380380
# # Make a nice display.
381-
# display = <<EOT
382-
# Generated JSON:
383-
# Without addition: #{json0} (#{json0.class})
384-
# With addition: #{json1} (#{json1.class})
385-
# Parsed JSON:
386-
# Without addition: #{ruby0.inspect} (#{ruby0.class})
387-
# With addition: #{ruby1.inspect} (#{ruby1.class})
381+
# display = <<~EOT
382+
# Generated JSON:
383+
# Without addition: #{json0} (#{json0.class})
384+
# With addition: #{json1} (#{json1.class})
385+
# Parsed JSON:
386+
# Without addition: #{ruby0.inspect} (#{ruby0.class})
387+
# With addition: #{ruby1.inspect} (#{ruby1.class})
388388
# EOT
389389
# puts display
390390
#
@@ -562,13 +562,13 @@
562562
# json1 = JSON.generate(foo1)
563563
# obj1 = JSON.parse(json1, create_additions: true)
564564
# # Make a nice display.
565-
# display = <<EOT
566-
# Generated JSON:
567-
# Without custom addition: #{json0} (#{json0.class})
568-
# With custom addition: #{json1} (#{json1.class})
569-
# Parsed JSON:
570-
# Without custom addition: #{obj0.inspect} (#{obj0.class})
571-
# With custom addition: #{obj1.inspect} (#{obj1.class})
565+
# display = <<~EOT
566+
# Generated JSON:
567+
# Without custom addition: #{json0} (#{json0.class})
568+
# With custom addition: #{json1} (#{json1.class})
569+
# Parsed JSON:
570+
# Without custom addition: #{obj0.inspect} (#{obj0.class})
571+
# With custom addition: #{obj1.inspect} (#{obj1.class})
572572
# EOT
573573
# puts display
574574
#

ext/json/lib/json/common.rb

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,17 @@ class MissingUnicodeSupport < JSONError; end
195195
# {Parsing \JSON}[#module-JSON-label-Parsing+JSON].
196196
#
197197
# Parses nested JSON objects:
198-
# source = <<-EOT
199-
# {
200-
# "name": "Dave",
201-
# "age" :40,
202-
# "hats": [
203-
# "Cattleman's",
204-
# "Panama",
205-
# "Tophat"
206-
# ]
207-
# }
208-
# EOT
198+
# source = <<~JSON
199+
# {
200+
# "name": "Dave",
201+
# "age" :40,
202+
# "hats": [
203+
# "Cattleman's",
204+
# "Panama",
205+
# "Tophat"
206+
# ]
207+
# }
208+
# JSON
209209
# ruby = JSON.parse(source)
210210
# ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]}
211211
#
@@ -445,17 +445,17 @@ class << self
445445
# <tt>parse(source, opts)</tt>; see #parse.
446446
#
447447
# Source for following examples:
448-
# source = <<-EOT
449-
# {
450-
# "name": "Dave",
451-
# "age" :40,
452-
# "hats": [
453-
# "Cattleman's",
454-
# "Panama",
455-
# "Tophat"
456-
# ]
457-
# }
458-
# EOT
448+
# source = <<~JSON
449+
# {
450+
# "name": "Dave",
451+
# "age" :40,
452+
# "hats": [
453+
# "Cattleman's",
454+
# "Panama",
455+
# "Tophat"
456+
# ]
457+
# }
458+
# JSON
459459
#
460460
# Load a \String:
461461
# ruby = JSON.load(source)

test/json/json_generator_test.rb

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@ def setup
1919
}
2020
@json2 = '{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},' +
2121
'"g":"\\"\\u0000\\u001f","h":1000.0,"i":0.001}'
22-
@json3 = <<'EOT'.chomp
23-
{
24-
"a": 2,
25-
"b": 3.141,
26-
"c": "c",
27-
"d": [
28-
1,
29-
"b",
30-
3.14
31-
],
32-
"e": {
33-
"foo": "bar"
34-
},
35-
"g": "\"\u0000\u001f",
36-
"h": 1000.0,
37-
"i": 0.001
38-
}
39-
EOT
22+
@json3 = <<~'JSON'.chomp
23+
{
24+
"a": 2,
25+
"b": 3.141,
26+
"c": "c",
27+
"d": [
28+
1,
29+
"b",
30+
3.14
31+
],
32+
"e": {
33+
"foo": "bar"
34+
},
35+
"g": "\"\u0000\u001f",
36+
"h": 1000.0,
37+
"i": 0.001
38+
}
39+
JSON
4040
end
4141

4242
def silence
@@ -93,13 +93,13 @@ def test_generate_pretty
9393
assert_equal('{}', json)
9494

9595
json = pretty_generate({1=>{}, 2=>[], 3=>4})
96-
assert_equal(<<'EOT'.chomp, json)
97-
{
98-
"1": {},
99-
"2": [],
100-
"3": 4
101-
}
102-
EOT
96+
assert_equal(<<~'JSON'.chomp, json)
97+
{
98+
"1": {},
99+
"2": [],
100+
"3": 4
101+
}
102+
JSON
103103

104104
json = pretty_generate(@hash)
105105
# hashes aren't (insertion) ordered on every ruby implementation
@@ -108,11 +108,11 @@ def test_generate_pretty
108108
parsed_json = parse(json)
109109
assert_equal(@hash, parsed_json)
110110
json = pretty_generate({1=>2})
111-
assert_equal(<<'EOT'.chomp, json)
112-
{
113-
"1": 2
114-
}
115-
EOT
111+
assert_equal(<<~'JSON'.chomp, json)
112+
{
113+
"1": 2
114+
}
115+
JSON
116116
parsed_json = parse(json)
117117
assert_equal({"1"=>2}, parsed_json)
118118
assert_equal '666', pretty_generate(666)
@@ -121,14 +121,14 @@ def test_generate_pretty
121121
def test_generate_custom
122122
state = State.new(:space_before => " ", :space => " ", :indent => "<i>", :object_nl => "\n", :array_nl => "<a_nl>")
123123
json = generate({1=>{2=>3,4=>[5,6]}}, state)
124-
assert_equal(<<'EOT'.chomp, json)
125-
{
126-
<i>"1" : {
127-
<i><i>"2" : 3,
128-
<i><i>"4" : [<a_nl><i><i><i>5,<a_nl><i><i><i>6<a_nl><i><i>]
129-
<i>}
130-
}
131-
EOT
124+
assert_equal(<<~'JSON'.chomp, json)
125+
{
126+
<i>"1" : {
127+
<i><i>"2" : 3,
128+
<i><i>"4" : [<a_nl><i><i><i>5,<a_nl><i><i><i>6<a_nl><i><i>]
129+
<i>}
130+
}
131+
JSON
132132
end
133133

134134
def test_fast_generate

test/json/json_parser_test.rb

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -247,50 +247,50 @@ def test_freeze
247247
end
248248

249249
def test_parse_comments
250-
json = <<EOT
251-
{
252-
"key1":"value1", // eol comment
253-
"key2":"value2" /* multi line
254-
* comment */,
255-
"key3":"value3" /* multi line
256-
// nested eol comment
257-
* comment */
258-
}
259-
EOT
250+
json = <<~JSON
251+
{
252+
"key1":"value1", // eol comment
253+
"key2":"value2" /* multi line
254+
* comment */,
255+
"key3":"value3" /* multi line
256+
// nested eol comment
257+
* comment */
258+
}
259+
JSON
260260
assert_equal(
261261
{ "key1" => "value1", "key2" => "value2", "key3" => "value3" },
262262
parse(json))
263-
json = <<EOT
264-
{
265-
"key1":"value1" /* multi line
266-
// nested eol comment
267-
/* illegal nested multi line comment */
268-
* comment */
269-
}
270-
EOT
263+
json = <<~JSON
264+
{
265+
"key1":"value1" /* multi line
266+
// nested eol comment
267+
/* illegal nested multi line comment */
268+
* comment */
269+
}
270+
JSON
271271
assert_raise(ParserError) { parse(json) }
272-
json = <<EOT
273-
{
274-
"key1":"value1" /* multi line
275-
// nested eol comment
276-
/* legal nested multi line comment start sequence */
277-
}
278-
EOT
272+
json = <<~JSON
273+
{
274+
"key1":"value1" /* multi line
275+
// nested eol comment
276+
/* legal nested multi line comment start sequence */
277+
}
278+
JSON
279279
assert_equal({ "key1" => "value1" }, parse(json))
280-
json = <<EOT
281-
{
282-
"key1":"value1" /* multi line
283-
// nested eol comment
284-
closed multi comment */
285-
and again, throw an Error */
286-
}
287-
EOT
280+
json = <<~JSON
281+
{
282+
"key1":"value1" /* multi line
283+
// nested eol comment
284+
closed multi comment */
285+
and again, throw an Error */
286+
}
287+
JSON
288288
assert_raise(ParserError) { parse(json) }
289-
json = <<EOT
290-
{
291-
"key1":"value1" /*/*/
292-
}
293-
EOT
289+
json = <<~JSON
290+
{
291+
"key1":"value1" /*/*/
292+
}
293+
JSON
294294
assert_equal({ "key1" => "value1" }, parse(json))
295295
end
296296

0 commit comments

Comments
 (0)