Skip to content

Commit 0479b66

Browse files
committed
Update Hash syntax in tests
1 parent 4a7a53b commit 0479b66

4 files changed

Lines changed: 102 additions & 102 deletions

File tree

Rakefile

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ if defined?(RUBY_ENGINE) and RUBY_ENGINE == 'jruby'
143143
end
144144

145145
desc "Compiling jruby extension"
146-
task :compile => JAVA_CLASSES
146+
task compile: JAVA_CLASSES
147147

148148
desc "Package the jruby gem"
149-
task :jruby_gem => :create_jar do
149+
task jruby_gem: :create_jar do
150150
mkdir_p 'pkg'
151151
sh "gem build -o pkg/json-#{PKG_VERSION}-java.gem json.gemspec"
152152
end
@@ -158,7 +158,7 @@ if defined?(RUBY_ENGINE) and RUBY_ENGINE == 'jruby'
158158
t.options = '-v'
159159
end
160160
desc "Testing library (jruby)"
161-
task :test => [:create_jar ]
161+
task test: [:create_jar ]
162162

163163
file JRUBY_PARSER_JAR => :compile do
164164
cd 'java/src' do
@@ -178,7 +178,7 @@ if defined?(RUBY_ENGINE) and RUBY_ENGINE == 'jruby'
178178
end
179179

180180
desc "Create parser jar"
181-
task :create_parser_jar => JRUBY_PARSER_JAR
181+
task create_parser_jar: JRUBY_PARSER_JAR
182182

183183
file JRUBY_GENERATOR_JAR => :compile do
184184
cd 'java/src' do
@@ -198,15 +198,15 @@ if defined?(RUBY_ENGINE) and RUBY_ENGINE == 'jruby'
198198
end
199199

200200
desc "Create generator jar"
201-
task :create_generator_jar => JRUBY_GENERATOR_JAR
201+
task create_generator_jar: JRUBY_GENERATOR_JAR
202202

203203
desc "Create parser and generator jars"
204-
task :create_jar => [ :create_parser_jar, :create_generator_jar ]
204+
task create_jar: [ :create_parser_jar, :create_generator_jar ]
205205

206206
desc "Build all gems and archives for a new release of the jruby extension."
207-
task :build => [ :clean, :jruby_gem ]
207+
task build: [ :clean, :jruby_gem ]
208208

209-
task :release => :build
209+
task release: :build
210210
else
211211
require 'rake/extensiontask'
212212

@@ -224,7 +224,7 @@ else
224224
end
225225

226226
desc "Testing library (extension)"
227-
task :test => [ :compile ]
227+
task test: [ :compile ]
228228

229229
begin
230230
require "ruby_memcheck"
@@ -249,10 +249,10 @@ else
249249
end
250250

251251
desc "Build all gems and archives for a new release of json"
252-
task :build => [ :clean, :package ]
252+
task build: [ :clean, :package ]
253253

254-
task :release => :build
254+
task release: :build
255255
end
256256

257257
desc "Compile in the the source directory"
258-
task :default => [ :clean, :test ]
258+
task default: [ :clean, :test ]

test/json/json_common_interface_test.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,16 @@ def test_load_with_proc
158158

159159
def test_load_with_options
160160
json = '{ "foo": NaN }'
161-
assert JSON.load(json, nil, :allow_nan => true)['foo'].nan?
162-
assert JSON.load(json, :allow_nan => true)['foo'].nan?
161+
assert JSON.load(json, nil, allow_nan: true)['foo'].nan?
162+
assert JSON.load(json, allow_nan: true)['foo'].nan?
163163
end
164164

165165
def test_load_null
166-
assert_equal nil, JSON.load(nil, nil, :allow_blank => true)
167-
assert_raise(TypeError) { JSON.load(nil, nil, :allow_blank => false) }
168-
assert_raise(JSON::ParserError) { JSON.load('', nil, :allow_blank => false) }
169-
assert_raise(TypeError) { JSON.load([], nil, :allow_blank => true) }
170-
assert_raise(TypeError) { JSON.load({}, nil, :allow_blank => true) }
166+
assert_equal nil, JSON.load(nil, nil, allow_blank: true)
167+
assert_raise(TypeError) { JSON.load(nil, nil, allow_blank: false) }
168+
assert_raise(JSON::ParserError) { JSON.load('', nil, allow_blank: false) }
169+
assert_raise(TypeError) { JSON.load([], nil, allow_blank: true) }
170+
assert_raise(TypeError) { JSON.load({}, nil, allow_blank: true) }
171171
end
172172

173173
def test_unsafe_load
@@ -240,16 +240,16 @@ def test_unsafe_load_default_options
240240

241241
def test_unsafe_load_with_options
242242
nan_json = '{ "foo": NaN }'
243-
assert_raise(JSON::ParserError) { JSON.unsafe_load(nan_json, nil, :allow_nan => false)['foo'].nan? }
243+
assert_raise(JSON::ParserError) { JSON.unsafe_load(nan_json, nil, allow_nan: false)['foo'].nan? }
244244
# make sure it still uses the defaults when something is provided
245-
assert JSON.unsafe_load(nan_json, nil, :allow_blank => true)['foo'].nan?
246-
assert JSON.unsafe_load(nan_json, :allow_nan => true)['foo'].nan?
245+
assert JSON.unsafe_load(nan_json, nil, allow_blank: true)['foo'].nan?
246+
assert JSON.unsafe_load(nan_json, allow_nan: true)['foo'].nan?
247247
end
248248

249249
def test_unsafe_load_null
250-
assert_equal nil, JSON.unsafe_load(nil, nil, :allow_blank => true)
251-
assert_raise(TypeError) { JSON.unsafe_load(nil, nil, :allow_blank => false) }
252-
assert_raise(JSON::ParserError) { JSON.unsafe_load('', nil, :allow_blank => false) }
250+
assert_equal nil, JSON.unsafe_load(nil, nil, allow_blank: true)
251+
assert_raise(TypeError) { JSON.unsafe_load(nil, nil, allow_blank: false) }
252+
assert_raise(JSON::ParserError) { JSON.unsafe_load('', nil, allow_blank: false) }
253253
end
254254

255255
def test_dump

test/json/json_generator_test.rb

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def test_generate_pretty
175175
end
176176

177177
def test_generate_pretty_custom
178-
state = State.new(:space_before => "<psb>", :space => "<ps>", :indent => "<pi>", :object_nl => "\n<po_nl>\n", :array_nl => "<pa_nl>")
178+
state = State.new(space_before: "<psb>", space: "<ps>", indent: "<pi>", object_nl: "\n<po_nl>\n", array_nl: "<pa_nl>")
179179
json = pretty_generate({1=>{}, 2=>['a','b'], 3=>4}, state)
180180
assert_equal(<<~'JSON'.chomp, json)
181181
{
@@ -244,7 +244,7 @@ def test_generate_sort_keys_with_proc
244244
end
245245

246246
def test_generate_custom
247-
state = State.new(:space_before => " ", :space => " ", :indent => "<i>", :object_nl => "\n", :array_nl => "<a_nl>")
247+
state = State.new(space_before: " ", space: " ", indent: "<i>", object_nl: "\n", array_nl: "<a_nl>")
248248
json = generate({1=>{2=>3,4=>[5,6]}}, state)
249249
assert_equal(<<~'JSON'.chomp, json)
250250
{
@@ -307,62 +307,62 @@ def test_falsy_state
307307
def test_state_defaults
308308
state = JSON::State.new
309309
assert_equal({
310-
:allow_duplicate_key => false,
311-
:allow_nan => false,
312-
:array_nl => "",
313-
:as_json => false,
314-
:ascii_only => false,
315-
:buffer_initial_length => 1024,
316-
:depth => 0,
317-
:script_safe => false,
318-
:strict => false,
319-
:indent => "",
320-
:max_nesting => 100,
321-
:object_nl => "",
322-
:space => "",
323-
:space_before => "",
324-
:sort_keys => false,
310+
allow_duplicate_key: false,
311+
allow_nan: false,
312+
array_nl: "",
313+
as_json: false,
314+
ascii_only: false,
315+
buffer_initial_length: 1024,
316+
depth: 0,
317+
script_safe: false,
318+
strict: false,
319+
indent: "",
320+
max_nesting: 100,
321+
object_nl: "",
322+
space: "",
323+
space_before: "",
324+
sort_keys: false,
325325
}.sort_by { |n,| n.to_s }.to_h, state.to_h.sort_by { |n,| n.to_s }.to_h)
326326

327327
state = JSON::State.new(allow_duplicate_key: true)
328328
assert_equal({
329-
:allow_duplicate_key => true,
330-
:allow_nan => false,
331-
:array_nl => "",
332-
:as_json => false,
333-
:ascii_only => false,
334-
:buffer_initial_length => 1024,
335-
:depth => 0,
336-
:script_safe => false,
337-
:strict => false,
338-
:indent => "",
339-
:max_nesting => 100,
340-
:object_nl => "",
341-
:space => "",
342-
:space_before => "",
343-
:sort_keys => false,
329+
allow_duplicate_key: true,
330+
allow_nan: false,
331+
array_nl: "",
332+
as_json: false,
333+
ascii_only: false,
334+
buffer_initial_length: 1024,
335+
depth: 0,
336+
script_safe: false,
337+
strict: false,
338+
indent: "",
339+
max_nesting: 100,
340+
object_nl: "",
341+
space: "",
342+
space_before: "",
343+
sort_keys: false,
344344
}.sort_by { |n,| n.to_s }, state.to_h.sort_by { |n,| n.to_s })
345345
end
346346

347347
def test_allow_nan
348348
error = assert_raise(GeneratorError) { generate([JSON::NaN]) }
349349
assert_same JSON::NaN, error.invalid_object
350-
assert_equal '[NaN]', generate([JSON::NaN], :allow_nan => true)
350+
assert_equal '[NaN]', generate([JSON::NaN], allow_nan: true)
351351
assert_raise(GeneratorError) { generate([JSON::NaN]) }
352352
assert_raise(GeneratorError) { pretty_generate([JSON::NaN]) }
353-
assert_equal "[\n NaN\n]", pretty_generate([JSON::NaN], :allow_nan => true)
353+
assert_equal "[\n NaN\n]", pretty_generate([JSON::NaN], allow_nan: true)
354354
error = assert_raise(GeneratorError) { generate([JSON::Infinity]) }
355355
assert_same JSON::Infinity, error.invalid_object
356-
assert_equal '[Infinity]', generate([JSON::Infinity], :allow_nan => true)
356+
assert_equal '[Infinity]', generate([JSON::Infinity], allow_nan: true)
357357
assert_raise(GeneratorError) { generate([JSON::Infinity]) }
358358
assert_raise(GeneratorError) { pretty_generate([JSON::Infinity]) }
359-
assert_equal "[\n Infinity\n]", pretty_generate([JSON::Infinity], :allow_nan => true)
359+
assert_equal "[\n Infinity\n]", pretty_generate([JSON::Infinity], allow_nan: true)
360360
error = assert_raise(GeneratorError) { generate([JSON::MinusInfinity]) }
361361
assert_same JSON::MinusInfinity, error.invalid_object
362-
assert_equal '[-Infinity]', generate([JSON::MinusInfinity], :allow_nan => true)
362+
assert_equal '[-Infinity]', generate([JSON::MinusInfinity], allow_nan: true)
363363
assert_raise(GeneratorError) { generate([JSON::MinusInfinity]) }
364364
assert_raise(GeneratorError) { pretty_generate([JSON::MinusInfinity]) }
365-
assert_equal "[\n -Infinity\n]", pretty_generate([JSON::MinusInfinity], :allow_nan => true)
365+
assert_equal "[\n -Infinity\n]", pretty_generate([JSON::MinusInfinity], allow_nan: true)
366366
end
367367

368368
# An object that changes state.depth when it receives to_json(state)
@@ -489,11 +489,11 @@ def test_gc
489489

490490
def test_configure_using_configure_and_merge
491491
numbered_state = {
492-
:indent => "1",
493-
:space => '2',
494-
:space_before => '3',
495-
:object_nl => '4',
496-
:array_nl => '5'
492+
indent: "1",
493+
space: '2',
494+
space_before: '3',
495+
object_nl: '4',
496+
array_nl: '5'
497497
}
498498
state1 = JSON.state.new
499499
state1.merge(numbered_state)
@@ -513,7 +513,7 @@ def test_configure_using_configure_and_merge
513513

514514
def test_configure_hash_conversion
515515
state = JSON.state.new
516-
state.configure(:indent => '1')
516+
state.configure(indent: '1')
517517
assert_equal '1', state.indent
518518
state = JSON.state.new
519519
foo = 'foo'.dup
@@ -595,14 +595,14 @@ def test_nesting
595595
too_deep = '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]'
596596
too_deep_ary = eval too_deep
597597
assert_raise(JSON::NestingError) { generate too_deep_ary }
598-
assert_raise(JSON::NestingError) { generate too_deep_ary, :max_nesting => 100 }
599-
ok = generate too_deep_ary, :max_nesting => 101
598+
assert_raise(JSON::NestingError) { generate too_deep_ary, max_nesting: 100 }
599+
ok = generate too_deep_ary, max_nesting: 101
600600
assert_equal too_deep, ok
601-
ok = generate too_deep_ary, :max_nesting => nil
601+
ok = generate too_deep_ary, max_nesting: nil
602602
assert_equal too_deep, ok
603-
ok = generate too_deep_ary, :max_nesting => false
603+
ok = generate too_deep_ary, max_nesting: false
604604
assert_equal too_deep, ok
605-
ok = generate too_deep_ary, :max_nesting => 0
605+
ok = generate too_deep_ary, max_nesting: 0
606606
assert_equal too_deep, ok
607607

608608
assert_raise(TypeError) { generate too_deep_ary, max_nesting: "garbage" }
@@ -631,27 +631,27 @@ def test_backslash
631631
#
632632
data = [ '/' ]
633633
json = '["\/"]'
634-
assert_equal json, generate(data, :script_safe => true)
634+
assert_equal json, generate(data, script_safe: true)
635635
#
636636
data = [ '///////////' ]
637637
json = '["\/\/\/\/\/\/\/\/\/\/\/"]'
638-
assert_equal json, generate(data, :script_safe => true)
638+
assert_equal json, generate(data, script_safe: true)
639639
#
640640
data = [ '///////////////////////////////////////////////////////' ]
641641
json = '["\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/"]'
642-
assert_equal json, generate(data, :script_safe => true)
642+
assert_equal json, generate(data, script_safe: true)
643643
#
644644
data = [ "\u2028\u2029" ]
645645
json = '["\u2028\u2029"]'
646-
assert_equal json, generate(data, :script_safe => true)
646+
assert_equal json, generate(data, script_safe: true)
647647
#
648648
data = [ "ABC \u2028 DEF \u2029 GHI" ]
649649
json = '["ABC \u2028 DEF \u2029 GHI"]'
650-
assert_equal json, generate(data, :script_safe => true)
650+
assert_equal json, generate(data, script_safe: true)
651651
#
652652
data = [ "/\u2028\u2029" ]
653653
json = '["\/\u2028\u2029"]'
654-
assert_equal json, generate(data, :script_safe => true)
654+
assert_equal json, generate(data, script_safe: true)
655655
#
656656
data = ['"']
657657
json = '["\""]'

0 commit comments

Comments
 (0)