oktest 1.3.1 → 1.5.0

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