oktest 1.4.0 → 1.5.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.
- checksums.yaml +4 -4
- data/README.md +42 -5
- data/Rakefile.rb +1 -1
- data/lib/oktest.rb +32 -9
- data/oktest.gemspec +3 -3
- data/test/assertion_test.rb +229 -227
- data/test/filter_test.rb +122 -120
- data/test/fixture_test.rb +33 -32
- data/test/generator_test.rb +20 -19
- data/test/helper_test.rb +280 -274
- data/test/init.rb +44 -0
- data/test/mainapp_test.rb +194 -190
- data/test/matcher_test.rb +156 -126
- data/test/misc_test.rb +31 -30
- data/test/nanot.rb +307 -0
- data/test/node_test.rb +296 -252
- data/test/reporter_test.rb +249 -208
- data/test/runner_test.rb +101 -100
- data/test/util_test.rb +196 -193
- data/test/utilhelper_test.rb +35 -38
- data/test/visitor_test.rb +54 -50
- metadata +10 -10
- data/test/initialize.rb +0 -22
- data/test/tc.rb +0 -128
- /data/test/{run_all.rb → all.rb} +0 -0
data/test/util_test.rb
CHANGED
@@ -2,159 +2,158 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
###
|
5
|
-
### $Release: 1.
|
5
|
+
### $Release: 1.5.0 $
|
6
6
|
### $Copyright: copyright(c) 2011-2024 kuwata-lab.com all rights reserved $
|
7
7
|
### $License: MIT License $
|
8
8
|
###
|
9
9
|
|
10
|
-
require_relative './
|
10
|
+
require_relative './init'
|
11
11
|
|
12
12
|
|
13
|
-
class
|
14
|
-
|
13
|
+
class Util__Test
|
14
|
+
extend NanoTest
|
15
|
+
extend Oktest::Util
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
lineno = __LINE__ + 2
|
25
|
-
_ = <<END
|
17
|
+
test_target 'Oktest::Util.file_line()' do
|
18
|
+
test_subject "[!4z65g] returns nil if file not exist or not a file." do
|
19
|
+
test_eq? Oktest::Util.file_line("not-exist-file", 1), nil
|
20
|
+
test_eq? Oktest::Util.file_line(".", 1), nil
|
21
|
+
end
|
22
|
+
test_subject "[!162e1] returns line string." do
|
23
|
+
lineno = __LINE__ + 2
|
24
|
+
_ = <<END
|
26
25
|
U6XYR-SH08J
|
27
26
|
END
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
27
|
+
test_eq? Oktest::Util.file_line(__FILE__, lineno), "U6XYR-SH08J\n"
|
28
|
+
end
|
29
|
+
test_subject "[!4a2ji] caches recent file content for performance reason." do
|
30
|
+
_ = Oktest::Util.file_line(__FILE__, 1)
|
31
|
+
c = Oktest::Util.instance_variable_get('@__cache')
|
32
|
+
test_ok? c.is_a?(Array), msg: "array object expected."
|
33
|
+
test_eq? c[0], __FILE__
|
34
|
+
test_eq? c[1][0], "# -*- coding: utf-8 -*-\n"
|
35
|
+
test_eq? c[1][16], " test_target 'Oktest::Util.file_line()' do\n"
|
36
|
+
#
|
37
|
+
data1 = c[1]
|
38
|
+
_ = Oktest::Util.file_line(__FILE__, 1)
|
39
|
+
c2 = Oktest::Util.instance_variable_get('@__cache')
|
40
|
+
test_ok? c2[1].equal?(data1), msg: "cache object changed unexpectedly."
|
41
|
+
end
|
42
|
+
test_subject "[!wtrl5] recreates cache data if other file requested." do
|
43
|
+
_ = Oktest::Util.file_line(__FILE__, 1)
|
44
|
+
c = Oktest::Util.instance_variable_get('@__cache')
|
45
|
+
data1 = c[1]
|
46
|
+
#
|
47
|
+
otherfile = File.join(File.dirname(__FILE__), "init.rb")
|
48
|
+
_ = Oktest::Util.file_line(otherfile, 1)
|
49
|
+
c3 = Oktest::Util.instance_variable_get('@__cache')
|
50
|
+
test_eq? c3[0], otherfile
|
51
|
+
test_ok? ! c3[1].equal?(data1), msg: "cache object should be recreated, but not."
|
54
52
|
end
|
53
|
+
end
|
55
54
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
55
|
+
test_target 'Oktest::Util.required_param_names_of_block()' do
|
56
|
+
test_subject "[!a9n46] returns nil if argument is nil." do
|
57
|
+
test_eq? required_param_names_of_block(nil), nil
|
58
|
+
end
|
59
|
+
test_subject "[!7m81p] returns empty array if block has no parameters." do
|
60
|
+
pr = proc { nil }
|
61
|
+
test_eq? required_param_names_of_block(pr), []
|
62
|
+
end
|
63
|
+
test_subject "[!n3g63] returns parameter names of block." do
|
64
|
+
pr = proc {|x, y, z| nil }
|
65
|
+
test_eq? required_param_names_of_block(pr), [:x, :y, :z]
|
66
|
+
end
|
67
|
+
test_subject "[!d5kym] collects only normal parameter names." do
|
68
|
+
pr = proc {|x, y, z=1, *rest, a: 1, b: 2, &blk| nil }
|
69
|
+
test_eq? required_param_names_of_block(pr), [:x, :y]
|
70
|
+
pr = proc {|a: 1, b: 2, &blk| nil }
|
71
|
+
test_eq? required_param_names_of_block(pr), []
|
72
|
+
pr = proc {|*rest, &blk| nil }
|
73
|
+
test_eq? required_param_names_of_block(pr), []
|
76
74
|
end
|
75
|
+
end
|
77
76
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end
|
77
|
+
test_target 'Oktest::Util.keyword_param_names_of_block()' do
|
78
|
+
test_subject "[!p6qqp] returns keyword param names of proc object." do
|
79
|
+
pr = proc {|a, b=nil, c: nil, d: 1| nil }
|
80
|
+
test_eq? keyword_param_names_of_block(pr), [:c, :d]
|
81
|
+
pr = proc {|a, b=nil| nil }
|
82
|
+
test_eq? keyword_param_names_of_block(pr), []
|
85
83
|
end
|
84
|
+
end
|
86
85
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
end
|
86
|
+
test_target 'Oktest::Util.strfold()' do
|
87
|
+
test_subject "[!wb7m8] returns string as test_subject is if string is not long." do
|
88
|
+
s = "*" * 79
|
89
|
+
test_eq? strfold(s, 80), s
|
90
|
+
s = "*" * 80
|
91
|
+
test_eq? strfold(s, 80), s
|
92
|
+
end
|
93
|
+
test_subject "[!a2igb] shorten string if test_subject is enough long." do
|
94
|
+
expected = "*" * 77 + "..."
|
95
|
+
s = "*" * 81
|
96
|
+
test_eq? strfold(s, 80), expected
|
97
|
+
end
|
98
|
+
test_subject "[!0gjye] supports non-ascii characters." do
|
99
|
+
expected = "あ" * 38 + "..."
|
100
|
+
s = "あ" * 41
|
101
|
+
test_eq? strfold(s, 80), expected
|
102
|
+
#
|
103
|
+
expected = "x" + "あ" * 37 + "..."
|
104
|
+
s = "x" + "あ" * 40
|
105
|
+
test_eq? strfold(s, 80), expected
|
108
106
|
end
|
107
|
+
end
|
109
108
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
end
|
131
|
-
it "[!ijx52] converts 56.8888 into '56.9'." do
|
132
|
-
x = 56.8888
|
133
|
-
assert_eq hhmmss(x), "56.9"
|
134
|
-
end
|
135
|
-
it "[!2kra2] converts 9.777 into '9.78'." do
|
136
|
-
x = 9.777
|
137
|
-
assert_eq hhmmss(x), "9.78"
|
138
|
-
end
|
139
|
-
it "[!4aomb] converts 0.7777 into '0.778'." do
|
140
|
-
x = 0.7777
|
141
|
-
assert_eq hhmmss(x), "0.778"
|
142
|
-
end
|
109
|
+
test_target 'Oktest::Util.hhmmss()' do
|
110
|
+
test_subject "[!shyl1] converts 400953.444 into '111:22:33.4'." do
|
111
|
+
x = 111*60*60 + 22*60 + 33.444
|
112
|
+
test_eq? x, 400953.444
|
113
|
+
test_eq? hhmmss(x), "111:22:33.4"
|
114
|
+
end
|
115
|
+
test_subject "[!vyi2v] converts 5025.678 into '1:23:45.7'." do
|
116
|
+
x = 1*60*60 + 23*60 + 45.678
|
117
|
+
test_eq? x, 5025.678
|
118
|
+
test_eq? hhmmss(x), "1:23:45.7"
|
119
|
+
end
|
120
|
+
test_subject "[!pm4xf] converts 754.888 into '12:34.9'." do
|
121
|
+
x = 12*60 + 34.888
|
122
|
+
test_eq? x, 754.888
|
123
|
+
test_eq? hhmmss(x), "12:34.9"
|
124
|
+
end
|
125
|
+
test_subject "[!lwewr] converts 83.444 into '1:23.4'." do
|
126
|
+
x = 1*60 + 23.444
|
127
|
+
test_eq? x, 83.444
|
128
|
+
test_eq? hhmmss(x), "1:23.4"
|
143
129
|
end
|
130
|
+
test_subject "[!ijx52] converts 56.8888 into '56.9'." do
|
131
|
+
x = 56.8888
|
132
|
+
test_eq? hhmmss(x), "56.9"
|
133
|
+
end
|
134
|
+
test_subject "[!2kra2] converts 9.777 into '9.78'." do
|
135
|
+
x = 9.777
|
136
|
+
test_eq? hhmmss(x), "9.78"
|
137
|
+
end
|
138
|
+
test_subject "[!4aomb] converts 0.7777 into '0.778'." do
|
139
|
+
x = 0.7777
|
140
|
+
test_eq? hhmmss(x), "0.778"
|
141
|
+
end
|
142
|
+
end
|
144
143
|
|
145
|
-
|
146
|
-
|
147
|
-
|
144
|
+
test_target 'Oktest::Util.hhmmss()' do
|
145
|
+
test_subject "[!wf4ns] calculates unified diff from two text strings." do
|
146
|
+
s1 = <<'END'
|
148
147
|
Haruhi
|
149
148
|
Mikuru
|
150
149
|
Yuki
|
151
150
|
END
|
152
|
-
|
151
|
+
s2 = <<'END'
|
153
152
|
Haruhi
|
154
153
|
Michiru
|
155
154
|
Yuki
|
156
155
|
END
|
157
|
-
|
156
|
+
expected = <<'END'
|
158
157
|
--- old
|
159
158
|
+++ new
|
160
159
|
@@ -1,4 +1,4 @@
|
@@ -163,21 +162,21 @@ END
|
|
163
162
|
+Michiru
|
164
163
|
Yuki
|
165
164
|
END
|
166
|
-
|
167
|
-
|
168
|
-
end
|
165
|
+
diff = Oktest::Util.unified_diff(s1, s2)
|
166
|
+
test_eq? diff, expected
|
169
167
|
end
|
168
|
+
end
|
170
169
|
|
171
|
-
|
172
|
-
|
173
|
-
|
170
|
+
test_target 'Oktest::Util.unified_diff()' do
|
171
|
+
test_subject "[!rnx4f] checks whether text string ends with newline char." do
|
172
|
+
s1 = <<'END'
|
174
173
|
Haruhi
|
175
174
|
Mikuru
|
176
175
|
Yuki
|
177
176
|
END
|
178
|
-
|
179
|
-
|
180
|
-
|
177
|
+
s2 = s1
|
178
|
+
#
|
179
|
+
expected1 = <<'END'
|
181
180
|
--- old
|
182
181
|
+++ new
|
183
182
|
@@ -1,4 +1,4 @@
|
@@ -186,10 +185,10 @@ END
|
|
186
185
|
-Yuki\ No newline at end of string
|
187
186
|
+Yuki
|
188
187
|
END
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
188
|
+
diff = Oktest::Util.unified_diff(s1.chomp, s2)
|
189
|
+
test_eq? diff, expected1
|
190
|
+
#
|
191
|
+
expected2 = <<'END'
|
193
192
|
--- old
|
194
193
|
+++ new
|
195
194
|
@@ -1,4 +1,4 @@
|
@@ -198,24 +197,24 @@ END
|
|
198
197
|
-Yuki
|
199
198
|
+Yuki\ No newline at end of string
|
200
199
|
END
|
201
|
-
|
202
|
-
|
203
|
-
end
|
200
|
+
diff = Oktest::Util.unified_diff(s1, s2.chomp)
|
201
|
+
test_eq? diff, expected2
|
204
202
|
end
|
203
|
+
end
|
205
204
|
|
206
|
-
|
207
|
-
|
208
|
-
|
205
|
+
test_target 'Oktest::Util.diff_unified()' do
|
206
|
+
test_subject "[!ulyq5] returns unified diff string of two text strings." do
|
207
|
+
s1 = <<'END'
|
209
208
|
Haruhi
|
210
209
|
Mikuru
|
211
210
|
Yuki
|
212
211
|
END
|
213
|
-
|
212
|
+
s2 = <<'END'
|
214
213
|
Haruhi
|
215
214
|
Michiru
|
216
215
|
Yuki
|
217
216
|
END
|
218
|
-
|
217
|
+
expected = <<'END'
|
219
218
|
--- old
|
220
219
|
+++ new
|
221
220
|
@@ -1,3 +1,3 @@
|
@@ -224,18 +223,18 @@ END
|
|
224
223
|
+Michiru
|
225
224
|
Yuki
|
226
225
|
END
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
226
|
+
diff = Oktest::Util.diff_unified(s1, s2)
|
227
|
+
test_eq? diff, expected
|
228
|
+
end
|
229
|
+
test_subject "[!6tgum] detects whether char at end of file is newline or not." do
|
230
|
+
s1 = <<'END'
|
232
231
|
Haruhi
|
233
232
|
Mikuru
|
234
233
|
Yuki
|
235
234
|
END
|
236
|
-
|
237
|
-
|
238
|
-
|
235
|
+
s2 = s1
|
236
|
+
#
|
237
|
+
expected1 = <<'END'
|
239
238
|
--- old
|
240
239
|
+++ new
|
241
240
|
@@ -1,3 +1,3 @@
|
@@ -245,10 +244,10 @@ END
|
|
245
244
|
|
246
245
|
+Yuki
|
247
246
|
END
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
247
|
+
diff = Oktest::Util.diff_unified(s1.chomp, s2)
|
248
|
+
test_eq? diff, expected1
|
249
|
+
#
|
250
|
+
expected2 = <<'END'
|
252
251
|
--- old
|
253
252
|
+++ new
|
254
253
|
@@ -1,3 +1,3 @@
|
@@ -258,71 +257,75 @@ END
|
|
258
257
|
+Yuki
|
259
258
|
|
260
259
|
END
|
261
|
-
|
262
|
-
|
263
|
-
end
|
260
|
+
diff = Oktest::Util.diff_unified(s1, s2.chomp)
|
261
|
+
test_eq? diff, expected2
|
264
262
|
end
|
263
|
+
end
|
265
264
|
|
266
|
-
|
267
|
-
|
265
|
+
test_target 'Oktest::Util.partial_regexp!()' do
|
266
|
+
test_subject "[!peyu4] returns PartialRegexp object which inspect string is function call styel." do
|
268
267
|
pattern_str = <<'HEREDOC'
|
269
268
|
* [Date] {== \d\d\d\d-\d\d-\d\d ==}
|
270
269
|
* [Secret] {== [0-9a-f]{8} ==}
|
271
270
|
HEREDOC
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
end
|
271
|
+
prexp = Oktest::Util.partial_regexp!(pattern_str)
|
272
|
+
test_eq? prexp.class, Oktest::Util::PartialRegexp
|
273
|
+
test_eq? prexp.pattern_string, pattern_str
|
276
274
|
end
|
275
|
+
end
|
277
276
|
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
end
|
283
|
-
assert_exc(ArgumentError, "\"{= == =}\": mark should contain only one space (ex: `{== ==}`).") do
|
284
|
-
Oktest::Util.partial_regexp("xxx", '', '', "{= == =}")
|
285
|
-
end
|
277
|
+
test_target 'Oktest::Util.partial_regexp()' do
|
278
|
+
test_subject "[!ostkw] raises error if mark has no space or has more than two spaces." do
|
279
|
+
exc = test_exception? ArgumentError do
|
280
|
+
Oktest::Util.partial_regexp("xxx", '\A', '\z', "{====}")
|
286
281
|
end
|
287
|
-
|
288
|
-
|
282
|
+
test_eq? exc.message, "\"{====}\": mark should contain only one space (ex: `{== ==}`)."
|
283
|
+
exc = test_exception? ArgumentError do
|
284
|
+
Oktest::Util.partial_regexp("xxx", '', '', "{= == =}")
|
285
|
+
end
|
286
|
+
test_eq? exc.message, "\"{= == =}\": mark should contain only one space (ex: `{== ==}`)."
|
287
|
+
end
|
288
|
+
test_subject "[!wn524] returns PartialRegexp object which inspect string is regexp literal style." do
|
289
|
+
pattern_str = <<'HEREDOC'
|
289
290
|
* [Date] {== \d\d\d\d-\d\d-\d\d ==}
|
290
291
|
* [Secret] {== [0-9a-f]{8} ==}
|
291
292
|
HEREDOC
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
end
|
293
|
+
prexp = Oktest::Util.partial_regexp(pattern_str)
|
294
|
+
test_eq? prexp.class, Oktest::Util::PartialRegexp
|
295
|
+
test_eq? prexp.pattern_string, nil
|
296
296
|
end
|
297
|
-
|
298
297
|
end
|
299
298
|
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
299
|
+
end
|
300
|
+
|
301
|
+
|
302
|
+
class Util_PartialRegexp__Test
|
303
|
+
extend NanoTest
|
304
|
+
|
305
|
+
test_target 'Oktest::Util::PartialRegexp#inspect()' do
|
306
|
+
test_subject "[!uyh31] returns function call style string if @pattern_string is set." do
|
307
|
+
prexp = Oktest::Util.partial_regexp!(<<'HEREHERE')
|
304
308
|
* [Date] {== \d\d\d\d-\d\d-\d\d ==}
|
305
309
|
* [Secret] {== [0-9a-f]{8} ==}
|
306
310
|
HEREHERE
|
307
|
-
|
311
|
+
test_eq? prexp.inspect, <<'HEREHERE'
|
308
312
|
partial_regexp(<<PREXP, '\A', '\z')
|
309
313
|
* [Date] {== \d\d\d\d-\d\d-\d\d ==}
|
310
314
|
* [Secret] {== [0-9a-f]{8} ==}
|
311
315
|
PREXP
|
312
316
|
HEREHERE
|
313
|
-
|
314
|
-
|
315
|
-
|
317
|
+
end
|
318
|
+
test_subject "[!ts9v4] returns regexp literal style string if @pattern_string is not set." do
|
319
|
+
prexp = Oktest::Util.partial_regexp(<<'HEREHERE')
|
316
320
|
* [Date] {== \d\d\d\d-\d\d-\d\d ==}
|
317
321
|
* [Secret] {== [0-9a-f]{8} ==}
|
318
322
|
HEREHERE
|
319
|
-
|
323
|
+
test_eq? prexp.inspect, <<'HEREHERE'.chomp
|
320
324
|
/\A
|
321
325
|
\*\ \[Date\]\ \ \ \ \d\d\d\d-\d\d-\d\d\n
|
322
326
|
\*\ \[Secret\]\ \ [0-9a-f]{8}\n
|
323
327
|
\z/x
|
324
328
|
HEREHERE
|
325
|
-
end
|
326
329
|
end
|
327
330
|
end
|
328
331
|
|
data/test/utilhelper_test.rb
CHANGED
@@ -2,84 +2,81 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
###
|
5
|
-
### $Release: 1.
|
5
|
+
### $Release: 1.5.0 $
|
6
6
|
### $Copyright: copyright(c) 2011-2024 kuwata-lab.com all rights reserved $
|
7
7
|
### $License: MIT License $
|
8
8
|
###
|
9
9
|
|
10
|
-
require_relative './
|
10
|
+
require_relative './init'
|
11
11
|
|
12
12
|
|
13
|
-
class
|
13
|
+
class UtilHelper__Test
|
14
|
+
extend NanoTest
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
describe '#partial_regexp!()' do
|
18
|
-
pat = <<'END'
|
16
|
+
test_target 'Oktest::UtilHelper#partial_regexp!()' do
|
17
|
+
pat = <<'END'
|
19
18
|
* [Date] {== \d\d\d\d-\d\d-\d\d ==}
|
20
19
|
* [Secret] {== [0-9a-f]{12} ==}
|
21
20
|
END
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
21
|
+
test_subject "[!9drtn] is available in both topic and spec blocks." do
|
22
|
+
r1 = nil; r2 = nil
|
23
|
+
Oktest.scope do
|
24
|
+
topic "topic" do
|
25
|
+
r1 = partial_regexp!(pat, '\A', '\z')
|
26
|
+
spec "spec" do
|
27
|
+
r2 = partial_regexp!(pat, "", "")
|
30
28
|
end
|
31
29
|
end
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
end
|
31
|
+
capture_output! { Oktest.run() }
|
32
|
+
test_eq? r1.class, Oktest::Util::PartialRegexp
|
33
|
+
test_eq? r2.class, Oktest::Util::PartialRegexp
|
34
|
+
test_eq? r1.inspect, <<'END'
|
36
35
|
partial_regexp(<<PREXP, '\A', '\z')
|
37
36
|
* [Date] {== \d\d\d\d-\d\d-\d\d ==}
|
38
37
|
* [Secret] {== [0-9a-f]{12} ==}
|
39
38
|
PREXP
|
40
39
|
END
|
41
|
-
|
40
|
+
test_eq? r2.inspect, <<'END'
|
42
41
|
partial_regexp(<<PREXP, "", "")
|
43
42
|
* [Date] {== \d\d\d\d-\d\d-\d\d ==}
|
44
43
|
* [Secret] {== [0-9a-f]{12} ==}
|
45
44
|
PREXP
|
46
45
|
END
|
47
|
-
end
|
48
46
|
end
|
47
|
+
end
|
49
48
|
|
50
|
-
|
51
|
-
|
52
|
-
|
49
|
+
test_target 'Oktest::UtilHelper#partial_regexp()' do
|
50
|
+
test_subject "[!wo4hp] is available in both topic and spec blocks." do
|
51
|
+
pat = <<'END'
|
53
52
|
* [Date] {== \d\d\d\d-\d\d-\d\d ==}
|
54
53
|
* [Secret] {== [0-9a-f]{12} ==}
|
55
54
|
END
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
55
|
+
r1 = nil; r2 = nil
|
56
|
+
Oktest.scope do
|
57
|
+
topic "topic" do
|
58
|
+
r1 = partial_regexp(pat, '\A', '\z')
|
59
|
+
spec "spec" do
|
60
|
+
r2 = partial_regexp(pat, "", "")
|
63
61
|
end
|
64
62
|
end
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
63
|
+
end
|
64
|
+
capture_output! { Oktest.run() }
|
65
|
+
test_eq? r1.class, Oktest::Util::PartialRegexp
|
66
|
+
test_eq? r2.class, Oktest::Util::PartialRegexp
|
67
|
+
test_eq? r1.inspect, <<'END'.chomp
|
69
68
|
/\A
|
70
69
|
\*\ \[Date\]\ \ \ \ \d\d\d\d-\d\d-\d\d\n
|
71
70
|
\*\ \[Secret\]\ \ [0-9a-f]{12}\n
|
72
71
|
\z/x
|
73
72
|
END
|
74
|
-
|
73
|
+
test_eq? r2.inspect, <<'END'.chomp
|
75
74
|
/
|
76
75
|
\*\ \[Date\]\ \ \ \ \d\d\d\d-\d\d-\d\d\n
|
77
76
|
\*\ \[Secret\]\ \ [0-9a-f]{12}\n
|
78
77
|
/x
|
79
78
|
END
|
80
|
-
end
|
81
79
|
end
|
82
|
-
|
83
80
|
end
|
84
81
|
|
85
82
|
end
|