Class: TestLineEnder
- Inherits:
-
Test:: Unit::TestCase
- Object
- Test:: Unit::TestCase
- TestLineEnder
- Defined in:
- lib/test_line_ender.rb
Defined Under Namespace
Classes: TLE
Instance Method Summary collapse
- #helper_for_file_test(start_value, expected_value, ending_to_use, new_output_file = false) ⇒ Object
- #helper_for_hexdump(which_file, file_name) ⇒ Object
- #helper_print_output_value(output_value) ⇒ Object
- #helper_print_start_values(start_value, expected_value) ⇒ Object
- #helper_read_file(file_name) ⇒ Object
- #helper_write_file(file_name, value) ⇒ Object
- #setup ⇒ Object
- #teardown ⇒ Object
- #test_mac_to_unix_written_to_new_file ⇒ Object
- #test_mac_to_windows_string_dump ⇒ Object
- #test_mac_to_windows_write_to_same_file ⇒ Object
Instance Method Details
#helper_for_file_test(start_value, expected_value, ending_to_use, new_output_file = false) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/test_line_ender.rb', line 75 def helper_for_file_test(start_value, expected_value, ending_to_use, new_output_file = false) helper_write_file(@file1, start_value) helper_for_hexdump("start", @file1) if new_output_file @tle.output_to_file( @file1, ending_to_use, @file2 ) output_file = @file2 else @tle.output_to_file( @file1, ending_to_use) output_file = @file1 end helper_for_hexdump("output", output_file) if File.exists?(output_file) helper_read_file(output_file) if File.exists?(output_file) end |
#helper_for_hexdump(which_file, file_name) ⇒ Object
107 108 109 110 |
# File 'lib/test_line_ender.rb', line 107 def helper_for_hexdump(which_file, file_name) puts "#{which_file} file looks like this ..." system "hexdump -C #{file_name}" end |
#helper_print_output_value(output_value) ⇒ Object
71 72 73 |
# File 'lib/test_line_ender.rb', line 71 def helper_print_output_value(output_value) puts("output value (as string): #{output_value.inspect}") end |
#helper_print_start_values(start_value, expected_value) ⇒ Object
66 67 68 69 |
# File 'lib/test_line_ender.rb', line 66 def helper_print_start_values(start_value, expected_value) puts("start value ... getting pushed into file1.txt: #{start_value.inspect}") puts("expected value: #{expected_value.inspect}") end |
#helper_read_file(file_name) ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/test_line_ender.rb', line 96 def helper_read_file(file_name) file_string = "" if File.exists?(file_name) file = File.open(file_name, "rb") file.binmode file_string = file.read #puts "contents of file #{file_name} as a string ... #{file_string.inspect}" end file_string end |
#helper_write_file(file_name, value) ⇒ Object
89 90 91 92 93 94 |
# File 'lib/test_line_ender.rb', line 89 def helper_write_file(file_name, value) file = File.new(file_name, "wb") file.binmode file.write(value) file.close end |
#setup ⇒ Object
12 13 14 15 16 17 |
# File 'lib/test_line_ender.rb', line 12 def setup puts 'setup' @tle = TLE.new @file1 = "file1.txt" @file2 = "file2.txt" end |
#teardown ⇒ Object
19 20 21 22 23 24 |
# File 'lib/test_line_ender.rb', line 19 def teardown puts 'teardown' @tle = nil system "rm #{@file1}" if File.exists?(@file1) system "rm #{@file2}" if File.exists?(@file2) end |
#test_mac_to_unix_written_to_new_file ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/test_line_ender.rb', line 26 def test_mac_to_unix_written_to_new_file puts "---> in test: #{__method__} ..." start_value = ["a", "b", "c"].join("\r") expected_value = ["a", "b", "c"].join("\n") helper_print_start_values(start_value, expected_value) output_string = helper_for_file_test(start_value, expected_value , LineEnder::Ending::Unix, true) helper_print_output_value(output_string) assert(File.exists?(@file2), "#{__method__} ... has not written to new file") assert(output_string == expected_value, "#{__method__} ... output string is not a match to expected value") if File.exists?(@file2) end |
#test_mac_to_windows_string_dump ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/test_line_ender.rb', line 51 def test_mac_to_windows_string_dump puts "---> in test: #{__method__} ..." start_value = ["a", "b", "c"].join("\r") expected_value = ["a", "b", "c"].join("\r\n") helper_print_start_values(start_value, expected_value) helper_write_file(@file1, start_value) helper_for_hexdump("start", @file1) output_string= @tle.output_to_string(@file1, LineEnder::Ending::Windows) helper_print_output_value(output_string) assert(output_string == expected_value, "#{__method__} ... output string is not a match to expected value") end |
#test_mac_to_windows_write_to_same_file ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/test_line_ender.rb', line 39 def test_mac_to_windows_write_to_same_file puts "---> in test: #{__method__} ..." start_value = ["a", "b", "c"].join("\r") expected_value = ["a", "b", "c"].join("\r\n") helper_print_start_values(start_value, expected_value) output_string = helper_for_file_test(start_value, expected_value , LineEnder::Ending::Windows) helper_print_output_value(output_string) assert(output_string == expected_value, "#{__method__} ... output string is not a match to expected value") end |