File: test_subclass.rb

package info (click to toggle)
ruby-nokogiri 1.13.10%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,416 kB
  • sloc: ansic: 38,198; xml: 28,086; ruby: 22,271; java: 15,517; cpp: 7,037; yacc: 244; sh: 148; makefile: 136
file content (46 lines) | stat: -rw-r--r-- 1,492 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
# frozen_string_literal: true

require "helper"

module Nokogiri
  module XML
    class Node
      class TestSubclass < Nokogiri::TestCase
        {
          Nokogiri::XML::CDATA => 'doc, "foo"',
          Nokogiri::XML::Attr => 'doc, "foo"',
          Nokogiri::XML::Comment => 'doc, "foo"',
          Nokogiri::XML::EntityReference => 'doc, "foo"',
          Nokogiri::XML::ProcessingInstruction => 'doc, "foo", "bar"',
          Nokogiri::XML::DocumentFragment => "doc",
          Nokogiri::XML::Node => '"foo", doc',
          Nokogiri::XML::Text => '"foo", doc',
        }.each do |klass, constructor|
          class_eval %{
            def test_subclass_#{klass.name.gsub("::", "_")}
              doc = Nokogiri::XML::Document.new
              klass = Class.new(#{klass.name})
              node = klass.new(#{constructor})
              assert_instance_of klass, node
            end
          }

          class_eval <<-eocode, __FILE__, __LINE__ + 1
            def test_subclass_initialize_#{klass.name.gsub("::", "_")}
              doc = Nokogiri::XML::Document.new
              klass = Class.new(#{klass.name}) do
                attr_accessor :initialized_with

                def initialize *args
                  @initialized_with = args
                end
              end
              node = klass.new(#{constructor}, 1)
              assert_equal [#{constructor}, 1], node.initialized_with
            end
          eocode
        end
      end
    end
  end
end