Module: Text2svgCLITest
- Defined in:
- lib/text2svg/cli_test.rb
Instance Method Summary collapse
- #capture ⇒ Object
- #check(t) ⇒ Object
- #test_bold(t) ⇒ Object
- #test_encoding(t) ⇒ Object
- #test_italic(t) ⇒ Object
- #test_start(t) ⇒ Object
Instance Method Details
#capture ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/text2svg/cli_test.rb', line 55 def capture out = StringIO.new orig = $stdout $stdout = out yield out.string.dup ensure $stdout = orig end |
#check(t) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/text2svg/cli_test.rb', line 4 def check(t) out = capture do Text2svg::CLI.start end unless String === out t.error 'return value was break' end unless 0 < out.length t.error 'unsupported font?' end if out.strip[0, 4] != '<svg' t.error 'output format was break' end end |
#test_bold(t) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/text2svg/cli_test.rb', line 41 def test_bold(t) ARGV[0] = 'Hello' ARGV[1] = '--font=data/sporq.ttf' ARGV[2] = '--bold' check(t) end |
#test_encoding(t) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/text2svg/cli_test.rb', line 29 def test_encoding(t) [ ['utf-8', "\xEF\x82\x9B".force_encoding(Encoding::ASCII_8BIT)], ['utf-32', "\x00\x00\xFE\xFF\x00\x00\xF0\x9B".force_encoding(Encoding::ASCII_8BIT)], ].each do |(encoding, text)| ARGV[0] = text ARGV[1] = '--font=data/sporq.ttf' ARGV[2] = "--encoding=#{encoding}" check(t) end end |
#test_italic(t) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/text2svg/cli_test.rb', line 48 def test_italic(t) ARGV[0] = 'Hello' ARGV[1] = '--font=data/sporq.ttf' ARGV[2] = '--italic' check(t) end |
#test_start(t) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/text2svg/cli_test.rb', line 19 def test_start(t) %w(left right center).each do |text_align| ARGV[0] = "Hello,\nWorld!" ARGV[1] = '--font=data/sporq.ttf' ARGV[2] = "--text-align=#{text_align}" check(t) end end |