Sha256: e0fe4899c993388b3827220a1ce7260892c37e68f2dfdd11099393018f89b1e9

Contents?: true

Size: 1.62 KB

Versions: 10

Compression:

Stored size: 1.62 KB

Contents

require 'spec_helper'

RSpec.describe Prawn::SVG::CSS::SelectorParser do
  describe "::parse" do
    it "parses a simple selector" do
      expect(described_class.parse("div")).to eq [{name: "div"}]
      expect(described_class.parse(".c1")).to eq [{class: ["c1"]}]
    end

    it "parses a complex selector" do
      result = described_class.parse("div#count .c1.c2 > span.large + div~.other:first-child *:nth-child(3)")
      expect(result).to eq [
        {name: "div", id: ["count"]},
        {combinator: :descendant, class: ["c1", "c2"]},
        {combinator: :child, name: "span", class: ["large"]},
        {combinator: :adjacent, name: "div"},
        {combinator: :siblings, class: ["other"], pseudo_class: ["first-child"]},
        {combinator: :descendant, name: "*", pseudo_class: ["nth-child(3)"]},
      ]
    end

    it "parses attributes" do
      expect(described_class.parse("[abc]")).to eq [{attribute: [["abc", nil, nil]]}]
      expect(described_class.parse("[abc=123]")).to eq [{attribute: [["abc", '=', '123']]}]
      expect(described_class.parse("[abc^=123]")).to eq [{attribute: [["abc", '^=', '123']]}]
      expect(described_class.parse("[ abc ^= 123 ]")).to eq [{attribute: [["abc", '^=', '123']]}]
      expect(described_class.parse("[abc^='123']")).to eq [{attribute: [["abc", '^=', '123']]}]
      expect(described_class.parse("[abc^= '123' ]")).to eq [{attribute: [["abc", '^=', '123']]}]
      expect(described_class.parse("[abc^= '123\\'456' ]")).to eq [{attribute: [["abc", '^=', '123\'456']]}]
      expect(described_class.parse('[abc^= "123\\"456" ]')).to eq [{attribute: [["abc", '^=', '123"456']]}]
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
prawn-svg-0.34.2 spec/prawn/svg/css/selector_parser_spec.rb
prawn-svg-0.34.1 spec/prawn/svg/css/selector_parser_spec.rb
prawn-svg-0.34.0 spec/prawn/svg/css/selector_parser_spec.rb
prawn-svg-0.33.0 spec/prawn/svg/css/selector_parser_spec.rb
prawn-svg-0.32.0 spec/prawn/svg/css/selector_parser_spec.rb
prawn-svg-0.31.0 spec/prawn/svg/css/selector_parser_spec.rb
prawn-svg-0.30.0 spec/prawn/svg/css/selector_parser_spec.rb
prawn-svg-0.29.1 spec/prawn/svg/css/selector_parser_spec.rb
prawn-svg-0.29.0 spec/prawn/svg/css/selector_parser_spec.rb
prawn-svg-0.28.0 spec/prawn/svg/css/selector_parser_spec.rb