Class: ODDB::FiPDF::TestParagraphWrapper

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
ext/fipdf/test/paragraph_wrapper_test.rb

Defined Under Namespace

Classes: StubFormat, StubParagraph

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



43
44
45
46
# File 'ext/fipdf/test/paragraph_wrapper_test.rb', line 43

def setup
  @paragraph = StubParagraph.new
  @wrapper = ParagraphWrapper.new(@paragraph)
end

- (Object) test_3_line_paragraph_no_new_page



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'ext/fipdf/test/paragraph_wrapper_test.rb', line 134

def test_3_line_paragraph_no_new_page
  @wrapper.instance_eval "def lines_per_height(*args)\n3\nend\n"
  height = 10
  width = 200
  fmt_name = StubFormat.new
  fmt_name.line_count = 3
  fmt_name.spacing_before = 0
  fmt_name.height = 10
  formats = {
    :preformatted => "foo",
    :paragraph   => fmt_name,
  }
  @paragraph.preformatted = false
  @paragraph.text = "foo baar" 
  result = @wrapper.need_new_page?(height, width, formats)
  assert_equal(false, result)
end

- (Object) test_3_line_paragraph_widow



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'ext/fipdf/test/paragraph_wrapper_test.rb', line 112

def test_3_line_paragraph_widow
  @wrapper.instance_eval "def lines_per_height(*args)\n2\nend\n"
  height = 10
  width = 200
  fmt_name = StubFormat.new
  fmt_name.line_count = 3
  fmt_name.spacing_before = 0
  fmt_name.height = 11
  formats = {
    :preformatted => "foo",
    :paragraph   => fmt_name,
  }
  @paragraph.preformatted = false
  @paragraph.text = "foo baar" 
  result = @wrapper.need_new_page?(height, width, formats)
  assert_equal(true, result)
end

- (Object) test_enforce_page_height_no_widow



57
58
59
60
61
62
63
64
65
66
# File 'ext/fipdf/test/paragraph_wrapper_test.rb', line 57

def test_enforce_page_height_no_widow
  fmt = StubFormat.new
  fmt.line_count = 20
  first_height = 43 
  fmt.size = 5
  column_height = 50
  width = 200
  result = @wrapper.enforce_page_break?(first_height, column_height, width, fmt)
  assert_equal(false, result)
end

- (Object) test_enforce_page_height_with_widow



47
48
49
50
51
52
53
54
55
56
# File 'ext/fipdf/test/paragraph_wrapper_test.rb', line 47

def test_enforce_page_height_with_widow
  fmt = StubFormat.new
  first_height = 45 
  fmt.size = 5
  fmt.line_count = 20
  column_height = 50
  width = 200
  result = @wrapper.enforce_page_break?(first_height, column_height, width, fmt)
  assert_equal(18, result)
end

- (Object) test_format_paragraph_bold



164
165
166
167
168
169
170
171
172
# File 'ext/fipdf/test/paragraph_wrapper_test.rb', line 164

def test_format_paragraph_bold
  paragraph = ODDB::Text::Paragraph.new
  paragraph.set_format(:bold)
  paragraph << "Bold Text!"
  wrapper = ParagraphWrapper.new(paragraph)
  formatted = wrapper.format_text
  expected = "<b>Bold Text!</b>"
  assert_equal(expected, formatted)
end

- (Object) test_format_paragraph_italic



173
174
175
176
177
178
179
180
181
# File 'ext/fipdf/test/paragraph_wrapper_test.rb', line 173

def test_format_paragraph_italic
  paragraph = ODDB::Text::Paragraph.new
  paragraph.set_format(:italic)
  paragraph << "Kursiv Text!"
  wrapper = ParagraphWrapper.new(paragraph)
  formatted = wrapper.format_text
  expected = "<i>Kursiv Text!</i>"
  assert_equal(expected, formatted)
end

- (Object) test_format_paragraph_mixed



182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'ext/fipdf/test/paragraph_wrapper_test.rb', line 182

def test_format_paragraph_mixed
  paragraph = ODDB::Text::Paragraph.new
  paragraph.set_format(:italic)
  paragraph << "Kursiv Text!"
  paragraph.set_format(:bold)
  paragraph << " und ein bisschen Bold..."
  paragraph.set_format(:bold, :italic)
  paragraph << " und auch mal beide." 
  wrapper = ParagraphWrapper.new(paragraph)
  formatted = wrapper.format_text
  expected = "<i>Kursiv Text!</i><b> und ein bisschen Bold...</b><b><i> und auch mal beide.</i></b>"
  assert_equal(expected, formatted)
end

- (Object) test_format_paragraph_symbol



195
196
197
198
199
200
201
202
203
204
205
# File 'ext/fipdf/test/paragraph_wrapper_test.rb', line 195

def test_format_paragraph_symbol
  paragraph = ODDB::Text::Paragraph.new
  paragraph.set_format(:symbol)
  paragraph << "a"
  paragraph.set_format
  paragraph << "-Tocopherol"
  wrapper = ParagraphWrapper.new(paragraph)
  formatted = wrapper.format_text
  expected = "<f:Symbol>a</f>-Tocopherol"
  assert_equal(expected, formatted)
end

- (Object) test_lines_per_height



156
157
158
159
160
161
162
163
# File 'ext/fipdf/test/paragraph_wrapper_test.rb', line 156

def test_lines_per_height
  height = 10
  size = 2
  fmt = StubFormat.new
  fmt.size = 2
  fmt.line_count = 2
  assert_equal(5, @wrapper.lines_per_height(height, fmt))
end

- (Object) test_need_new_page_no



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'ext/fipdf/test/paragraph_wrapper_test.rb', line 89

def test_need_new_page_no
  @wrapper.instance_eval "def lines_per_height(*args)\n2\nend\n"
  height = 15
  width = 200
  fmt_name = StubFormat.new
  fmt_name.line_count = 3
  fmt_name.spacing_before = 0
  fmt_name.height = 8
  fmt_name.size = 2
  formats = {
    :preformatted => "foo",
    :paragraph   => fmt_name,
  }
  @paragraph.preformatted = false
  @paragraph.text = "foo baar"
  result = @wrapper.need_new_page?(height, width, formats)
  assert_equal(false, result)
end

- (Object) test_need_new_page_paragraph_total_more_3_old_2



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'ext/fipdf/test/paragraph_wrapper_test.rb', line 67

def test_need_new_page_paragraph_total_more_3_old_2
  @wrapper.instance_eval "def lines_per_height(*args)\n2\nend\n"
  @paragraph.text = "foo"
  height = 12
  width = 200
  fmt_name = StubFormat.new
  fmt_name.line_count = 20
  fmt_name.spacing_before = 0
  fmt_name.height = 13
  fmt_name.size = 1
  formats = {
    :preformatted  => "foo",
    :paragraph   => fmt_name,
  }
  result = @wrapper.need_new_page?(height, width, formats)
  assert_equal(false, result)
end