Class: ADSP::Test::Stream::ReaderHelpers
- Inherits:
-
Minitest::Test
- Object
- Minitest::Test
- ADSP::Test::Stream::ReaderHelpers
- Defined in:
- lib/adsp/test/stream/reader_helpers.rb
Overview
ADSP::Test::Stream::ReaderHelpers class.
Constant Summary collapse
- Target =
Mock::Stream::Reader
- Option =
Test::Option
- String =
Mock::String
- ARCHIVE_PATH =
Common::ARCHIVE_PATH
- ENCODINGS =
Common::ENCODINGS
- TRANSCODE_OPTIONS =
Common::TRANSCODE_OPTIONS
- TEXTS =
Common::TEXTS
- LARGE_TEXTS =
Common::LARGE_TEXTS
- BUFFER_LENGTH_NAMES =
%i[source_buffer_length destination_buffer_length].freeze
- BUFFER_LENGTH_MAPPING =
{ :source_buffer_length => :destination_buffer_length, :destination_buffer_length => :source_buffer_length } .freeze
- LIMITS =
[nil, 1].freeze
Instance Method Summary collapse
- #get_compatible_decompressor_options(compressor_options, &block) ⇒ Object
- #parallel_compressor_options(&block) ⇒ Object
- #test_byte ⇒ Object
- #test_char ⇒ Object
- #test_char_encoding ⇒ Object
-
#test_invalid_gets ⇒ Object
– lines –.
-
#test_invalid_open ⇒ Object
– etc –.
- #test_invalid_ungetbyte ⇒ Object
-
#test_invalid_ungetc ⇒ Object
– char –.
- #test_invalid_ungetline ⇒ Object
- #test_lines ⇒ Object
- #test_lines_encoding ⇒ Object
- #test_open ⇒ Object
- #test_open_with_large_texts ⇒ Object
Instance Method Details
#get_compatible_decompressor_options(compressor_options, &block) ⇒ Object
412 413 414 |
# File 'lib/adsp/test/stream/reader_helpers.rb', line 412 def (, &block) option. , BUFFER_LENGTH_MAPPING, &block end |
#parallel_compressor_options(&block) ⇒ Object
408 409 410 |
# File 'lib/adsp/test/stream/reader_helpers.rb', line 408 def (&block) Common. option.(BUFFER_LENGTH_NAMES), &block end |
#test_byte ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/adsp/test/stream/reader_helpers.rb', line 49 def test_byte do |, worker_index| archive_path = Common.get_path ARCHIVE_PATH, worker_index TEXTS.each do |text| write_archive archive_path, text, do || target.open archive_path, do |instance| # getbyte byte = instance.getbyte instance.ungetbyte byte unless byte.nil? # readbyte begin byte = instance.readbyte instance.ungetc byte rescue ::EOFError # ok end # each_byte decompressed_text = "".b instance.each_byte { |current_byte| decompressed_text << current_byte } decompressed_text.force_encoding text.encoding assert_equal text, decompressed_text end end end end end |
#test_char ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/adsp/test/stream/reader_helpers.rb', line 97 def test_char do |, worker_index| archive_path = Common.get_path ARCHIVE_PATH, worker_index TEXTS.each do |text| write_archive archive_path, text, do || target.open archive_path, do |instance| # getc char = instance.getc instance.ungetc char unless char.nil? # readchar begin char = instance.readchar instance.ungetc char rescue ::EOFError # ok end # each_char decompressed_text = "".b instance.each_char { |current_char| decompressed_text << current_char } decompressed_text.force_encoding text.encoding assert_equal text, decompressed_text end end end end end |
#test_char_encoding ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/adsp/test/stream/reader_helpers.rb', line 133 def test_char_encoding do |, worker_index| archive_path = Common.get_path ARCHIVE_PATH, worker_index TEXTS.each do |text| write_archive archive_path, text, external_encoding = text.encoding (ENCODINGS - [external_encoding]).each do |internal_encoding| target_text = text.encode internal_encoding, **TRANSCODE_OPTIONS do || target.open archive_path, do |instance| instance.set_encoding external_encoding, internal_encoding, TRANSCODE_OPTIONS # getc char = instance.getc unless char.nil? assert_equal internal_encoding, char.encoding instance.ungetc char end # readchar begin char = instance.readchar assert_equal internal_encoding, char.encoding instance.ungetc char rescue ::EOFError # ok end # each_char decompressed_text = ::String.new :encoding => internal_encoding instance.each_char do |current_char| assert_equal internal_encoding, current_char.encoding decompressed_text << current_char end assert_equal target_text, decompressed_text end end end end end end |
#test_invalid_gets ⇒ Object
– lines –
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/adsp/test/stream/reader_helpers.rb', line 188 def test_invalid_gets instance = target.new ::StringIO.new (Validation::INVALID_STRINGS - [nil, 1, 1.1]).each do |invalid_string| assert_raises ValidateError do instance.gets invalid_string end end (Validation::INVALID_POSITIVE_INTEGERS - [nil]).each do |invalid_integer| assert_raises ValidateError do instance.gets nil, invalid_integer end end end |
#test_invalid_open ⇒ Object
– etc –
359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'lib/adsp/test/stream/reader_helpers.rb', line 359 def test_invalid_open Validation::INVALID_STRINGS.each do |invalid_string| assert_raises ValidateError do target.open(invalid_string) {} # no-op end end # Proc is required. assert_raises ValidateError do target.open ARCHIVE_PATH end end |
#test_invalid_ungetbyte ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/adsp/test/stream/reader_helpers.rb', line 39 def test_invalid_ungetbyte instance = target.new ::StringIO.new Validation::INVALID_STRINGS.each do |invalid_string| assert_raises ValidateError do instance.ungetbyte invalid_string end end end |
#test_invalid_ungetc ⇒ Object
– char –
87 88 89 90 91 92 93 94 95 |
# File 'lib/adsp/test/stream/reader_helpers.rb', line 87 def test_invalid_ungetc instance = target.new ::StringIO.new Validation::INVALID_STRINGS.each do |invalid_string| assert_raises ValidateError do instance.ungetc invalid_string end end end |
#test_invalid_ungetline ⇒ Object
204 205 206 207 208 209 210 211 212 |
# File 'lib/adsp/test/stream/reader_helpers.rb', line 204 def test_invalid_ungetline instance = target.new ::StringIO.new Validation::INVALID_STRINGS.each do |invalid_string| assert_raises ValidateError do instance.ungetline invalid_string end end end |
#test_lines ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/adsp/test/stream/reader_helpers.rb', line 214 def test_lines do |, worker_index| archive_path = Common.get_path ARCHIVE_PATH, worker_index TEXTS.each do |text| write_archive archive_path, text, separator = if text.empty? nil else text[0] end do || target.open archive_path, do |instance| # lineno assert_equal 0, instance.lineno instance.lineno = 1 assert_equal 1, instance.lineno instance.lineno = 0 assert_equal 0, instance.lineno # gets LIMITS.each do |limit| line = instance.gets limit next if line.nil? assert_equal 1, instance.lineno instance.ungetline line assert_equal 0, instance.lineno # Same test with separator. line = instance.gets separator, limit next if line.nil? assert_equal 1, instance.lineno instance.ungetline line assert_equal 0, instance.lineno end # readline begin line = instance.readline assert_equal 1, instance.lineno instance.ungetline line assert_equal 0, instance.lineno rescue ::EOFError # ok end # readlines lines = instance.readlines lines.each { |current_line| instance.ungetline current_line } decompressed_text = lines.join decompressed_text.force_encoding text.encoding assert_equal text, decompressed_text # each_line decompressed_text = "".b instance.each_line { |current_line| decompressed_text << current_line } decompressed_text.force_encoding text.encoding assert_equal text, decompressed_text end end end end end |
#test_lines_encoding ⇒ Object
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/adsp/test/stream/reader_helpers.rb', line 297 def test_lines_encoding do |, worker_index| archive_path = Common.get_path ARCHIVE_PATH, worker_index TEXTS.each do |text| write_archive archive_path, text, external_encoding = text.encoding (ENCODINGS - [external_encoding]).each do |internal_encoding| target_text = text.encode internal_encoding, **TRANSCODE_OPTIONS separator = if text.empty? nil else text[0] end do || target.open archive_path, do |instance| instance.set_encoding external_encoding, internal_encoding, TRANSCODE_OPTIONS # gets line = instance.gets separator unless line.nil? assert_equal internal_encoding, line.encoding instance.ungetline line end # readline begin line = instance.readline assert_equal internal_encoding, line.encoding instance.ungetline line rescue ::EOFError # ok end # each_line decompressed_text = ::String.new :encoding => internal_encoding instance.each_line do |current_line| assert_equal internal_encoding, current_line.encoding decompressed_text << current_line end assert_equal target_text, decompressed_text end end end end end end |
#test_open ⇒ Object
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
# File 'lib/adsp/test/stream/reader_helpers.rb', line 372 def test_open do |, worker_index| archive_path = Common.get_path ARCHIVE_PATH, worker_index TEXTS.each do |text| write_archive archive_path, text, do || decompressed_text = target.open archive_path, , &:read decompressed_text.force_encoding text.encoding assert_equal text, decompressed_text end end end end |
#test_open_with_large_texts ⇒ Object
389 390 391 392 393 394 395 396 397 398 399 |
# File 'lib/adsp/test/stream/reader_helpers.rb', line 389 def test_open_with_large_texts Common.parallel LARGE_TEXTS do |text, worker_index| archive_path = Common.get_path ARCHIVE_PATH, worker_index write_archive archive_path, text decompressed_text = target.open archive_path, &:read decompressed_text.force_encoding text.encoding assert_equal text, decompressed_text end end |