File: test_nokogiri.rb

package info (click to toggle)
ruby-nokogiri 1.18.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 8,076 kB
  • sloc: ansic: 38,893; xml: 27,665; ruby: 27,285; java: 15,348; cpp: 7,107; yacc: 244; sh: 208; makefile: 154; sed: 14
file content (60 lines) | stat: -rw-r--r-- 1,791 bytes parent folder | download | duplicates (2)
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
# frozen_string_literal: true

require "helper"

module Nokogiri
  class TestCase
    describe Nokogiri do
      def test_libxml_iconv
        skip_unless_libxml2("this constant is only set in the C extension when libxml2 is used")
        assert(Nokogiri.const_defined?(:LIBXML_ICONV_ENABLED))
      end

      def test_parse_with_io
        doc = Nokogiri.parse(StringIO.new("<html><head><title></title><body></body></html>"))
        assert_instance_of(Nokogiri::HTML4::Document, doc)
      end

      def test_xml?
        doc = Nokogiri.parse(File.read(XML_FILE))
        assert_predicate(doc, :xml?)
        refute_predicate(doc, :html?)
      end

      def test_atom_is_xml?
        doc = Nokogiri.parse(File.read(XML_ATOM_FILE))
        assert_predicate(doc, :xml?)
        refute_predicate(doc, :html?)
      end

      def test_html?
        doc = Nokogiri.parse(File.read(HTML_FILE))
        refute_predicate(doc, :xml?)
        assert_predicate(doc, :html?)
      end

      def test_nokogiri_method_with_html
        doc1 = Nokogiri(File.read(HTML_FILE))
        doc2 = Nokogiri.parse(File.read(HTML_FILE))
        assert_equal(doc1.serialize, doc2.serialize)
      end

      def test_nokogiri_method_with_block
        root = Nokogiri { b("bold tag") }
        assert_instance_of(Nokogiri::HTML4::Document, root.document)
        assert_equal("<b>bold tag</b>", root.to_html.chomp)
      end

      def test_make_with_html
        root = Nokogiri.make("<b>bold tag</b>")
        assert_instance_of(Nokogiri::HTML4::Document, root.document)
        assert_equal("<b>bold tag</b>", root.to_html.chomp)
      end

      def test_make_with_block
        doc = Nokogiri.make { b("bold tag") }
        assert_equal("<b>bold tag</b>", doc.to_html.chomp)
      end
    end
  end
end