mail 1.3.3 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of mail might be problematic. Click here for more details.
- data/Rakefile +1 -1
- data/lib/mail.rb +2 -1
- data/lib/mail/version.rb +1 -1
- data/lib/vendor/treetop-1.4.3/History.txt +18 -0
- data/lib/vendor/treetop-1.4.3/LICENSE +19 -0
- data/lib/vendor/treetop-1.4.3/README.md +164 -0
- data/lib/vendor/treetop-1.4.3/Rakefile +23 -0
- data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Snippets/grammar ___ end.tmSnippet +20 -0
- data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Snippets/rule ___ end.tmSnippet +18 -0
- data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Support/nibs/SyntaxTreeViewer.nib/designable.nib +1524 -0
- data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Support/nibs/SyntaxTreeViewer.nib/keyedobjects.nib +0 -0
- data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Support/syntax_tree_viewer.rb +117 -0
- data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Syntaxes/Treetop Grammar.tmLanguage +251 -0
- data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/info.plist +10 -0
- data/lib/vendor/treetop-1.4.3/benchmark/seqpar.gnuplot +15 -0
- data/lib/vendor/treetop-1.4.3/benchmark/seqpar.treetop +16 -0
- data/lib/vendor/treetop-1.4.3/benchmark/seqpar_benchmark.rb +107 -0
- data/lib/vendor/treetop-1.4.3/bin/tt +112 -0
- data/lib/vendor/treetop-1.4.3/doc/contributing_and_planned_features.markdown +103 -0
- data/lib/vendor/treetop-1.4.3/doc/grammar_composition.markdown +65 -0
- data/lib/vendor/treetop-1.4.3/doc/index.markdown +90 -0
- data/lib/vendor/treetop-1.4.3/doc/pitfalls_and_advanced_techniques.markdown +51 -0
- data/lib/vendor/treetop-1.4.3/doc/semantic_interpretation.markdown +189 -0
- data/lib/vendor/treetop-1.4.3/doc/site.rb +112 -0
- data/lib/vendor/treetop-1.4.3/doc/sitegen.rb +65 -0
- data/lib/vendor/treetop-1.4.3/doc/syntactic_recognition.markdown +100 -0
- data/lib/vendor/treetop-1.4.3/doc/using_in_ruby.markdown +21 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic.rb +551 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic.treetop +97 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic_node_classes.rb +7 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic_test.rb +54 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/lambda_calculus +0 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/lambda_calculus.rb +718 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/lambda_calculus.treetop +132 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/lambda_calculus_node_classes.rb +5 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/lambda_calculus_test.rb +89 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/test_helper.rb +18 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop.rb +17 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/bootstrap_gen_1_metagrammar.rb +45 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler.rb +6 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/grammar_compiler.rb +44 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/lexical_address_space.rb +17 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/metagrammar.rb +3366 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/metagrammar.treetop +436 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes.rb +20 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/anything_symbol.rb +18 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/atomic_expression.rb +14 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/character_class.rb +28 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/choice.rb +31 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/declaration_sequence.rb +24 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/grammar.rb +28 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/inline_module.rb +27 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/nonterminal.rb +13 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/optional.rb +19 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/parenthesized_expression.rb +9 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/parsing_expression.rb +146 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/parsing_rule.rb +58 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/predicate.rb +45 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/predicate_block.rb +16 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/repetition.rb +55 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/sequence.rb +71 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/terminal.rb +20 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/transient_prefix.rb +9 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/treetop_file.rb +9 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/ruby_builder.rb +113 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/ruby_extensions.rb +2 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/ruby_extensions/string.rb +42 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime.rb +5 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/compiled_parser.rb +110 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/interval_skip_list.rb +4 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/interval_skip_list/head_node.rb +15 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/interval_skip_list/interval_skip_list.rb +200 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/interval_skip_list/node.rb +164 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/syntax_node.rb +114 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/terminal_parse_failure.rb +16 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/terminal_syntax_node.rb +17 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/version.rb +9 -0
- data/lib/vendor/treetop-1.4.3/script/generate_metagrammar.rb +14 -0
- data/lib/vendor/treetop-1.4.3/script/svnadd +11 -0
- data/lib/vendor/treetop-1.4.3/script/svnrm +11 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/and_predicate_spec.rb +36 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/anything_symbol_spec.rb +44 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/character_class_spec.rb +276 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/choice_spec.rb +80 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/circular_compilation_spec.rb +28 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/failure_propagation_functional_spec.rb +21 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/grammar_compiler_spec.rb +84 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/grammar_spec.rb +41 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/multibyte_chars_spec.rb +46 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/nonterminal_symbol_spec.rb +40 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/not_predicate_spec.rb +38 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/one_or_more_spec.rb +35 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/optional_spec.rb +37 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/parenthesized_expression_spec.rb +19 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/parsing_rule_spec.rb +61 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/repeated_subrule_spec.rb +29 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/semantic_predicate_spec.rb +175 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/sequence_spec.rb +115 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/terminal_spec.rb +81 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/terminal_symbol_spec.rb +37 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/test_grammar.treetop +7 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/test_grammar.tt +7 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/test_grammar_do.treetop +7 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/tt_compiler_spec.rb +216 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/zero_or_more_spec.rb +56 -0
- data/lib/vendor/treetop-1.4.3/spec/composition/a.treetop +11 -0
- data/lib/vendor/treetop-1.4.3/spec/composition/b.treetop +11 -0
- data/lib/vendor/treetop-1.4.3/spec/composition/c.treetop +10 -0
- data/lib/vendor/treetop-1.4.3/spec/composition/d.treetop +10 -0
- data/lib/vendor/treetop-1.4.3/spec/composition/f.treetop +17 -0
- data/lib/vendor/treetop-1.4.3/spec/composition/grammar_composition_spec.rb +40 -0
- data/lib/vendor/treetop-1.4.3/spec/composition/subfolder/e_includes_c.treetop +15 -0
- data/lib/vendor/treetop-1.4.3/spec/ruby_extensions/string_spec.rb +32 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/compiled_parser_spec.rb +101 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/delete_spec.rb +147 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/expire_range_spec.rb +349 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/insert_and_delete_node.rb +385 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/insert_spec.rb +660 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/interval_skip_list_spec.graffle +6175 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/interval_skip_list_spec.rb +58 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/palindromic_fixture.rb +23 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/palindromic_fixture_spec.rb +164 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/spec_helper.rb +84 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/syntax_node_spec.rb +77 -0
- data/lib/vendor/treetop-1.4.3/spec/spec_helper.rb +110 -0
- data/lib/vendor/treetop-1.4.3/spec/spec_suite.rb +4 -0
- data/lib/vendor/treetop-1.4.3/treetop.gemspec +18 -0
- data/lib/vendor/treetop.rb +5 -0
- metadata +126 -11
@@ -0,0 +1,216 @@
|
|
1
|
+
require 'digest/sha1'
|
2
|
+
|
3
|
+
# ensure the Kernel.system and Kernel.open's always use the correct tt and
|
4
|
+
# Treetop library versions, not a previously installed gem
|
5
|
+
ENV['PATH'] = File.expand_path(File.dirname(__FILE__) + '../../../bin' +
|
6
|
+
File::PATH_SEPARATOR + ENV['PATH'])
|
7
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '../../../lib'))
|
8
|
+
|
9
|
+
describe "The 'tt' comand line compiler" do
|
10
|
+
|
11
|
+
context 'when processing a single grammar file' do
|
12
|
+
before(:each) do
|
13
|
+
# create a fresh but dumb grammar file for each example
|
14
|
+
@test_base = "dumb-#{rand(1000)}"
|
15
|
+
@test_grammar = "#{@test_base}.tt"
|
16
|
+
File.open(@test_grammar, 'w+') do |f|
|
17
|
+
f.print("grammar Dumb\n")
|
18
|
+
f.print("end\n")
|
19
|
+
end unless File.exists?(@test_grammar)
|
20
|
+
end
|
21
|
+
|
22
|
+
after(:each) do
|
23
|
+
# cleanup test grammar and parser output files
|
24
|
+
f = "#{@test_base}.rb"
|
25
|
+
File.delete(@test_grammar) if File.exists?(@test_grammar)
|
26
|
+
File.delete(f) if File.exists?(f)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'can compile a grammar file' do
|
30
|
+
# puts %q{emulate 'tt dumb.tt'}
|
31
|
+
system("ruby -S tt #{@test_grammar}").should be_true
|
32
|
+
|
33
|
+
pf = "#{@test_base}.rb"
|
34
|
+
File.exists?(pf).should be_true
|
35
|
+
File.zero?(pf).should_not be_true
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'can compile a relative pathed grammar file' do
|
39
|
+
dir = File.basename(File.expand_path(File.dirname(@test_grammar)))
|
40
|
+
|
41
|
+
# puts %q{emulate 'tt "../<current_dir>/dumb.tt"'}
|
42
|
+
system("ruby -S tt \"../#{dir}/#{@test_grammar}\"").should be_true
|
43
|
+
|
44
|
+
pf = "#{@test_base}.rb"
|
45
|
+
File.exists?(pf).should be_true
|
46
|
+
File.zero?(pf).should_not be_true
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'can compile an absolute pathed grammar file' do
|
50
|
+
# puts %q{emulate 'tt "/path/to/dumb.tt"'}
|
51
|
+
system("ruby -S tt \"#{File.expand_path(@test_grammar)}\"").should be_true
|
52
|
+
|
53
|
+
pf = "#{@test_base}.rb"
|
54
|
+
File.exists?(pf).should be_true
|
55
|
+
File.zero?(pf).should_not be_true
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'can compile without explicit file extensions' do
|
59
|
+
# puts %q{emulate 'tt dumb'}
|
60
|
+
system("ruby -S tt #{@test_base}").should be_true
|
61
|
+
|
62
|
+
pf = "#{@test_base}.rb"
|
63
|
+
File.exists?(pf).should be_true
|
64
|
+
File.zero?(pf).should_not be_true
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'skips nonexistent grammar file without failing or creating bogus output' do
|
68
|
+
# puts %q{emulate 'tt dumb.bad'}
|
69
|
+
Kernel.open("|ruby -S tt #{@test_base}.bad") do |io|
|
70
|
+
(io.read =~ /ERROR.*?not exist.*?continuing/).should_not be_nil
|
71
|
+
end
|
72
|
+
|
73
|
+
File.exists?("#{@test_base}.rb").should be_false
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'can compile to a specified parser source file' do
|
77
|
+
# puts %q{emulate 'tt -o my_dumb_test_parser.rb dumb'}
|
78
|
+
pf = 'my_dumb_test_parser.rb'
|
79
|
+
begin
|
80
|
+
system("ruby -S tt -o #{pf} #{@test_base}").should be_true
|
81
|
+
|
82
|
+
File.exists?(pf).should be_true
|
83
|
+
File.zero?(pf).should_not be_true
|
84
|
+
ensure
|
85
|
+
File.delete(pf) if File.exists?(pf)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'by default, does not overwrite an existing file without an autogenerated header' do
|
90
|
+
# puts %q{emulate 'tt -o must_save_parser.rb dumb'}
|
91
|
+
pf = 'must_save_parser.rb'
|
92
|
+
begin
|
93
|
+
system("ruby -S tt -o #{pf} #{@test_base}").should be_true
|
94
|
+
|
95
|
+
File.exists?(pf).should be_true
|
96
|
+
File.zero?(pf).should_not be_true
|
97
|
+
|
98
|
+
# Modify the file and make sure it remains unchanged:
|
99
|
+
File.open(pf, "r+") { |f| f.write("# Changed...") }
|
100
|
+
orig_file_hash = Digest::SHA1.hexdigest(File.read(pf))
|
101
|
+
|
102
|
+
Kernel.open("|ruby -S tt -o #{pf} #{@test_base}") do |io|
|
103
|
+
(io.read =~ /ERROR.*?already exists.*?skipping/).should_not be_nil
|
104
|
+
end
|
105
|
+
|
106
|
+
Digest::SHA1.hexdigest(File.read(pf)).should == orig_file_hash
|
107
|
+
ensure
|
108
|
+
File.delete(pf) if File.exists?(pf)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'by default, overwrites a changed file with an intact autogenerated header' do
|
113
|
+
# puts %q{emulate 'tt -o must_save_parser.rb dumb'}
|
114
|
+
pf = 'must_save_parser.rb'
|
115
|
+
begin
|
116
|
+
system("ruby -S tt -o #{pf} #{@test_base}").should be_true
|
117
|
+
|
118
|
+
File.exists?(pf).should be_true
|
119
|
+
File.zero?(pf).should_not be_true
|
120
|
+
orig_file_hash = Digest::SHA1.hexdigest(File.read(pf))
|
121
|
+
|
122
|
+
# Modify the file and make sure it gets reverted:
|
123
|
+
File.open(pf, "r+") { |f| f.gets; f.write("#") }
|
124
|
+
|
125
|
+
system("ruby -S tt -o #{pf} #{@test_base}").should be_true
|
126
|
+
Digest::SHA1.hexdigest(File.read(pf)).should == orig_file_hash
|
127
|
+
ensure
|
128
|
+
File.delete(pf) if File.exists?(pf)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'can be forced to overwrite existing file #{@test_base}' do
|
133
|
+
pf = "#{@test_base}.rb"
|
134
|
+
system("echo some junk >#{pf}").should be_true
|
135
|
+
|
136
|
+
File.exists?(pf).should be_true
|
137
|
+
File.zero?(pf).should_not be_true
|
138
|
+
orig_file_hash = Digest::SHA1.hexdigest(File.read(pf))
|
139
|
+
|
140
|
+
system("ruby -S tt -f #{@test_base}").should be_true
|
141
|
+
Digest::SHA1.hexdigest(File.read(pf)).should_not == orig_file_hash
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
context 'when processing multiple grammar files' do
|
147
|
+
|
148
|
+
before(:each) do
|
149
|
+
# provide fresh but dumb grammar files for each test
|
150
|
+
@test_bases = []
|
151
|
+
@test_grammars = []
|
152
|
+
|
153
|
+
%w[dumb1 dumb2].each do |e|
|
154
|
+
base = "#{e}-#{rand(1000)}"
|
155
|
+
grammar_file = "#{base}.tt"
|
156
|
+
@test_bases << base
|
157
|
+
@test_grammars << grammar_file
|
158
|
+
|
159
|
+
File.open(grammar_file, 'w+') do |f|
|
160
|
+
f.print("grammar #{e.capitalize}\n")
|
161
|
+
f.print("end\n")
|
162
|
+
end unless File.exists?(grammar_file)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
after(:each) do
|
167
|
+
# cleanup test grammar and output parser files
|
168
|
+
@test_grammars.each { |f| File.delete(f) if File.exists?(f) }
|
169
|
+
@test_bases.each { |f| File.delete("#{f}.rb") if File.exists?("#{f}.rb") }
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'can compile them in one invocation' do
|
173
|
+
# puts %q{emulate 'tt dumb1.tt dumb2.tt'}
|
174
|
+
system("ruby -S tt #{@test_grammars.join(' ')}").should be_true
|
175
|
+
|
176
|
+
@test_bases.each do |f|
|
177
|
+
pf = "#{f}.rb"
|
178
|
+
File.exists?(pf).should be_true
|
179
|
+
File.zero?(pf).should_not be_true
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'can compile them without explicit file extenstions' do
|
184
|
+
# puts %q{emulate 'tt dumb1 dumb2'}
|
185
|
+
system("ruby -S tt #{@test_bases.join(' ')}").should be_true
|
186
|
+
|
187
|
+
@test_bases.each do |f|
|
188
|
+
pf = "#{f}.rb"
|
189
|
+
File.exists?(pf).should be_true
|
190
|
+
File.zero?(pf).should_not be_true
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'can skip nonexistent and invalid extension named grammar files' do
|
195
|
+
# puts %q{emulate 'tt not_here bad_ext.ttg dumb1 dumb2'}
|
196
|
+
system("ruby -S tt not_here bad_ext.ttg #{@test_bases.join(' ')} >/dev/null 2>&1").should be_true
|
197
|
+
|
198
|
+
File.exists?('not_here.rb').should_not be_true
|
199
|
+
File.exists?('bad_ext.rb').should_not be_true
|
200
|
+
|
201
|
+
@test_bases.each do |f|
|
202
|
+
pf = "#{f}.rb"
|
203
|
+
File.exists?(pf).should be_true
|
204
|
+
File.zero?(pf).should_not be_true
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'can not specify an output file' do
|
209
|
+
# puts %q{emulate 'tt -o my_bogus_test_parser.rb dumb1 dumb2'}
|
210
|
+
pf = 'my_bogus_test_parser.rb'
|
211
|
+
system("ruby -S tt -o #{pf} #{@test_bases.join(' ')} >/dev/null 2>&1").should be_false
|
212
|
+
File.exists?(pf).should be_false
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
|
+
|
3
|
+
module ZeroOrMoreSpec
|
4
|
+
class Foo < Treetop::Runtime::SyntaxNode
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "zero or more of a terminal symbol followed by a node class declaration and a block" do
|
8
|
+
testing_expression '"foo"* <ZeroOrMoreSpec::Foo> { def a_method; end }'
|
9
|
+
|
10
|
+
it "successfully parses epsilon, returning an instance declared node class and recording a terminal failure" do
|
11
|
+
parse('') do |result|
|
12
|
+
result.should_not be_nil
|
13
|
+
result.should be_an_instance_of(Foo)
|
14
|
+
result.should respond_to(:a_method)
|
15
|
+
|
16
|
+
terminal_failures = parser.terminal_failures
|
17
|
+
terminal_failures.size.should == 1
|
18
|
+
failure = terminal_failures.first
|
19
|
+
failure.index.should == 0
|
20
|
+
failure.expected_string.should == 'foo'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it "successfully parses two of that terminal in a row, returning an instance of the declared node class and recording a failure representing the third attempt " do
|
25
|
+
parse("foofoo") do |result|
|
26
|
+
result.should_not be_nil
|
27
|
+
result.should be_an_instance_of(Foo)
|
28
|
+
|
29
|
+
terminal_failures = parser.terminal_failures
|
30
|
+
terminal_failures.size.should == 1
|
31
|
+
failure = terminal_failures.first
|
32
|
+
failure.index.should == 6
|
33
|
+
failure.expected_string.should == 'foo'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "Zero or more of a sequence" do
|
39
|
+
testing_expression '("foo" "bar")*'
|
40
|
+
|
41
|
+
it "resets the index appropriately following partially matcing input" do
|
42
|
+
parse('foobarfoo', :consume_all_input => false) do |result|
|
43
|
+
result.should_not be_nil
|
44
|
+
result.interval.should == (0...6)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "Zero or more of a choice" do
|
50
|
+
testing_expression '("a" / "b")*'
|
51
|
+
|
52
|
+
it "successfully parses matching input" do
|
53
|
+
parse('abba').should_not be_nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
|
+
|
3
|
+
module GrammarCompositionSpec
|
4
|
+
describe "several composed grammars" do
|
5
|
+
before do
|
6
|
+
dir = File.dirname(__FILE__)
|
7
|
+
Treetop.load File.join(dir, 'a')
|
8
|
+
Treetop.load File.join(dir, 'b')
|
9
|
+
Treetop.load File.join(dir, 'c')
|
10
|
+
# Check that polyglot finds d.treetop and loads it:
|
11
|
+
$: << dir
|
12
|
+
require 'd'
|
13
|
+
|
14
|
+
@c = ::Test::CParser.new
|
15
|
+
@d = ::Test::DParser.new
|
16
|
+
end
|
17
|
+
|
18
|
+
specify "rules in C have access to rules defined in A and B" do
|
19
|
+
@c.parse('abc').should_not be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
specify "rules in C can override rules in A and B with super semantics" do
|
23
|
+
@d.parse('superkeywordworks').should_not be_nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "composed grammar chaining with require" do
|
28
|
+
before do
|
29
|
+
# Load f with polyglot without using the load path:
|
30
|
+
require File.dirname(__FILE__) + '/f'
|
31
|
+
|
32
|
+
@f = ::Test::FParser.new
|
33
|
+
end
|
34
|
+
|
35
|
+
specify "rules in F have access to rule defined in E" do
|
36
|
+
@f.parse('abcef').should_not be_nil
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
|
+
|
3
|
+
describe String do
|
4
|
+
before do
|
5
|
+
@string = %{
|
6
|
+
0123456789
|
7
|
+
012345
|
8
|
+
01234567
|
9
|
+
0123
|
10
|
+
}.tabto(0).strip
|
11
|
+
end
|
12
|
+
|
13
|
+
it "can translate indices to column numbers" do
|
14
|
+
@string.column_of(0).should == 1
|
15
|
+
@string.column_of(5).should == 6
|
16
|
+
@string.column_of(10).should == 11
|
17
|
+
@string.column_of(11).should == 1
|
18
|
+
@string.column_of(17).should == 7
|
19
|
+
@string.column_of(18).should == 1
|
20
|
+
@string.column_of(24).should == 7
|
21
|
+
end
|
22
|
+
|
23
|
+
it "can translate indices to line numbers" do
|
24
|
+
@string.line_of(0).should == 1
|
25
|
+
@string.line_of(5).should == 1
|
26
|
+
@string.line_of(10).should == 1
|
27
|
+
@string.line_of(11).should == 2
|
28
|
+
@string.line_of(17).should == 2
|
29
|
+
@string.line_of(18).should == 3
|
30
|
+
@string.line_of(24).should == 3
|
31
|
+
end
|
32
|
+
end
|