erubis 2.3.1 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{CHANGES → CHANGES.txt} +373 -3
- data/MIT-LICENSE +1 -1
- data/README.txt +6 -5
- data/benchmark/bench.rb +18 -11
- data/bin/erubis +3 -4
- data/contrib/erubis +3462 -5
- data/contrib/inline-require +54 -28
- data/doc/docstyle.css +25 -4
- data/doc/users-guide.html +814 -110
- data/doc-api/classes/ActionView/TemplateHandlers/ErubisHandler.html +209 -0
- data/doc-api/classes/ActionView.html +105 -0
- data/doc-api/classes/Erubis/ArrayBufferEnhancer.html +14 -14
- data/doc-api/classes/Erubis/ArrayEnhancer.html +16 -16
- data/doc-api/classes/Erubis/Basic/Converter.html +36 -31
- data/doc-api/classes/Erubis/BiPatternEnhancer.html +16 -13
- data/doc-api/classes/Erubis/CGenerator.html +70 -70
- data/doc-api/classes/Erubis/Context.html +49 -49
- data/doc-api/classes/Erubis/Converter.html +30 -29
- data/doc-api/classes/Erubis/CppGenerator.html +382 -0
- data/doc-api/classes/Erubis/DeleteIndentEnhancer.html +7 -7
- data/doc-api/classes/Erubis/Ecpp.html +126 -0
- data/doc-api/classes/Erubis/Engine.html +46 -43
- data/doc-api/classes/Erubis/ErboutEnhancer.html +16 -16
- data/doc-api/classes/Erubis/EscapeEnhancer.html +7 -7
- data/doc-api/classes/Erubis/EscapedEcpp.html +120 -0
- data/doc-api/classes/Erubis/Evaluator.html +22 -22
- data/doc-api/classes/Erubis/Generator.html +70 -70
- data/doc-api/classes/Erubis/HeaderFooterEnhancer.html +18 -15
- data/doc-api/classes/Erubis/Helpers/RailsFormHelper.html +787 -0
- data/doc-api/classes/Erubis/Helpers/RailsHelper/TemplateConverter.html +213 -0
- data/doc-api/classes/Erubis/Helpers/RailsHelper.html +103 -54
- data/doc-api/classes/Erubis/Helpers.html +6 -1
- data/doc-api/classes/Erubis/InterpolationEnhancer.html +42 -41
- data/doc-api/classes/Erubis/JavaGenerator.html +69 -69
- data/doc-api/classes/Erubis/JavascriptGenerator.html +79 -74
- data/doc-api/classes/Erubis/Main.html +49 -48
- data/doc-api/classes/Erubis/NoCodeEnhancer.html +35 -35
- data/doc-api/classes/Erubis/NoTextEnhancer.html +7 -7
- data/doc-api/classes/Erubis/OptimizedEruby.html +7 -7
- data/doc-api/classes/Erubis/OptimizedGenerator.html +84 -84
- data/doc-api/classes/Erubis/OptimizedXmlEruby.html +7 -7
- data/doc-api/classes/Erubis/PI/Converter.html +23 -22
- data/doc-api/classes/Erubis/PI/Ec.html +7 -7
- data/doc-api/classes/Erubis/PI/Ecpp.html +166 -0
- data/doc-api/classes/Erubis/PI/Ejava.html +7 -7
- data/doc-api/classes/Erubis/PI/Ejavascript.html +7 -7
- data/doc-api/classes/Erubis/PI/Eperl.html +7 -7
- data/doc-api/classes/Erubis/PI/Ephp.html +7 -7
- data/doc-api/classes/Erubis/PI/Eruby.html +6 -6
- data/doc-api/classes/Erubis/PI/Escheme.html +7 -7
- data/doc-api/classes/Erubis/PI/TinyEruby.html +28 -27
- data/doc-api/classes/Erubis/PI.html +1 -0
- data/doc-api/classes/Erubis/PercentLineEnhancer.html +18 -29
- data/doc-api/classes/Erubis/PerlGenerator.html +63 -63
- data/doc-api/classes/Erubis/PhpGenerator.html +63 -63
- data/doc-api/classes/Erubis/PrefixedLineEnhancer.html +210 -0
- data/doc-api/classes/Erubis/PrefixedLineEruby.html +120 -0
- data/doc-api/classes/Erubis/PreprocessingEruby.html +183 -0
- data/doc-api/classes/Erubis/PreprocessingHelper.html +212 -0
- data/doc-api/classes/Erubis/PrintEnabledEnhancer.html +23 -23
- data/doc-api/classes/Erubis/PrintOutEnhancer.html +38 -38
- data/doc-api/classes/Erubis/RubyEvaluator.html +59 -22
- data/doc-api/classes/Erubis/RubyGenerator.html +53 -52
- data/doc-api/classes/Erubis/SchemeGenerator.html +70 -70
- data/doc-api/classes/Erubis/SimplifyEnhancer.html +10 -9
- data/doc-api/classes/Erubis/StdoutEnhancer.html +3 -3
- data/doc-api/classes/Erubis/StringBufferEnhancer.html +16 -16
- data/doc-api/classes/Erubis/TinyEruby.html +33 -33
- data/doc-api/classes/Erubis/XmlHelper.html +80 -15
- data/doc-api/classes/Erubis.html +25 -1
- data/doc-api/classes/Kernel.html +155 -0
- data/doc-api/created.rid +1 -1
- data/doc-api/files/README_txt.html +8 -8
- data/doc-api/files/erubis/context_rb.html +2 -2
- data/doc-api/files/erubis/converter_rb.html +3 -3
- data/doc-api/files/erubis/engine/ec_rb.html +2 -2
- data/doc-api/files/erubis/engine/ecpp_rb.html +115 -0
- data/doc-api/files/erubis/engine/ejava_rb.html +2 -2
- data/doc-api/files/erubis/engine/ejavascript_rb.html +2 -2
- data/doc-api/files/erubis/engine/enhanced_rb.html +2 -2
- data/doc-api/files/erubis/engine/eperl_rb.html +2 -2
- data/doc-api/files/erubis/engine/ephp_rb.html +2 -2
- data/doc-api/files/erubis/engine/eruby_rb.html +2 -2
- data/doc-api/files/erubis/engine/escheme_rb.html +2 -2
- data/doc-api/files/erubis/engine/optimized_rb.html +2 -2
- data/doc-api/files/erubis/engine_rb.html +2 -2
- data/doc-api/files/erubis/enhancer_rb.html +2 -2
- data/doc-api/files/erubis/error_rb.html +2 -2
- data/doc-api/files/erubis/evaluator_rb.html +2 -2
- data/doc-api/files/erubis/generator_rb.html +3 -3
- data/doc-api/files/erubis/helper_rb.html +2 -2
- data/doc-api/files/erubis/helpers/rails_form_helper_rb.html +107 -0
- data/doc-api/files/erubis/helpers/rails_helper_rb.html +3 -2
- data/doc-api/files/erubis/local-setting_rb.html +2 -2
- data/doc-api/files/erubis/main_rb.html +4 -2
- data/doc-api/files/erubis/preprocessing_rb.html +114 -0
- data/doc-api/files/erubis/tiny_rb.html +2 -2
- data/doc-api/files/erubis/util_rb.html +107 -0
- data/doc-api/files/erubis_rb.html +2 -2
- data/doc-api/fr_class_index.html +13 -0
- data/doc-api/fr_file_index.html +4 -0
- data/doc-api/fr_method_index.html +237 -179
- data/examples/basic/Makefile +7 -2
- data/examples/basic/example.ecpp +33 -0
- data/lib/erubis/context.rb +2 -3
- data/lib/erubis/converter.rb +17 -11
- data/lib/erubis/engine/ec.rb +2 -3
- data/lib/erubis/engine/ecpp.rb +113 -0
- data/lib/erubis/engine/ejava.rb +9 -10
- data/lib/erubis/engine/ejavascript.rb +14 -9
- data/lib/erubis/engine/enhanced.rb +7 -3
- data/lib/erubis/engine/eperl.rb +2 -3
- data/lib/erubis/engine/ephp.rb +2 -3
- data/lib/erubis/engine/eruby.rb +8 -8
- data/lib/erubis/engine/escheme.rb +2 -3
- data/lib/erubis/engine/optimized.rb +2 -3
- data/lib/erubis/engine.rb +13 -11
- data/lib/erubis/enhancer.rb +101 -34
- data/lib/erubis/error.rb +2 -3
- data/lib/erubis/evaluator.rb +27 -10
- data/lib/erubis/generator.rb +3 -4
- data/lib/erubis/helper.rb +14 -3
- data/lib/erubis/helpers/rails_form_helper.rb +197 -0
- data/lib/erubis/helpers/rails_helper.rb +219 -77
- data/lib/erubis/local-setting.rb +2 -3
- data/lib/erubis/main.rb +85 -60
- data/lib/erubis/preprocessing.rb +58 -0
- data/lib/erubis/tiny.rb +9 -9
- data/lib/erubis/util.rb +22 -0
- data/lib/erubis.rb +4 -4
- data/test/assert-text-equal.rb +2 -3
- data/test/data/users-guide/bufvar-example.rb +10 -0
- data/test/data/users-guide/bufvar-example.result +17 -0
- data/test/data/users-guide/def_method.rb +14 -0
- data/test/data/users-guide/def_method.result +3 -0
- data/test/data/users-guide/example.ecpp +30 -0
- data/test/data/users-guide/example1.rb +1 -0
- data/test/data/users-guide/example_c.result +22 -19
- data/test/data/users-guide/fasteruby-example.rb +8 -0
- data/test/data/users-guide/fasteruby-example.result +18 -0
- data/test/data/users-guide/main_program1.rb +8 -0
- data/test/data/users-guide/main_program1.result +6 -0
- data/test/data/users-guide/main_program2.rb +8 -0
- data/test/data/users-guide/main_program2.result +6 -0
- data/test/data/users-guide/percentline-example.rhtml +3 -1
- data/test/data/users-guide/percentline_example.result +5 -3
- data/test/data/users-guide/prefixedline-example.rb +9 -0
- data/test/data/users-guide/prefixedline-example.rhtml +6 -0
- data/test/data/users-guide/prefixedline_example.result +9 -0
- data/test/data/users-guide/tail_260.result +4 -0
- data/test/data/users-guide/tailnewline.rhtml +3 -0
- data/test/data/users-guide/template1.rhtml +4 -0
- data/test/data/users-guide/template2.rhtml +4 -0
- data/test/test-engines.rb +88 -5
- data/test/test-enhancers.rb +83 -6
- data/test/test-erubis.rb +115 -11
- data/test/test-index-cgi.rb +191 -0
- data/test/test-main.rb +143 -31
- data/test/test-users-guide.rb +20 -3
- data/test/test.rb +18 -3
- data/test/testutil.rb +44 -8
- metadata +104 -67
- data/contrib/action_view_base_rb.patch +0 -23
data/test/test-main.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
##
|
2
|
-
## $Rev
|
3
|
-
## $Release: 2.
|
4
|
-
## $Date
|
2
|
+
## $Rev$
|
3
|
+
## $Release: 2.7.0 $
|
4
|
+
## $Date$
|
5
5
|
##
|
6
6
|
|
7
7
|
require "#{File.dirname(__FILE__)}/test.rb"
|
8
8
|
|
9
9
|
require 'tempfile'
|
10
|
+
require 'fileutils'
|
10
11
|
require 'erubis/main'
|
11
12
|
|
12
13
|
|
@@ -22,6 +23,26 @@ class StringWriter < String
|
|
22
23
|
def write(arg)
|
23
24
|
self << arg
|
24
25
|
end
|
26
|
+
def flush(*args)
|
27
|
+
# pass
|
28
|
+
end
|
29
|
+
def puts(arg)
|
30
|
+
case arg
|
31
|
+
when Array
|
32
|
+
arg.each do |item|
|
33
|
+
self << item << "\n"
|
34
|
+
end
|
35
|
+
else
|
36
|
+
self << arg.to_s
|
37
|
+
self << "\n" unless arg =~ /\n$/
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Erubis::Main
|
43
|
+
public :usage
|
44
|
+
public :show_properties
|
45
|
+
public :show_enhancers
|
25
46
|
end
|
26
47
|
|
27
48
|
|
@@ -132,27 +153,15 @@ END
|
|
132
153
|
END
|
133
154
|
|
134
155
|
def _test()
|
135
|
-
if $target
|
136
|
-
name = (caller()[0] =~ /in `test_(.*?)'/) && $1
|
137
|
-
return unless name == $target
|
138
|
-
end
|
139
156
|
if @filename.nil?
|
140
157
|
method = (caller[0] =~ /in `(.*)'/) && $1 #'
|
158
|
+
method =~ /block in (.*)/ and method = $1 # for Ruby 1.9
|
141
159
|
@filename = "tmp.#{method}"
|
142
160
|
end
|
143
|
-
File.open(@filename, 'w') {
|
161
|
+
File.open(@filename, 'w') {|f| f.write(@input) } if @filename
|
144
162
|
begin
|
145
|
-
|
146
|
-
|
147
|
-
#else
|
148
|
-
# command = "ruby #{$script} #{@options} #{@filename}"
|
149
|
-
#end
|
150
|
-
#output = `#{command}`
|
151
|
-
if @options.is_a?(Array)
|
152
|
-
argv = @options + [ @filename ]
|
153
|
-
else
|
154
|
-
argv = "#{@options} #{@filename}".split
|
155
|
-
end
|
163
|
+
argv = @options.is_a?(Array) ? @options.dup : @options.split
|
164
|
+
argv << @filename if @filename
|
156
165
|
$stdout = output = StringWriter.new
|
157
166
|
Erubis::Main.new.execute(argv)
|
158
167
|
ensure
|
@@ -162,10 +171,23 @@ END
|
|
162
171
|
assert_text_equal(@expected, output)
|
163
172
|
end
|
164
173
|
|
174
|
+
def _error_test(errclass, errmsg)
|
175
|
+
ex = assert_raise(errclass) { _test() }
|
176
|
+
assert_equal(errmsg, ex.message)
|
177
|
+
end
|
178
|
+
|
179
|
+
|
180
|
+
def test_help # -h
|
181
|
+
@options = '-h'
|
182
|
+
m = Erubis::Main.new
|
183
|
+
@expected = m.usage() + "\n" + m.show_properties() + m.show_enhancers()
|
184
|
+
@filename = false
|
185
|
+
_test()
|
186
|
+
end
|
165
187
|
|
166
188
|
def test_version # -v
|
167
189
|
@options = '-v'
|
168
|
-
@expected = (("$Release: 2.
|
190
|
+
@expected = (("$Release: 2.7.0 $" =~ /[.\d]+/) && $&) + "\n"
|
169
191
|
@filename = false
|
170
192
|
_test()
|
171
193
|
end
|
@@ -187,11 +209,35 @@ END
|
|
187
209
|
end
|
188
210
|
|
189
211
|
|
212
|
+
def _with_dummy_file
|
213
|
+
bindir = File.join(File.dirname(File.dirname(__FILE__)), 'bin')
|
214
|
+
env_path = ENV['PATH']
|
215
|
+
env__ = ENV['_']
|
216
|
+
begin
|
217
|
+
ENV['PATH'] = bindir + File::PATH_SEPARATOR + ENV['PATH']
|
218
|
+
ENV['_'] = 'erubis'
|
219
|
+
Tempfile.open(self.name.gsub(/[^\w]/,'_')) do |f|
|
220
|
+
f.write(INPUT)
|
221
|
+
f.flush
|
222
|
+
yield(f.path)
|
223
|
+
end
|
224
|
+
ensure
|
225
|
+
ENV['PATH'] = env_path
|
226
|
+
ENV['_'] = env__ if env__
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
|
190
231
|
def test_syntax1 # -z (syntax ok)
|
191
232
|
@input = INPUT
|
192
233
|
@expected = "Syntax OK\n"
|
193
234
|
@options = '-z'
|
194
235
|
_test()
|
236
|
+
#
|
237
|
+
_with_dummy_file do |filepath|
|
238
|
+
actual = `erubis #{@options} #{filepath}`
|
239
|
+
assert_equal @expected, actual
|
240
|
+
end
|
195
241
|
end
|
196
242
|
|
197
243
|
|
@@ -214,7 +260,32 @@ END
|
|
214
260
|
basename = 'tmp.test_syntax2_%d.rhtml'
|
215
261
|
filenames = [ basename % 0, basename % 1 ]
|
216
262
|
errmsgs = []
|
217
|
-
|
263
|
+
if ruby19?
|
264
|
+
errmsgs << <<'END'
|
265
|
+
3: syntax error, unexpected ']', expecting ')'
|
266
|
+
_buf << ' <li>'; _buf << ( item[:name]] ).to_s; _buf << '</li>
|
267
|
+
^
|
268
|
+
-:4: syntax error, unexpected keyword_end, expecting ')'
|
269
|
+
'; end
|
270
|
+
^
|
271
|
+
-:7: syntax error, unexpected $end, expecting ')'
|
272
|
+
END
|
273
|
+
errmsgs << <<'END'
|
274
|
+
7: syntax error, unexpected $end, expecting keyword_end
|
275
|
+
END
|
276
|
+
elsif rubinius?
|
277
|
+
errmsgs << <<'END'
|
278
|
+
3: expecting ')'
|
279
|
+
_buf << ' <li>'; _buf << ( item[:name]] ).to_s; _buf << '</li>
|
280
|
+
^
|
281
|
+
END
|
282
|
+
errmsgs << <<'END'
|
283
|
+
7: missing 'end' for 'for' started on line 2
|
284
|
+
_buf.to_s
|
285
|
+
^
|
286
|
+
END
|
287
|
+
else
|
288
|
+
errmsgs << <<'END'
|
218
289
|
3: syntax error, unexpected ']', expecting ')'
|
219
290
|
_buf << ' <li>'; _buf << ( item[:name]] ).to_s; _buf << '</li>
|
220
291
|
^
|
@@ -223,21 +294,26 @@ END
|
|
223
294
|
^
|
224
295
|
-:7: syntax error, unexpected $end, expecting ')'
|
225
296
|
END
|
226
|
-
|
297
|
+
errmsgs << <<'END'
|
227
298
|
7: syntax error, unexpected $end, expecting kEND
|
228
299
|
END
|
300
|
+
end
|
229
301
|
#
|
230
302
|
max = inputs.length
|
231
303
|
(0...max).each do |i|
|
232
304
|
@input = inputs[i]
|
233
305
|
@expected = "tmp.test_syntax2:#{errmsgs[i]}"
|
234
306
|
@options = '-z'
|
307
|
+
if rubinius?
|
308
|
+
@expected.sub! /unexpected kEND/, 'unexpected keyword_end'
|
309
|
+
@expected.sub! /expecting kEND/, 'expecting keyword_end'
|
310
|
+
end
|
235
311
|
_test()
|
236
312
|
end
|
237
313
|
#
|
238
314
|
begin
|
239
315
|
(0...max).each do |i|
|
240
|
-
File.open(filenames[i], 'w') {
|
316
|
+
File.open(filenames[i], 'w') {|f| f.write(inputs[i]) }
|
241
317
|
end
|
242
318
|
@input = '<ok/>'
|
243
319
|
@expected = ''
|
@@ -246,6 +322,10 @@ END
|
|
246
322
|
@expected << "#{filenames[i]}:#{errmsgs[i]}"
|
247
323
|
@options << " #{filenames[i]}"
|
248
324
|
end
|
325
|
+
if rubinius?
|
326
|
+
@expected.sub! /unexpected kEND/, 'unexpected keyword_end'
|
327
|
+
@expected.sub! /expecting kEND/, 'expecting keyword_end'
|
328
|
+
end
|
249
329
|
_test()
|
250
330
|
ensure
|
251
331
|
(0...max).each do |i|
|
@@ -336,7 +416,7 @@ END
|
|
336
416
|
user: Hello
|
337
417
|
password: world
|
338
418
|
END
|
339
|
-
File.open(datafile, 'w') {
|
419
|
+
File.open(datafile, 'w') {|f| f.write(str) }
|
340
420
|
begin
|
341
421
|
_test()
|
342
422
|
ensure
|
@@ -355,7 +435,7 @@ END
|
|
355
435
|
@user = 'Hello'
|
356
436
|
@password = 'world'
|
357
437
|
END
|
358
|
-
File.open(datafile, 'w') {
|
438
|
+
File.open(datafile, 'w') {|f| f.write(str) }
|
359
439
|
begin
|
360
440
|
_test()
|
361
441
|
ensure
|
@@ -374,7 +454,7 @@ END
|
|
374
454
|
user: Hello
|
375
455
|
password: world
|
376
456
|
END
|
377
|
-
File.open(yamlfile, 'w') {
|
457
|
+
File.open(yamlfile, 'w') {|f| f.write(yaml) }
|
378
458
|
begin
|
379
459
|
_test()
|
380
460
|
ensure
|
@@ -396,11 +476,11 @@ END
|
|
396
476
|
- bbb
|
397
477
|
- ccc
|
398
478
|
END
|
399
|
-
File.open(yamlfile, 'w') {
|
479
|
+
File.open(yamlfile, 'w') {|f| f.write(yaml) }
|
400
480
|
assert_raise(ArgumentError) do
|
401
481
|
_test()
|
402
482
|
end
|
403
|
-
File.open(yamlfile, 'w') {
|
483
|
+
File.open(yamlfile, 'w') {|f| f.write(yaml.gsub(/\t/, ' '*8)) }
|
404
484
|
_test()
|
405
485
|
ensure
|
406
486
|
File.unlink(yamlfile) if test(?f, yamlfile)
|
@@ -466,7 +546,7 @@ list:
|
|
466
546
|
- bbb
|
467
547
|
- ccc
|
468
548
|
END
|
469
|
-
File.open(yamlfile, 'w') {
|
549
|
+
File.open(yamlfile, 'w') {|f| f.write(yaml) }
|
470
550
|
begin
|
471
551
|
_test()
|
472
552
|
ensure
|
@@ -517,7 +597,7 @@ END
|
|
517
597
|
_test()
|
518
598
|
ensure
|
519
599
|
File.unlink filename if test(?f, filename)
|
520
|
-
|
600
|
+
FileUtils.rm_r dir if test(?d, dir)
|
521
601
|
end
|
522
602
|
end
|
523
603
|
|
@@ -543,7 +623,7 @@ END
|
|
543
623
|
_test()
|
544
624
|
ensure
|
545
625
|
File.unlink filename if test(?f, filename)
|
546
|
-
|
626
|
+
FileUtils.rm_r dir if test(?d, dir)
|
547
627
|
end
|
548
628
|
end
|
549
629
|
|
@@ -585,6 +665,36 @@ END
|
|
585
665
|
end
|
586
666
|
|
587
667
|
|
668
|
+
def test_invalid_option # -1 (invalid option)
|
669
|
+
@input = INPUT
|
670
|
+
@options = '-1'
|
671
|
+
_error_test(Erubis::CommandOptionError, "-1: unknown option.")
|
672
|
+
end
|
673
|
+
|
674
|
+
|
675
|
+
def test_invalid_enhancer # -E hoge
|
676
|
+
@options = '-E hoge'
|
677
|
+
errmsg = "hoge: no such Enhancer (try '-h' to show all enhancers)."
|
678
|
+
_error_test(Erubis::CommandOptionError, errmsg)
|
679
|
+
end
|
680
|
+
|
681
|
+
|
682
|
+
def test_invalid_lang # -l hoge
|
683
|
+
@options = '-l hoge'
|
684
|
+
errmsg = "-l hoge: invalid language name (class Erubis::Ehoge not found)."
|
685
|
+
_error_test(Erubis::CommandOptionError, errmsg)
|
686
|
+
end
|
687
|
+
|
688
|
+
|
689
|
+
def test_missing_argument # -E
|
690
|
+
@filename = false
|
691
|
+
@options = '-E'
|
692
|
+
_error_test(Erubis::CommandOptionError, "-E: enhancers required.")
|
693
|
+
@options = '-l'
|
694
|
+
_error_test(Erubis::CommandOptionError, "-l: lang required.")
|
695
|
+
end
|
696
|
+
|
697
|
+
|
588
698
|
def test_pi1 # --pi -x
|
589
699
|
@input = PI_INPUT
|
590
700
|
@expected = PI_SRC
|
@@ -637,4 +747,6 @@ END
|
|
637
747
|
end
|
638
748
|
|
639
749
|
|
750
|
+
self.post_definition()
|
751
|
+
|
640
752
|
end
|
data/test/test-users-guide.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
###
|
2
|
-
### $
|
3
|
-
###
|
4
|
-
### copyright(c) 2006-2007 kuwata-lab.com all rights reserved.
|
2
|
+
### $Release: 2.7.0 $
|
3
|
+
### copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
5
4
|
###
|
6
5
|
|
7
6
|
require "#{File.dirname(__FILE__)}/test.rb"
|
@@ -29,6 +28,22 @@ class KwarkUsersGuideTest < Test::Unit::TestCase
|
|
29
28
|
s =~ /\A\$ (.*?)\n/
|
30
29
|
command = $1
|
31
30
|
expected = $'
|
31
|
+
if ruby19?
|
32
|
+
case @name
|
33
|
+
when 'test_main_program1_result'
|
34
|
+
expected.sub!('["eruby", "items", "x", "_buf"]', '[:_buf, :eruby, :items, :x]')
|
35
|
+
when 'test_main_program2_result'
|
36
|
+
expected.sub!('["_context", "x", "_buf"]', '[:_buf, :x, :_context]')
|
37
|
+
end
|
38
|
+
elsif rubinius?
|
39
|
+
command.sub!(/^ruby\b/, 'rbx')
|
40
|
+
case @name
|
41
|
+
when 'test_main_program1_result'
|
42
|
+
expected.sub!('["eruby", "items", "x", "_buf"]', '["_buf", "eruby", "items", "x"]')
|
43
|
+
when 'test_main_program2_result'
|
44
|
+
expected.sub!('["_context", "x", "_buf"]', '["_buf", "x", "_context"]')
|
45
|
+
end
|
46
|
+
end
|
32
47
|
result = `#{command}`
|
33
48
|
assert_text_equal(expected, result)
|
34
49
|
end
|
@@ -53,4 +68,6 @@ class KwarkUsersGuideTest < Test::Unit::TestCase
|
|
53
68
|
end
|
54
69
|
|
55
70
|
|
71
|
+
self.post_definition()
|
72
|
+
|
56
73
|
end
|
data/test/test.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
##
|
2
|
-
## $
|
3
|
-
##
|
4
|
-
## copyright(c) 2006-2007 kuwata-lab.com all rights reserved.
|
2
|
+
## $Release: 2.7.0 $
|
3
|
+
## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
5
4
|
##
|
6
5
|
|
7
6
|
|
@@ -21,6 +20,22 @@ require 'testutil'
|
|
21
20
|
require 'erubis'
|
22
21
|
|
23
22
|
|
23
|
+
Test::Unit::TestCase.class_eval do
|
24
|
+
if RUBY_VERSION >= "1.9"
|
25
|
+
## minitest doesn't have 'name()' method
|
26
|
+
def name
|
27
|
+
@name || @__name__
|
28
|
+
end
|
29
|
+
def ruby19
|
30
|
+
yield
|
31
|
+
end
|
32
|
+
else
|
33
|
+
def ruby19
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
24
39
|
if $0 == __FILE__
|
25
40
|
require "#{TESTDIR}/test-erubis.rb"
|
26
41
|
require "#{TESTDIR}/test-engines.rb"
|
data/test/testutil.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
###
|
2
|
-
### $
|
3
|
-
###
|
4
|
-
### copyright(c) 2006-2007 kuwata-lab.com all rights reserved.
|
2
|
+
### $Release: 2.7.0 $
|
3
|
+
### copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
5
4
|
###
|
6
5
|
|
7
6
|
require 'yaml'
|
@@ -9,6 +8,21 @@ require 'yaml'
|
|
9
8
|
require 'test/unit/testcase'
|
10
9
|
|
11
10
|
|
11
|
+
|
12
|
+
def ruby18? # :nodoc:
|
13
|
+
RUBY_VERSION =~ /\A1.8/
|
14
|
+
end
|
15
|
+
|
16
|
+
def ruby19? # :nodoc:
|
17
|
+
RUBY_VERSION =~ /\A1.9/
|
18
|
+
end
|
19
|
+
|
20
|
+
def rubinius? # :nodoc:
|
21
|
+
defined?(RUBY_ENGINE) && RUBY_ENGINE == "rbx"
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
|
12
26
|
class Test::Unit::TestCase
|
13
27
|
|
14
28
|
|
@@ -20,11 +34,7 @@ class Test::Unit::TestCase
|
|
20
34
|
s = $'
|
21
35
|
end
|
22
36
|
# untabify
|
23
|
-
unless options[:tabify] == false
|
24
|
-
s = s.inject('') do |sb, line|
|
25
|
-
sb << line.gsub(/([^\t]{8})|([^\t]*)\t/n) { [$+].pack("A8") }
|
26
|
-
end
|
27
|
-
end
|
37
|
+
s = _untabify(s) unless options[:tabify] == false
|
28
38
|
# load yaml document
|
29
39
|
testdata_list = []
|
30
40
|
YAML.load_documents(s) do |ydoc|
|
@@ -72,4 +82,30 @@ class Test::Unit::TestCase
|
|
72
82
|
end
|
73
83
|
|
74
84
|
|
85
|
+
def self.post_definition
|
86
|
+
if ENV['TEST']
|
87
|
+
target = "test_#{ENV['TEST']}"
|
88
|
+
self.instance_methods.each do |method_name|
|
89
|
+
m = method_name.to_s
|
90
|
+
private m if m =~ /\Atest_/ && m != target
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
def self._untabify(str, width=8)
|
97
|
+
return str if str.nil?
|
98
|
+
list = str.split(/\t/, -1) # if 2nd arg is negative then split() doesn't remove tailing empty strings
|
99
|
+
last = list.pop
|
100
|
+
sb = ''
|
101
|
+
list.each do |s|
|
102
|
+
column = (n = s.rindex(?\n)) ? s.length - n - 1 : s.length
|
103
|
+
n = width - (column % width)
|
104
|
+
sb << s << (' ' * n)
|
105
|
+
end
|
106
|
+
sb << last if last
|
107
|
+
return sb
|
108
|
+
end
|
109
|
+
|
110
|
+
|
75
111
|
end
|