1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
require "test_helper"
require "multi_xml/parsers/sax_handler"
# Test harness that includes SaxHandler for testing
class SaxHandlerTestHarness
include MultiXml::Parsers::SaxHandler
def initialize
initialize_handler
end
# Expose private method for testing
def test_normalize_attrs(attrs)
normalize_attrs(attrs)
end
end
# Tests for SaxHandler normalize_attrs method
class SaxHandlerNormalizeAttrsTest < Minitest::Test
cover "MultiXml*"
def setup
@handler = SaxHandlerTestHarness.new
end
def test_normalize_attrs_returns_hash_when_given_hash
attrs = {"class" => "foo", "id" => "bar"}
result = @handler.test_normalize_attrs(attrs)
assert_equal attrs, result
assert_same attrs, result # Should return the same object
end
def test_normalize_attrs_converts_array_to_hash
attrs = [%w[class foo], %w[id bar]]
result = @handler.test_normalize_attrs(attrs)
assert_equal({"class" => "foo", "id" => "bar"}, result)
end
end
|