File: test_parser.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-- 972 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
# frozen_string_literal: true
require "helper"

class TestNokogiri < Nokogiri::TestCase
  describe Nokogiri::CSS::Parser do
    let(:parser) { Nokogiri::CSS::Parser.new }

    it "#find_by_type" do
      ast = parser.parse("a:nth-child(2)").first
      matches = ast.find_by_type(
        [:CONDITIONAL_SELECTOR,
         [:ELEMENT_NAME],
         [:PSEUDO_CLASS,
          [:FUNCTION]]]
      )
      assert_equal(1, matches.length)
      assert_equal(ast, matches.first)
    end

    it "#to_type" do
      ast = parser.parse("a:nth-child(2)").first
      assert_equal(
        [:CONDITIONAL_SELECTOR,
         [:ELEMENT_NAME],
         [:PSEUDO_CLASS,
          [:FUNCTION]]], ast.to_type
      )
    end

    it "#to_a_" do
      asts = parser.parse("a:nth-child(2)")
      assert_equal(
        [:CONDITIONAL_SELECTOR,
         [:ELEMENT_NAME, ["a"]],
         [:PSEUDO_CLASS,
          [:FUNCTION, ["nth-child("], ["2"]]]], asts.first.to_a
      )
    end
  end
end