diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml index 671f7676..8eb2c070 100644 --- a/.github/workflows/rubocop.yml +++ b/.github/workflows/rubocop.yml @@ -9,11 +9,17 @@ on: - ".rubocop*.yml" - ".github/workflows/rubocop.yml" - "**/*.rb" + - "**/*.gemspec" + - "**/*.gemfile" + - "Gemfile" pull_request: paths: - ".rubocop*.yml" - ".github/workflows/rubocop.yml" - "**/*.rb" + - "**/*.gemspec" + - "**/*.gemfile" + - "Gemfile" jobs: formatting-check: @@ -28,12 +34,10 @@ jobs: uses: ruby/setup-ruby@v1 with: ruby-version: "2.7" - - - name: Install rubocop - run: gem install rubocop --no-doc + bundler-cache: true - name: Set-up RuboCop Problem Matcher uses: r7kamura/rubocop-problem-matchers-action@v1 - name: Run rubocop - run: rubocop + run: bundle exec rubocop diff --git a/.rubocop.yml b/.rubocop.yml index 6e46f13a..a487a402 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,6 +4,9 @@ AllCops: TargetRubyVersion: 2.7 NewCops: enable +Layout/SpaceAroundEqualsInParameterDefault: + EnforcedStyle: no_space + Naming/MethodName: EnforcedStyle: snake_case Exclude: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4ed89c38..06b1219a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -16,86 +16,6 @@ Layout/MultilineHashBraceLayout: - 'test/sample/file.rb' - 'test/tests.rb' -# Offense count: 26 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: space, no_space -Layout/SpaceAroundEqualsInParameterDefault: - Exclude: - - 'lib/ox/bag.rb' - - 'lib/ox/document.rb' - - 'lib/ox/element.rb' - - 'test/ox/change.rb' - - 'test/ox/doc.rb' - - 'test/ox/oval.rb' - - 'test/ox/rect.rb' - - 'test/ox/shape.rb' - - 'test/ox/text.rb' - - 'test/perf_mars.rb' - - 'test/sample.rb' - - 'test/sample/change.rb' - - 'test/sample/doc.rb' - - 'test/sample/oval.rb' - - 'test/sample/rect.rb' - - 'test/sample/shape.rb' - - 'test/sample/text.rb' - - 'test/tests.rb' - -# Offense count: 10 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator. -# SupportedStylesForExponentOperator: space, no_space -Layout/SpaceAroundOperators: - Exclude: - - 'contrib/xbuilder_test.rb' - - 'lib/ox/element.rb' - - 'test/perf_mars.rb' - - 'test/sax/sax_test.rb' - - 'test/tests.rb' - -# Offense count: 4 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. -# SupportedStyles: space, no_space -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideBlockBraces: - Exclude: - - 'contrib/xbuilder.rb' - - 'test/perf.rb' - - 'test/sax/smart_test.rb' - - 'test/tests.rb' - -# Offense count: 106 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. -# SupportedStyles: space, no_space, compact -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideHashLiteralBraces: - Exclude: - - 'contrib/xbuilder_test.rb' - - 'examples/obj.rb' - - 'lib/ox/bag.rb' - - 'lib/ox/document.rb' - - 'lib/ox/hasattrs.rb' - - 'test/ox/doc.rb' - - 'test/ox/hasprops.rb' - - 'test/perf_gen.rb' - - 'test/perf_mars.rb' - - 'test/sample/doc.rb' - - 'test/sample/file.rb' - - 'test/sample/hasprops.rb' - - 'test/sax/sax_test.rb' - - 'test/sax/smart_test.rb' - - 'test/tests.rb' - -# Offense count: 12 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: space, compact, no_space -Layout/SpaceInsideParens: - Exclude: - - 'test/tests.rb' - # Offense count: 2 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowSafeAssignment. diff --git a/contrib/sax_benchmark.rb b/contrib/sax_benchmark.rb index a3ce7f90..99298a87 100644 --- a/contrib/sax_benchmark.rb +++ b/contrib/sax_benchmark.rb @@ -93,7 +93,7 @@ def end_element(key) end end - def start_element(key, attrs = []) + def start_element(key, attrs=[]) @stack << @node = {} attrs.each do |attr| key, val = *attr diff --git a/contrib/xbuilder.rb b/contrib/xbuilder.rb index 4fb7c0cc..15f5f0c1 100644 --- a/contrib/xbuilder.rb +++ b/contrib/xbuilder.rb @@ -16,7 +16,7 @@ def x(name, *args) when Hash arg.each { |k, v| n[k.to_s] = v } when Array - arg.each { |c| n << c if c} + arg.each { |c| n << c if c } else n << arg if arg end diff --git a/contrib/xbuilder_test.rb b/contrib/xbuilder_test.rb index 823db6c7..79ed23ab 100755 --- a/contrib/xbuilder_test.rb +++ b/contrib/xbuilder_test.rb @@ -32,13 +32,13 @@ def test_build x_if(false, 'child5') ] - n=x('parent', - x('child1', {'atr1'=>'atr1_value', :atr2 => 'atr2_value'}, - x('subchild1', 'some text'), - x('subchild2', {'atr3' => 'default_value'}, {'atr3' => 'atr3_value'}, - x('sometag'), - x_if(false, 'never'))), - children) + n = x('parent', + x('child1', { 'atr1' => 'atr1_value', :atr2 => 'atr2_value' }, + x('subchild1', 'some text'), + x('subchild2', { 'atr3' => 'default_value' }, { 'atr3' => 'atr3_value' }, + x('sometag'), + x_if(false, 'never'))), + children) assert_equal(Ox.dump(n), Ox.dump(Ox.parse(xml))) end diff --git a/examples/obj.rb b/examples/obj.rb index 17264d4a..96a49e4f 100755 --- a/examples/obj.rb +++ b/examples/obj.rb @@ -21,7 +21,7 @@ def to_s end end -obj = Classy.new(23, ['abc', {x: true}]) +obj = Classy.new(23, ['abc', { x: true }]) doc = Ox.dump(obj, mode: :object) diff --git a/examples/sax_ractor.rb b/examples/sax_ractor.rb index aa3d7b0e..0b717323 100755 --- a/examples/sax_ractor.rb +++ b/examples/sax_ractor.rb @@ -18,7 +18,7 @@ class Saxtor < Ox::Sax # yield it if its `ietf` matches our `needle`, # and throw it away otherwise. CYO = Struct.new(:ietf, :globs, :description) do - def initialize(ietf = nil, globs = [], description = nil) + def initialize(ietf=nil, globs=[], description=nil) super(ietf, globs, description) end diff --git a/lib/ox/bag.rb b/lib/ox/bag.rb index f6fb13c8..e6c29f17 100644 --- a/lib/ox/bag.rb +++ b/lib/ox/bag.rb @@ -14,7 +14,7 @@ class Bag # # Ox::Bag.new(:@x => 42, :@y => 57) # - def initialize(args={ }) + def initialize(args={}) args.each do |k, v| instance_variable_set(k, v) end diff --git a/lib/ox/document.rb b/lib/ox/document.rb index e86ded65..3e11062f 100644 --- a/lib/ox/document.rb +++ b/lib/ox/document.rb @@ -9,7 +9,7 @@ class Document < Element # - _:standalone_ [String] indicates the document is standalone def initialize(prolog={}) super(nil) - @attributes = { } + @attributes = {} @attributes[:version] = prolog[:version] unless prolog[:version].nil? @attributes[:encoding] = prolog[:encoding] unless prolog[:encoding].nil? @attributes[:standalone] = prolog[:standalone] unless prolog[:standalone].nil? diff --git a/lib/ox/element.rb b/lib/ox/element.rb index bc2069e5..11334b0c 100644 --- a/lib/ox/element.rb +++ b/lib/ox/element.rb @@ -269,7 +269,7 @@ def alocate(path, found) name = step qual = nil else - name = step[0..i-1] + name = step[0..i - 1] raise InvalidPath.new(path) unless step.end_with?(']') i += 1 @@ -350,7 +350,7 @@ def del_locate(path) name = step qual = nil else - name = step[0..i-1] + name = step[0..i - 1] raise InvalidPath.new(path) unless step.end_with?(']') i += 1 diff --git a/lib/ox/hasattrs.rb b/lib/ox/hasattrs.rb index fed21d4b..c62f757d 100644 --- a/lib/ox/hasattrs.rb +++ b/lib/ox/hasattrs.rb @@ -8,7 +8,7 @@ module HasAttrs # Returns all the attributes of the Instruct as a Hash. # *return* [Hash] all attributes and attribute values. def attributes - @attributes = { } if !instance_variable_defined?(:@attributes) or @attributes.nil? + @attributes = {} if !instance_variable_defined?(:@attributes) or @attributes.nil? @attributes end @@ -26,7 +26,7 @@ def [](attr) def []=(attr, value) raise 'argument to [] must be a Symbol or a String.' unless attr.is_a?(Symbol) or attr.is_a?(String) - @attributes = { } if !instance_variable_defined?(:@attributes) or @attributes.nil? + @attributes = {} if !instance_variable_defined?(:@attributes) or @attributes.nil? a_str = attr.to_s a_sym = attr.to_sym if @attributes.has_key?(a_str) diff --git a/test/ox/doc.rb b/test/ox/doc.rb index 73812720..7eb5c36c 100644 --- a/test/ox/doc.rb +++ b/test/ox/doc.rb @@ -24,7 +24,7 @@ def initialize(title) @title = title @user = ENV['USER'] @create_time = Time.now - @layers = { } + @layers = {} @change_history = [] end diff --git a/test/ox/hasprops.rb b/test/ox/hasprops.rb index e86b0e14..c85fb75f 100644 --- a/test/ox/hasprops.rb +++ b/test/ox/hasprops.rb @@ -2,12 +2,12 @@ module Test module Ox module HasProps def add_prop(key, value) - @props = { } unless instance_variable_defined?(:@props) + @props = {} unless instance_variable_defined?(:@props) @props[key] = value end def props - @props = { } unless instance_variable_defined?(:@props) + @props = {} unless instance_variable_defined?(:@props) @props end end # HashProps diff --git a/test/perf.rb b/test/perf.rb index 64848706..d1d981c8 100644 --- a/test/perf.rb +++ b/test/perf.rb @@ -17,7 +17,7 @@ def before(title, &blk) end def run(iter) - base = Item.new(nil, nil) { } + base = Item.new(nil, nil) {} base.run(iter, 0.0) @items.each do |i| i.run(iter, base.duration) diff --git a/test/perf_gen.rb b/test/perf_gen.rb index 501b3065..11f41ca8 100755 --- a/test/perf_gen.rb +++ b/test/perf_gen.rb @@ -55,7 +55,7 @@ opts.on('-h', '--help', 'Show this display') { puts opts; Process.exit!(0) } files = opts.parse(ARGV) -Ox.default_options = {mode: :generic} +Ox.default_options = { mode: :generic } data = [] diff --git a/test/perf_mars.rb b/test/perf_mars.rb index 192d9fd6..0251265d 100755 --- a/test/perf_mars.rb +++ b/test/perf_mars.rb @@ -61,10 +61,10 @@ def initialize(v=[]) data[:Symbol].values << "Symbol#{i}".to_sym data[:Time].values << (Time.now + i) data[:Array].values << [] - data[:Hash].values << { } + data[:Hash].values << {} data[:Range].values << (0..7) data[:Regexp].values << /^[0-9]/ - data[:Bignum].values << (7 ** 55) + data[:Bignum].values << (7**55) data[:Complex].values << Complex(1, 2) data[:Rational].values << Rational(1, 3) data[:Struct].values << s.new(1, 3, 5) diff --git a/test/perf_sax.rb b/test/perf_sax.rb index 4615c630..c784b754 100755 --- a/test/perf_sax.rb +++ b/test/perf_sax.rb @@ -117,7 +117,7 @@ def warning(message); end class NoAllSax < NoSax - def start_element(name, attrs = []); end + def start_element(name, attrs=[]); end def characters(text); end def cdata_block(string); end def comment(string); end diff --git a/test/sample/doc.rb b/test/sample/doc.rb index d51473d0..d47e2a91 100644 --- a/test/sample/doc.rb +++ b/test/sample/doc.rb @@ -23,7 +23,7 @@ def initialize(title) @title = title @user = ENV['USER'] @create_time = Time.now - @layers = { } + @layers = {} @change_history = [] end diff --git a/test/sample/file.rb b/test/sample/file.rb index 46dc6d1f..bedc7c64 100644 --- a/test/sample/file.rb +++ b/test/sample/file.rb @@ -17,15 +17,15 @@ def initialize(filename) 'user' => { 'read' => (0 != (stat.mode & 0x0100)), 'write' => (0 != (stat.mode & 0x0080)), - 'execute' => (0 != (stat.mode & 0x0040))}, + 'execute' => (0 != (stat.mode & 0x0040)) }, 'group' => { 'read' => (0 != (stat.mode & 0x0020)), 'write' => (0 != (stat.mode & 0x0010)), - 'execute' => (0 != (stat.mode & 0x0008))}, + 'execute' => (0 != (stat.mode & 0x0008)) }, 'other' => { 'read' => (0 != (stat.mode & 0x0004)), 'write' => (0 != (stat.mode & 0x0002)), - 'execute' => (0 != (stat.mode & 0x0001))} + 'execute' => (0 != (stat.mode & 0x0001)) } } else @permissions = { diff --git a/test/sample/hasprops.rb b/test/sample/hasprops.rb index 2833b7d6..090bfe0c 100644 --- a/test/sample/hasprops.rb +++ b/test/sample/hasprops.rb @@ -1,12 +1,12 @@ module Sample module HasProps def add_prop(key, value) - @props = { } unless instance_variable_defined?(:@props) + @props = {} unless instance_variable_defined?(:@props) @props[key] = value end def props - @props = { } unless instance_variable_defined?(:@props) + @props = {} unless instance_variable_defined?(:@props) @props end end # HasProps diff --git a/test/sax/helpers.rb b/test/sax/helpers.rb index 763e643a..d547b38b 100644 --- a/test/sax/helpers.rb +++ b/test/sax/helpers.rb @@ -15,7 +15,7 @@ module SaxTestHelpers # [:end_element, :top] # ], AllSax, :convert_special => true, :smart => true) # - def parse_compare(xml, expected, handler_class = AllSax, opts = {}, handler_attr = :calls) + def parse_compare(xml, expected, handler_class=AllSax, opts={}, handler_attr=:calls) handler = handler_class.new input = StringIO.new(xml) options = { diff --git a/test/sax/sax_test.rb b/test/sax/sax_test.rb index 93c6cde2..0934cc1d 100755 --- a/test/sax/sax_test.rb +++ b/test/sax/sax_test.rb @@ -1276,7 +1276,7 @@ def test_sax_html_inactive Ox.default_options = $ox_sax_options handler = AllSax.new - Ox.sax_html(handler, '

title


Hello

', :overlay => {'hr'=>:inactive}) + Ox.sax_html(handler, '

title


Hello

', :overlay => { 'hr' => :inactive }) assert_equal([ [:start_element, :html], [:start_element, :h1], diff --git a/test/sax/smart_test.rb b/test/sax/smart_test.rb index 0e69f458..42f7fef9 100755 --- a/test/sax/smart_test.rb +++ b/test/sax/smart_test.rb @@ -40,7 +40,7 @@ class SaxSmartTest < Test::Unit::TestCase 'cite' => {}, 'colgroup' => { 'parents' => ['table'], 'childs' => ['col'] }, 'data' => {}, - 'datalist' => { 'childs' => ['option']}, + 'datalist' => { 'childs' => ['option'] }, 'dl' => { 'childs' => ['dt', 'dd'] }, 'dt' => { 'parents' => ['dl'] }, 'dd' => { 'parents' => ['dl'] }, @@ -136,7 +136,7 @@ class SaxSmartTest < Test::Unit::TestCase } # Make the :smart => true option the default one - def smart_parse_compare(xml, expected, handler = AllSax, opts = {}, handler_attr = :calls) + def smart_parse_compare(xml, expected, handler=AllSax, opts={}, handler_attr=:calls) parse_compare(xml, expected, handler, opts.merge(:smart => true, :skip => :skip_white), handler_attr) end end @@ -155,7 +155,7 @@ def parents_of(el) NORMALELEMENTS[el]['parents'] || ['body'] end - def ancestry_of(el, parent = nil) + def ancestry_of(el, parent=nil) p = parent || parents_of(el)[0] [el] + (p ? ancestry_of(p) : []) end @@ -357,7 +357,7 @@ def test_comment_active } overlay = Ox.sax_html_overlay.dup - overlay.each_key {|k| overlay[k] = :off } + overlay.each_key { |k| overlay[k] = :off } overlay['!--'] = :active handler = AllSax.new @@ -588,7 +588,7 @@ def test_html_bad_table [:end_element, :html]]) end - def html_parse_compare(xml, expected, opts = {}) + def html_parse_compare(xml, expected, opts={}) handler = AllSax.new input = StringIO.new(xml) options = { @@ -634,7 +634,7 @@ def test_nest_ok [:end_element, :table], [:end_element, :body], [:end_element, :html]], - {:overlay => hints}) + { :overlay => hints }) end def test_nest_ok_auto_closing @@ -650,6 +650,6 @@ def test_nest_ok_auto_closing [:end_element, :h5], [:end_element, :body], [:end_element, :html]], - {:overlay => hints}) + { :overlay => hints }) end end diff --git a/test/tests.rb b/test/tests.rb index 69a62377..c9cbcaf0 100755 --- a/test/tests.rb +++ b/test/tests.rb @@ -104,7 +104,7 @@ def test_set_options :strip_namespace => 'spaced', :overlay => nil, } - o3 = { :xsd_date=>false } + o3 = { :xsd_date => false } Ox.default_options = o2 opts = Ox.default_options assert_equal(o2, opts); @@ -179,7 +179,7 @@ def test_array def test_hash Ox.default_options = $ox_object_options - dump_and_load({ }, false) + dump_and_load({}, false) dump_and_load({ 'a' => 1, 2 => 'b' }, false) end @@ -209,8 +209,8 @@ def test_regex def test_bignum Ox.default_options = $ox_object_options - dump_and_load(7 ** 55, false) - dump_and_load(-7 ** 55, false) + dump_and_load(7**55, false) + dump_and_load(-7**55, false) end def test_bigdecimal @@ -241,7 +241,7 @@ def test_rational def test_object Ox.default_options = $ox_object_options - dump_and_load(Bag.new({ }), false) + dump_and_load(Bag.new({}), false) dump_and_load(Bag.new(:@x => 3), false) end @@ -307,7 +307,7 @@ def test_dump_invalid_character end def test_unsupported_ox_version - assert_raise(Ox::SyntaxError) { Ox.parse(%{foobar})} + assert_raise(Ox::SyntaxError) { Ox.parse(%{foobar}) } end def test_prolog_syntax_error @@ -350,7 +350,7 @@ def test_embedded_instruction assert_equal(Ox::Instruct, inst.class) assert_equal('attrs', inst.target) assert_nil(inst.content) - assert_equal({:dog=>'big'}, inst.attributes) + assert_equal({ :dog => 'big' }, inst.attributes) inst = doc.top.content assert_equal(Ox::Instruct, inst.class) @@ -782,12 +782,12 @@ def test_object_multi def test_complex Ox.default_options = $ox_object_options - dump_and_load(Bag.new(:@o => Bag.new(:@a => [2]), :@a => [1, {:b => 3, :a => [5], :c => Bag.new(:@x => 7)}]), false) + dump_and_load(Bag.new(:@o => Bag.new(:@a => [2]), :@a => [1, { :b => 3, :a => [5], :c => Bag.new(:@x => 7) }]), false) end def test_dump_margin Ox.default_options = $ox_object_options - x = Ox.dump(Bag.new(:@o => Bag.new(:@a => [2]), :@a => [1, {:b => 3, :a => [5], :c => Bag.new(:@x => 7)}]), :indent => 1, :margin => '##') + x = Ox.dump(Bag.new(:@o => Bag.new(:@a => [2]), :@a => [1, { :b => 3, :a => [5], :c => Bag.new(:@x => 7) }]), :indent => 1, :margin => '##') assert(x.include?('## ## @@ -1195,52 +1195,52 @@ def test_locate_qual_index Ox.default_options = $ox_object_options doc = Ox.parse(locate_xml) nodes = doc.locate('Family/Pete/?[0]') - assert_equal(['Kid1'], nodes.map { |e| e.value } ) + assert_equal(['Kid1'], nodes.map { |e| e.value }) nodes = doc.locate('Family/Pete/?[1]') - assert_equal(['Nicole'], nodes.map { |e| e.value } ) + assert_equal(['Nicole'], nodes.map { |e| e.value }) nodes = doc.locate('Family/Pete/?[2]') - assert_equal(['Kid2'], nodes.map { |e| e.value } ) + assert_equal(['Kid2'], nodes.map { |e| e.value }) end def test_locate_qual_less Ox.default_options = $ox_object_options doc = Ox.parse(locate_xml) nodes = doc.locate('Family/Pete/?[<1]') - assert_equal(['Kid1'], nodes.map { |e| e.value } ) + assert_equal(['Kid1'], nodes.map { |e| e.value }) end def test_locate_qual_great Ox.default_options = $ox_object_options doc = Ox.parse(locate_xml) nodes = doc.locate('Family/Pete/?[>1]') - assert_equal(['Kid2', 'Pamela'], nodes.map { |e| e.value } ) + assert_equal(['Kid2', 'Pamela'], nodes.map { |e| e.value }) end def test_locate_qual_last Ox.default_options = $ox_object_options doc = Ox.parse(locate_xml) nodes = doc.locate('Family/Pete/?[-1]') - assert_equal(['Pamela'], nodes.map { |e| e.value } ) + assert_equal(['Pamela'], nodes.map { |e| e.value }) end def test_locate_qual_last_attr Ox.default_options = $ox_object_options doc = Ox.parse(locate_xml) nodes = doc.locate('Family/Pete/?[-2]/@age') - assert_equal(['31'], nodes ) + assert_equal(['31'], nodes) end def test_locate_attr_match Ox.default_options = $ox_object_options doc = Ox.parse(locate_xml) nodes = doc.locate('Family/Pete/?[@age=32]') - assert_equal(['Kid1'], nodes.map { |e| e.value } ) + assert_equal(['Kid1'], nodes.map { |e| e.value }) nodes = doc.locate('Family/Pete/Kid1[@age=32]') - assert_equal(['Kid1'], nodes.map { |e| e.value } ) + assert_equal(['Kid1'], nodes.map { |e| e.value }) nodes = doc.locate('Family/Pete/Kid1[@age=31]') - assert_equal([], nodes.map { |e| e.value } ) + assert_equal([], nodes.map { |e| e.value }) end def test_locate_attr_presence @@ -1418,7 +1418,7 @@ def test_namespace_no_strip def test_namespace_strip_wild Ox.default_options = $ox_generic_options results = [] - doc = Ox.load('inside', :strip_namespace => true ) + doc = Ox.load('inside', :strip_namespace => true) assert_equal(%| inside @@ -1722,7 +1722,7 @@ def test_hash_no_attrs_mode_simple xml = %{This is the top. } doc = Ox.load(xml, :mode => :hash) - assert_equal({top: 'This is the top.'}, doc) + assert_equal({ top: 'This is the top.' }, doc) end def test_hash_no_attrs_mode_simple_nested @@ -1737,7 +1737,7 @@ def test_hash_no_attrs_mode_simple_nested } doc = Ox.load(xml, :mode => :hash) - assert_equal({top: {one: 'This is a one.', mid: {a: 'alpha', b: 'bravo'}}}, doc) + assert_equal({ top: { one: 'This is a one.', mid: { a: 'alpha', b: 'bravo' } } }, doc) end def test_hash_no_attrs_mode_multi_text @@ -1745,7 +1745,7 @@ def test_hash_no_attrs_mode_multi_text xml = %{FirstSecondThird } doc = Ox.load(xml, :mode => :hash) - assert_equal({top: ['First', {empty: nil}, 'Second', {empty: nil}, 'Third']}, doc) + assert_equal({ top: ['First', { empty: nil }, 'Second', { empty: nil }, 'Third'] }, doc) end def test_hash_mode_simple @@ -1753,7 +1753,7 @@ def test_hash_mode_simple xml = %{This is the top. } doc = Ox.load(xml, :mode => :hash) - assert_equal({top: 'This is the top.'}, doc) + assert_equal({ top: 'This is the top.' }, doc) end def test_hash_mode_simple_nested @@ -1768,7 +1768,7 @@ def test_hash_mode_simple_nested } doc = Ox.load(xml, :mode => :hash) - assert_equal({top: {one: 'This is a one.', mid: {a: 'alpha', b: 'bravo'}}}, doc) + assert_equal({ top: { one: 'This is a one.', mid: { a: 'alpha', b: 'bravo' } } }, doc) end def test_hash_mode_simple_cdata @@ -1783,10 +1783,10 @@ def test_hash_mode_simple_cdata } doc = Ox.load(xml, mode: :hash, with_cdata: true) - assert_equal({top: {one: 'This is a one.', mid: {a: 'alpha', b: 'bravo'}}}, doc) + assert_equal({ top: { one: 'This is a one.', mid: { a: 'alpha', b: 'bravo' } } }, doc) doc = Ox.load(xml, mode: :hash, with_cdata: false) - assert_equal({top: {one: 'This is a one.', mid: {a: nil, b: nil}}}, doc) + assert_equal({ top: { one: 'This is a one.', mid: { a: nil, b: nil } } }, doc) end def test_hash_mode_multi_text @@ -1794,7 +1794,7 @@ def test_hash_mode_multi_text xml = %{FirstSecondThird } doc = Ox.load(xml, :mode => :hash) - assert_equal({top: ['First', {empty: nil}, 'Second', {empty: nil}, 'Third']}, doc) + assert_equal({ top: ['First', { empty: nil }, 'Second', { empty: nil }, 'Third'] }, doc) end def test_hash_mode_simple_attrs @@ -1802,7 +1802,7 @@ def test_hash_mode_simple_attrs xml = %{This is the top. } doc = Ox.load(xml, :mode => :hash) - assert_equal({top: [{type: 'string'}, 'This is the top.']}, doc) + assert_equal({ top: [{ type: 'string' }, 'This is the top.'] }, doc) end def test_hash_mode_attrs @@ -1818,13 +1818,13 @@ def test_hash_mode_attrs } doc = Ox.load(xml, :mode => :hash) - assert_equal({result: { + assert_equal({ result: { variables: { var: [ - [{name: 'Blue'}, '14'], - [{name: 'Jack'}, '14'], - [{name: 'Magenta'}, '12'], - [{name: 'Yellow'}, '14'] + [{ name: 'Blue' }, '14'], + [{ name: 'Jack' }, '14'], + [{ name: 'Magenta' }, '12'], + [{ name: 'Yellow' }, '14'] ], } } @@ -1844,13 +1844,13 @@ def test_hash_mode_attrs2 } doc = Ox.load(xml, :mode => :hash) - assert_equal({result: { + assert_equal({ result: { variables: { var: [ '14', - [{name: 'Jack'}, '14'], - [{name: 'Magenta'}, '12'], - [{name: 'Yellow'}, '14'] + [{ name: 'Jack' }, '14'], + [{ name: 'Magenta' }, '12'], + [{ name: 'Yellow' }, '14'] ], } } @@ -1870,13 +1870,13 @@ def test_hash_mode_attrs3 } doc = Ox.load(xml, :mode => :hash) - assert_equal({result: { + assert_equal({ result: { variables: { var: [ - [{name: 'Blue'}, '14'], + [{ name: 'Blue' }, '14'], '14', - [{name: 'Magenta'}, '12'], - [{name: 'Yellow'}, '14'] + [{ name: 'Magenta' }, '12'], + [{ name: 'Yellow' }, '14'] ], } } @@ -1890,7 +1890,7 @@ def test_key_mod } ep = lambda { |k| k.downcase } ap = lambda { |k| 'a' + k } - doc = Ox.load(xml, mode: :generic, attr_key_mod: ap, element_key_mod: ep ) + doc = Ox.load(xml, mode: :generic, attr_key_mod: ap, element_key_mod: ep) xml2 = Ox.dump(doc) assert_equal(%{ diff --git a/test/weather/wnosax.rb b/test/weather/wnosax.rb index 2b777360..1a36077a 100644 --- a/test/weather/wnosax.rb +++ b/test/weather/wnosax.rb @@ -23,7 +23,7 @@ def initialize(as_time) @cell = 0 end - def start_element(name, attrs = []) + def start_element(name, attrs=[]) case name when 'Cell' @cell += 1