Module: KorInputYamlTest
- Defined in:
- lib/kor/input/yaml_test.rb
Instance Method Summary collapse
- #ready ⇒ Object
- #test_e2e(t) ⇒ Object
- #test_gets(t) ⇒ Object
- #test_gets_with_none_guess(t) ⇒ Object
- #test_gets_with_prekeys(t) ⇒ Object
- #test_head(t) ⇒ Object
- #test_head_with_prekeys(t) ⇒ Object
- #test_initialize(t) ⇒ Object
Instance Method Details
#ready ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/kor/input/yaml_test.rb', line 16 def ready io = StringIO.new(<<-YAML) --- foo: 100 bar: 200 --- bar: 500 baz: 600 YAML Kor::Input::Yaml.new(io) end |
#test_e2e(t) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/kor/input/yaml_test.rb', line 104 def test_e2e(t) actual = `ruby -ryaml -e '3.times { [{"a"=>1},{"b"=>2},{"c"=>3}].each{|h| puts YAML.dump(h)} }' | bundle ex kor yaml --guess-time=3 csv` expect = <<-CSV a,b,c 1,, ,2, ,,3 1,, ,2, ,,3 1,, ,2, ,,3 CSV if actual != expect t.error("expect #{expect.inspect} got #{actual.inspect}") end end |
#test_gets(t) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/kor/input/yaml_test.rb', line 50 def test_gets(t) yaml = ready yaml.head expects = [ [100, 200, nil], [nil, 500, 600], nil, nil, nil, nil, nil ].each do |expect| actual = yaml.gets if actual != expect t.error("expect #{expect} got #{actual}") end end end |
#test_gets_with_none_guess(t) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/kor/input/yaml_test.rb', line 66 def test_gets_with_none_guess(t) yaml = ready opt = OptionParser.new yaml.parse(opt) opt.parse ["--guess-time=0"] yaml.head expects = [ [100, 200, nil], [nil, 500, 600], nil, nil, nil, nil, nil ].each do |expect| actual = yaml.gets if actual != expect t.error("expect #{expect} got #{actual}") end end end |
#test_gets_with_prekeys(t) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/kor/input/yaml_test.rb', line 85 def test_gets_with_prekeys(t) yaml = ready opt = OptionParser.new yaml.parse(opt) opt.parse ["--key=bar,foo"] yaml.head expects = [ [200, 100], [500, nil], nil, nil, nil, nil, nil ].each do |expect| actual = yaml.gets if actual != expect t.error("expect #{expect} got #{actual}") end end end |
#test_head(t) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/kor/input/yaml_test.rb', line 28 def test_head(t) yaml = ready head = yaml.head expect = %w(foo bar baz) if head != expect t.error("expect #{expect} got #{head}") end end |
#test_head_with_prekeys(t) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/kor/input/yaml_test.rb', line 37 def test_head_with_prekeys(t) yaml = ready opt = OptionParser.new yaml.parse(opt) opt.parse ["--key=bar,foo"] head = yaml.head expect = ["bar", "foo"] if head != expect t.error("expect #{expect} got #{head}") end end |
#test_initialize(t) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/kor/input/yaml_test.rb', line 4 def test_initialize(t) _, err = go { Kor::Input::Yaml.new } unless ArgumentError === err t.error("expect raise an ArgumentError got #{err.class}:#{err}") end _, err = go { Kor::Input::Yaml.new(nil) } if err != nil t.error("expect not raise an error got #{err.class}:#{err}") end end |