fork(1) download
  1. require 'minitest/autorun'
  2.  
  3. def parse_fat
  4. #--------------
  5. m=gets
  6. s=->b,l{b.slice!(0,l).to_i 2}
  7. t=->b{'%02d:%02d:%02d %d/%d/%d'%[s[b,5],s[b,6],2*s[b,5],s[b,7]+1980,s[b,4],s[b,5],]}
  8. i=(0..q=32).map{|i|m[i*8,8].to_i 2}
  9. c=i.map(&:chr).join
  10. n=c[0,8].strip
  11. e=c[8,3].strip
  12. e>?!&&n<<?.+e
  13. f=''
  14. 6.times{|j|i[11][j]>0&&f<<%w(RO H S VL SD A)[j]}
  15. $><<[n,f,t[m[112,q]],t[m[176,q]],(f[/VL|SD/]?0:m[-q,q].to_i(2))]*' '
  16. #--------------
  17. end
  18.  
  19. describe 'msdos_fat_parser' do
  20. it 'can parse files' do
  21. file_descriptor = '0111000001110010011011110110011101110010011000010110110101101101011010010110111001100111000001100000000000000000101000100100010001001000110101000000000000000000000000000000000010100010010001000100100011010100000000000000000000000000000000001101000000000000'
  22. expected = 'programm.ing HS 20:18:08 2016/6/20 20:18:08 2016/6/20 53248'
  23. assert_equal expected, call_parse_fat(file_descriptor)
  24. end
  25.  
  26. it 'can parse non-files' do
  27. file_descriptor = '0010000000100000001000000010000001110000011100000110001101100111001000000010000000100000000101000000000000000000010111010110110000111101100111110000000000000000000000000000000010100010010001000100100011010100000000000000000011110000000100111111001011100001'
  28.  
  29. expected = 'ppcg SSD 11:43:24 2010/12/31 20:18:08 2016/6/20 0'
  30. assert_equal expected, call_parse_fat(file_descriptor)
  31. end
  32.  
  33. def call_parse_fat(bit_string)
  34. capture_stdout(bit_string){ parse_fat }
  35. end
  36. end
  37.  
  38. # capture STDIN/STDOUT for testing purposes
  39. require 'stringio'
  40. module Kernel
  41. def capture_stdout(console_input = '')
  42. $stdin = StringIO.new(console_input)
  43. out = StringIO.new
  44. $stdout = out
  45. yield
  46. return out.string.chomp
  47. ensure
  48. $stdout = STDOUT
  49. $stdin = STDIN
  50. end
  51. end
  52.  
  53.  
Success #stdin #stdout 0.08s 10752KB
stdin
Standard input is empty
stdout
Run options: --seed 18049

# Running tests:

..

Finished tests in 0.001109s, 1803.6477 tests/s, 1803.6477 assertions/s.

2 tests, 2 assertions, 0 failures, 0 errors, 0 skips