File: test_comment.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 (40 lines) | stat: -rw-r--r-- 1,033 bytes parent folder | download | duplicates (3)
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 "helper"

module Nokogiri
  module XML
    class TestComment < Nokogiri::TestCase
      def setup
        super
        @xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
      end

      def test_new
        comment = Nokogiri::XML::Comment.new(@xml, 'hello world')
        assert_equal('<!--hello world-->', comment.to_s)
      end

      def test_comment?
        comment = Nokogiri::XML::Comment.new(@xml, 'hello world')
        assert(comment.comment?)
        assert(!@xml.root.comment?)
      end

      def test_passing_a_node_uses_the_node_document
        comment = Nokogiri::XML::Comment.new(@xml.at_css("employee"), 'hello world')
        assert_equal @xml, comment.document
      end

      def test_passing_anything_else
        assert_raises ArgumentError do
          Nokogiri::XML::Comment.new("NOT A NOKOGIRI CLASS", 'hello world')
        end
      end

      def test_many_comments
        100.times {
          Nokogiri::XML::Comment.new(@xml, 'hello world')
        }
      end
    end
  end
end