File: sax_handler_test.rb

package info (click to toggle)
ruby-multi-xml 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 472 kB
  • sloc: ruby: 2,822; sh: 4; makefile: 2
file content (40 lines) | stat: -rw-r--r-- 984 bytes parent folder | download
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