/
test_catalog.rb
136 lines (116 loc) · 2.1 KB
/
test_catalog.rb
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
require 'test_helper'
require 'review/catalog'
class CatalogTest < Test::Unit::TestCase
include ReVIEW
def test_predef
sut = Catalog.new(yaml)
exp =<<-EOS
pre01.re
pre02.re
EOS
assert_equal(exp.chomp, sut.predef)
end
def test_chaps
sut = Catalog.new(yaml)
exp =<<-EOS
ch01.re
ch02.re
EOS
assert_equal(exp.chomp, sut.chaps)
end
def test_chaps_empty
yaml = StringIO.new
sut = Catalog.new(yaml)
assert_equal("", sut.chaps)
end
def test_appendix
sut = Catalog.new(yaml)
exp =<<-EOS
post01.re
post02.re
EOS
assert_equal(exp.chomp, sut.appendix)
end
def test_chaps_with_parts
sut = Catalog.new(yaml_with_parts)
exp =<<-EOS
ch01.re
ch02.re
ch03.re
ch04.re
ch05.re
EOS
assert_equal(exp.chomp, sut.chaps)
end
def test_parts
sut = Catalog.new(yaml_with_parts)
exp =<<-EOS
part1.re
part2.re
EOS
assert_equal(exp.chomp, sut.parts)
end
def test_parts_with_empty
sut = Catalog.new(yaml)
assert_equal("", sut.parts)
end
def test_parts2
sut = Catalog.new(yaml_with_parts)
assert_equal(["ch01.re",
{"part1.re" => ["ch02.re"]},
"ch03.re",
{"part2.re" => ["ch04.re", "ch05.re"]}],
sut.parts_with_chaps)
end
def test_postdef
sut = Catalog.new(yaml)
exp =<<-EOS
back01.re
back02.re
EOS
assert_equal(exp.chomp, sut.postdef)
end
def test_from_object
sut = Catalog.new(yaml_hash)
exp =<<-EOS
ch01.re
ch02.re
EOS
assert_equal(exp.chomp, sut.chaps)
end
private
def yaml
StringIO.new <<-EOS
PREDEF:
- pre01.re
- pre02.re
CHAPS:
- ch01.re
- ch02.re
APPENDIX:
- post01.re
- post02.re
POSTDEF:
- back01.re
- back02.re
EOS
end
def yaml_hash
{"PREDEF" => %w(pre01.re pre02.re),
"CHAPS" => %w(ch01.re ch02.re),
"APPENDIX" => %w(post01.re post02.re),
"POSTDEF" => %w(back01.re back02.re)}
end
def yaml_with_parts
StringIO.new <<-EOS
CHAPS:
- ch01.re
- part1.re:
- ch02.re
- ch03.re
- part2.re:
- ch04.re
- ch05.re
EOS
end
end