kwartz 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +340 -0
- data/ChangeLog +103 -0
- data/README.txt +37 -0
- data/bin/kwartz +12 -0
- data/doc-api/classes/Kwartz.html +218 -0
- data/doc-api/classes/Kwartz/Assertion.html +140 -0
- data/doc-api/classes/Kwartz/AssertionError.html +148 -0
- data/doc-api/classes/Kwartz/AttrInfo.html +320 -0
- data/doc-api/classes/Kwartz/BaseError.html +206 -0
- data/doc-api/classes/Kwartz/BaseTranslator.html +331 -0
- data/doc-api/classes/Kwartz/CharacterType.html +212 -0
- data/doc-api/classes/Kwartz/CommandOptionError.html +154 -0
- data/doc-api/classes/Kwartz/CommandOptions.html +374 -0
- data/doc-api/classes/Kwartz/Config.html +150 -0
- data/doc-api/classes/Kwartz/ConvertError.html +191 -0
- data/doc-api/classes/Kwartz/Converter.html +252 -0
- data/doc-api/classes/Kwartz/CssStyleParser.html +483 -0
- data/doc-api/classes/Kwartz/DocumentRuleset.html +369 -0
- data/doc-api/classes/Kwartz/ElementExpander.html +325 -0
- data/doc-api/classes/Kwartz/ElementInfo.html +312 -0
- data/doc-api/classes/Kwartz/ElementRuleset.html +582 -0
- data/doc-api/classes/Kwartz/EperlHandler.html +338 -0
- data/doc-api/classes/Kwartz/EperlTranslator.html +167 -0
- data/doc-api/classes/Kwartz/ErubisHandler.html +113 -0
- data/doc-api/classes/Kwartz/ErubisTranslator.html +168 -0
- data/doc-api/classes/Kwartz/ErubyHandler.html +337 -0
- data/doc-api/classes/Kwartz/ErubyTranslator.html +167 -0
- data/doc-api/classes/Kwartz/ExpandStatement.html +227 -0
- data/doc-api/classes/Kwartz/Expression.html +119 -0
- data/doc-api/classes/Kwartz/Handler.html +558 -0
- data/doc-api/classes/Kwartz/JstlHandler.html +657 -0
- data/doc-api/classes/Kwartz/JstlTranslator.html +226 -0
- data/doc-api/classes/Kwartz/KwartzError.html +146 -0
- data/doc-api/classes/Kwartz/Main.html +384 -0
- data/doc-api/classes/Kwartz/NativeExpression.html +236 -0
- data/doc-api/classes/Kwartz/NativeStatement.html +254 -0
- data/doc-api/classes/Kwartz/Node.html +156 -0
- data/doc-api/classes/Kwartz/ParseError.html +148 -0
- data/doc-api/classes/Kwartz/PhpHandler.html +333 -0
- data/doc-api/classes/Kwartz/PhpTranslator.html +194 -0
- data/doc-api/classes/Kwartz/PresentationLogicParser.html +830 -0
- data/doc-api/classes/Kwartz/PrintStatement.html +221 -0
- data/doc-api/classes/Kwartz/RailsHandler.html +587 -0
- data/doc-api/classes/Kwartz/RailsTranslator.html +167 -0
- data/doc-api/classes/Kwartz/RubyStyleParser.html +558 -0
- data/doc-api/classes/Kwartz/Ruleset.html +117 -0
- data/doc-api/classes/Kwartz/Statement.html +119 -0
- data/doc-api/classes/Kwartz/StrutsTranslator.html +190 -0
- data/doc-api/classes/Kwartz/TagInfo.html +314 -0
- data/doc-api/classes/Kwartz/TextConverter.html +270 -0
- data/doc-api/classes/Kwartz/Translator.html +318 -0
- data/doc-api/classes/Test.html +107 -0
- data/doc-api/classes/Test/Unit.html +101 -0
- data/doc-api/created.rid +1 -0
- data/doc-api/files/__/README_txt.html +150 -0
- data/doc-api/files/kwartz/assert_rb.html +114 -0
- data/doc-api/files/kwartz/binding/eperl_rb.html +116 -0
- data/doc-api/files/kwartz/binding/erubis_rb.html +116 -0
- data/doc-api/files/kwartz/binding/eruby_rb.html +115 -0
- data/doc-api/files/kwartz/binding/jstl_rb.html +116 -0
- data/doc-api/files/kwartz/binding/php_rb.html +116 -0
- data/doc-api/files/kwartz/binding/rails_rb.html +115 -0
- data/doc-api/files/kwartz/binding/struts_rb.html +117 -0
- data/doc-api/files/kwartz/config_rb.html +107 -0
- data/doc-api/files/kwartz/converter_rb.html +119 -0
- data/doc-api/files/kwartz/error_rb.html +107 -0
- data/doc-api/files/kwartz/main_rb.html +124 -0
- data/doc-api/files/kwartz/node_rb.html +114 -0
- data/doc-api/files/kwartz/parser_rb.html +117 -0
- data/doc-api/files/kwartz/translator_rb.html +115 -0
- data/doc-api/files/kwartz/util/assert-text-equal_rb.html +115 -0
- data/doc-api/files/kwartz/util/testcase-helper_rb.html +115 -0
- data/doc-api/files/kwartz_rb.html +120 -0
- data/doc-api/fr_class_index.html +75 -0
- data/doc-api/fr_file_index.html +45 -0
- data/doc-api/fr_method_index.html +216 -0
- data/doc-api/index.html +24 -0
- data/doc-api/rdoc-style.css +208 -0
- data/doc/docstyle.css +188 -0
- data/doc/p-pattern.html +1207 -0
- data/doc/reference.html +3396 -0
- data/doc/users-guide.html +1670 -0
- data/examples/breadcrumbs1/Makefile +15 -0
- data/examples/breadcrumbs1/breadcrumbs.eruby.plogic +27 -0
- data/examples/breadcrumbs1/breadcrumbs.html +12 -0
- data/examples/breadcrumbs1/breadcrumbs.jstl.plogic +28 -0
- data/examples/breadcrumbs1/breadcrumbs.php.plogic +26 -0
- data/examples/breadcrumbs1/main.php +12 -0
- data/examples/breadcrumbs1/main.rb +12 -0
- data/examples/breadcrumbs2/Makefile +15 -0
- data/examples/breadcrumbs2/breadcrumbs.eruby.plogic +22 -0
- data/examples/breadcrumbs2/breadcrumbs.html +14 -0
- data/examples/breadcrumbs2/breadcrumbs.jstl.plogic +24 -0
- data/examples/breadcrumbs2/breadcrumbs.php.plogic +23 -0
- data/examples/breadcrumbs2/main.php +12 -0
- data/examples/breadcrumbs2/main.rb +12 -0
- data/examples/pagelayout/Makefile +47 -0
- data/examples/pagelayout/content.eruby.plogic +44 -0
- data/examples/pagelayout/content.jstl.plogic +36 -0
- data/examples/pagelayout/content.php.plogic +37 -0
- data/examples/pagelayout/content1.html +36 -0
- data/examples/pagelayout/content2.html +29 -0
- data/examples/pagelayout/design.css +40 -0
- data/examples/pagelayout/layout.html +50 -0
- data/examples/pagelayout/main.php +55 -0
- data/examples/pagelayout/main.rb +77 -0
- data/examples/pagelayout/menu.eruby.plogic +14 -0
- data/examples/pagelayout/menu.html +13 -0
- data/examples/pagelayout/menu.jstl.plogic +14 -0
- data/examples/pagelayout/menu.php.plogic +14 -0
- data/examples/rails1/Makefile +36 -0
- data/examples/rails1/README +19 -0
- data/examples/rails1/application_helper.rb +31 -0
- data/examples/rails1/edit.html +28 -0
- data/examples/rails1/edit.plogic +10 -0
- data/examples/rails1/form.html +52 -0
- data/examples/rails1/form.plogic +33 -0
- data/examples/rails1/layout.plogic +15 -0
- data/examples/rails1/link_to.plogic +19 -0
- data/examples/rails1/list.html +48 -0
- data/examples/rails1/list.plogic +28 -0
- data/examples/rails1/new.html +27 -0
- data/examples/rails1/new.plogic +10 -0
- data/examples/rails1/reader.plogic +29 -0
- data/examples/rails1/show.html +40 -0
- data/examples/rails1/show.plogic +4 -0
- data/examples/rails1/writer.plogic +8 -0
- data/examples/table1/Makefile +15 -0
- data/examples/table1/main.php +11 -0
- data/examples/table1/main.rb +11 -0
- data/examples/table1/table1.eruby.plogic +21 -0
- data/examples/table1/table1.html +16 -0
- data/examples/table1/table1.jstl.plogic +21 -0
- data/examples/table1/table1.php.plogic +22 -0
- data/kwartz.gemspec +55 -0
- data/lib/kwartz.rb +13 -0
- data/lib/kwartz/assert.rb +31 -0
- data/lib/kwartz/binding/eperl.rb +166 -0
- data/lib/kwartz/binding/erubis.rb +61 -0
- data/lib/kwartz/binding/eruby.rb +164 -0
- data/lib/kwartz/binding/jstl.rb +334 -0
- data/lib/kwartz/binding/php.rb +167 -0
- data/lib/kwartz/binding/rails.rb +295 -0
- data/lib/kwartz/binding/struts.rb +109 -0
- data/lib/kwartz/config.rb +28 -0
- data/lib/kwartz/converter.rb +920 -0
- data/lib/kwartz/error.rb +41 -0
- data/lib/kwartz/main.rb +464 -0
- data/lib/kwartz/node.rb +454 -0
- data/lib/kwartz/parser.rb +903 -0
- data/lib/kwartz/translator.rb +153 -0
- data/lib/kwartz/util/assert-text-equal.rb +44 -0
- data/lib/kwartz/util/testcase-helper.rb +112 -0
- data/setup.rb +1331 -0
- data/test/test-compile.rb +36 -0
- data/test/test-compile.yaml +178 -0
- data/test/test-converter.rb +34 -0
- data/test/test-converter.yaml +127 -0
- data/test/test-directives.rb +32 -0
- data/test/test-directives.yaml +1411 -0
- data/test/test-main.rb +464 -0
- data/test/test-parser.rb +54 -0
- data/test/test-parser.yaml +394 -0
- data/test/test-rails.rb +28 -0
- data/test/test-rails.yaml +301 -0
- data/test/test-ruleset.rb +36 -0
- data/test/test-ruleset.yaml +804 -0
- data/test/test.rb +44 -0
- metadata +236 -0
data/test/test-main.rb
ADDED
@@ -0,0 +1,464 @@
|
|
1
|
+
###
|
2
|
+
### $Rev: 112 $
|
3
|
+
### $Release: 3.0.0 $
|
4
|
+
### copyright(c) 2004-2006 kuwata-lab.com all rights reserved
|
5
|
+
###
|
6
|
+
|
7
|
+
require "#{File.dirname(__FILE__)}/test.rb"
|
8
|
+
|
9
|
+
|
10
|
+
PDATA = <<END
|
11
|
+
<html>
|
12
|
+
<body>
|
13
|
+
<h1 id="doctitle">hoge</h1>
|
14
|
+
<table id="content">
|
15
|
+
<tr id="mark:list">
|
16
|
+
<td id="mark:item">item</td>
|
17
|
+
</tr>
|
18
|
+
</table>
|
19
|
+
</body>
|
20
|
+
</html>
|
21
|
+
END
|
22
|
+
|
23
|
+
|
24
|
+
ERUBY_PLOGIC = <<END
|
25
|
+
#doctitle {
|
26
|
+
value: @title;
|
27
|
+
remove: "id";
|
28
|
+
}
|
29
|
+
#list {
|
30
|
+
logic: {
|
31
|
+
for item in @list
|
32
|
+
_elem
|
33
|
+
end
|
34
|
+
}
|
35
|
+
}
|
36
|
+
#item {
|
37
|
+
Value: item;
|
38
|
+
}
|
39
|
+
END
|
40
|
+
|
41
|
+
|
42
|
+
ERUBY_OUTPUT = <<END
|
43
|
+
<html>
|
44
|
+
<body>
|
45
|
+
<h1><%= @title %></h1>
|
46
|
+
<table id="content">
|
47
|
+
<% for item in @list %>
|
48
|
+
<tr>
|
49
|
+
<td><%=h item %></td>
|
50
|
+
</tr>
|
51
|
+
<% end %>
|
52
|
+
</table>
|
53
|
+
</body>
|
54
|
+
</html>
|
55
|
+
END
|
56
|
+
|
57
|
+
|
58
|
+
PHP_PLOGIC = <<END
|
59
|
+
#doctitle {
|
60
|
+
value: $title;
|
61
|
+
remove: "id";
|
62
|
+
}
|
63
|
+
#list {
|
64
|
+
logic: {
|
65
|
+
foreach ($list as $item) {
|
66
|
+
_elem();
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
#item {
|
71
|
+
Value: $item;
|
72
|
+
}
|
73
|
+
END
|
74
|
+
|
75
|
+
|
76
|
+
PHP_OUTPUT = <<END
|
77
|
+
<html>
|
78
|
+
<body>
|
79
|
+
<h1><?php echo $title; ?></h1>
|
80
|
+
<table id="content">
|
81
|
+
<?php foreach ($list as $item) { ?>
|
82
|
+
<tr>
|
83
|
+
<td><?php echo htmlspecialchars($item); ?></td>
|
84
|
+
</tr>
|
85
|
+
<?php } ?>
|
86
|
+
</table>
|
87
|
+
</body>
|
88
|
+
</html>
|
89
|
+
END
|
90
|
+
|
91
|
+
|
92
|
+
YAML_DATA = <<END
|
93
|
+
title: kwartz example
|
94
|
+
list:
|
95
|
+
- <aaa>
|
96
|
+
- b&b
|
97
|
+
- '"ccc"'
|
98
|
+
END
|
99
|
+
|
100
|
+
YAML_OUTPUT = <<END
|
101
|
+
<html>
|
102
|
+
<body>
|
103
|
+
<h1>kwartz example</h1>
|
104
|
+
<table id="content">
|
105
|
+
<tr>
|
106
|
+
<td><aaa></td>
|
107
|
+
</tr>
|
108
|
+
<tr>
|
109
|
+
<td>b&b</td>
|
110
|
+
</tr>
|
111
|
+
<tr>
|
112
|
+
<td>"ccc"</td>
|
113
|
+
</tr>
|
114
|
+
</table>
|
115
|
+
</body>
|
116
|
+
</html>
|
117
|
+
END
|
118
|
+
|
119
|
+
|
120
|
+
class File
|
121
|
+
def self.write(filename, content)
|
122
|
+
File.open(filename, 'w') { |f| f.write(content) }
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
class MainTest < Test::Unit::TestCase
|
128
|
+
|
129
|
+
## define test methods
|
130
|
+
#filename = __FILE__.sub(/\.rb$/, '.yaml')
|
131
|
+
#load_yaml_testdata(filename)
|
132
|
+
|
133
|
+
|
134
|
+
def _test
|
135
|
+
@name = (caller()[0] =~ /in `test_(.*?)'/) && $1
|
136
|
+
begin
|
137
|
+
File.write("#{@name}.pdata", @pdata) if @pdata
|
138
|
+
File.write("#{@name}.plogic", @plogic) if @plogic
|
139
|
+
File.write("#{@name}.yaml", @yamldata) if @yamldata
|
140
|
+
main = Kwartz::Main.new(@argv)
|
141
|
+
if @exception
|
142
|
+
mesg = nil
|
143
|
+
assert_raise(@exception) do
|
144
|
+
begin
|
145
|
+
actual = main.execute()
|
146
|
+
rescue => ex
|
147
|
+
mesg = ex.message
|
148
|
+
raise ex
|
149
|
+
end
|
150
|
+
end
|
151
|
+
assert_text_equal(@message, mesg) if @message
|
152
|
+
else
|
153
|
+
actual = main.execute()
|
154
|
+
@actual = actual
|
155
|
+
assert_text_equal(@expected, actual)
|
156
|
+
end
|
157
|
+
ensure
|
158
|
+
f = nil
|
159
|
+
File.unlink(f) if test(?f, f = "#{@name}.pdata")
|
160
|
+
File.unlink(f) if test(?f, f = "#{@name}.plogic")
|
161
|
+
File.unlink(f) if test(?f, f = "#{@name}.yaml")
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
def test_pdata1
|
167
|
+
@pdata = PDATA
|
168
|
+
@argv = %w[pdata1.pdata]
|
169
|
+
@expected = PDATA.gsub(/ id="mark:\w+"/, '')
|
170
|
+
_test
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
def test_pstyle1 # -P
|
175
|
+
# OK
|
176
|
+
@pdata = PDATA
|
177
|
+
@plogic = ERUBY_PLOGIC
|
178
|
+
@argv = %w[-Pcss -p pstyle1 pstyle1.pdata]
|
179
|
+
@expected = ERUBY_OUTPUT
|
180
|
+
_test
|
181
|
+
# NG
|
182
|
+
@argv = %w[-Phoge -p pstyle1 pstyle1.pdata]
|
183
|
+
@exception = Kwartz::CommandOptionError
|
184
|
+
@message = "-P hoge: unknown style name (parser class not registered)."
|
185
|
+
_test
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
def test_lang1 # -l
|
190
|
+
# OK
|
191
|
+
@pdata = PDATA
|
192
|
+
@plogic = PHP_PLOGIC
|
193
|
+
@argv = %w[-l php -p lang1 lang1.pdata]
|
194
|
+
@expected = PHP_OUTPUT
|
195
|
+
_test
|
196
|
+
# NG
|
197
|
+
@argv = %w[-l hoge -p lang1 lang1.pdata]
|
198
|
+
@exception = Kwartz::CommandOptionError
|
199
|
+
@message = "-l hoge: unknown lang name (handler class not registered)."
|
200
|
+
_test
|
201
|
+
end
|
202
|
+
|
203
|
+
|
204
|
+
def test_requires1 # -r
|
205
|
+
# OK
|
206
|
+
@pdata = PDATA
|
207
|
+
@argv = %w[-rstringio,tsort requires1.pdata]
|
208
|
+
@expected = PDATA.gsub(/ id="mark:.*?"/, '')
|
209
|
+
_test
|
210
|
+
assert_nothing_raised do
|
211
|
+
obj = StringIO.new("")
|
212
|
+
s = TSort.name
|
213
|
+
end
|
214
|
+
# NG
|
215
|
+
@argv = %w[-rhogeratta requires1.pdata]
|
216
|
+
assert_raise(LoadError) do
|
217
|
+
_test
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
|
222
|
+
def test_plogics1 # -p
|
223
|
+
# OK
|
224
|
+
@pdata = PDATA
|
225
|
+
@plogic = ERUBY_PLOGIC
|
226
|
+
@argv = %w[-p plogics1.plogic plogics1.pdata]
|
227
|
+
@expected = ERUBY_OUTPUT
|
228
|
+
_test
|
229
|
+
# NG (not found)
|
230
|
+
@argv = %w[-p hogeratta plogics1.pdata]
|
231
|
+
@exception = Kwartz::CommandOptionError
|
232
|
+
@message = "-p hogeratta[.plogic]: file not found."
|
233
|
+
_test
|
234
|
+
# NG (syntax error)
|
235
|
+
@plogic = ERUBY_PLOGIC.sub(/@title;/, '@title')
|
236
|
+
@argv = %w[-p plogics1 plogics1.pdata]
|
237
|
+
@exception = Kwartz::ParseError
|
238
|
+
@message = "plogics1.plogic:3:1: 'value:': ';' is required."
|
239
|
+
_test
|
240
|
+
end
|
241
|
+
|
242
|
+
|
243
|
+
def test_escape1 # -e, --escape
|
244
|
+
# OK
|
245
|
+
@pdata = PDATA
|
246
|
+
@plogic = ERUBY_PLOGIC
|
247
|
+
@expected = ERUBY_OUTPUT.sub(/<%= @title %>/, '<%=h @title %>')
|
248
|
+
@argv = %w[-epescape1 escape1.pdata]
|
249
|
+
_test
|
250
|
+
# OK
|
251
|
+
@pdata = PDATA
|
252
|
+
@plogic = PHP_PLOGIC
|
253
|
+
@expected = PHP_OUTPUT.sub(/echo \$title;/, 'echo htmlspecialchars($title);')
|
254
|
+
@argv = %w[--escape -lphp -pescape1 escape1.pdata]
|
255
|
+
_test
|
256
|
+
end
|
257
|
+
|
258
|
+
|
259
|
+
def test_import1 # -i
|
260
|
+
# OK
|
261
|
+
@pdata = PDATA
|
262
|
+
@plogic = ERUBY_PLOGIC.sub(/^\#doctitle.*?\}/m, "#doctitle{logic:{\n_element(sectitle)\n}\n}")
|
263
|
+
@expected = ERUBY_OUTPUT.sub(/^\s*<h1>.*?<\/h1>/, '<%= sectitle %>')
|
264
|
+
s = <<END
|
265
|
+
<div>
|
266
|
+
<span id="mark:sectitle">foo</span>
|
267
|
+
</div>
|
268
|
+
END
|
269
|
+
File.write('import1a.pdata', s)
|
270
|
+
s = <<END
|
271
|
+
#sectitle {
|
272
|
+
elem: sectitle;
|
273
|
+
}
|
274
|
+
END
|
275
|
+
File.write('import1a.plogic', s)
|
276
|
+
@argv = %w[-p import1,import1a -i import1a.pdata import1.pdata]
|
277
|
+
begin
|
278
|
+
_test
|
279
|
+
ensure
|
280
|
+
%w[import1a.pdata import1a.plogic].each do |filename|
|
281
|
+
File.unlink filename if test(?f, filename)
|
282
|
+
end
|
283
|
+
end
|
284
|
+
# NG
|
285
|
+
@argv = %w[-p import1 -i hogehoge import1.pdata]
|
286
|
+
@exception = Kwartz::CommandOptionError
|
287
|
+
@message = "-i hogehoge: file not found."
|
288
|
+
_test
|
289
|
+
end
|
290
|
+
|
291
|
+
|
292
|
+
def test_layout1 # -L
|
293
|
+
# OK
|
294
|
+
@pdata = PDATA
|
295
|
+
@plogic = ERUBY_PLOGIC
|
296
|
+
s = <<END
|
297
|
+
<?xml version="1.0" charset="utf8"?>
|
298
|
+
<html>
|
299
|
+
<head>
|
300
|
+
<title title="replace_content_with: content(doctitle)">layout file</title>
|
301
|
+
</head>
|
302
|
+
<body>
|
303
|
+
|
304
|
+
<div title="replace_element_with: element(content)">
|
305
|
+
foo
|
306
|
+
bar
|
307
|
+
</div>
|
308
|
+
|
309
|
+
</body>
|
310
|
+
</html>
|
311
|
+
END
|
312
|
+
File.write('layout.html', s)
|
313
|
+
content_str = (ERUBY_OUTPUT =~ /^\s*<table.*?<\/table>/m) && $&
|
314
|
+
@expected = s.sub(/^(\s*)<title.*?<\/title>/, '\1<title><%= @title %></title>')
|
315
|
+
@expected.sub!(/^( *)<div .*?<\/div>/m, content_str)
|
316
|
+
@argv = %w[-p layout1 -L layout.html layout1.pdata]
|
317
|
+
begin
|
318
|
+
_test
|
319
|
+
ensure
|
320
|
+
%w[layout.html].each do |filename|
|
321
|
+
File.unlink filename if test(?f, filename)
|
322
|
+
end
|
323
|
+
end
|
324
|
+
# NG
|
325
|
+
@argv = %w[-p layout1 -L hogehoge layout1.pdata]
|
326
|
+
@exception = Kwartz::CommandOptionError
|
327
|
+
@message = "-L hogehoge: file not found."
|
328
|
+
_test
|
329
|
+
end
|
330
|
+
|
331
|
+
|
332
|
+
def test_extract1 # -X
|
333
|
+
# OK
|
334
|
+
@pdata = PDATA
|
335
|
+
@plogic = ERUBY_PLOGIC
|
336
|
+
@argv = %w[-X content -p extract1 extract1.pdata]
|
337
|
+
@expected = (ERUBY_OUTPUT =~ /^ *<table.*?<\/table>\n/m) && $&
|
338
|
+
_test
|
339
|
+
# NG
|
340
|
+
@exception = Kwartz::ConvertError
|
341
|
+
@message = "extract1.pdata:: element 'hogehoge' not found."
|
342
|
+
@argv = %w[-X hogehoge -p extract1 extract1.pdata]
|
343
|
+
_test
|
344
|
+
end
|
345
|
+
|
346
|
+
|
347
|
+
def test_extract2 # -x
|
348
|
+
# OK
|
349
|
+
@pdata = PDATA
|
350
|
+
@plogic = ERUBY_PLOGIC
|
351
|
+
@argv = %w[-x content -p extract2 extract2.pdata]
|
352
|
+
@expected = (ERUBY_OUTPUT =~ /<table id=".*?">\n(.*)^ *<\/table>/m) && $1
|
353
|
+
_test
|
354
|
+
# NG
|
355
|
+
@exception = Kwartz::ConvertError
|
356
|
+
@message = "extract2.pdata:: element 'hogehoge' not found."
|
357
|
+
@argv = %w[-x hogehoge -p extract2 extract2.pdata]
|
358
|
+
_test
|
359
|
+
end
|
360
|
+
|
361
|
+
|
362
|
+
def test_yamlfile1 # -f
|
363
|
+
# OK
|
364
|
+
@pdata = PDATA
|
365
|
+
@plogic = ERUBY_PLOGIC
|
366
|
+
@argv = %w[-f yamlfile1.yaml -p yamlfile1 yamlfile1.pdata]
|
367
|
+
@yamldata = YAML_DATA.gsub(/\t/, ' ')
|
368
|
+
@expected = YAML_OUTPUT
|
369
|
+
_test
|
370
|
+
# NG (not found)
|
371
|
+
@argv = %w[-f hogehoge.yaml -p yamlfile1 yamlfile1.pdata]
|
372
|
+
@exception = Kwartz::CommandOptionError
|
373
|
+
@message = "-f hogehoge.yaml: file not found."
|
374
|
+
_test
|
375
|
+
# NG (not a mapping)
|
376
|
+
@yamldata = <<END
|
377
|
+
- title: kwartz test
|
378
|
+
- list:
|
379
|
+
- aaa
|
380
|
+
- bbb
|
381
|
+
- ccc
|
382
|
+
END
|
383
|
+
@argv = %w[-f yamlfile1.yaml -p yamlfile1 yamlfile1.pdata]
|
384
|
+
@exception = Kwartz::CommandOptionError
|
385
|
+
@message = "-f yamlfile1.yaml: not a mapping."
|
386
|
+
_test
|
387
|
+
end
|
388
|
+
|
389
|
+
|
390
|
+
def test_untabify1 # -t
|
391
|
+
# OK
|
392
|
+
@pdata = PDATA
|
393
|
+
@plogic = ERUBY_PLOGIC
|
394
|
+
@argv = %w[-tf untabify1.yaml -p untabify1 untabify1.pdata]
|
395
|
+
@yamldata = YAML_DATA
|
396
|
+
@expected = YAML_OUTPUT
|
397
|
+
_test
|
398
|
+
# NG
|
399
|
+
@argv = %w[-f untabify1.yaml -p untabify1 untabify1.pdata]
|
400
|
+
@exception = ArgumentError # yaml syntax error
|
401
|
+
end
|
402
|
+
|
403
|
+
|
404
|
+
def test_intern1 # -S
|
405
|
+
# OK
|
406
|
+
@pdata = <<END
|
407
|
+
<span title="value: @aaa[:bb1][:cc1][:dd1]">xxx</span>
|
408
|
+
<span title="value: @aaa[:bb1][:cc1][:dd2][:bb2]">xxx</span>
|
409
|
+
END
|
410
|
+
@yamldata = <<END
|
411
|
+
aaa: &anchor1
|
412
|
+
bb1:
|
413
|
+
cc1:
|
414
|
+
dd1: foo
|
415
|
+
dd2: *anchor1
|
416
|
+
bb2: bar
|
417
|
+
END
|
418
|
+
@expected = <<END
|
419
|
+
<span>foo</span>
|
420
|
+
<span>bar</span>
|
421
|
+
END
|
422
|
+
@argv = %w[-tSf intern1.yaml intern1.pdata]
|
423
|
+
_test
|
424
|
+
# OK
|
425
|
+
@pdata = <<END
|
426
|
+
<span title="value: @aaa['bb1']['cc1']['dd1']">xxx</span>
|
427
|
+
<span title="value: @aaa['bb1']['cc1']['dd2']['bb2']">xxx</span>
|
428
|
+
END
|
429
|
+
@argv = %w[-tf intern1.yaml intern1.pdata]
|
430
|
+
_test
|
431
|
+
end
|
432
|
+
|
433
|
+
|
434
|
+
def test_no_args
|
435
|
+
@exception = Kwartz::CommandOptionError
|
436
|
+
tuples = [
|
437
|
+
[?l, 'lang name'],
|
438
|
+
[?k, 'kanji code'],
|
439
|
+
[?r, 'library name'],
|
440
|
+
[?p, 'file name'],
|
441
|
+
[?P, 'parser style'],
|
442
|
+
[?x, 'element id'],
|
443
|
+
[?X, 'element id'],
|
444
|
+
[?i, 'file name'],
|
445
|
+
[?L, 'file name'],
|
446
|
+
[?f, 'yaml file'],
|
447
|
+
]
|
448
|
+
tuples.each do |char, argname|
|
449
|
+
@argv = ["-#{char.chr}"]
|
450
|
+
@message = "-#{char.chr}: #{argname} required."
|
451
|
+
_test
|
452
|
+
end
|
453
|
+
end
|
454
|
+
|
455
|
+
|
456
|
+
def test_no_filenames
|
457
|
+
@exception = Kwartz::CommandOptionError
|
458
|
+
@argv = %w[-p foo]
|
459
|
+
@message = 'filename of presentation data is required.'
|
460
|
+
_test
|
461
|
+
end
|
462
|
+
|
463
|
+
|
464
|
+
end
|