-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathattribute_scanner_spec.rb
44 lines (37 loc) · 1.11 KB
/
attribute_scanner_spec.rb
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
describe Curly::AttributeScanner do
it "scans attributes" do
expect(scan("width=10px height=20px")).to eq({
"width" => "10px",
"height" => "20px"
})
end
it "scans single quoted values" do
expect(scan("title='hello world'")).to eq({ "title" => "hello world" })
end
it "scans double quoted values" do
expect(scan('title="hello world"')).to eq({ "title" => "hello world" })
end
it "scans mixed quotes" do
expect(scan(%[x=y q="foo's bar" v='bim " bum' t="foo ' bar"])).to eq({
"x" => "y",
"q" => "foo's bar",
"t" => "foo ' bar",
"v" => 'bim " bum'
})
end
it "deals with weird whitespace" do
expect(scan(" size=big ")).to eq({ "size" => "big" })
end
it "scans empty attribute lists" do
expect(scan(nil)).to eq({})
expect(scan("")).to eq({})
expect(scan(" ")).to eq({})
end
it "fails when an invalid attribute list is passed" do
expect { scan("foo") }.to raise_exception(Curly::AttributeError)
expect { scan("foo=") }.to raise_exception(Curly::AttributeError)
end
def scan(str)
described_class.scan(str)
end
end