Class: ADSP::Test::Stream::WriterHelpers
- Inherits:
-
Minitest::Test
- Object
- Minitest::Test
- ADSP::Test::Stream::WriterHelpers
- Defined in:
- lib/adsp/test/stream/writer_helpers.rb
Overview
ADSP::Test::Stream::WriterHelpers class.
Constant Summary collapse
- Target =
Mock::Stream::Writer
- Option =
Test::Option
- String =
Mock::String
- ARCHIVE_PATH =
Common::ARCHIVE_PATH
- TEXTS =
Common::TEXTS
- LARGE_TEXTS =
Common::LARGE_TEXTS
- PORTION_LENGTHS =
Common::PORTION_LENGTHS
- LARGE_PORTION_LENGTHS =
Common::LARGE_PORTION_LENGTHS
- BUFFER_LENGTH_NAMES =
i[destination_buffer_length].freeze
- BUFFER_LENGTH_MAPPING =
{ :destination_buffer_length => :destination_buffer_length }.freeze
Instance Method Summary collapse
- #get_compatible_decompressor_options(compressor_options, &block) ⇒ Object
- #parallel_compressor_options(&block) ⇒ Object
- #test_invalid_open ⇒ Object
- #test_invalid_putc ⇒ Object
- #test_open ⇒ Object
- #test_open_with_large_texts ⇒ Object
- #test_print ⇒ Object
- #test_printf ⇒ Object
- #test_putc ⇒ Object
- #test_puts ⇒ Object
- #test_write ⇒ Object
Instance Method Details
#get_compatible_decompressor_options(compressor_options, &block) ⇒ Object
258 259 260 |
# File 'lib/adsp/test/stream/writer_helpers.rb', line 258 def (, &block) option. , BUFFER_LENGTH_MAPPING, &block end |
#parallel_compressor_options(&block) ⇒ Object
254 255 256 |
# File 'lib/adsp/test/stream/writer_helpers.rb', line 254 def (&block) Common. option.(BUFFER_LENGTH_NAMES), &block end |
#test_invalid_open ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/adsp/test/stream/writer_helpers.rb', line 181 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_putc ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/adsp/test/stream/writer_helpers.rb', line 106 def test_invalid_putc instance = target.new ::StringIO.new Validation::INVALID_CHARS.each do |invalid_char| assert_raises ValidateError do instance.putc invalid_char end end end |
#test_open ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/adsp/test/stream/writer_helpers.rb', line 194 def test_open do |, worker_index| archive_path = Common.get_path ARCHIVE_PATH, worker_index TEXTS.each do |text| target.open(archive_path, ) { |instance| instance.write text } compressed_text = ::File.read archive_path, :mode => "rb" do || check_text text, compressed_text, end end end end |
#test_open_with_large_texts ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/adsp/test/stream/writer_helpers.rb', line 210 def test_open_with_large_texts = OCG.new( :text => LARGE_TEXTS, :portion_length => LARGE_PORTION_LENGTHS ) Common. do |, worker_index| text = [:text] portion_length = [:portion_length] archive_path = Common.get_path ARCHIVE_PATH, worker_index sources = get_sources text, portion_length target.open archive_path do |instance| sources.each { |source| instance.write source } end compressed_text = ::File.read archive_path, :mode => "rb" check_text text, compressed_text, {} end end |
#test_print ⇒ Object
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 |
# File 'lib/adsp/test/stream/writer_helpers.rb', line 55 def test_print do |, worker_index| archive_path = Common.get_path ARCHIVE_PATH, worker_index TEXTS.reject(&:empty?).each do |text| PORTION_LENGTHS.each do |portion_length| sources = get_sources text, portion_length field_separator = " ".encode text.encoding record_separator = "\n".encode text.encoding target_text = "".encode text.encoding sources.each { |source| target_text << (source + field_separator) } target_text << record_separator target.open archive_path, do |instance| keyword_args = { :field_separator => field_separator, :record_separator => record_separator } instance.print(*sources, **keyword_args) end compressed_text = ::File.read archive_path, :mode => "rb" do || check_text target_text, compressed_text, end end end end end |
#test_printf ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/adsp/test/stream/writer_helpers.rb', line 84 def test_printf do |, worker_index| archive_path = Common.get_path ARCHIVE_PATH, worker_index TEXTS.each do |text| PORTION_LENGTHS.each do |portion_length| sources = get_sources text, portion_length target.open archive_path, do |instance| sources.each { |source| instance.printf "%s", source } end compressed_text = ::File.read archive_path, :mode => "rb" do || check_text text, compressed_text, end end end end end |
#test_putc ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/adsp/test/stream/writer_helpers.rb', line 116 def test_putc do |, worker_index| archive_path = Common.get_path ARCHIVE_PATH, worker_index TEXTS.each do |text| target.open archive_path, do |instance| # Putc should process numbers and strings. text.chars.each.with_index do |char, index| if index.even? instance.putc char.ord, :encoding => text.encoding else instance.putc char end end end compressed_text = ::File.read archive_path, :mode => "rb" do || check_text text, compressed_text, end end end end |
#test_puts ⇒ Object
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 |
# File 'lib/adsp/test/stream/writer_helpers.rb', line 141 def test_puts do |, worker_index| archive_path = Common.get_path ARCHIVE_PATH, worker_index TEXTS.each do |text| PORTION_LENGTHS.each do |portion_length| newline = "\n".encode text.encoding sources = get_sources text, portion_length sources = sources.map do |source| source.delete_suffix! newline while source.end_with? newline source end target_text = "".encode text.encoding sources.each { |source| target_text << (source + newline) } target.open archive_path, do |instance| # Puts should ignore additional newlines and process arrays. args = sources.map.with_index do |source, index| if index.even? source + newline else [source] end end instance.puts(*args) end compressed_text = ::File.read archive_path, :mode => "rb" do || check_text target_text, compressed_text, end end end end end |
#test_write ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/adsp/test/stream/writer_helpers.rb', line 33 def test_write do |, worker_index| archive_path = Common.get_path ARCHIVE_PATH, worker_index TEXTS.each do |text| PORTION_LENGTHS.each do |portion_length| sources = get_sources text, portion_length target.open archive_path, do |instance| sources.each { |current_source| instance << current_source } end compressed_text = ::File.read archive_path, :mode => "rb" do || check_text text, compressed_text, end end end end end |