Class: ODDB::FiPDF::TestSectionWrapper

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

Defined Under Namespace

Classes: StubFormat, StubParagraph, StubParagraphWrapper, StubSection

Instance Method Summary collapse

Instance Method Details

#setupObject



48
49
50
51
# File 'ext/fipdf/test/test_section_wrapper.rb', line 48

def setup
	@section = StubSection.new
	@wrapper = SectionWrapper.new(@section)
end

#test_each_paragraphObject



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

def test_each_paragraph
	@section.subheading = "foo\n"
	count = 0
	@wrapper.paragraphs = []
	@wrapper.each_paragraph {
		count += 1
	}
	assert_equal(0, count)
	@wrapper.paragraphs = ["foo"]
	count = 0
	@wrapper.each_paragraph {
		count += 1
	}
	assert_equal(1, count)
	@wrapper.paragraphs = ["foo","baar"]
	count = 0
	@wrapper.each_paragraph {
		count += 1
	}
	assert_equal(2, count)
end

#test_need_new_page_noObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'ext/fipdf/test/test_section_wrapper.rb', line 81

def test_need_new_page_no
	@wrapper.wrapper_class = StubParagraphWrapper
	@section.subheading = "Tinky Winky" 
	fmt_subheading = StubFormat.new
	fmt_subheading.height = 6
	formats = {
		:section => fmt_subheading
	}
	height = 7
	width = "ignored in this test "
	paragraph = StubParagraph.new
	paragraph.need_new_page = false
	@section.paragraphs = [paragraph]
	result = @wrapper.need_new_page?(height, width, formats)
	assert_equal(false, result)
end

#test_need_new_page_with_paragraphObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'ext/fipdf/test/test_section_wrapper.rb', line 65

def test_need_new_page_with_paragraph
	@wrapper.wrapper_class = StubParagraphWrapper
	@section.subheading = "Tinky Winky" 
	fmt_subheading = StubFormat.new
	fmt_subheading.height = 6
	formats = {
		:section => fmt_subheading
	}
	height = 7
	width = "ignored in this test "
	paragraph = StubParagraph.new
	paragraph.need_new_page = true
	@section.paragraphs = [paragraph]
	result = @wrapper.need_new_page?(height, width, formats)
	assert_equal(true, result)
end

#test_need_new_page_with_subheadingObject



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'ext/fipdf/test/test_section_wrapper.rb', line 52

def test_need_new_page_with_subheading
	@wrapper.wrapper_class = StubParagraphWrapper
	@section.subheading = "Tinky Winky" 
	fmt_subheading = StubFormat.new
	fmt_subheading.height = 6
	formats = {
		:section => fmt_subheading
	}
	height = 5
	width = "ignored in this test "
	result = @wrapper.need_new_page?(height, width, formats)
	assert_equal(true, result)
end

#test_prepend_paragraphObject



97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'ext/fipdf/test/test_section_wrapper.rb', line 97

def test_prepend_paragraph
	section = ODDB::Text::Section.new
	section.subheading = 'no newline'
	paragraph = section.next_paragraph
	paragraph << "the Paragraph"

	wrapper = SectionWrapper.new(section)
	para_wrapper = wrapper.first_paragraph
	assert_equal('<i>no newline </i>the Paragraph', para_wrapper.text)
	assert_equal('', wrapper.subheading)
	assert_equal('no newline', section.subheading)
	assert_equal('the Paragraph', paragraph.text)
end