File: test_element_description.rb

package info (click to toggle)
ruby-nokogiri 1.11.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,576 kB
  • sloc: xml: 28,086; ruby: 18,456; java: 13,067; ansic: 5,138; yacc: 265; sh: 208; makefile: 27
file content (105 lines) | stat: -rw-r--r-- 2,784 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
95
96
97
98
99
100
101
102
103
104
105
require "helper"

module Nokogiri
  module HTML
    class TestElementDescription < Nokogiri::TestCase
      def test_fetch_nonexistent
        assert_nil ElementDescription['foo']
      end

      def test_fetch_element_description
        assert desc = ElementDescription['a']
        assert_instance_of ElementDescription, desc
      end

      def test_name
        assert_equal 'a', ElementDescription['a'].name
      end

      def test_implied_start_tag?
        assert !ElementDescription['a'].implied_start_tag?
      end

      def test_implied_end_tag?
        assert !ElementDescription['a'].implied_end_tag?
        assert ElementDescription['p'].implied_end_tag?
      end

      def test_save_end_tag?
        assert !ElementDescription['a'].save_end_tag?
        assert ElementDescription['br'].save_end_tag?
      end

      def test_empty?
        assert ElementDescription['br'].empty?
        assert !ElementDescription['a'].empty?
      end

      def test_deprecated?
        assert ElementDescription['applet'].deprecated?
        assert !ElementDescription['br'].deprecated?
      end

      def test_inline?
        assert ElementDescription['a'].inline?
        assert !ElementDescription['div'].inline?
      end

      def test_block?
        element = ElementDescription['a']
        assert_equal(!element.inline?, element.block?)
      end

      def test_description
        assert ElementDescription['a'].description
      end

      def test_subelements
        sub_elements = ElementDescription['body'].sub_elements
        if Nokogiri.uses_libxml?(">= 2.7.7")
          assert_equal 65, sub_elements.length
        elsif Nokogiri.uses_libxml?
          assert_equal 61, sub_elements.length
        else
          assert sub_elements.length > 0
        end
      end

      def test_default_sub_element
        assert_equal 'div', ElementDescription['body'].default_sub_element
      end

      def test_null_default_sub_element
        doc = Nokogiri::HTML('foo')
        doc.root.description.default_sub_element
      end

      def test_optional_attributes
        attrs = ElementDescription['table'].optional_attributes
        assert attrs
      end

      def test_deprecated_attributes
        attrs = ElementDescription['table'].deprecated_attributes
        assert attrs
        assert_equal 2, attrs.length
      end

      def test_required_attributes
        attrs = ElementDescription['table'].required_attributes
        assert attrs
        assert_equal 0, attrs.length
      end

      def test_inspect
        desc = ElementDescription['input']
        assert_match desc.name, desc.inspect
      end

      def test_to_s
        desc = ElementDescription['input']
        assert_match desc.name, desc.to_s
      end
    end
  end
end