2018-06-04 17:56:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Capybara::Selector::CSS::Splitter do
|
|
|
|
let :splitter do
|
|
|
|
::Capybara::Selector::CSS::Splitter.new
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
context 'split not needed' do
|
|
|
|
it 'normal CSS selector' do
|
2018-06-04 17:56:05 -04:00
|
|
|
css = 'div[id="abc"]'
|
|
|
|
expect(splitter.split(css)).to eq [css]
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'comma in strings' do
|
2018-06-04 17:56:05 -04:00
|
|
|
css = 'div[id="a,bc"]'
|
|
|
|
expect(splitter.split(css)).to eq [css]
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'comma in pseudo-selector' do
|
2018-06-04 17:56:05 -04:00
|
|
|
css = 'div.class1:not(.class1, .class2)'
|
|
|
|
expect(splitter.split(css)).to eq [css]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
context 'split needed' do
|
|
|
|
it 'root level comma' do
|
2018-06-04 17:56:05 -04:00
|
|
|
css = 'div.class1, span, p.class2'
|
|
|
|
expect(splitter.split(css)).to eq ['div.class1', 'span', 'p.class2']
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'root level comma when quotes and pseudo selectors' do
|
2018-06-04 17:56:05 -04:00
|
|
|
css = 'div.class1[id="abc\\"def,ghi"]:not(.class3, .class4), span[id=\'a"c\\\'de\'], section, #abc\\,def'
|
|
|
|
expect(splitter.split(css)).to eq ['div.class1[id="abc\\"def,ghi"]:not(.class3, .class4)', 'span[id=\'a"c\\\'de\']', 'section', '#abc\\,def']
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|