1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 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 48 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 74 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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
#!/usr/bin/env ruby -w
# encoding: UTF-8
#
# = test_TextFormatter.rb -- The TaskJuggler III Project Management Software
#
# Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014
# by Chris Schlaeger <cs@taskjuggler.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib') if __FILE__ == $0
require 'test/unit'
require 'taskjuggler/TextFormatter'
class TestTextFormatter < Test::Unit::TestCase
def setup
end
def teardown
end
def test_format_empty
ftr = TaskJuggler::TextFormatter.new(20, 2, 4)
inp = ''
ref = "\n"
out = ftr.format(inp)
assert_equal(ref, out)
end
def test_format_singleWord
ftr = TaskJuggler::TextFormatter.new(20, 2, 4)
inp = 'foo'
ref = " foo\n"
out = ftr.format(inp)
assert_equal(ref, out)
end
def test_format_multipleWords
ftr = TaskJuggler::TextFormatter.new(20, 2, 4)
inp = "foo bar \n foobar"
ref = " foo bar foobar\n"
out = ftr.format(inp)
assert_equal(ref, out)
end
def test_format_multipleLines
ftr = TaskJuggler::TextFormatter.new(23, 2, 4)
inp = <<EOT
The quick brown fox jumps over the lazy dog.
EOT
ref = <<EOT
The quick brown fox
jumps over the lazy
dog.
EOT
out = ftr.format(inp)
assert_equal(ref, out)
end
def test_format_multipleParagraphs
ftr = TaskJuggler::TextFormatter.new(30, 6, 3)
inp = <<EOT
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
EOT
ref = <<EOT
The quick brown fox jumps
over the lazy dog.
The quick brown fox jumps
over the lazy dog.
EOT
out = ftr.format(inp)
assert_equal(ref, out)
end
def test_format_longWords
ftr = TaskJuggler::TextFormatter.new(15, 2)
inp = <<EOT
The quick brown_fox_jumps over the lazy dog.
The quick brown_fox_jumps_over the lazy dog.
The_quick_brown_fox_jumps_over the lazy dog.
EOT
ref = <<EOT
The quick
brown_fox_jumps
over the lazy
dog. The
quick
brown_fox_jumps_over
the lazy dog.
The_quick_brown_fox_jumps_over
the lazy dog.
EOT
out = ftr.format(inp)
assert_equal(ref, out)
end
def test_format_junkSpaces
ftr = TaskJuggler::TextFormatter.new(15, 2)
inp = " foo \n\n \n bar\n \n"
ref = <<EOT
foo
bar
EOT
out = ftr.format(inp)
assert_equal(ref, out)
end
def test_ident
ftr = TaskJuggler::TextFormatter.new(15, 4, 2)
inp = <<EOT
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
EOT
ref = <<EOT
The quick bro
The quick b
EOT
out = ftr.indent(inp)
assert_equal(ref, out)
end
end
|