Module: KorInputMarkdownTest
- Defined in:
- lib/kor/input/markdown_test.rb
Instance Method Summary collapse
- #go ⇒ Object
- #test_gets(t) ⇒ Object
- #test_head(t) ⇒ Object
- #test_main(m) ⇒ Object
- #test_with_key(t) ⇒ Object
Instance Method Details
#go ⇒ Object
115 116 117 118 119 |
# File 'lib/kor/input/markdown_test.rb', line 115 def go [yield, nil] rescue Exception => err [nil, err] end |
#test_gets(t) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/kor/input/markdown_test.rb', line 75 def test_gets(t) @io.rewind md = Kor::Input::Markdown.new(@io) md.head value = md.gets if value != %w(1 2 3) t.error("expect #{%w(1 2 3)} got #{value}") end value = md.gets if value != %w(a b c) t.error("expect #{%w(a b c)} got #{value}") end 2.times do value = md.gets if value != nil t.error("expect nil got #{value}") end end @io2.rewind md = Kor::Input::Markdown.new(@io2) md.head value = md.gets if value != %w(1 2 3) t.error("expect #{%w(1 2 3)} got #{value}") end value = md.gets if value != %w(a b c) t.error("expect #{%w(a b c)} got #{value}") end 2.times do value = md.gets if value != nil t.error("expect nil got #{value}") end end end |
#test_head(t) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/kor/input/markdown_test.rb', line 21 def test_head(t) md = Kor::Input::Markdown.new(StringIO.new) _, err = go { md.head } unless Kor::ReadError === err t.error("expect raise an error Kor::ReadError got #{err.class}:#{err}") end md = Kor::Input::Markdown.new(StringIO.new("|foo|\n")) _, err = go { md.head } unless Kor::ReadError === err t.error("expect raise an error Kor::ReadError got #{err.class}:#{err}") end @io.rewind md = Kor::Input::Markdown.new(@io) head = md.head if head != %w(foo bar baz) t.error("expect #{%w(foo bar baz)} got #{head}") end @io2.rewind md = Kor::Input::Markdown.new(@io2) head = md.head if head != %w(foo bar baz) t.error("expect #{%w(foo bar baz)} got #{head}") end end |
#test_main(m) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/kor/input/markdown_test.rb', line 5 def test_main(m) @io = StringIO.new("| foo | bar | baz |\n| --- | --- | --- |\n| 1 | 2 | 3 |\n| a | b | c |\n") @io2 = StringIO.new("foo | bar | baz |\n--- | --- | ---\n| 1 | 2 | 3\na | b | c |\n") exit m.run end |
#test_with_key(t) ⇒ 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 |
# File 'lib/kor/input/markdown_test.rb', line 49 def test_with_key(t) @io.rewind md = Kor::Input::Markdown.new(@io) opt = OptionParser.new md.parse(opt) @io.rewind opt.parse ["--key=bar,foo,non"] actual = md.head expect = %w(foo bar) if actual != expect t.error("expect #{expect} got #{actual}") end expects = [ %w(1 2), %w(a b), nil, nil, nil, nil, nil ].each do |expect| actual = md.gets if actual != expect t.error("expect #{expect} got #{actual}") end end end |