less 0.8.13 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -1
- data/Rakefile +21 -3
- data/VERSION +1 -1
- data/bin/lessc +0 -8
- data/less.gemspec +138 -15
- data/lib/less.rb +67 -11
- data/lib/less/command.rb +24 -25
- data/lib/less/engine.rb +36 -140
- data/lib/less/engine/builder.rb +8 -0
- data/lib/less/engine/less.tt +374 -0
- data/lib/less/engine/nodes.rb +8 -0
- data/lib/less/engine/nodes/element.rb +150 -0
- data/lib/less/engine/nodes/entity.rb +73 -0
- data/lib/less/engine/nodes/function.rb +82 -0
- data/lib/less/engine/nodes/literal.rb +135 -0
- data/lib/less/engine/nodes/property.rb +112 -0
- data/lib/less/engine/nodes/selector.rb +39 -0
- data/lib/less/engine/parser.rb +3860 -0
- data/lib/vendor/treetop/.gitignore +7 -0
- data/lib/vendor/treetop/LICENSE +19 -0
- data/lib/vendor/treetop/README +164 -0
- data/lib/vendor/treetop/Rakefile +19 -0
- data/lib/vendor/treetop/benchmark/seqpar.gnuplot +15 -0
- data/lib/vendor/treetop/benchmark/seqpar.treetop +16 -0
- data/lib/vendor/treetop/benchmark/seqpar_benchmark.rb +107 -0
- data/lib/vendor/treetop/bin/tt +28 -0
- data/lib/vendor/treetop/lib/treetop.rb +8 -0
- data/lib/vendor/treetop/lib/treetop/bootstrap_gen_1_metagrammar.rb +45 -0
- data/lib/vendor/treetop/lib/treetop/compiler.rb +6 -0
- data/lib/vendor/treetop/lib/treetop/compiler/grammar_compiler.rb +42 -0
- data/lib/vendor/treetop/lib/treetop/compiler/lexical_address_space.rb +17 -0
- data/lib/vendor/treetop/lib/treetop/compiler/metagrammar.rb +3097 -0
- data/lib/vendor/treetop/lib/treetop/compiler/metagrammar.treetop +408 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes.rb +19 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/anything_symbol.rb +18 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/atomic_expression.rb +14 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb +23 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/choice.rb +31 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/declaration_sequence.rb +24 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/grammar.rb +28 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/inline_module.rb +27 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/nonterminal.rb +13 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/optional.rb +19 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/parenthesized_expression.rb +9 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/parsing_expression.rb +146 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/parsing_rule.rb +55 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/predicate.rb +45 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/repetition.rb +55 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/sequence.rb +68 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/terminal.rb +20 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/transient_prefix.rb +9 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/treetop_file.rb +9 -0
- data/lib/vendor/treetop/lib/treetop/compiler/ruby_builder.rb +113 -0
- data/lib/vendor/treetop/lib/treetop/ruby_extensions.rb +2 -0
- data/lib/vendor/treetop/lib/treetop/ruby_extensions/string.rb +42 -0
- data/lib/vendor/treetop/lib/treetop/runtime.rb +5 -0
- data/lib/vendor/treetop/lib/treetop/runtime/compiled_parser.rb +109 -0
- data/lib/vendor/treetop/lib/treetop/runtime/interval_skip_list.rb +4 -0
- data/lib/vendor/treetop/lib/treetop/runtime/interval_skip_list/head_node.rb +15 -0
- data/lib/vendor/treetop/lib/treetop/runtime/interval_skip_list/interval_skip_list.rb +200 -0
- data/lib/vendor/treetop/lib/treetop/runtime/interval_skip_list/node.rb +164 -0
- data/lib/vendor/treetop/lib/treetop/runtime/syntax_node.rb +90 -0
- data/lib/vendor/treetop/lib/treetop/runtime/terminal_parse_failure.rb +16 -0
- data/lib/vendor/treetop/lib/treetop/runtime/terminal_syntax_node.rb +17 -0
- data/lib/vendor/treetop/lib/treetop/version.rb +9 -0
- data/lib/vendor/treetop/spec/compiler/and_predicate_spec.rb +36 -0
- data/lib/vendor/treetop/spec/compiler/anything_symbol_spec.rb +44 -0
- data/lib/vendor/treetop/spec/compiler/character_class_spec.rb +247 -0
- data/lib/vendor/treetop/spec/compiler/choice_spec.rb +80 -0
- data/lib/vendor/treetop/spec/compiler/circular_compilation_spec.rb +28 -0
- data/lib/vendor/treetop/spec/compiler/failure_propagation_functional_spec.rb +21 -0
- data/lib/vendor/treetop/spec/compiler/grammar_compiler_spec.rb +84 -0
- data/lib/vendor/treetop/spec/compiler/grammar_spec.rb +41 -0
- data/lib/vendor/treetop/spec/compiler/nonterminal_symbol_spec.rb +40 -0
- data/lib/vendor/treetop/spec/compiler/not_predicate_spec.rb +38 -0
- data/lib/vendor/treetop/spec/compiler/one_or_more_spec.rb +35 -0
- data/lib/vendor/treetop/spec/compiler/optional_spec.rb +37 -0
- data/lib/vendor/treetop/spec/compiler/parenthesized_expression_spec.rb +19 -0
- data/lib/vendor/treetop/spec/compiler/parsing_rule_spec.rb +32 -0
- data/lib/vendor/treetop/spec/compiler/sequence_spec.rb +115 -0
- data/lib/vendor/treetop/spec/compiler/terminal_spec.rb +81 -0
- data/lib/vendor/treetop/spec/compiler/terminal_symbol_spec.rb +37 -0
- data/lib/vendor/treetop/spec/compiler/test_grammar.treetop +7 -0
- data/lib/vendor/treetop/spec/compiler/test_grammar.tt +7 -0
- data/lib/vendor/treetop/spec/compiler/test_grammar_do.treetop +7 -0
- data/lib/vendor/treetop/spec/compiler/zero_or_more_spec.rb +56 -0
- data/lib/vendor/treetop/spec/composition/a.treetop +11 -0
- data/lib/vendor/treetop/spec/composition/b.treetop +11 -0
- data/lib/vendor/treetop/spec/composition/c.treetop +10 -0
- data/lib/vendor/treetop/spec/composition/d.treetop +10 -0
- data/lib/vendor/treetop/spec/composition/f.treetop +17 -0
- data/lib/vendor/treetop/spec/composition/grammar_composition_spec.rb +40 -0
- data/lib/vendor/treetop/spec/composition/subfolder/e_includes_c.treetop +15 -0
- data/lib/vendor/treetop/spec/ruby_extensions/string_spec.rb +32 -0
- data/lib/vendor/treetop/spec/runtime/compiled_parser_spec.rb +101 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/delete_spec.rb +147 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/expire_range_spec.rb +349 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/insert_and_delete_node.rb +385 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/insert_spec.rb +660 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/interval_skip_list_spec.graffle +6175 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/interval_skip_list_spec.rb +58 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/palindromic_fixture.rb +23 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/palindromic_fixture_spec.rb +164 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/spec_helper.rb +84 -0
- data/lib/vendor/treetop/spec/runtime/syntax_node_spec.rb +68 -0
- data/lib/vendor/treetop/spec/spec_helper.rb +106 -0
- data/lib/vendor/treetop/spec/spec_suite.rb +4 -0
- data/lib/vendor/treetop/treetop.gemspec +17 -0
- data/spec/command_spec.rb +2 -6
- data/spec/css/accessors-1.0.css +18 -0
- data/spec/css/big-1.0.css +3768 -0
- data/spec/css/comments-1.0.css +9 -0
- data/spec/css/css-1.0.css +40 -0
- data/spec/css/functions-1.0.css +6 -0
- data/spec/css/import-1.0.css +11 -0
- data/spec/css/mixins-1.0.css +28 -0
- data/spec/css/operations-1.0.css +28 -0
- data/spec/css/rulesets-1.0.css +17 -0
- data/spec/css/scope-1.0.css +14 -0
- data/spec/css/strings-1.0.css +12 -0
- data/spec/css/variables-1.0.css +6 -0
- data/spec/css/whitespace-1.0.css +9 -0
- data/spec/engine_spec.rb +66 -18
- data/spec/less/accessors-1.0.less +20 -0
- data/spec/less/big-1.0.less +4810 -0
- data/spec/less/colors-1.0.less +0 -0
- data/spec/less/comments-1.0.less +46 -0
- data/spec/less/css-1.0.less +84 -0
- data/spec/less/exceptions/mixed-units-error.less +3 -0
- data/spec/less/exceptions/name-error-1.0.less +3 -0
- data/spec/less/exceptions/syntax-error-1.0.less +3 -0
- data/spec/less/functions-1.0.less +6 -0
- data/spec/less/import-1.0.less +7 -0
- data/spec/less/import/import-test-a.less +2 -0
- data/spec/less/import/import-test-b.less +8 -0
- data/spec/less/import/import-test-c.less +5 -0
- data/spec/less/mixins-1.0.less +43 -0
- data/spec/less/operations-1.0.less +39 -0
- data/spec/less/rulesets-1.0.less +30 -0
- data/spec/less/scope-1.0.less +33 -0
- data/spec/less/strings-1.0.less +14 -0
- data/spec/less/variables-1.0.less +18 -0
- data/spec/less/whitespace-1.0.less +21 -0
- data/spec/spec.css +79 -24
- data/spec/spec.less +2 -3
- data/spec/spec_helper.rb +4 -1
- metadata +136 -13
- data/lib/less/tree.rb +0 -82
- data/spec/css/less-0.8.10.css +0 -30
- data/spec/css/less-0.8.11.css +0 -31
- data/spec/css/less-0.8.12.css +0 -28
- data/spec/css/less-0.8.5.css +0 -24
- data/spec/css/less-0.8.6.css +0 -24
- data/spec/css/less-0.8.7.css +0 -24
- data/spec/css/less-0.8.8.css +0 -25
- data/spec/tree_spec.rb +0 -5
@@ -0,0 +1,58 @@
|
|
1
|
+
#require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
|
2
|
+
#
|
3
|
+
#MAX_INTERVAL = 100000
|
4
|
+
#
|
5
|
+
#describe IntervalSkipList do
|
6
|
+
# describe "#next_node_height" do
|
7
|
+
# attr_reader :list
|
8
|
+
#
|
9
|
+
# before do
|
10
|
+
# @list = IntervalSkipList.new
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# it "returns a number between 1 and the max_height of the list" do
|
14
|
+
# height = list.next_node_height
|
15
|
+
# height.should be <= list.max_height
|
16
|
+
# height.should be > 0
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# describe "a list with 1000 random intervals" do
|
21
|
+
# attr_reader :list, :inserted_ranges
|
22
|
+
#
|
23
|
+
# before do
|
24
|
+
# @list = IntervalSkipList.new
|
25
|
+
# @inserted_ranges = []
|
26
|
+
#
|
27
|
+
# 0.upto(10) do |i|
|
28
|
+
# first, last = [rand(MAX_INTERVAL), rand(MAX_INTERVAL)].sort
|
29
|
+
# range = first..last
|
30
|
+
# list.insert(range, i)
|
31
|
+
# inserted_ranges.push(range)
|
32
|
+
# end
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# it "functions correctly for stabbing queries" do
|
36
|
+
# 10000.times do
|
37
|
+
# n = rand(MAX_INTERVAL)
|
38
|
+
# ranges = list.containing(n).sort
|
39
|
+
#
|
40
|
+
# expected_ranges = []
|
41
|
+
# inserted_ranges.each_with_index do |range,i|
|
42
|
+
# expected_ranges.push(i) if n > range.first && n < range.last
|
43
|
+
# end
|
44
|
+
# expected_ranges.sort!
|
45
|
+
# unless ranges == expected_ranges
|
46
|
+
# puts "N = #{n}"
|
47
|
+
# puts "Expected: " + expected_ranges.inspect
|
48
|
+
# puts "Actual: " + ranges.inspect
|
49
|
+
# expected_ranges.size.should be <= ranges.size
|
50
|
+
# puts "Missing containers: #{(expected_ranges.map {|o| o.object_id} - ranges.map {|o| o.object_id}).inspect}"
|
51
|
+
# puts "Unexpected containers: #{(ranges.map {|o| o.object_id} - expected_ranges.map {|o| o.object_id}).inspect}"
|
52
|
+
# puts "Inserted Ranges: #{inserted_ranges.inspect}"
|
53
|
+
# puts "Expected Ranges: #{expected_ranges.map {|i| inserted_ranges[i]}.inspect}"
|
54
|
+
# end
|
55
|
+
# end
|
56
|
+
# end
|
57
|
+
# end
|
58
|
+
#end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
describe "the palindromic fixture", :shared => true do
|
2
|
+
attr_reader :list, :node
|
3
|
+
include IntervalSkipListSpecHelper
|
4
|
+
|
5
|
+
before do
|
6
|
+
@list = IntervalSkipList.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it_should_behave_like "#next_node_height is deterministic"
|
10
|
+
def expected_node_heights
|
11
|
+
[3, 2, 1, 3, 1, 2, 3]
|
12
|
+
end
|
13
|
+
|
14
|
+
before do
|
15
|
+
list.insert(1..3, :a)
|
16
|
+
list.insert(1..5, :b)
|
17
|
+
list.insert(1..7, :c)
|
18
|
+
list.insert(1..9, :d)
|
19
|
+
list.insert(1..11, :e)
|
20
|
+
list.insert(1..13, :f)
|
21
|
+
list.insert(5..13, :g)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
|
3
|
+
|
4
|
+
describe "The palindromic fixture" do
|
5
|
+
it_should_behave_like "the palindromic fixture"
|
6
|
+
|
7
|
+
describe " #nodes" do
|
8
|
+
describe "[0]" do
|
9
|
+
before do
|
10
|
+
@node = list.nodes[0]
|
11
|
+
end
|
12
|
+
|
13
|
+
it "has a key of 1 and a height of 3" do
|
14
|
+
node.key.should == 1
|
15
|
+
node.height.should == 3
|
16
|
+
end
|
17
|
+
|
18
|
+
it "has :c, :d, :e, and :f as its only forward markers at level 2" do
|
19
|
+
node.forward_markers[2].should have_markers(:c, :d, :e, :f)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "has :a, :b as its only forward markers at level 1" do
|
23
|
+
node.forward_markers[1].should have_markers(:a, :b)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "has no forward markers at level 0" do
|
27
|
+
node.forward_markers[0].should be_empty
|
28
|
+
end
|
29
|
+
|
30
|
+
it "has no markers" do
|
31
|
+
node.markers.should be_empty
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "[1]" do
|
36
|
+
before do
|
37
|
+
@node = list.nodes[1]
|
38
|
+
end
|
39
|
+
|
40
|
+
it "has a key of 3 and a height of 2" do
|
41
|
+
node.key.should == 3
|
42
|
+
node.height.should == 2
|
43
|
+
end
|
44
|
+
|
45
|
+
it "has no forward markers at level 1" do
|
46
|
+
node.forward_markers[1].should be_empty
|
47
|
+
end
|
48
|
+
|
49
|
+
it "has :b as its only forward marker at level 0" do
|
50
|
+
node.forward_markers[0].should have_marker(:b)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "has :a and :b as its only markers" do
|
54
|
+
node.markers.should have_markers(:a, :b)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "[2]" do
|
59
|
+
before do
|
60
|
+
@node = list.nodes[2]
|
61
|
+
end
|
62
|
+
|
63
|
+
it "has a key of 5 and a height of 1" do
|
64
|
+
node.key.should == 5
|
65
|
+
node.height.should == 1
|
66
|
+
end
|
67
|
+
|
68
|
+
it "has :g as its only forward marker at level 0" do
|
69
|
+
node.forward_markers[0].should have_marker(:g)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "has :b as its only marker" do
|
73
|
+
node.markers.should have_marker(:b)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "[3]" do
|
78
|
+
before do
|
79
|
+
@node = list.nodes[3]
|
80
|
+
end
|
81
|
+
|
82
|
+
it "has a key of 7 and a height of 3" do
|
83
|
+
node.key.should == 7
|
84
|
+
node.height.should == 3
|
85
|
+
end
|
86
|
+
|
87
|
+
it "has :f and :g as its only forward markers at level 2" do
|
88
|
+
node.forward_markers[2].should have_markers(:f, :g)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "has :e as its only forward markers at level 1" do
|
92
|
+
node.forward_markers[1].should have_marker(:e)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "has :d as its only forward marker at level 0" do
|
96
|
+
node.forward_markers[0].should have_markers(:d)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "has :c, :d, :e, :f and :g as its only markers" do
|
100
|
+
node.markers.should have_markers(:c, :d, :e, :f, :g)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "[4]" do
|
105
|
+
before do
|
106
|
+
@node = list.nodes[4]
|
107
|
+
end
|
108
|
+
|
109
|
+
it "has a key of 9 and a height of 1" do
|
110
|
+
node.key.should == 9
|
111
|
+
node.height.should == 1
|
112
|
+
end
|
113
|
+
|
114
|
+
it "has no forward markers at any level" do
|
115
|
+
node.forward_markers[0].should be_empty
|
116
|
+
end
|
117
|
+
|
118
|
+
it "has :d as its only marker" do
|
119
|
+
node.markers.should have_markers(:d)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "[5]" do
|
124
|
+
before do
|
125
|
+
@node = list.nodes[5]
|
126
|
+
end
|
127
|
+
|
128
|
+
it "has a key of 11 and a height of 2" do
|
129
|
+
node.key.should == 11
|
130
|
+
node.height.should == 2
|
131
|
+
end
|
132
|
+
|
133
|
+
it "has no forward markers at any level" do
|
134
|
+
node.forward_markers[0].should be_empty
|
135
|
+
node.forward_markers[1].should be_empty
|
136
|
+
end
|
137
|
+
|
138
|
+
it "has :e as its only marker" do
|
139
|
+
node.markers.should have_markers(:e)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe "[6]" do
|
144
|
+
before do
|
145
|
+
@node = list.nodes[6]
|
146
|
+
end
|
147
|
+
|
148
|
+
it "has a key of 13 and a height of 3" do
|
149
|
+
node.key.should == 13
|
150
|
+
node.height.should == 3
|
151
|
+
end
|
152
|
+
|
153
|
+
it "has no forward markers at any level" do
|
154
|
+
node.forward_markers[0].should be_empty
|
155
|
+
node.forward_markers[1].should be_empty
|
156
|
+
node.forward_markers[2].should be_empty
|
157
|
+
end
|
158
|
+
|
159
|
+
it "has :f and :g as its only markers" do
|
160
|
+
node.markers.should have_markers(:f, :g)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
class IntervalSkipList
|
4
|
+
public :insert_node, :delete_node, :nodes, :head, :next_node_height
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "#next_node_height is deterministic", :shared => true do
|
8
|
+
before do
|
9
|
+
node_heights = expected_node_heights.dup
|
10
|
+
stub(list).next_node_height { node_heights.shift }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module IntervalSkipListSpecHelper
|
15
|
+
def contain_marker(marker)
|
16
|
+
ContainMarkers.new(list, [marker])
|
17
|
+
end
|
18
|
+
|
19
|
+
def contain_markers(*markers)
|
20
|
+
ContainMarkers.new(list, markers)
|
21
|
+
end
|
22
|
+
|
23
|
+
class ContainMarkers
|
24
|
+
attr_reader :failure_message
|
25
|
+
|
26
|
+
def initialize(list, expected_markers)
|
27
|
+
@list = list
|
28
|
+
@expected_markers = expected_markers
|
29
|
+
end
|
30
|
+
|
31
|
+
def matches?(target_range)
|
32
|
+
@target_range = target_range
|
33
|
+
|
34
|
+
@target_range.each do |i|
|
35
|
+
markers = @list.containing(i)
|
36
|
+
|
37
|
+
@expected_markers.each do |expected_marker|
|
38
|
+
unless markers.include?(expected_marker)
|
39
|
+
@failure_message = "Expected #{expected_marker.inspect} to contain #{i}, but it doesn't. #{i} is contained by: #{markers.inspect}."
|
40
|
+
return false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
markers.each do |marker|
|
45
|
+
unless @expected_markers.include?(marker)
|
46
|
+
@failure_message = "Did not expect #{marker.inspect} to contain #{i}. Only expected #{@expected_markers.inspect}."
|
47
|
+
return false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def have_markers(*markers)
|
57
|
+
HaveMarkers.new(markers)
|
58
|
+
end
|
59
|
+
|
60
|
+
def have_marker(marker)
|
61
|
+
HaveMarkers.new([marker])
|
62
|
+
end
|
63
|
+
|
64
|
+
class HaveMarkers
|
65
|
+
def initialize(expected_markers)
|
66
|
+
@expected_markers = expected_markers
|
67
|
+
end
|
68
|
+
|
69
|
+
def matches?(target)
|
70
|
+
@target = target
|
71
|
+
return false unless @target.size == @expected_markers.size
|
72
|
+
@expected_markers.each do |expected_marker|
|
73
|
+
return false unless @target.include?(expected_marker)
|
74
|
+
end
|
75
|
+
true
|
76
|
+
end
|
77
|
+
|
78
|
+
def failure_message
|
79
|
+
"Expected #{@target.inspect} to include only #{@expected_markers.inspect}"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
require "#{File.dirname(__FILE__)}/palindromic_fixture"
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
|
+
|
3
|
+
module SyntaxNodeSpec
|
4
|
+
describe "A new terminal syntax node" do
|
5
|
+
attr_reader :node
|
6
|
+
|
7
|
+
before do
|
8
|
+
@node = Runtime::SyntaxNode.new("input", 0...3)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "reports itself as terminal" do
|
12
|
+
node.should be_terminal
|
13
|
+
node.should_not be_nonterminal
|
14
|
+
end
|
15
|
+
|
16
|
+
it "has a text value based on the input and the interval" do
|
17
|
+
node.text_value.should == "inp"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "has itself as its only element" do
|
21
|
+
node.elements.should be_nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "A new nonterminal syntax node" do
|
26
|
+
attr_reader :node
|
27
|
+
|
28
|
+
before do
|
29
|
+
@input = 'test input'
|
30
|
+
@elements = [Runtime::SyntaxNode.new('input', 0...3)]
|
31
|
+
@node = Runtime::SyntaxNode.new('input', 0...3, @elements)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "reports itself as nonterminal" do
|
35
|
+
node.should be_nonterminal
|
36
|
+
node.should_not be_terminal
|
37
|
+
end
|
38
|
+
|
39
|
+
it "has a text value based on the input and the interval" do
|
40
|
+
node.text_value.should == "inp"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "has the elements with which it was instantiated" do
|
44
|
+
node.elements.should == @elements
|
45
|
+
end
|
46
|
+
|
47
|
+
it "sets itself as the parent of its elements" do
|
48
|
+
node.elements.each do |element|
|
49
|
+
element.parent.should == node
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "A new nonterminal syntax node with all children lazily instantiated" do
|
55
|
+
attr_reader :node
|
56
|
+
|
57
|
+
before do
|
58
|
+
@input = 'test input'
|
59
|
+
@node = Runtime::SyntaxNode.new('input', 0...3, [true, true, true])
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should lazily instantiate its child nodes" do
|
63
|
+
node.elements.size.should == 3
|
64
|
+
node.elements.first.interval.should == (0...1)
|
65
|
+
node.elements.first.parent.should == @node
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
dir = File.dirname(__FILE__)
|
2
|
+
require 'rubygems'
|
3
|
+
require 'benchmark'
|
4
|
+
require 'spec'
|
5
|
+
|
6
|
+
unless $bootstrapped_gen_1_metagrammar
|
7
|
+
load File.join(dir, '..', 'lib', 'treetop', 'bootstrap_gen_1_metagrammar.rb')
|
8
|
+
end
|
9
|
+
include Treetop
|
10
|
+
|
11
|
+
Spec::Runner.configure do |config|
|
12
|
+
config.mock_with :rr
|
13
|
+
end
|
14
|
+
|
15
|
+
module Treetop
|
16
|
+
class TreetopExampleGroup < Spec::Example::ExampleGroup
|
17
|
+
class << self
|
18
|
+
attr_accessor :parser_class_under_test
|
19
|
+
|
20
|
+
def testing_expression(expression_under_test)
|
21
|
+
testing_grammar(%{
|
22
|
+
grammar Test
|
23
|
+
rule expression_under_test
|
24
|
+
}+expression_under_test+%{
|
25
|
+
end
|
26
|
+
end
|
27
|
+
}.tabto(0))
|
28
|
+
end
|
29
|
+
|
30
|
+
def testing_grammar(grammar_under_test)
|
31
|
+
grammar_node = parse_with_metagrammar(grammar_under_test.strip, :grammar)
|
32
|
+
parser_code = grammar_node.compile
|
33
|
+
class_eval(parser_code)
|
34
|
+
self.parser_class_under_test = const_get(grammar_node.parser_name.to_sym)
|
35
|
+
end
|
36
|
+
|
37
|
+
def parse_with_metagrammar(input, root)
|
38
|
+
parser = Treetop::Compiler::MetagrammarParser.new
|
39
|
+
parser.root = root
|
40
|
+
node = parser.parse(input)
|
41
|
+
raise parser.failure_reason unless node
|
42
|
+
node
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
attr_reader :parser
|
48
|
+
|
49
|
+
def parse_with_metagrammar(input, root)
|
50
|
+
self.class.parse_with_metagrammar(input, root)
|
51
|
+
end
|
52
|
+
|
53
|
+
def parser_class_under_test
|
54
|
+
self.class.parser_class_under_test
|
55
|
+
end
|
56
|
+
|
57
|
+
def parse(input, options = {})
|
58
|
+
@parser = parser_class_under_test.new
|
59
|
+
unless options[:consume_all_input].nil?
|
60
|
+
parser.consume_all_input = options.delete(:consume_all_input)
|
61
|
+
end
|
62
|
+
result = parser.parse(input, options)
|
63
|
+
yield result if block_given?
|
64
|
+
result
|
65
|
+
end
|
66
|
+
|
67
|
+
def compiling_grammar(grammar_under_test)
|
68
|
+
lambda {
|
69
|
+
grammar_node = parse_with_metagrammar(grammar_under_test.strip, :grammar)
|
70
|
+
parser_code = grammar_node.compile
|
71
|
+
[grammar_node, parser_code]
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
def compiling_expression(expression_under_test)
|
76
|
+
compiling_grammar(%{
|
77
|
+
grammar Test
|
78
|
+
rule expression_under_test
|
79
|
+
#{expression_under_test}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
}.tabto(0))
|
83
|
+
end
|
84
|
+
|
85
|
+
def optionally_benchmark(&block)
|
86
|
+
if BENCHMARK
|
87
|
+
Benchmark.bm do |x|
|
88
|
+
x.report(&block)
|
89
|
+
end
|
90
|
+
else
|
91
|
+
yield
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
Spec::Example::ExampleGroupFactory.register(:compiler, self)
|
96
|
+
Spec::Example::ExampleGroupFactory.register(:runtime, self)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
class Symbol
|
101
|
+
def to_proc
|
102
|
+
lambda do |x|
|
103
|
+
x.send(self)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|