erubis 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/{ChangeLog → CHANGES} +139 -6
- data/MIT-LICENSE +20 -0
- data/README.txt +20 -5
- data/benchmark/erubybench.rb +465 -229
- data/benchmark/erubybench.rhtml +39 -15
- data/benchmark/erubybench.yaml +126 -46
- data/bin/erubis +2 -2
- data/bin/notext +3 -3
- data/contrib/action_view_base_rb.patch +23 -0
- data/contrib/erubis +466 -308
- data/contrib/inline-require +2 -2
- data/doc-api/classes/ERB.html +101 -0
- data/doc-api/classes/Erubis.html +59 -6
- data/doc-api/classes/Erubis/ArrayEnhancer.html +12 -12
- data/doc-api/classes/Erubis/Basic/Converter.html +61 -57
- data/doc-api/classes/Erubis/BiPatternEnhancer.html +14 -14
- data/doc-api/classes/Erubis/CGenerator.html +60 -60
- data/doc-api/classes/Erubis/Context.html +125 -29
- data/doc-api/classes/Erubis/Converter.html +73 -22
- data/doc-api/classes/Erubis/Engine.html +55 -39
- data/doc-api/classes/Erubis/EscapeEnhancer.html +6 -6
- data/doc-api/classes/Erubis/Evaluator.html +19 -19
- data/doc-api/classes/Erubis/Generator.html +16 -10
- data/doc-api/classes/Erubis/HeaderFooterEnhancer.html +14 -14
- data/doc-api/classes/Erubis/{Helper.html → Helpers.html} +5 -6
- data/doc-api/classes/Erubis/Helpers/RailsHelper.html +296 -0
- data/doc-api/classes/Erubis/JavaGenerator.html +54 -54
- data/doc-api/classes/Erubis/JavascriptGenerator.html +60 -60
- data/doc-api/classes/Erubis/Main.html +42 -30
- data/doc-api/classes/Erubis/NoCodeEnhancer.html +5 -5
- data/doc-api/classes/Erubis/NoTextEnhancer.html +7 -7
- data/doc-api/classes/Erubis/OptimizedEruby.html +6 -6
- data/doc-api/classes/Erubis/OptimizedGenerator.html +72 -72
- data/doc-api/classes/Erubis/OptimizedXmlEruby.html +6 -6
- data/doc-api/classes/Erubis/PI/Converter.html +28 -81
- data/doc-api/classes/Erubis/PI/Ec.html +6 -6
- data/doc-api/classes/Erubis/PI/Ejava.html +6 -6
- data/doc-api/classes/Erubis/PI/Ejavascript.html +6 -6
- data/doc-api/classes/Erubis/PI/Eperl.html +6 -6
- data/doc-api/classes/Erubis/PI/Ephp.html +6 -6
- data/doc-api/classes/Erubis/PI/Eruby.html +7 -7
- data/doc-api/classes/Erubis/PI/Escheme.html +6 -6
- data/doc-api/classes/Erubis/PI/TinyEruby.html +66 -79
- data/doc-api/classes/Erubis/PercentLineEnhancer.html +8 -8
- data/doc-api/classes/Erubis/PerlGenerator.html +54 -54
- data/doc-api/classes/Erubis/PhpGenerator.html +54 -54
- data/doc-api/classes/Erubis/PrintEnabledEnhancer.html +21 -21
- data/doc-api/classes/Erubis/PrintOutEnhancer.html +30 -30
- data/doc-api/classes/Erubis/RubyEvaluator.html +12 -12
- data/doc-api/classes/Erubis/RubyGenerator.html +9 -9
- data/doc-api/classes/Erubis/SimplifyEnhancer.html +7 -6
- data/doc-api/classes/Erubis/StdoutEnhancer.html +12 -12
- data/doc-api/classes/Erubis/StringBufferEnhancer.html +13 -13
- data/doc-api/classes/Erubis/TinyEruby.html +56 -68
- data/doc-api/classes/Erubis/XmlHelper.html +20 -23
- data/doc-api/created.rid +1 -1
- data/doc-api/files/{__/README_txt.html → README_txt.html} +35 -20
- data/doc-api/files/erubis/context_rb.html +2 -2
- data/doc-api/files/erubis/converter_rb.html +2 -2
- data/doc-api/files/erubis/engine/ec_rb.html +2 -2
- 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 -3
- 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 +2 -2
- data/doc-api/files/erubis/helper_rb.html +2 -2
- data/doc-api/files/erubis/{helper/rails_rb.html → helpers/rails_helper_rb.html} +6 -31
- 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/tiny_rb.html +2 -2
- data/doc-api/files/erubis_rb.html +2 -2
- data/doc-api/fr_class_index.html +3 -3
- data/doc-api/fr_file_index.html +2 -2
- data/doc-api/fr_method_index.html +142 -147
- data/doc-api/index.html +1 -1
- data/doc/users-guide.html +387 -218
- data/lib/erubis.rb +21 -25
- data/lib/erubis/context.rb +34 -4
- data/lib/erubis/converter.rb +159 -115
- data/lib/erubis/engine.rb +29 -12
- data/lib/erubis/engine/ec.rb +2 -2
- data/lib/erubis/engine/ejava.rb +2 -2
- data/lib/erubis/engine/ejavascript.rb +2 -2
- data/lib/erubis/engine/enhanced.rb +2 -2
- data/lib/erubis/engine/eperl.rb +2 -2
- data/lib/erubis/engine/ephp.rb +2 -2
- data/lib/erubis/engine/eruby.rb +5 -6
- data/lib/erubis/engine/escheme.rb +2 -2
- data/lib/erubis/engine/optimized.rb +2 -2
- data/lib/erubis/enhancer.rb +33 -7
- data/lib/erubis/error.rb +2 -2
- data/lib/erubis/evaluator.rb +2 -2
- data/lib/erubis/generator.rb +6 -3
- data/lib/erubis/helper.rb +6 -23
- data/lib/erubis/helpers/rails_helper.rb +202 -0
- data/lib/erubis/local-setting.rb +4 -4
- data/lib/erubis/main.rb +90 -35
- data/lib/erubis/tiny.rb +57 -52
- data/test/assert-text-equal.rb +2 -2
- data/test/test-engines.rb +5 -5
- data/test/test-erubis.rb +173 -63
- data/test/test-main.rb +135 -27
- data/test/test-notext.rb +2 -2
- data/test/test.rb +2 -2
- data/test/testutil.rb +2 -2
- metadata +16 -16
- data/LGPL +0 -504
- data/doc-api/classes/Erubis/Helper/CachedRailsTemplate.html +0 -198
- data/doc-api/classes/Erubis/Helper/RailsTemplate.html +0 -366
- data/lib/erubis/helper/rails.rb +0 -159
data/{ChangeLog → CHANGES}
RENAMED
|
@@ -1,12 +1,145 @@
|
|
|
1
|
-
# $Rev:
|
|
2
|
-
# $Release: 2.
|
|
3
|
-
# copyright(c) 2006 kuwata-lab all rights reserved.
|
|
1
|
+
# $Rev: 65 $
|
|
2
|
+
# $Release: 2.2.0 $
|
|
3
|
+
# copyright(c) 2006-2007 kuwata-lab all rights reserved.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
#
|
|
7
|
+
- release: 2.2.0
|
|
8
|
+
date: 2007-02-11
|
|
9
|
+
enhancements:
|
|
10
|
+
- |
|
|
11
|
+
Performance tuned up. Release 2.2.0 works about 8 percent faster
|
|
12
|
+
than 2.1.0.
|
|
13
|
+
As a result, Erubis works more than 10 percent faster than eruby.
|
|
14
|
+
(eruby is the extension module of eRuby written in C.)
|
|
15
|
+
|
|
16
|
+
- |
|
|
17
|
+
Support of Ruby on Rails improved.
|
|
18
|
+
If you want to use Erubis with Ruby on Rails, add the following code
|
|
19
|
+
into your 'config/environment.rb' and restart web server.
|
|
20
|
+
This will set Erubis as eRuby compiler in Ruby on Rails instead of ERB.
|
|
21
|
+
|
|
22
|
+
--------------------
|
|
23
|
+
require 'erubis/helpers/rails_helper'
|
|
24
|
+
#Erubis::Helpers::RailsHelper.engine_class = Erubis::Eruby
|
|
25
|
+
#Erubis::Helpers::RailsHelper.init_properties = {}
|
|
26
|
+
#Erubis::Helpers::RailsHelper.show_src = true
|
|
27
|
+
--------------------
|
|
28
|
+
|
|
29
|
+
Methods 'capture()' and 'content_for()' of ActionView::Helpers::CaptureHelper
|
|
30
|
+
are available. Methd ActionView::Helpers::TextHelper#concat() is also available.
|
|
31
|
+
|
|
32
|
+
If Erubis::Helpers::RailsHelper.show_src is ture, Erubis prints converted
|
|
33
|
+
Ruby code into log file (such as 'log/development.log').
|
|
34
|
+
|
|
35
|
+
- |
|
|
36
|
+
Erubis::Engine.load_file(filename) creates cache file (filename +
|
|
37
|
+
'.cache') automatically if cache file is old or not exist.
|
|
38
|
+
Caching makes Erubis about 40-50 percent faster.
|
|
39
|
+
|
|
40
|
+
ex.
|
|
41
|
+
--------------------
|
|
42
|
+
require 'erubis'
|
|
43
|
+
eruby = Erubis::Eruby.load_file('example.rhtml')
|
|
44
|
+
## cache file 'example.rhtml.cache' is created automatically
|
|
45
|
+
--------------------
|
|
46
|
+
|
|
47
|
+
- |
|
|
48
|
+
Command-line option '-f datafile' can take Ruby script ('*.rb')
|
|
49
|
+
as well as YAML file ('*.yaml' or '*.yml').
|
|
50
|
+
|
|
51
|
+
ex.
|
|
52
|
+
====================
|
|
53
|
+
$ cat context.rb
|
|
54
|
+
@title = 'Example'
|
|
55
|
+
@list = %w[AAA BBB CCC]
|
|
56
|
+
$ cat example.rhtml
|
|
57
|
+
<h1><%= @title %></h1>
|
|
58
|
+
<ul>
|
|
59
|
+
<% for item in @list %>
|
|
60
|
+
<li><%= item %></li>
|
|
61
|
+
<% end %>
|
|
62
|
+
</ul>
|
|
63
|
+
$ erubis -f context.rb example.rhtml
|
|
64
|
+
<h1>Example</h1>
|
|
65
|
+
<ul>
|
|
66
|
+
<li>AAA</li>
|
|
67
|
+
<li>BBB</li>
|
|
68
|
+
<li>CCC</li>
|
|
69
|
+
</ul>
|
|
70
|
+
====================
|
|
71
|
+
|
|
72
|
+
- |
|
|
73
|
+
New command-line option '-c context' support. It takes context string
|
|
74
|
+
in YAML inline style or Ruby code style.
|
|
75
|
+
|
|
76
|
+
ex. YAML inline style
|
|
77
|
+
====================
|
|
78
|
+
$ erubis -c '{title: Example, list: [AAA, BBB, CCC]}' example.rhtml
|
|
79
|
+
====================
|
|
80
|
+
|
|
81
|
+
ex. YAML inline style
|
|
82
|
+
====================
|
|
83
|
+
$ erubis -c '@title="Example"; @list=%w[AAA BBB CCC]' example.rhtml
|
|
84
|
+
====================
|
|
85
|
+
|
|
86
|
+
- |
|
|
87
|
+
New command-line option '-z' (syntax checking) support. It is similar
|
|
88
|
+
to 'erubis -x file.rhtml | ruby -wc', but it can take several filenames.
|
|
89
|
+
|
|
90
|
+
ex.
|
|
91
|
+
====================
|
|
92
|
+
$ erubis -z app/views/*/*.rhtml
|
|
93
|
+
Syntax OK
|
|
94
|
+
====================
|
|
95
|
+
|
|
96
|
+
- |
|
|
97
|
+
New constant Erubis::VERSION added.
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
changes:
|
|
101
|
+
- |
|
|
102
|
+
Class Erubis::Eruby changed to include Erubis::StringBufferEnhancer
|
|
103
|
+
instead of Erubis::ArrayBufferEnhancer.
|
|
104
|
+
This is for Ruby on Rails support.
|
|
105
|
+
|
|
106
|
+
ex.
|
|
107
|
+
====================
|
|
108
|
+
$ cat example.rhtml
|
|
109
|
+
<ul>
|
|
110
|
+
<% for item in @list %>
|
|
111
|
+
<li><%= item %></li>
|
|
112
|
+
<% end %>
|
|
113
|
+
</ul>
|
|
114
|
+
$ erubis -x example.rhtml
|
|
115
|
+
_buf = ''; _buf << '<ul>
|
|
116
|
+
'; for item in @list
|
|
117
|
+
_buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
|
|
118
|
+
'; end
|
|
119
|
+
_buf << '</ul>
|
|
120
|
+
';
|
|
121
|
+
_buf.to_s
|
|
122
|
+
====================
|
|
123
|
+
|
|
124
|
+
- |
|
|
125
|
+
Erubis::StringBufferEnhancer#add_postamble() prints "_buf.to_s"
|
|
126
|
+
instead of "_buf".
|
|
127
|
+
This is useful for 'erubis -x file.rhtml | ruby -wc'.
|
|
128
|
+
|
|
129
|
+
- |
|
|
130
|
+
Command-line option '-T' is removed. Use '--trim=false' instead.
|
|
131
|
+
|
|
132
|
+
- |
|
|
133
|
+
License is changed to MIT License.
|
|
134
|
+
|
|
135
|
+
- |
|
|
136
|
+
Embedded pattern '<%- -%>' can be handled.
|
|
4
137
|
|
|
5
138
|
|
|
6
139
|
#
|
|
7
140
|
- release: 2.1.0
|
|
8
141
|
date: 2006-09-23
|
|
9
|
-
|
|
142
|
+
enhancements:
|
|
10
143
|
- |
|
|
11
144
|
Ruby on Rails support. Add the following code to
|
|
12
145
|
your 'app/controllers/application.rb' and restart web server.
|
|
@@ -153,7 +286,7 @@
|
|
|
153
286
|
- module 'FastEnhancer' and class 'FastEruby' is obsolete because they are integrated into Eruby class
|
|
154
287
|
- Eruby#evaluate() calls instance_eval() instead of eval()
|
|
155
288
|
- XmlEruby.escape_xml() is moved to XmlHelper.escape_xml()
|
|
156
|
-
|
|
289
|
+
enhancements:
|
|
157
290
|
- multi programming language support (Ruby/PHP/C/Java/Scheme/Perl/Javascript)
|
|
158
291
|
- class Eruby runs very fast because FastEnhancer module is integrated into Eruby by default
|
|
159
292
|
- TinyEruby class (tiny.rb) is added
|
|
@@ -182,7 +315,7 @@
|
|
|
182
315
|
#
|
|
183
316
|
- release: 1.1.0
|
|
184
317
|
date: 2006-03-05
|
|
185
|
-
|
|
318
|
+
enhancements:
|
|
186
319
|
- '<%# ... %>' is supported
|
|
187
320
|
- PrintEnhancer, PrintEruby, and PrintXmlEruby added
|
|
188
321
|
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
copyright(c) 2006-2007 kuwata-lab all rights reserved.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.txt
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
= README
|
|
2
2
|
|
|
3
|
-
release:: $Release: 2.
|
|
4
|
-
copyright:: copyright(c) 2006 kuwata-lab all rights reserved.
|
|
3
|
+
release:: $Release: 2.2.0 $
|
|
4
|
+
copyright:: copyright(c) 2006-2007 kuwata-lab all rights reserved.
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
== About Erubis
|
|
9
9
|
|
|
10
10
|
Erubis is an implementation of eRuby. It has the following features.
|
|
11
|
-
* Very fast, almost three times faster than ERB and even faster than eruby
|
|
11
|
+
* Very fast, almost three times faster than ERB and even 10% faster than eruby
|
|
12
12
|
* Multi-language support (Ruby/PHP/C/Java/Scheme/Perl/Javascript)
|
|
13
13
|
* Auto escaping support
|
|
14
14
|
* Auto trimming spaces around '<% %>'
|
|
@@ -53,6 +53,22 @@ See doc/users-guide.html for details.
|
|
|
53
53
|
|
|
54
54
|
|
|
55
55
|
|
|
56
|
+
== Ruby on Rails Support
|
|
57
|
+
|
|
58
|
+
Erubis supports Ruby on Rails.
|
|
59
|
+
All you have to do is to add the following code into your 'config/environment.rb'
|
|
60
|
+
and restart web server.
|
|
61
|
+
|
|
62
|
+
require 'erubis/helpers/rails_helper'
|
|
63
|
+
#Erubis::Helpers::RailsHelper.engine_class = Erubis::Eruby
|
|
64
|
+
#Erubis::Helpers::RailsHelper.init_properties = {}
|
|
65
|
+
#Erubis::Helpers::RailsHelper.show_src = false
|
|
66
|
+
|
|
67
|
+
If Erubis::Helpers::RailsHelper.show_src is ture, Erubis prints converted Ruby code
|
|
68
|
+
into log file ('log/development.log' or so). It is useful for debug.
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
56
72
|
== Exploring Guide
|
|
57
73
|
|
|
58
74
|
If you are exploring Eruby, see the following class at first.
|
|
@@ -76,9 +92,8 @@ Try 'ruby erubybenchmark.rb' in benchmark directory.
|
|
|
76
92
|
|
|
77
93
|
== License
|
|
78
94
|
|
|
79
|
-
|
|
95
|
+
MIT License
|
|
80
96
|
|
|
81
|
-
If you need looser license, please suggest me.
|
|
82
97
|
|
|
83
98
|
|
|
84
99
|
== Author
|
data/benchmark/erubybench.rb
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
##
|
|
2
|
-
## $Rev:
|
|
3
|
-
## $Release: 2.
|
|
4
|
-
## copyright(c) 2006 kuwata-lab all rights reserved.
|
|
2
|
+
## $Rev: 64 $
|
|
3
|
+
## $Release: 2.2.0 $
|
|
4
|
+
## copyright(c) 2006-2007 kuwata-lab all rights reserved.
|
|
5
5
|
##
|
|
6
6
|
|
|
7
7
|
require 'eruby'
|
|
8
8
|
require 'erb'
|
|
9
9
|
require 'stringio'
|
|
10
|
+
require 'cgi'
|
|
11
|
+
include ERB::Util
|
|
12
|
+
#module ERB::Util
|
|
13
|
+
# ESCAPE_TABLE = { '&'=>'&', '<'=>'<', '>'=>'>', '"'=>'"', "'"=>''', }
|
|
14
|
+
# def h(value)
|
|
15
|
+
# value.to_s.gsub(/[&<>"]/) { |s| ESCAPE_TABLE[s] }
|
|
16
|
+
# end
|
|
17
|
+
# module_function :h
|
|
18
|
+
#end
|
|
10
19
|
|
|
11
20
|
require 'erubis'
|
|
12
21
|
require 'erubis/engine/enhanced'
|
|
@@ -15,49 +24,73 @@ require 'erubis/tiny'
|
|
|
15
24
|
require 'erubybench-lib'
|
|
16
25
|
|
|
17
26
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
27
|
+
## default value
|
|
28
|
+
defaults = {
|
|
29
|
+
:ntimes => 1000,
|
|
30
|
+
:erubyfile => 'erubybench.rhtml',
|
|
31
|
+
:datafile => 'erubybench.yaml',
|
|
32
|
+
:testmode => 'execute',
|
|
33
|
+
:outfile => '/dev/null',
|
|
34
|
+
}
|
|
23
35
|
|
|
24
36
|
|
|
25
37
|
## usage
|
|
26
|
-
def usage(
|
|
27
|
-
|
|
28
|
-
s <<
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
38
|
+
def usage(defaults)
|
|
39
|
+
script = File.basename($0)
|
|
40
|
+
s = <<END
|
|
41
|
+
Usage: ruby #{script} [..options..] [..testnames..] > /dev/null 2> bench.log
|
|
42
|
+
-h : help
|
|
43
|
+
-n N : number of times to loop (default #{defaults[:ntimes]})
|
|
44
|
+
-t erubyfile : eruby filename (default '#{defaults[:erubyfile]}')
|
|
45
|
+
-f datafile : data filename (default '#{defaults[:datafile]}')
|
|
46
|
+
-o outfile : output filename (default '#{defaults[:outfile]}')
|
|
47
|
+
-A : test all targets
|
|
48
|
+
-x testname,.. : exclude testnames
|
|
49
|
+
-m testmode : execute/convert/func (default '#{defaults[:testmode]}')
|
|
50
|
+
-X : expand loop
|
|
51
|
+
-p : print output
|
|
52
|
+
END
|
|
32
53
|
return s
|
|
33
54
|
end
|
|
34
55
|
|
|
35
56
|
|
|
36
57
|
## parse command-line options
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
when '-A' ; test_all = true
|
|
50
|
-
when '-C' ; compiler_name = ARGV.shift
|
|
51
|
-
when '-t' ; test_type = ARGV.shift
|
|
52
|
-
else ; raise "#{opt}: invalid option."
|
|
53
|
-
end
|
|
58
|
+
require 'optparse'
|
|
59
|
+
optparser = OptionParser.new
|
|
60
|
+
options = {}
|
|
61
|
+
['-h', '-n N', '-t erubyfile', '-f datafile', '-o outfile', '-A', '-e',
|
|
62
|
+
'-x exclude', '-m testmode', '-X', '-p', '-D'].each do |opt|
|
|
63
|
+
optparser.on(opt) { |val| options[opt[1].chr] = val }
|
|
64
|
+
end
|
|
65
|
+
begin
|
|
66
|
+
targets = optparser.parse!(ARGV)
|
|
67
|
+
rescue => ex
|
|
68
|
+
$stderr.puts "#{command}: #{ex.to_s}"
|
|
69
|
+
exit(1)
|
|
54
70
|
end
|
|
55
|
-
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
flag_help = options['h']
|
|
74
|
+
ntimes = (options['n'] || defaults[:ntimes]).to_i
|
|
75
|
+
$erubyfile = options['t'] || defaults[:erubyfile]
|
|
76
|
+
datafile = options['f'] || defaults[:datafile]
|
|
77
|
+
outfile = options['o'] || defaults[:outfile]
|
|
78
|
+
flag_all = options['A']
|
|
79
|
+
testmode = options['m'] || defaults[:testmode]
|
|
80
|
+
excludes = options['x']
|
|
81
|
+
$escape = options['e']
|
|
82
|
+
flag_expand = options['X'] ? true : false
|
|
83
|
+
flag_output = options['p'] ? true : false
|
|
84
|
+
$debug = options['D']
|
|
85
|
+
|
|
86
|
+
$ntimes = ntimes
|
|
87
|
+
|
|
88
|
+
$stderr.puts "** $ntimes=#{$ntimes.inspect}, flag_expand=#{flag_expand}, options=#{options.inspect}" if $debug
|
|
56
89
|
|
|
57
90
|
|
|
58
91
|
## help
|
|
59
92
|
if flag_help
|
|
60
|
-
puts usage(
|
|
93
|
+
puts usage(defaults)
|
|
61
94
|
exit()
|
|
62
95
|
end
|
|
63
96
|
|
|
@@ -65,25 +98,380 @@ end
|
|
|
65
98
|
## load data file
|
|
66
99
|
require 'yaml'
|
|
67
100
|
ydoc = YAML.load_file(datafile)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
101
|
+
context = ydoc
|
|
102
|
+
list = context['list']
|
|
103
|
+
if $escape
|
|
104
|
+
list.each do |item|
|
|
105
|
+
if item['name'] =~ / /
|
|
106
|
+
item['name'] = "<#{item['name'].gsub(/ /, '&')}>"
|
|
107
|
+
else
|
|
108
|
+
item['name'] = "\"#{item['name']}\""
|
|
109
|
+
end
|
|
110
|
+
end
|
|
72
111
|
end
|
|
73
|
-
|
|
74
|
-
#
|
|
112
|
+
#list = []
|
|
113
|
+
#ydoc['list'].each do |hash|
|
|
114
|
+
# list << hash.inject({}) { |h, t| h[t[0].intern] = t[1]; h }
|
|
115
|
+
# #h = {}; hash.each { |k, v| h[k.intern] = v } ; data << h
|
|
116
|
+
#end
|
|
117
|
+
#require 'pp'; pp list
|
|
75
118
|
|
|
76
119
|
|
|
77
|
-
##
|
|
78
|
-
|
|
120
|
+
## test definitions
|
|
121
|
+
testdefs = YAML.load(DATA)
|
|
122
|
+
testdefs.each do |testdef|
|
|
123
|
+
c = testdef['class']
|
|
124
|
+
testdef['code'] ||= "print #{c}.new(File.read(erubyfile)).result(binding())\n"
|
|
125
|
+
testdef['compile'] ||= "#{c}.new(str).src\n"
|
|
126
|
+
#require 'pp'; pp testdef
|
|
127
|
+
end
|
|
79
128
|
|
|
80
129
|
|
|
81
|
-
## test
|
|
82
|
-
|
|
83
|
-
|
|
130
|
+
## select test target
|
|
131
|
+
if flag_all
|
|
132
|
+
# nothing
|
|
133
|
+
elsif targets && !targets.empty?
|
|
134
|
+
testdefs = targets.collect { |t| testdefs.find { |h| h['name'] == t } }.compact
|
|
135
|
+
#testdefs.delete_if { |h| !targets.include?(h['name']) }
|
|
136
|
+
else
|
|
137
|
+
testdefs.delete_if { |h| h['skip'] }
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
## exclude target
|
|
141
|
+
if excludes
|
|
142
|
+
excludes = excluces.split(/,/)
|
|
143
|
+
testdefs.delete_if { |h| excludes.include?(h['name']) }
|
|
144
|
+
end
|
|
145
|
+
#require 'pp'; pp testdefs
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
## generate template
|
|
149
|
+
def erubyfilename(name)
|
|
150
|
+
case name
|
|
151
|
+
when /eruby/ ; s = '_eruby.'
|
|
152
|
+
when /ERB/ ; s = '_erb.'
|
|
153
|
+
when /PI/ ; s = '_pierubis.'
|
|
154
|
+
when /Tiny/ ; s = '_tiny.'
|
|
155
|
+
when /Erubis/ ; s = '_erubis.'
|
|
156
|
+
else
|
|
157
|
+
raise "#{name}: unknown name."
|
|
158
|
+
end
|
|
159
|
+
return $erubyfile.sub(/\./, s)
|
|
160
|
+
end
|
|
161
|
+
#
|
|
162
|
+
def File.write(filename, str)
|
|
163
|
+
File.open(filename, 'w') { |f| f.write(str) }
|
|
164
|
+
end
|
|
165
|
+
#
|
|
166
|
+
if $erubyfile == defaults[:erubyfile]
|
|
167
|
+
erubystr = File.read($erubyfile)
|
|
168
|
+
s = erubystr
|
|
169
|
+
erubystrs = {}
|
|
170
|
+
if $escape
|
|
171
|
+
erubystrs['eruby'] = s.gsub(/<%=(.*?)%>/, '<%= CGI.escapeHTML((\1).to_s) %>')
|
|
172
|
+
erubystrs['ERB'] = s.gsub(/<%=(.*?)%>/, '<%=h \1%>')
|
|
173
|
+
erubystrs['Erubis'] = s.gsub(/<%=(.*?)%>/, '<%==\1%>')
|
|
174
|
+
erubystrs['Tiny'] = s.gsub(/<%=(.*?)%>/, '<%=Erubis::XmlHelper.escape_xml((\1).to_s)%>')
|
|
175
|
+
erubystrs['PI'] = s.gsub(/<%=(.*?)%>/, '@{\1}@').gsub(/<%(.*?)%>/m, '<?rb\1?>')
|
|
176
|
+
else
|
|
177
|
+
erubystrs['eruby'] = s
|
|
178
|
+
erubystrs['ERB'] = s
|
|
179
|
+
erubystrs['Erubis'] = s
|
|
180
|
+
erubystrs['Tiny'] = s
|
|
181
|
+
erubystrs['PI'] = s.gsub(/<%=(.*?)%>/, '@!{\1}@').gsub(/<%(.*?)%>/m, '<?rb\1?>')
|
|
182
|
+
end
|
|
183
|
+
else
|
|
184
|
+
erubystr = File.read($erubyfile)
|
|
185
|
+
end
|
|
186
|
+
%w[eruby ERB PI Tiny Erubis].each do |name|
|
|
187
|
+
File.write(erubyfilename(name), erubystrs[name])
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
## define test functions for each classes
|
|
193
|
+
str = erubystr
|
|
194
|
+
testdefs.each do |h|
|
|
195
|
+
s = ''
|
|
196
|
+
s << "def test_execute_#{h['name']}(erubyfile, context)\n"
|
|
197
|
+
s << " list = context['list']\n"
|
|
198
|
+
if flag_expand
|
|
199
|
+
$ntimes.times do
|
|
200
|
+
s << " #{h['code']}\n"
|
|
201
|
+
end
|
|
202
|
+
else
|
|
203
|
+
s << " $ntimes.times do\n"
|
|
204
|
+
s << " #{h['code']}\n"
|
|
205
|
+
s << " end\n"
|
|
206
|
+
end
|
|
207
|
+
s << "end\n"
|
|
208
|
+
#puts s
|
|
209
|
+
eval s
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
## define view functions for each classes
|
|
214
|
+
str = erubystr
|
|
215
|
+
testdefs.each do |h|
|
|
216
|
+
if h['compile']
|
|
217
|
+
erubyfile = erubyfilename(h['name'])
|
|
218
|
+
code = eval h['compile']
|
|
219
|
+
s = <<-END
|
|
220
|
+
def view_#{h['name']}(context)
|
|
221
|
+
list = context['list']
|
|
222
|
+
#{code}
|
|
223
|
+
end
|
|
224
|
+
END
|
|
225
|
+
#puts s
|
|
226
|
+
eval s
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
## define tests for view functions
|
|
231
|
+
testdefs.each do |h|
|
|
232
|
+
pr = h['return'] ? 'print ' : ''
|
|
233
|
+
s = ''
|
|
234
|
+
s << "def test_func_#{h['name']}(context)\n"
|
|
235
|
+
s << " list = context['list']\n"
|
|
236
|
+
if flag_expand
|
|
237
|
+
$ntimes.times do
|
|
238
|
+
s << " #{pr}view_#{h['name']}(context)\n"
|
|
239
|
+
end
|
|
240
|
+
else
|
|
241
|
+
s << " $ntimes.times do\n"
|
|
242
|
+
s << " #{pr}view_#{h['name']}(context)\n"
|
|
243
|
+
s << " end\n"
|
|
244
|
+
end
|
|
245
|
+
s << "end\n"
|
|
246
|
+
#puts s
|
|
247
|
+
eval s
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
## define test for convertion
|
|
252
|
+
testdefs.each do |h|
|
|
253
|
+
if h['compile']
|
|
254
|
+
s = ''
|
|
255
|
+
s << "def test_convert_#{h['name']}(erubyfile)\n"
|
|
256
|
+
s << " str = File.read(erubyfile)\n"
|
|
257
|
+
if flag_expand
|
|
258
|
+
$ntimes.times do
|
|
259
|
+
s << " src = #{h['compile']}\n"
|
|
260
|
+
end
|
|
261
|
+
else
|
|
262
|
+
s << " $ntimes.times do \n"
|
|
263
|
+
s << " src = #{h['compile']}\n"
|
|
264
|
+
s << " end\n"
|
|
265
|
+
end
|
|
266
|
+
s << "end\n"
|
|
267
|
+
#puts s
|
|
268
|
+
eval s
|
|
269
|
+
end
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
## define tests for caching
|
|
274
|
+
str = erubystr
|
|
275
|
+
Dir.mkdir('src') unless test(?d, 'src')
|
|
276
|
+
testdefs.each do |h|
|
|
277
|
+
if h['compile']
|
|
278
|
+
# create file to read
|
|
279
|
+
erubyfile = erubyfilename(h['name'])
|
|
280
|
+
code = eval h['compile']
|
|
281
|
+
fname = "src/erubybench.#{h['name']}.rb"
|
|
282
|
+
File.open(fname, 'w') { |f| f.write(code) }
|
|
283
|
+
#at_exit do File.unlink fname if test(?f, fname) end
|
|
284
|
+
# define function
|
|
285
|
+
pr = h['return'] ? 'print' : ''
|
|
286
|
+
s = ''
|
|
287
|
+
s << "def test_cache_#{h['name']}(erubyfile, context)\n"
|
|
288
|
+
s << " list = context['list']\n"
|
|
289
|
+
if flag_expand
|
|
290
|
+
ntimes.times do
|
|
291
|
+
s << " #{pr} eval(File.read('#{fname}'))\n"
|
|
292
|
+
end
|
|
293
|
+
else
|
|
294
|
+
s << " $ntimes.times do\n"
|
|
295
|
+
s << " #{pr} eval(File.read('#{fname}'))\n"
|
|
296
|
+
s << " end\n"
|
|
297
|
+
end
|
|
298
|
+
s << "end\n"
|
|
299
|
+
#puts s
|
|
300
|
+
eval s
|
|
301
|
+
end
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
## output
|
|
306
|
+
if flag_output
|
|
307
|
+
testdefs.each do |h|
|
|
308
|
+
title = h['class']
|
|
309
|
+
func = 'test_basic_' + h['name']
|
|
310
|
+
puts "## #{h['class']}"
|
|
311
|
+
__send__(func, erubyfile, data)
|
|
312
|
+
puts
|
|
313
|
+
end
|
|
314
|
+
exit(0)
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
## rehearsal
|
|
319
|
+
$stdout = StringIO.new
|
|
320
|
+
testdefs.each do |h|
|
|
321
|
+
## execute test code
|
|
322
|
+
erubyfile = erubyfilename(h['name'])
|
|
323
|
+
eval h['code']
|
|
324
|
+
## execute view function
|
|
325
|
+
next unless h['compile']
|
|
326
|
+
v = __send__("view_#{h['name']}", context)
|
|
327
|
+
print v if h['return']
|
|
328
|
+
## execute caching function
|
|
329
|
+
fname = "src/erubybench.#{h['name']}.rb"
|
|
330
|
+
v = eval(File.read(fname))
|
|
331
|
+
print v if h['return']
|
|
332
|
+
end
|
|
333
|
+
$stdout = STDOUT
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
## open output file
|
|
337
|
+
$stdout = outfile == '-' ? STDOUT : File.open(outfile, 'w')
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
## change benchmark library to use $stderr instead of $stdout
|
|
341
|
+
require 'benchmark'
|
|
342
|
+
module Benchmark
|
|
343
|
+
class Report
|
|
344
|
+
def print(*args)
|
|
345
|
+
$stderr.print(*args)
|
|
346
|
+
end
|
|
347
|
+
end
|
|
348
|
+
module_function
|
|
349
|
+
def print(*args)
|
|
350
|
+
$stderr.print(*args)
|
|
351
|
+
end
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
## do benchmark
|
|
356
|
+
width = 30
|
|
357
|
+
begin
|
|
358
|
+
|
|
359
|
+
## evaluate
|
|
360
|
+
if !testmode || testmode == 'execute'
|
|
361
|
+
$stderr.puts "## execute"
|
|
362
|
+
Benchmark.bm(width) do |job|
|
|
363
|
+
testdefs.each do |h|
|
|
364
|
+
title = h['title'] || h['class']
|
|
365
|
+
func = 'test_execute_' + h['name']
|
|
366
|
+
GC.start
|
|
367
|
+
job.report(title) do
|
|
368
|
+
__send__(func, erubyfilename(h['name']), context)
|
|
369
|
+
end
|
|
370
|
+
end
|
|
371
|
+
end
|
|
372
|
+
$stderr.puts
|
|
373
|
+
end
|
|
374
|
+
|
|
375
|
+
## convert
|
|
376
|
+
if testmode == 'convert'
|
|
377
|
+
$stderr.puts "## convert"
|
|
378
|
+
Benchmark.bm(width) do |job|
|
|
379
|
+
testdefs.each do |h|
|
|
380
|
+
next unless h['compile']
|
|
381
|
+
title = h['title'] || h['class']
|
|
382
|
+
func = 'test_convert_' + h['name']
|
|
383
|
+
GC.start
|
|
384
|
+
job.report(title) do
|
|
385
|
+
__send__(func, erubyfilename(h['name']))
|
|
386
|
+
end
|
|
387
|
+
end
|
|
388
|
+
end
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
## caching
|
|
392
|
+
if testmode == 'cache'
|
|
393
|
+
$stderr.puts "## evaluate cache file"
|
|
394
|
+
Benchmark.bm(width) do |job|
|
|
395
|
+
testdefs.each do |h|
|
|
396
|
+
next unless h['compile']
|
|
397
|
+
#title = 'cache_' + h['name']
|
|
398
|
+
title = h['title'] || h['class']
|
|
399
|
+
func = 'test_cache_' + h['name']
|
|
400
|
+
GC.start
|
|
401
|
+
job.report(title) do
|
|
402
|
+
__send__(func, erubyfilename(h['name']), context)
|
|
403
|
+
end
|
|
404
|
+
end
|
|
405
|
+
end
|
|
406
|
+
$stderr.puts
|
|
407
|
+
end
|
|
408
|
+
|
|
409
|
+
## function
|
|
410
|
+
if testmode == 'func'
|
|
411
|
+
$stderr.puts "## evaluate function"
|
|
412
|
+
Benchmark.bm(width) do |job|
|
|
413
|
+
testdefs.each do |h|
|
|
414
|
+
next unless h['compile']
|
|
415
|
+
#title = 'func_' + h['name']
|
|
416
|
+
title = h['title'] || h['class']
|
|
417
|
+
func = 'test_func_' + h['name']
|
|
418
|
+
GC.start
|
|
419
|
+
job.report(title) do
|
|
420
|
+
__send__(func, context)
|
|
421
|
+
end
|
|
422
|
+
end
|
|
423
|
+
end
|
|
424
|
+
$stderr.puts
|
|
425
|
+
end
|
|
426
|
+
|
|
427
|
+
#Benchmark.bm(30) do |job|
|
|
428
|
+
# ## basic test
|
|
429
|
+
# testdefs.each do |h|
|
|
430
|
+
# title = h['class']
|
|
431
|
+
# func = 'test_basic_' + h['name']
|
|
432
|
+
# GC.start
|
|
433
|
+
# job.report(title) do
|
|
434
|
+
# __send__(func, erubyfile, context)
|
|
435
|
+
# end
|
|
436
|
+
# end if !testmode || testmode == 'basic'
|
|
437
|
+
#
|
|
438
|
+
# ## caching function
|
|
439
|
+
# testdefs.each do |h|
|
|
440
|
+
# next unless h['compile']
|
|
441
|
+
# title = 'cache_' + h['name']
|
|
442
|
+
# func = 'test_cache_' + h['name']
|
|
443
|
+
# GC.start
|
|
444
|
+
# job.report(title) do
|
|
445
|
+
# __send__(func, erubyfile, context)
|
|
446
|
+
# end
|
|
447
|
+
# end if !testmode || testmode == 'cache'
|
|
448
|
+
#
|
|
449
|
+
# ## view-function test
|
|
450
|
+
# testdefs.each do |h|
|
|
451
|
+
# next unless h['compile']
|
|
452
|
+
# title = 'func_' + h['name']
|
|
453
|
+
# func = 'test_func_' + h['name']
|
|
454
|
+
# GC.start
|
|
455
|
+
# job.report(title) do
|
|
456
|
+
# __send__(func, list)
|
|
457
|
+
# end
|
|
458
|
+
# end if !testmode || testmode == 'func'
|
|
459
|
+
#
|
|
460
|
+
#end
|
|
461
|
+
|
|
462
|
+
ensure
|
|
463
|
+
$stdout.close() unless outfile == '-'
|
|
464
|
+
end
|
|
465
|
+
|
|
466
|
+
__END__
|
|
467
|
+
|
|
468
|
+
## testdefs
|
|
469
|
+
|
|
470
|
+
- name: eruby
|
|
84
471
|
class: ERuby
|
|
472
|
+
title: eruby
|
|
85
473
|
code: |
|
|
86
|
-
ERuby.import(
|
|
474
|
+
ERuby.import(erubyfile)
|
|
87
475
|
compile: |
|
|
88
476
|
ERuby::Compiler.new.compile_string(str)
|
|
89
477
|
return: null
|
|
@@ -91,8 +479,8 @@ testdefs_str = <<END
|
|
|
91
479
|
- name: ERB
|
|
92
480
|
class: ERB
|
|
93
481
|
code: |
|
|
94
|
-
print ERB.new(File.read(
|
|
95
|
-
# eruby = ERB.new(File.read(
|
|
482
|
+
print ERB.new(File.read(erubyfile)).result(binding())
|
|
483
|
+
# eruby = ERB.new(File.read(erubyfile))
|
|
96
484
|
# print eruby.result(binding())
|
|
97
485
|
compile: |
|
|
98
486
|
ERB.new(str).src
|
|
@@ -106,11 +494,20 @@ testdefs_str = <<END
|
|
|
106
494
|
desc: print _buf #, no binding()
|
|
107
495
|
class: Erubis::Eruby2
|
|
108
496
|
code: |
|
|
109
|
-
#Erubis::Eruby2.new(File.read(
|
|
110
|
-
Erubis::Eruby2.new(File.read(
|
|
497
|
+
#Erubis::Eruby2.new(File.read(erubyfile)).result()
|
|
498
|
+
Erubis::Eruby2.new(File.read(erubyfile)).result(binding())
|
|
111
499
|
return: null
|
|
112
500
|
skip: yes
|
|
113
501
|
|
|
502
|
+
- name: ErubisEruby_cached
|
|
503
|
+
class: Erubis::Eruby
|
|
504
|
+
title: Erubis::Eruby(cached)
|
|
505
|
+
code: |
|
|
506
|
+
Erubis::Eruby.load_file(erubyfile).result(binding())
|
|
507
|
+
compile: |
|
|
508
|
+
Erubis::Eruby.load_file(erubyfile)
|
|
509
|
+
return: str
|
|
510
|
+
|
|
114
511
|
- name: ErubisExprStripped
|
|
115
512
|
desc: strip expr code
|
|
116
513
|
class: Erubis::ExprStrippedEruby
|
|
@@ -127,19 +524,19 @@ testdefs_str = <<END
|
|
|
127
524
|
return: str
|
|
128
525
|
skip: yes
|
|
129
526
|
|
|
130
|
-
|
|
131
|
-
|
|
527
|
+
- name: ErubisArrayBuffer
|
|
528
|
+
class: Erubis::ArrayBufferEruby
|
|
132
529
|
# code: |
|
|
133
|
-
# Erubis::ArrayBufferEruby.new(File.read(
|
|
530
|
+
# Erubis::ArrayBufferEruby.new(File.read(erubyfile)).result(binding())
|
|
134
531
|
# compile: |
|
|
135
532
|
# Erubis::ArrayBufferEruby.new(str).src
|
|
136
|
-
|
|
137
|
-
|
|
533
|
+
return: str
|
|
534
|
+
skip: no
|
|
138
535
|
|
|
139
536
|
- name: ErubisStringBuffer
|
|
140
537
|
class: Erubis::StringBufferEruby
|
|
141
538
|
return: str
|
|
142
|
-
skip:
|
|
539
|
+
skip: yes
|
|
143
540
|
|
|
144
541
|
- name: ErubisStringIO
|
|
145
542
|
class: Erubis::StringIOEruby
|
|
@@ -159,7 +556,7 @@ testdefs_str = <<END
|
|
|
159
556
|
- name: ErubisStdoutSimplified
|
|
160
557
|
class: Erubis::StdoutSimplifiedEruby
|
|
161
558
|
return: str
|
|
162
|
-
skip:
|
|
559
|
+
skip: yes
|
|
163
560
|
|
|
164
561
|
- name: ErubisPrintOut
|
|
165
562
|
class: Erubis::PrintOutEruby
|
|
@@ -169,7 +566,7 @@ testdefs_str = <<END
|
|
|
169
566
|
- name: ErubisPrintOutSimplified
|
|
170
567
|
class: Erubis::PrintOutSimplifiedEruby
|
|
171
568
|
return: str
|
|
172
|
-
skip:
|
|
569
|
+
skip: yes
|
|
173
570
|
|
|
174
571
|
- name: ErubisTiny
|
|
175
572
|
class: Erubis::TinyEruby
|
|
@@ -179,186 +576,25 @@ testdefs_str = <<END
|
|
|
179
576
|
- name: ErubisTinyStdout
|
|
180
577
|
class: Erubis::TinyStdoutEruby
|
|
181
578
|
return: null
|
|
182
|
-
skip:
|
|
579
|
+
skip: yes
|
|
183
580
|
|
|
184
581
|
- name: ErubisTinyPrint
|
|
185
582
|
class: Erubis::TinyPrintEruby
|
|
186
583
|
return: null
|
|
187
|
-
skip:
|
|
584
|
+
skip: yes
|
|
585
|
+
|
|
586
|
+
- name: ErubisPIEruby
|
|
587
|
+
class: Erubis::PI::Eruby
|
|
588
|
+
code: |
|
|
589
|
+
Erubis::PI::Eruby.new(File.read(erubyfile)).result(binding())
|
|
590
|
+
compile: |
|
|
591
|
+
Erubis::PI::Eruby.new(File.read(erubyfile)).src
|
|
592
|
+
return: str
|
|
188
593
|
|
|
189
594
|
#- name: load
|
|
190
595
|
# class: load
|
|
191
596
|
# code: |
|
|
192
|
-
# load($
|
|
597
|
+
# load($load_erubyfile)
|
|
193
598
|
# compile: null
|
|
194
599
|
# return: null
|
|
195
600
|
# skip: yes
|
|
196
|
-
|
|
197
|
-
END
|
|
198
|
-
testdefs = YAML.load(testdefs_str)
|
|
199
|
-
|
|
200
|
-
## manipulate
|
|
201
|
-
testdefs.each do |testdef|
|
|
202
|
-
c = testdef['class']
|
|
203
|
-
testdef['code'] ||= "print #{c}.new(File.read(filename)).result(binding())\n"
|
|
204
|
-
testdef['compile'] ||= "#{c}.new(str).src\n"
|
|
205
|
-
require 'pp'
|
|
206
|
-
#pp testdef
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
### create file for load
|
|
211
|
-
#if testdefs.find { |h| h['name'] == 'load' }
|
|
212
|
-
# $load_filename = filename + ".tmp" # for load
|
|
213
|
-
# $data = data
|
|
214
|
-
# str = File.read(filename)
|
|
215
|
-
# str.gsub!(/\bdata\b/, '$data')
|
|
216
|
-
# hash = testdefs.find { |h| h['name'] == compiler_name }
|
|
217
|
-
# code = eval hash['compile']
|
|
218
|
-
# code.sub!(/_buf\s*\z/, 'print \&')
|
|
219
|
-
# File.open($load_filename, 'w') { |f| f.write(code) }
|
|
220
|
-
# at_exit do
|
|
221
|
-
# File.unlink $load_filename if test(?f, $load_filename)
|
|
222
|
-
# end
|
|
223
|
-
#end
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
## select test target
|
|
227
|
-
if test_all
|
|
228
|
-
#testdefs.each { |h| h['skip'] = false }
|
|
229
|
-
elsif !ARGV.empty?
|
|
230
|
-
#testdefs.each { |h| h['skip'] = ARGV.include?(h['name']) }
|
|
231
|
-
testdefs.delete_if { |h| !ARGV.include?(h['name']) }
|
|
232
|
-
else
|
|
233
|
-
testdefs.delete_if { |h| h['skip'] }
|
|
234
|
-
end
|
|
235
|
-
#require 'pp'
|
|
236
|
-
#pp testdefs
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
## define test functions for each classes
|
|
240
|
-
testdefs.each do |h|
|
|
241
|
-
s = ''
|
|
242
|
-
s << "def test_#{h['name']}(filename, data)\n"
|
|
243
|
-
s << " $stdout = $devnull\n"
|
|
244
|
-
n.times do
|
|
245
|
-
s << ' ' << h['code'] #<< "\n"
|
|
246
|
-
end
|
|
247
|
-
s << " $stdout = STDOUT\n"
|
|
248
|
-
s << "end\n"
|
|
249
|
-
#puts s
|
|
250
|
-
eval s
|
|
251
|
-
end
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
## define view functions for each classes
|
|
255
|
-
str = File.read(filename)
|
|
256
|
-
testdefs.each do |h|
|
|
257
|
-
next unless h['compile']
|
|
258
|
-
code = eval h['compile']
|
|
259
|
-
s = <<-END
|
|
260
|
-
def view_#{h['name']}(data)
|
|
261
|
-
#{code}
|
|
262
|
-
end
|
|
263
|
-
END
|
|
264
|
-
#puts s
|
|
265
|
-
eval s
|
|
266
|
-
end
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
## define tests for view functions
|
|
270
|
-
testdefs.each do |h|
|
|
271
|
-
pr = h['return'] ? 'print ' : ''
|
|
272
|
-
s = ''
|
|
273
|
-
s << "def test_view_#{h['name']}(data)\n"
|
|
274
|
-
s << " $stdout = $devnull\n"
|
|
275
|
-
n.times do
|
|
276
|
-
s << " #{pr}view_#{h['name']}(data)\n"
|
|
277
|
-
end
|
|
278
|
-
s << " $stdout = STDOUT\n"
|
|
279
|
-
s << "end\n"
|
|
280
|
-
#puts s
|
|
281
|
-
eval s
|
|
282
|
-
end
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
## define tests for caching
|
|
286
|
-
str = File.read(filename)
|
|
287
|
-
testdefs.each do |h|
|
|
288
|
-
next unless h['compile']
|
|
289
|
-
# create file to read
|
|
290
|
-
code = eval h['compile']
|
|
291
|
-
fname = "#{filename}.#{h['name']}"
|
|
292
|
-
File.open(fname, 'w') { |f| f.write(code) }
|
|
293
|
-
#at_exit do File.unlink fname if test(?f, fname) end
|
|
294
|
-
# define function
|
|
295
|
-
pr = h['return'] ? 'print ' : ''
|
|
296
|
-
s = ''
|
|
297
|
-
s << "def test_cache_#{h['name']}(filename, data)\n"
|
|
298
|
-
s << " $stdout = $devnull\n"
|
|
299
|
-
n.times do
|
|
300
|
-
s << " #{pr}eval(File.read(\"\#{filename}.#{h['name']}\"))\n"
|
|
301
|
-
end
|
|
302
|
-
s << " $stdout = STDOUT\n"
|
|
303
|
-
s << "end\n"
|
|
304
|
-
#puts s
|
|
305
|
-
eval s
|
|
306
|
-
end
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
## rehearsal
|
|
310
|
-
$stdout = $devnull
|
|
311
|
-
testdefs.each do |h|
|
|
312
|
-
## execute test code
|
|
313
|
-
eval h['code']
|
|
314
|
-
## execute view function
|
|
315
|
-
next unless h['compile']
|
|
316
|
-
v = __send__("view_#{h['name']}", data)
|
|
317
|
-
print v if h['return']
|
|
318
|
-
## execute caching function
|
|
319
|
-
v = eval(File.read("#{filename}.#{h['name']}"))
|
|
320
|
-
print v if h['return']
|
|
321
|
-
end
|
|
322
|
-
$stdout = STDOUT
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
## do benchmark
|
|
326
|
-
require 'benchmark'
|
|
327
|
-
begin
|
|
328
|
-
Benchmark.bmbm(25) do |job|
|
|
329
|
-
## basic test
|
|
330
|
-
testdefs.each do |h|
|
|
331
|
-
title = h['class']
|
|
332
|
-
func = 'test_' + h['name']
|
|
333
|
-
GC.start
|
|
334
|
-
job.report(title) do
|
|
335
|
-
__send__(func, filename, data)
|
|
336
|
-
end
|
|
337
|
-
end if !test_type || test_type == 'basic'
|
|
338
|
-
|
|
339
|
-
## caching function
|
|
340
|
-
testdefs.each do |h|
|
|
341
|
-
next unless h['compile']
|
|
342
|
-
title = 'cache_' + h['name']
|
|
343
|
-
func = 'test_cache_' + h['name']
|
|
344
|
-
GC.start
|
|
345
|
-
job.report(title) do
|
|
346
|
-
__send__(func, filename, data)
|
|
347
|
-
end
|
|
348
|
-
end if !test_type || test_type == 'eval'
|
|
349
|
-
|
|
350
|
-
## view-function test
|
|
351
|
-
testdefs.each do |h|
|
|
352
|
-
next unless h['compile']
|
|
353
|
-
title = 'func_' + h['name']
|
|
354
|
-
func = 'test_view_' + h['name']
|
|
355
|
-
GC.start
|
|
356
|
-
job.report(title) do
|
|
357
|
-
__send__(func, data)
|
|
358
|
-
end
|
|
359
|
-
end if !test_type || test_type == 'func'
|
|
360
|
-
|
|
361
|
-
end
|
|
362
|
-
ensure
|
|
363
|
-
$devnull.close()
|
|
364
|
-
end
|