piko-max-mod 0.0.1

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.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/piko-max-mod.gemspec +12 -0
  3. data/test-unit-3.7.8/BSDL +24 -0
  4. data/test-unit-3.7.8/COPYING +64 -0
  5. data/test-unit-3.7.8/PSFL +271 -0
  6. data/test-unit-3.7.8/README.md +108 -0
  7. data/test-unit-3.7.8/Rakefile +74 -0
  8. data/test-unit-3.7.8/bin/test-unit +5 -0
  9. data/test-unit-3.7.8/doc/text/getting-started.md +120 -0
  10. data/test-unit-3.7.8/doc/text/how-to.md +90 -0
  11. data/test-unit-3.7.8/doc/text/news.md +2070 -0
  12. data/test-unit-3.7.8/lib/test/unit/assertion-failed-error.rb +60 -0
  13. data/test-unit-3.7.8/lib/test/unit/assertions.rb +2536 -0
  14. data/test-unit-3.7.8/lib/test/unit/attribute-matcher.rb +26 -0
  15. data/test-unit-3.7.8/lib/test/unit/attribute.rb +228 -0
  16. data/test-unit-3.7.8/lib/test/unit/auto-runner-loader.rb +17 -0
  17. data/test-unit-3.7.8/lib/test/unit/autorunner.rb +654 -0
  18. data/test-unit-3.7.8/lib/test/unit/code-snippet-fetcher.rb +58 -0
  19. data/test-unit-3.7.8/lib/test/unit/collector/descendant.rb +20 -0
  20. data/test-unit-3.7.8/lib/test/unit/collector/dir.rb +110 -0
  21. data/test-unit-3.7.8/lib/test/unit/collector/load.rb +201 -0
  22. data/test-unit-3.7.8/lib/test/unit/collector/objectspace.rb +35 -0
  23. data/test-unit-3.7.8/lib/test/unit/collector/xml.rb +249 -0
  24. data/test-unit-3.7.8/lib/test/unit/collector.rb +104 -0
  25. data/test-unit-3.7.8/lib/test/unit/color-scheme.rb +225 -0
  26. data/test-unit-3.7.8/lib/test/unit/color.rb +134 -0
  27. data/test-unit-3.7.8/lib/test/unit/data-sets.rb +127 -0
  28. data/test-unit-3.7.8/lib/test/unit/data.rb +371 -0
  29. data/test-unit-3.7.8/lib/test/unit/diff.rb +745 -0
  30. data/test-unit-3.7.8/lib/test/unit/error.rb +158 -0
  31. data/test-unit-3.7.8/lib/test/unit/exception-handler.rb +82 -0
  32. data/test-unit-3.7.8/lib/test/unit/failure.rb +169 -0
  33. data/test-unit-3.7.8/lib/test/unit/fault-location-detector.rb +104 -0
  34. data/test-unit-3.7.8/lib/test/unit/fixture.rb +304 -0
  35. data/test-unit-3.7.8/lib/test/unit/notification.rb +138 -0
  36. data/test-unit-3.7.8/lib/test/unit/omission.rb +198 -0
  37. data/test-unit-3.7.8/lib/test/unit/pending.rb +155 -0
  38. data/test-unit-3.7.8/lib/test/unit/priority.rb +194 -0
  39. data/test-unit-3.7.8/lib/test/unit/process-test-result.rb +55 -0
  40. data/test-unit-3.7.8/lib/test/unit/process-worker.rb +87 -0
  41. data/test-unit-3.7.8/lib/test/unit/runner/console.rb +86 -0
  42. data/test-unit-3.7.8/lib/test/unit/runner/emacs.rb +8 -0
  43. data/test-unit-3.7.8/lib/test/unit/runner/xml.rb +15 -0
  44. data/test-unit-3.7.8/lib/test/unit/sub-test-result.rb +59 -0
  45. data/test-unit-3.7.8/lib/test/unit/test-process-run-context.rb +21 -0
  46. data/test-unit-3.7.8/lib/test/unit/test-run-context.rb +16 -0
  47. data/test-unit-3.7.8/lib/test/unit/test-suite-creator.rb +103 -0
  48. data/test-unit-3.7.8/lib/test/unit/test-suite-process-runner.rb +205 -0
  49. data/test-unit-3.7.8/lib/test/unit/test-suite-runner.rb +132 -0
  50. data/test-unit-3.7.8/lib/test/unit/test-suite-thread-runner.rb +96 -0
  51. data/test-unit-3.7.8/lib/test/unit/test-thread-run-context.rb +23 -0
  52. data/test-unit-3.7.8/lib/test/unit/testcase.rb +1058 -0
  53. data/test-unit-3.7.8/lib/test/unit/testresult.rb +132 -0
  54. data/test-unit-3.7.8/lib/test/unit/testsuite.rb +133 -0
  55. data/test-unit-3.7.8/lib/test/unit/ui/console/outputlevel.rb +15 -0
  56. data/test-unit-3.7.8/lib/test/unit/ui/console/testrunner.rb +891 -0
  57. data/test-unit-3.7.8/lib/test/unit/ui/emacs/testrunner.rb +49 -0
  58. data/test-unit-3.7.8/lib/test/unit/ui/testrunner.rb +53 -0
  59. data/test-unit-3.7.8/lib/test/unit/ui/testrunnermediator.rb +131 -0
  60. data/test-unit-3.7.8/lib/test/unit/ui/testrunnerutilities.rb +41 -0
  61. data/test-unit-3.7.8/lib/test/unit/ui/xml/testrunner.rb +225 -0
  62. data/test-unit-3.7.8/lib/test/unit/util/backtracefilter.rb +65 -0
  63. data/test-unit-3.7.8/lib/test/unit/util/memory-usage.rb +47 -0
  64. data/test-unit-3.7.8/lib/test/unit/util/method-owner-finder.rb +28 -0
  65. data/test-unit-3.7.8/lib/test/unit/util/observable.rb +86 -0
  66. data/test-unit-3.7.8/lib/test/unit/util/output.rb +32 -0
  67. data/test-unit-3.7.8/lib/test/unit/util/procwrapper.rb +48 -0
  68. data/test-unit-3.7.8/lib/test/unit/version.rb +5 -0
  69. data/test-unit-3.7.8/lib/test/unit/warning.rb +3 -0
  70. data/test-unit-3.7.8/lib/test/unit/worker-context.rb +20 -0
  71. data/test-unit-3.7.8/lib/test/unit.rb +521 -0
  72. data/test-unit-3.7.8/lib/test-unit.rb +19 -0
  73. data/test-unit-3.7.8/sample/adder.rb +13 -0
  74. data/test-unit-3.7.8/sample/subtracter.rb +12 -0
  75. data/test-unit-3.7.8/sample/test_adder.rb +20 -0
  76. data/test-unit-3.7.8/sample/test_subtracter.rb +20 -0
  77. data/test-unit-3.7.8/sample/test_user.rb +23 -0
  78. metadata +117 -0
@@ -0,0 +1,371 @@
1
+ require_relative "data-sets"
2
+
3
+ module Test
4
+ module Unit
5
+ module Data
6
+ class << self
7
+ def included(base)
8
+ base.extend(ClassMethods)
9
+ end
10
+ end
11
+
12
+ module ClassMethods
13
+ # This method provides Data-Driven-Test functionality.
14
+ #
15
+ # Define test data in the test code.
16
+ #
17
+ # @overload data(label, data, options={})
18
+ # @param [String] label specify test case name.
19
+ # @param data specify test data.
20
+ # @param [Hash] options specify options.
21
+ # @option options [Boolean] :keep whether or not to use
22
+ # this data in the following test methods
23
+ #
24
+ # @example data(label, data)
25
+ # data("empty string", [true, ""])
26
+ # data("plain string", [false, "hello"])
27
+ # def test_empty?(data)
28
+ # expected, target = data
29
+ # assert_equal(expected, target.empty?)
30
+ # end
31
+ #
32
+ # @overload data(variable, patterns, options={})
33
+ # @param [Symbol] variable specify test pattern variable name.
34
+ # @param [Array] patterns specify test patterns for the variable.
35
+ # @param [Hash] options specify options.
36
+ # @option options [Boolean] :keep whether or not to use
37
+ # this data in the following test methods
38
+ # @option options [Object] :group the test pattern group.
39
+ # Test matrix is generated for each test pattern group separately.
40
+ #
41
+ # @example data(variable, patterns)
42
+ # data(:x, [1, 2, 3])
43
+ # data(:y, ["a", "b"])
44
+ # def test_patterns(data)
45
+ # # 3 * 2 times executed
46
+ # # 3: the number of patterns of :x
47
+ # # 2: the number of patterns of :y
48
+ # p data
49
+ # # => {:x => 1, :y => "a"}
50
+ # # => {:x => 1, :y => "b"}
51
+ # # => {:x => 2, :y => "a"}
52
+ # # => {:x => 2, :y => "b"}
53
+ # # => {:x => 3, :y => "a"}
54
+ # # => {:x => 3, :y => "b"}
55
+ # end
56
+ #
57
+ # Generates test matrix from variable and patterns pairs.
58
+ #
59
+ # @overload data(data_set, options={})
60
+ # @param [Hash] data_set specify test data as a Hash that
61
+ # key is test label and value is test data.
62
+ # @param [Hash] options specify options.
63
+ # @option options [Boolean] :keep whether or not to use
64
+ # this data in the following test methods
65
+ #
66
+ # @example data(data_set)
67
+ # data("empty string" => [true, ""],
68
+ # "plain string" => [false, "hello"])
69
+ # def test_empty?(data)
70
+ # expected, target = data
71
+ # assert_equal(expected, target.empty?)
72
+ # end
73
+ #
74
+ # @overload data(options={}, &block)
75
+ # @param [Hash] options specify options.
76
+ # @option options [Boolean] :keep whether or not to use
77
+ # this data in the following test methods
78
+ # @yieldreturn [Hash<String, Object>] return test data set
79
+ # as a Hash that key is test label and value is test data.
80
+ #
81
+ # @example data(&block)
82
+ # data do
83
+ # data_set = {}
84
+ # data_set["empty string"] = [true, ""]
85
+ # data_set["plain string"] = [false, "hello"]
86
+ # data_set
87
+ # end
88
+ # def test_empty?(data)
89
+ # expected, target = data
90
+ # assert_equal(expected, target.empty?)
91
+ # end
92
+ #
93
+ # @overload data(options={}, &block)
94
+ # @param [Hash] options specify options.
95
+ # @option options [Boolean] :keep whether or not to use
96
+ # this data in the following test methods
97
+ # @yieldreturn [Array<Symbol, Array>] return test data set
98
+ # as an Array of variable and patterns.
99
+ #
100
+ # @example data(&block)
101
+ # data do
102
+ # patterns = 3.times.to_a
103
+ # [:x, patterns]
104
+ # end
105
+ # data do
106
+ # patterns = []
107
+ # character = "a"
108
+ # 2.times.each do
109
+ # patterns << character
110
+ # character = character.succ
111
+ # end
112
+ # [:y, patterns]
113
+ # end
114
+ # def test_patterns(data)
115
+ # # 3 * 2 times executed
116
+ # # 3: the number of patterns of :x
117
+ # # 2: the number of patterns of :y
118
+ # p data
119
+ # # => {:x => 0, :y => "a"}
120
+ # # => {:x => 0, :y => "b"}
121
+ # # => {:x => 1, :y => "a"}
122
+ # # => {:x => 1, :y => "b"}
123
+ # # => {:x => 2, :y => "a"}
124
+ # # => {:x => 2, :y => "b"}
125
+ # end
126
+ #
127
+ # Generates test matrix from variable and patterns pairs.
128
+ #
129
+ def data(*arguments, &block)
130
+ options = nil
131
+ n_arguments = arguments.size
132
+ case n_arguments
133
+ when 0
134
+ raise ArgumentError, "no block is given" unless block_given?
135
+ data_set = block
136
+ when 1
137
+ if block_given?
138
+ data_set = block
139
+ options = arguments[0]
140
+ else
141
+ data_set = arguments[0]
142
+ end
143
+ when 2
144
+ case arguments[0]
145
+ when String
146
+ data_set = {arguments[0] => arguments[1]}
147
+ when Hash
148
+ data_set = arguments[0]
149
+ options = arguments[1]
150
+ else
151
+ variable = arguments[0]
152
+ patterns = arguments[1]
153
+ data_set = [variable, patterns]
154
+ end
155
+ when 3
156
+ case arguments[0]
157
+ when String
158
+ data_set = {arguments[0] => arguments[1]}
159
+ options = arguments[2]
160
+ else
161
+ variable = arguments[0]
162
+ patterns = arguments[1]
163
+ data_set = [variable, patterns]
164
+ options = arguments[2]
165
+ end
166
+ else
167
+ message = "wrong number arguments(#{n_arguments} for 0..3)"
168
+ raise ArgumentError, message
169
+ end
170
+ options ||= {}
171
+ data_sets = current_attribute(:data)[:value] || DataSets.new
172
+ data_sets.add(data_set, options)
173
+ if options[:keep] or data_sets.have_keep?
174
+ keep_hook = lambda do |attr|
175
+ attr.merge(value: attr[:value].keep)
176
+ end
177
+ options = options.merge(keep: true, keep_hook: keep_hook)
178
+ end
179
+ attribute(:data, data_sets, options)
180
+ end
181
+
182
+ # This method provides Data-Driven-Test functionality.
183
+ #
184
+ # Load test data from the file. This is shorthand to load
185
+ # test data from file. If you want to load complex file, you
186
+ # can use {#data} with block.
187
+ #
188
+ # @param [String] file_name full path to test data file.
189
+ # File format is automatically detected from filename extension.
190
+ # @raise [ArgumentError] if `file_name` is not supported file format.
191
+ # @see Loader#load
192
+ #
193
+ # @example Load data from CSV file
194
+ # load_data("/path/to/test-data.csv")
195
+ # def test_empty?(data)
196
+ # assert_equal(data["expected"], data["target"].empty?)
197
+ # end
198
+ #
199
+ def load_data(file_name)
200
+ loader = Loader.new(self)
201
+ loader.load(file_name)
202
+ end
203
+
204
+ class Loader
205
+ # @api private
206
+ def initialize(test_case)
207
+ @test_case = test_case
208
+ end
209
+
210
+ # Load data from file.
211
+ #
212
+ # @param [String] file_name full path to test data file.
213
+ # File format is automatically detected from filename extension.
214
+ # @raise [ArgumentError] if `file_name` is not supported file format.
215
+ # @see #load_csv
216
+ # @see #load_tsv
217
+ # @api private
218
+ def load(file_name)
219
+ case File.extname(file_name).downcase
220
+ when ".csv"
221
+ load_csv(file_name)
222
+ when ".tsv"
223
+ load_tsv(file_name)
224
+ else
225
+ raise ArgumentError, "unsupported file format: <#{file_name}>"
226
+ end
227
+ end
228
+
229
+ # Load data from CSV file.
230
+ #
231
+ # There are 2 types of CSV file as following examples.
232
+ # First, there is a header on first row and it's first column is "label".
233
+ # Another, there is no header in the file.
234
+ #
235
+ # @example Load data from CSV file with header
236
+ # # test-data.csv:
237
+ # # label,expected,target
238
+ # # empty string,true,""
239
+ # # plain string,false,hello
240
+ # #
241
+ # load_data("/path/to/test-data.csv")
242
+ # def test_empty?(data)
243
+ # assert_equal(data["expected"], data["target"].empty?)
244
+ # end
245
+ #
246
+ # @example Load data from CSV file without header
247
+ # # test-data-without-header.csv:
248
+ # # empty string,true,""
249
+ # # plain string,false,hello
250
+ # #
251
+ # load_data("/path/to/test-data-without-header.csv")
252
+ # def test_empty?(data)
253
+ # expected, target = data
254
+ # assert_equal(expected, target.empty?)
255
+ # end
256
+ #
257
+ # @api private
258
+ def load_csv(file_name)
259
+ require 'csv'
260
+ first_row = true
261
+ header = nil
262
+ CSV.foreach(file_name) do |row|
263
+ if first_row
264
+ first_row = false
265
+ if row.first == "label"
266
+ header = row[1..-1]
267
+ next
268
+ end
269
+ end
270
+
271
+ set_test_data(header, row)
272
+ end
273
+ end
274
+
275
+ # Load data from TSV file.
276
+ #
277
+ # There are 2 types of TSV file as following examples.
278
+ # First, there is a header on first row and it's first column is "label".
279
+ # Another, there is no header in the file.
280
+ #
281
+ # @example Load data from TSV file with header
282
+ # # test-data.tsv:
283
+ # # label expected target
284
+ # # empty string true ""
285
+ # # plain string false hello
286
+ # #
287
+ # load_data("/path/to/test-data.tsv")
288
+ # def test_empty?(data)
289
+ # assert_equal(data["expected"], data["target"].empty?)
290
+ # end
291
+ #
292
+ # @example Load data from TSV file without header
293
+ # # test-data-without-header.tsv:
294
+ # # empty string true ""
295
+ # # plain string false hello
296
+ # #
297
+ # load_data("/path/to/test-data-without-header.tsv")
298
+ # def test_empty?(data)
299
+ # expected, target = data
300
+ # assert_equal(expected, target.empty?)
301
+ # end
302
+ #
303
+ # @api private
304
+ def load_tsv(file_name)
305
+ require "csv"
306
+ if CSV.const_defined?(:VERSION)
307
+ first_row = true
308
+ header = nil
309
+ CSV.foreach(file_name, :col_sep => "\t") do |row|
310
+ if first_row
311
+ first_row = false
312
+ if row.first == "label"
313
+ header = row[1..-1]
314
+ next
315
+ end
316
+ end
317
+
318
+ set_test_data(header, row)
319
+ end
320
+ else
321
+ # for old CSV library
322
+ first_row = true
323
+ header = nil
324
+ CSV.open(file_name, "r", "\t") do |row|
325
+ if first_row
326
+ first_row = false
327
+ if row.first == "label"
328
+ header = row[1..-1]
329
+ next
330
+ end
331
+ end
332
+
333
+ set_test_data(header, row)
334
+ end
335
+ end
336
+ end
337
+
338
+ private
339
+ def normalize_value(value)
340
+ return true if value == "true"
341
+ return false if value == "false"
342
+ begin
343
+ Integer(value)
344
+ rescue ArgumentError
345
+ begin
346
+ Float(value)
347
+ rescue ArgumentError
348
+ value
349
+ end
350
+ end
351
+ end
352
+
353
+ def set_test_data(header, row)
354
+ label = row.shift
355
+ if header
356
+ data = {}
357
+ header.each_with_index do |key, i|
358
+ data[key] = normalize_value(row[i])
359
+ end
360
+ else
361
+ data = row.collect do |cell|
362
+ normalize_value(cell)
363
+ end
364
+ end
365
+ @test_case.data(label, data)
366
+ end
367
+ end
368
+ end
369
+ end
370
+ end
371
+ end