forked from zmoazeni/csscss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_helper.rb
More file actions
68 lines (56 loc) · 1.4 KB
/
test_helper.rb
File metadata and controls
68 lines (56 loc) · 1.4 KB
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
61
62
63
64
65
66
67
68
require 'rubygems'
require 'bundler/setup'
require 'minitest/autorun'
require 'minitest/rg'
require 'byebug'
require 'csscss'
module TypeHelpers
def sel(s)
Csscss::Selector.new(s)
end
def dec(p, v)
Csscss::Declaration.new(p, v)
end
def rs(selectors, decs)
Csscss::Ruleset.new(selectors, decs)
end
end
module MiniTest::Assertions
def assert_parse(parser, string)
assert parser.parse(string)
rescue Parslet::ParseFailed => ex
assert false, ex.cause.ascii_tree
end
def assert_not_parse(parser, string)
parser.parse(string)
assert false, "expected #{parser} to not successfully parse \"#{string}\" and it did"
rescue Parslet::ParseFailed => ex
assert ex
end
end
Parslet::Atoms::DSL.infect_an_assertion :assert_parse, :must_parse, :do_not_flip
Parslet::Atoms::DSL.infect_an_assertion :assert_not_parse, :wont_parse, :do_not_flip
module CommonParserTests
def self.included(base)
base.instance_eval do
include Helpers
include TypeHelpers
describe "common parser tests" do
it "parses inherit" do
trans("inherit").must_equal([])
end
it "doesn't parse unknown values" do
@parser.wont_parse("foo")
end
end
end
end
module Helpers
def trans(s)
@trans.apply(@parser.parse(s))
rescue Parslet::ParseFailed => e
puts e.cause.ascii_tree
raise e
end
end
end