File: roundtrip_test.rb

package info (click to toggle)
libhtmlentities-ruby 4.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 136 kB
  • ctags: 294
  • sloc: ruby: 2,172; makefile: 2
file content (94 lines) | stat: -rw-r--r-- 2,568 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
$:.unshift(File.dirname(__FILE__) + '/../lib')
require 'htmlentities'
require 'test/unit'
require 'htmlentities/xhtml1'
require 'htmlentities/html4'

class HTMLEntities::RoundtripTest < Test::Unit::TestCase
  
  attr_reader :xhtml1_entities, :html4_entities
  
  def setup
    @xhtml1_entities = HTMLEntities.new('xhtml1')
    @html4_entities = HTMLEntities.new('html4')
  end
  
  def test_should_roundtrip_xhtml1_entities_via_named_encoding
    each_mapping('xhtml1') do |name, string|
      assert_equal(
        string, 
        xhtml1_entities.decode(xhtml1_entities.encode(string, :named))
      )
    end
  end

  def test_should_roundtrip_xhtml1_entities_via_basic_and_named_encoding
    each_mapping('xhtml1') do |name, string|
      assert_equal(
        string, 
        xhtml1_entities.decode(xhtml1_entities.encode(string, :basic, :named))
      )
    end
  end
  
  def test_should_roundtrip_xhtml1_entities_via_basic_named_and_decimal_encoding
    each_mapping('xhtml1') do |name, string|
      assert_equal(
        string, 
        xhtml1_entities.decode(xhtml1_entities.encode(string, :basic, :named, :decimal))
      )
    end
  end
  
  def test_should_roundtrip_xhtml1_entities_via_hexadecimal_encoding
    each_mapping('xhtml1') do |name, string|
      assert_equal(
        string, 
        xhtml1_entities.decode(xhtml1_entities.encode(string, :hexadecimal))
      )
    end
  end
  
  def test_should_roundtrip_html4_entities_via_named_encoding
    each_mapping('html4') do |name, string|
      assert_equal(
        string, 
        html4_entities.decode(html4_entities.encode(string, :named))
      )
    end
  end

  def test_should_roundtrip_html4_entities_via_basic_and_named_encoding
    each_mapping('html4') do |name, string|
      assert_equal(
        string, 
        html4_entities.decode(html4_entities.encode(string, :basic, :named))
      )
    end
  end
  
  def test_should_roundtrip_html4_entities_via_basic_named_and_decimal_encoding
    each_mapping('html4') do |name, string|
      assert_equal(
        string, 
        html4_entities.decode(html4_entities.encode(string, :basic, :named, :decimal))
      )
    end
  end
  
  def test_should_roundtrip_html4_entities_via_hexadecimal_encoding
    each_mapping('html4') do |name, string|
      assert_equal(
        string, 
        html4_entities.decode(html4_entities.encode(string, :hexadecimal))
      )
    end
  end
  
  def each_mapping(flavor)
    HTMLEntities::MAPPINGS[flavor].each do |name, codepoint|
      yield name, [codepoint].pack('U')
    end
  end
  
end