citeproc-ruby 0.0.6 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.document +4 -0
  4. data/.gitignore +10 -0
  5. data/.rspec +3 -0
  6. data/.simplecov +4 -0
  7. data/.travis.yml +17 -0
  8. data/.yardopts +2 -0
  9. data/AGPL +662 -0
  10. data/BSDL +29 -0
  11. data/Gemfile +42 -0
  12. data/Guardfile +14 -0
  13. data/README.md +32 -76
  14. data/Rakefile +60 -0
  15. data/citeproc-ruby.gemspec +46 -0
  16. data/cucumber.yml +1 -0
  17. data/features/bibliography.feature +25 -0
  18. data/features/name_options.feature +37 -0
  19. data/features/names.feature +192 -0
  20. data/features/renderer.feature +74 -0
  21. data/features/sort.feature +50 -0
  22. data/features/step_definitions/renderer.rb +80 -0
  23. data/features/support/env.rb +33 -0
  24. data/features/support/hooks.rb +10 -0
  25. data/lib/citeproc/ruby.rb +32 -0
  26. data/lib/citeproc/ruby/engine.rb +122 -0
  27. data/lib/citeproc/ruby/format.rb +303 -0
  28. data/lib/citeproc/ruby/formats/default.rb +25 -0
  29. data/lib/citeproc/ruby/formats/html.rb +221 -0
  30. data/lib/citeproc/ruby/renderer.rb +140 -0
  31. data/lib/citeproc/ruby/renderer/choose.rb +106 -0
  32. data/lib/citeproc/ruby/renderer/date.rb +90 -0
  33. data/lib/citeproc/ruby/renderer/format.rb +129 -0
  34. data/lib/citeproc/ruby/renderer/group.rb +34 -0
  35. data/lib/citeproc/ruby/renderer/history.rb +40 -0
  36. data/lib/citeproc/ruby/renderer/label.rb +66 -0
  37. data/lib/citeproc/ruby/renderer/layout.rb +20 -0
  38. data/lib/citeproc/ruby/renderer/locale.rb +26 -0
  39. data/lib/citeproc/ruby/renderer/macro.rb +20 -0
  40. data/lib/citeproc/ruby/renderer/names.rb +401 -0
  41. data/lib/citeproc/ruby/renderer/number.rb +41 -0
  42. data/lib/citeproc/ruby/renderer/observer.rb +44 -0
  43. data/lib/citeproc/ruby/renderer/state.rb +96 -0
  44. data/lib/citeproc/ruby/renderer/text.rb +62 -0
  45. data/lib/citeproc/ruby/sort.rb +82 -0
  46. data/lib/citeproc/ruby/version.rb +5 -0
  47. data/spec/citeproc/ruby/engine_spec.rb +94 -0
  48. data/spec/citeproc/ruby/formats/default_spec.rb +159 -0
  49. data/spec/citeproc/ruby/formats/html_spec.rb +162 -0
  50. data/spec/citeproc/ruby/renderer/choose_spec.rb +293 -0
  51. data/spec/citeproc/ruby/renderer/date_spec.rb +173 -0
  52. data/spec/citeproc/ruby/renderer/group_spec.rb +88 -0
  53. data/spec/citeproc/ruby/renderer/history_spec.rb +38 -0
  54. data/spec/citeproc/ruby/renderer/label_spec.rb +225 -0
  55. data/spec/citeproc/ruby/renderer/layout_spec.rb +41 -0
  56. data/spec/citeproc/ruby/renderer/macro_spec.rb +31 -0
  57. data/spec/citeproc/ruby/renderer/names_spec.rb +396 -0
  58. data/spec/citeproc/ruby/renderer/number_spec.rb +120 -0
  59. data/spec/citeproc/ruby/renderer/text_spec.rb +120 -0
  60. data/spec/citeproc/ruby/renderer_spec.rb +65 -0
  61. data/spec/fixtures/items.rb +80 -0
  62. data/{resource/locale → spec/fixtures/locales}/locales-en-US.xml +2 -11
  63. data/{resource/locale → spec/fixtures/locales}/locales-fr-FR.xml +77 -66
  64. data/{resource/style → spec/fixtures/styles}/apa.csl +5 -5
  65. data/spec/spec_helper.rb +67 -14
  66. metadata +121 -211
  67. data/lib/citeproc.rb +0 -100
  68. data/lib/citeproc/bibliography.rb +0 -57
  69. data/lib/citeproc/data.rb +0 -149
  70. data/lib/citeproc/date.rb +0 -133
  71. data/lib/citeproc/formatter.rb +0 -38
  72. data/lib/citeproc/item.rb +0 -53
  73. data/lib/citeproc/name.rb +0 -284
  74. data/lib/citeproc/processor.rb +0 -166
  75. data/lib/citeproc/selector.rb +0 -61
  76. data/lib/citeproc/variable.rb +0 -82
  77. data/lib/citeproc/version.rb +0 -3
  78. data/lib/csl/locale.rb +0 -223
  79. data/lib/csl/node.rb +0 -72
  80. data/lib/csl/nodes.rb +0 -1418
  81. data/lib/csl/renderer.rb +0 -88
  82. data/lib/csl/sort.rb +0 -61
  83. data/lib/csl/style.rb +0 -110
  84. data/lib/csl/term.rb +0 -124
  85. data/lib/extensions/core.rb +0 -43
  86. data/lib/plugins/filters/bibtex.rb +0 -12
  87. data/lib/plugins/formats/default.rb +0 -134
  88. data/lib/plugins/formats/html.rb +0 -67
  89. data/lib/support/attributes.rb +0 -99
  90. data/lib/support/compatibility.rb +0 -83
  91. data/lib/support/tree.rb +0 -80
  92. data/resource/locale/locales-af-ZA.xml +0 -305
  93. data/resource/locale/locales-ar-AR.xml +0 -306
  94. data/resource/locale/locales-bg-BG.xml +0 -305
  95. data/resource/locale/locales-ca-AD.xml +0 -305
  96. data/resource/locale/locales-cs-CZ.xml +0 -305
  97. data/resource/locale/locales-da-DK.xml +0 -305
  98. data/resource/locale/locales-de-AT.xml +0 -304
  99. data/resource/locale/locales-de-CH.xml +0 -304
  100. data/resource/locale/locales-de-DE.xml +0 -332
  101. data/resource/locale/locales-el-GR.xml +0 -305
  102. data/resource/locale/locales-en-GB.xml +0 -304
  103. data/resource/locale/locales-es-ES.xml +0 -305
  104. data/resource/locale/locales-et-EE.xml +0 -304
  105. data/resource/locale/locales-eu.xml +0 -305
  106. data/resource/locale/locales-fa-IR.xml +0 -304
  107. data/resource/locale/locales-fi-FI.xml +0 -304
  108. data/resource/locale/locales-fr-CA.xml +0 -306
  109. data/resource/locale/locales-he-IL.xml +0 -304
  110. data/resource/locale/locales-hu-HU.xml +0 -305
  111. data/resource/locale/locales-is-IS.xml +0 -304
  112. data/resource/locale/locales-it-IT.xml +0 -305
  113. data/resource/locale/locales-ja-JP.xml +0 -305
  114. data/resource/locale/locales-kh-KH.xml +0 -303
  115. data/resource/locale/locales-km-KH.xml +0 -304
  116. data/resource/locale/locales-ko-KR.xml +0 -305
  117. data/resource/locale/locales-mn-MN.xml +0 -306
  118. data/resource/locale/locales-nb-NO.xml +0 -304
  119. data/resource/locale/locales-nl-NL.xml +0 -304
  120. data/resource/locale/locales-nn-NO.xml +0 -304
  121. data/resource/locale/locales-pl-PL.xml +0 -305
  122. data/resource/locale/locales-pt-BR.xml +0 -304
  123. data/resource/locale/locales-pt-PT.xml +0 -305
  124. data/resource/locale/locales-ro-RO.xml +0 -305
  125. data/resource/locale/locales-ru-RU.xml +0 -306
  126. data/resource/locale/locales-sk-SK.xml +0 -304
  127. data/resource/locale/locales-sl-SI.xml +0 -305
  128. data/resource/locale/locales-sr-RS.xml +0 -305
  129. data/resource/locale/locales-sv-SE.xml +0 -305
  130. data/resource/locale/locales-th-TH.xml +0 -304
  131. data/resource/locale/locales-tr-TR.xml +0 -305
  132. data/resource/locale/locales-uk-UA.xml +0 -306
  133. data/resource/locale/locales-vi-VN.xml +0 -305
  134. data/resource/locale/locales-zh-CN.xml +0 -304
  135. data/resource/locale/locales-zh-TW.xml +0 -305
  136. data/resource/schema/csl-categories.rnc +0 -39
  137. data/resource/schema/csl-data.rnc +0 -98
  138. data/resource/schema/csl-terms.rnc +0 -106
  139. data/resource/schema/csl-types.rnc +0 -39
  140. data/resource/schema/csl-variables.rnc +0 -182
  141. data/resource/schema/csl.rnc +0 -941
  142. data/resource/style/bibtex.csl +0 -177
  143. data/resource/style/chicago-annotated-bibliography.csl +0 -513
  144. data/resource/style/chicago-author-date-basque.csl +0 -707
  145. data/resource/style/chicago-author-date-de.csl +0 -394
  146. data/resource/style/chicago-author-date-listing.csl +0 -434
  147. data/resource/style/chicago-author-date.csl +0 -425
  148. data/resource/style/chicago-dated-note-biblio-no-ibid.csl +0 -472
  149. data/resource/style/chicago-fullnote-bibliography-bb.csl +0 -928
  150. data/resource/style/chicago-fullnote-bibliography-delimiter-fixes.csl +0 -972
  151. data/resource/style/chicago-fullnote-bibliography-no-ibid-delimiter-fixes.csl +0 -963
  152. data/resource/style/chicago-fullnote-bibliography-no-ibid.csl +0 -785
  153. data/resource/style/chicago-fullnote-bibliography.csl +0 -803
  154. data/resource/style/chicago-library-list.csl +0 -511
  155. data/resource/style/chicago-note-biblio-no-ibid.csl +0 -514
  156. data/resource/style/chicago-note-bibliography.csl +0 -530
  157. data/resource/style/chicago-note.csl +0 -388
  158. data/resource/style/chicago-quick-copy.csl +0 -685
  159. data/resource/style/ieee.csl +0 -299
  160. data/resource/style/mla-notes.csl +0 -796
  161. data/resource/style/mla-underline.csl +0 -175
  162. data/resource/style/mla-url.csl +0 -214
  163. data/resource/style/mla.csl +0 -394
  164. data/resource/style/vancouver-brackets.csl +0 -256
  165. data/resource/style/vancouver-superscript-bracket-only-year.csl +0 -165
  166. data/resource/style/vancouver-superscript.csl +0 -256
  167. data/resource/style/vancouver.csl +0 -256
  168. data/spec/citeproc/bibliography_spec.rb +0 -45
  169. data/spec/citeproc/citeproc_spec.rb +0 -80
  170. data/spec/citeproc/date_spec.rb +0 -89
  171. data/spec/citeproc/formatter_spec.rb +0 -101
  172. data/spec/citeproc/item_spec.rb +0 -71
  173. data/spec/citeproc/name_spec.rb +0 -30
  174. data/spec/citeproc/processor_spec.rb +0 -61
  175. data/spec/citeproc/selector_spec.rb +0 -82
  176. data/spec/citeproc/variable_spec.rb +0 -69
  177. data/spec/csl/locale_spec.rb +0 -208
  178. data/spec/csl/node_spec.rb +0 -25
  179. data/spec/csl/nodes_spec.rb +0 -145
  180. data/spec/csl/style_spec.rb +0 -62
  181. data/spec/csl/term_spec.rb +0 -56
  182. data/spec/fixtures/dates.yaml +0 -80
  183. data/spec/fixtures/names.yaml +0 -115
  184. data/spec/fixtures/nodes.yaml +0 -245
  185. data/spec/support/attributes_spec.rb +0 -39
  186. data/spec/support/tree_spec.rb +0 -163
@@ -1,245 +0,0 @@
1
- ---
2
- - class: CSL::Nodes::Text
3
- describe:
4
- processing:
5
- returns an empty string by default:
6
- input:
7
- - <text/>
8
- expected:
9
- - ""
10
- item: {}
11
- format: default
12
- handles terms correctly:
13
- item: {}
14
- format: default
15
- input:
16
- - <text term="editorial-director" plural="false" />
17
- - <text term="editorial-director" plural="true" />
18
- - <text term="section" form="symbol" plural="false" />
19
- - <text term="section" form="symbol" plural="true" />
20
- expected:
21
- - editor
22
- - editors
23
- - §
24
- - §§
25
- - class: CSL::Nodes::Number
26
- describe:
27
- processing:
28
- returns an empty string by default:
29
- format: default
30
- input:
31
- - <number/>
32
- expected:
33
- - ""
34
- item: {}
35
- supports variables and return numeric value by default:
36
- format: default
37
- item:
38
- edition: '3'
39
- input:
40
- - <number variable="edition"/>
41
- expected:
42
- - '3'
43
- supports ordinals and roman numbers:
44
- format: default
45
- item:
46
- issue: '1'
47
- volume: '2'
48
- edition: '3'
49
- number: '23'
50
- input:
51
- - <number variable="issue" form="ordinal"/>
52
- - <number variable="volume" form="ordinal"/>
53
- - <number variable="edition" form="ordinal"/>
54
- - <number variable="number" form="ordinal"/>
55
- - <number variable="issue" form="long-ordinal"/>
56
- - <number variable="volume" form="long-ordinal"/>
57
- - <number variable="edition" form="long-ordinal"/>
58
- - <number variable="issue" form="roman"/>
59
- - <number variable="volume" form="roman"/>
60
- - <number variable="edition" form="roman"/>
61
- - <number variable="number" form="roman"/>
62
- - <number variable="number" form="roman" text-case="uppercase"/>
63
- expected:
64
- - 1st
65
- - 2nd
66
- - 3rd
67
- - 23rd
68
- - first
69
- - second
70
- - third
71
- - i
72
- - ii
73
- - iii
74
- - xxiii
75
- - XXIII
76
- - class: CSL::Nodes::Date
77
- describe:
78
- localized processing:
79
- returns an empty string by default for numeric:
80
- format: default
81
- item: {}
82
- input:
83
- - <date form="numeric"/>
84
- expected:
85
- - ""
86
- returns an empty string by default for text:
87
- format: default
88
- item: {}
89
- input:
90
- - <date form="text"/>
91
- expected:
92
- - ""
93
- returns numeric result given date-parts:
94
- format: default
95
- item:
96
- issued:
97
- date-parts:
98
- - - 1983
99
- - 3
100
- - 12
101
- input:
102
- - <date variable="issued" form="numeric"/>
103
- - <date variable="issued" form="numeric" date-parts="year-month-day"/>
104
- - <date variable="issued" form="numeric" date-parts="year-month"/>
105
- - <date variable="issued" form="numeric" date-parts="year"/>
106
- expected:
107
- - '03/12/1983'
108
- - '03/12/1983'
109
- - '03/1983'
110
- - '1983'
111
- returns numeric season correctly:
112
- format: default
113
- item:
114
- issued:
115
- date-parts:
116
- - - 1983
117
- - 3
118
- - 12
119
- season: 1
120
- input:
121
- - <date variable="issued" form="numeric"/>
122
- - <date variable="issued" form="numeric" date-parts="year-month-day"/>
123
- - <date variable="issued" form="numeric" date-parts="year-month"/>
124
- - <date variable="issued" form="numeric" date-parts="year"/>
125
- expected:
126
- - 'Spring/12/1983'
127
- - 'Spring/12/1983'
128
- - 'Spring/1983'
129
- - '1983'
130
- returns string-numeric season correctly:
131
- format: default
132
- item:
133
- issued:
134
- date-parts:
135
- - - 1983
136
- - 3
137
- - 12
138
- season: '2'
139
- input:
140
- - <date variable="issued" form="numeric"/>
141
- - <date variable="issued" form="numeric" date-parts="year-month-day"/>
142
- - <date variable="issued" form="numeric" date-parts="year-month"/>
143
- - <date variable="issued" form="numeric" date-parts="year"/>
144
- expected:
145
- - 'Summer/12/1983'
146
- - 'Summer/12/1983'
147
- - 'Summer/1983'
148
- - '1983'
149
- returns literal season correctly:
150
- format: default
151
- item:
152
- issued:
153
- date-parts:
154
- - - 1983
155
- - 3
156
- - 12
157
- season: 'THE SEASON'
158
- input:
159
- - <date variable="issued" form="numeric"/>
160
- - <date variable="issued" form="numeric" date-parts="year-month-day"/>
161
- - <date variable="issued" form="numeric" date-parts="year-month"/>
162
- - <date variable="issued" form="numeric" date-parts="year"/>
163
- expected:
164
- - 'THE SEASON/12/1983'
165
- - 'THE SEASON/12/1983'
166
- - 'THE SEASON/1983'
167
- - '1983'
168
- returns text result given date-parts:
169
- format: default
170
- item:
171
- issued:
172
- date-parts:
173
- - - 1983
174
- - 3
175
- - 7
176
- input:
177
- - <date variable="issued" form="text"/>
178
- - <date variable="issued" form="text" date-parts="year-month-day"/>
179
- - <date variable="issued" form="text" date-parts="year-month"/>
180
- - <date variable="issued" form="text" date-parts="year"/>
181
- expected:
182
- - 'March 07, 1983'
183
- - 'March 07, 1983'
184
- - 'March 1983'
185
- - '1983'
186
- returns text result given date-parts and overrule:
187
- format: default
188
- item:
189
- issued:
190
- date-parts:
191
- - - 1983
192
- - 3
193
- - 7
194
- input:
195
- - <date variable="issued" form="text"><date-part name="month" form="short"/><date-part name="day" form="numeric"/></date>
196
- - <date variable="issued" form="text" date-parts="year-month-day"><date-part name="month" form="verb-short"/><date-part name="day" form="numeric"/></date>
197
- - <date variable="issued" form="text" date-parts="year-month"><date-part name="month" form="short"/><date-part name="day" form="numeric"/></date>
198
- - <date variable="issued" form="text" date-parts="year"><date-part name="month" form="short"/><date-part name="day" form="numeric"/></date>
199
- expected:
200
- - 'Mar. 7, 1983'
201
- - 'March 7, 1983'
202
- - 'Mar. 1983'
203
- - '1983'
204
- returns text result given date-parts and overrule in HTML:
205
- format: html
206
- item:
207
- issued:
208
- date-parts:
209
- - - 1983
210
- - 3
211
- - 7
212
- input:
213
- - <date variable="issued" form="text"><date-part name="month" form="short"/><date-part name="day" form="numeric"/></date>
214
- - <date variable="issued" form="text" date-parts="year-month-day"><date-part name="month" form="verb-short" text-case="uppercase"/><date-part name="day" form="numeric"/></date>
215
- expected:
216
- - 'Mar. 7, 1983'
217
- - '<span style="text-transform: uppercase">March </span>7, 1983'
218
- non-localized processing:
219
- returns an empty string by default:
220
- format: default
221
- item: {}
222
- input:
223
- - <date/>
224
- expected:
225
- - ""
226
- returns result given date-parts:
227
- format: default
228
- item:
229
- issued:
230
- date-parts:
231
- - - 1983
232
- - 3
233
- - 12
234
- input:
235
- - <date variable="issued"/>
236
- - <date variable="issued"><date-part name="year" form="long" suffix="-"/><date-part name="month" form="numeric" suffix="-"/><date-part name="day" form="numeric"/></date>
237
- - <date variable="issued"><date-part name="year" form="long" suffix="-"/><date-part name="month" form="numeric-leading-zeros" suffix=""/></date>
238
- - <date variable="issued"><date-part name="year"/><date>
239
- - <date variable="issued"><date-part name="year" form="short" suffix=" "/><date-part name="month" form="long" suffix=" "/><date-part name="day" form="ordinal"/></date>
240
- expected:
241
- - ''
242
- - '1983-3-12'
243
- - '1983-03'
244
- - '1983'
245
- - '83 March 12th'
@@ -1,39 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Support::Attributes do
4
-
5
- before(:each) { Object.instance_eval { include Support::Attributes } }
6
-
7
- let(:instance) { o = Object.new }
8
- let(:other) { o = Object.new; o['foo'] = 'bar'; o }
9
-
10
- it { should_not be_nil }
11
- it { should be_empty }
12
-
13
- describe '#attributes' do
14
-
15
- # before(:all) { class Object; attr_fields :value, %w[ is-numeric punctuation-mode ]; end }
16
-
17
- it 'generates setters for attr_field values' do
18
- pending
19
- # lambda { Object.new.is_numeric }.should_not raise_error
20
- end
21
-
22
- it 'generates no other setters' do
23
- lambda { Object.new.some_other_value }.should raise_error
24
- end
25
- end
26
-
27
- describe '#merge' do
28
-
29
- it 'merges non-existent values from other object' do
30
- Object.new.merge(other)['foo'].should == 'bar'
31
- end
32
-
33
- # it 'does not overwrite existing values when merging other object' do
34
- # instance.merge(other)['foo'].should == 'bar'
35
- # end
36
-
37
- end
38
-
39
- end
@@ -1,163 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Support::Tree do
4
-
5
- before(:each) { Object.instance_eval { include Support::Tree } }
6
-
7
- let(:node) { Object.new }
8
-
9
- describe '#children' do
10
- context 'when it has no children' do
11
- it 'returns an empty list' do
12
- node.children.should be_empty
13
- end
14
- end
15
-
16
- context 'when it has children' do
17
- before(:each) { node.add_children([Object.new, Object.new, Object.new]) }
18
-
19
- it 'returns a list of all children' do
20
- node.children.should have(3).items
21
- end
22
- end
23
- end
24
-
25
- describe '#name' do
26
- it 'returns the class name in attribute form by default' do
27
- node.name.should == 'object'
28
- end
29
- end
30
-
31
- describe '#add_children' do
32
- it 'adds a single node to the children array' do
33
- node.add_children(Object.new).children.should have(1).item
34
- end
35
-
36
- it 'adds a list of nodes to the children array' do
37
- node.add_children(Object.new, Object.new).children.should have(2).item
38
- end
39
-
40
- it 'adds an array of nodes to the children array' do
41
- node.add_children([Object.new, Object.new]).children.should have(2).item
42
- end
43
-
44
- it 'sets self as parent of the added nodes' do
45
- node.add_children([Object.new, Object.new]).children.map(&:parent).uniq.should == [node]
46
- end
47
-
48
- it 'does not alter the state if no argument given' do
49
- node.add_children().children.should be_empty
50
- end
51
-
52
- it 'does not alter the state if nil argument given' do
53
- node.add_children(nil).children.should be_empty
54
- end
55
-
56
- it 'does not alter the state if nil arguments given' do
57
- node.add_children(nil, nil).children.should be_empty
58
- end
59
-
60
- it 'does not alter the state if empty list argument given' do
61
- node.add_children([]).children.should be_empty
62
- end
63
-
64
- it 'does not alter the state if nil list argument given' do
65
- node.add_children([nil, nil]).children.should be_empty
66
- end
67
-
68
- end
69
-
70
- describe '#ancestors' do
71
- context 'when it has no ancestors' do
72
- it 'returns and empty list' do
73
- node.ancestors.should be_empty
74
- end
75
- end
76
-
77
- context 'when it has ancestors' do
78
-
79
- let(:node1) { node.add_children(Object.new).children[0] }
80
- let(:node2) { node1.add_children(Object.new).children[0] }
81
- let(:node3) { node2.add_children(Object.new).children[0] }
82
-
83
- it 'returns a list containing the ancestors (depth 0)' do
84
- node.ancestors.should be_empty
85
- end
86
-
87
- it 'returns a list containing the ancestors (depth 1)' do
88
- node1.ancestors.should == [node]
89
- end
90
-
91
- it 'returns a list containing the ancestors (depth 2)' do
92
- node2.ancestors.should == [node1, node]
93
- end
94
-
95
- it 'returns a list containing the ancestors (depth 3)' do
96
- node3.ancestors.should == [node2, node1, node]
97
- end
98
-
99
- end
100
- end
101
-
102
- describe '#root' do
103
- context 'when it has no ancestors' do
104
- it 'returns itself' do
105
- node.root.should == node
106
- node.should be_root
107
- end
108
- end
109
-
110
- context 'when it has ancestors' do
111
-
112
- let(:node1) { node.add_children(Object.new).children[0] }
113
- let(:node2) { node1.add_children(Object.new).children[0] }
114
- let(:node3) { node2.add_children(Object.new).children[0] }
115
-
116
- it 'returns the root node (depth 0)' do
117
- node.root.should == node
118
- node.should be_root
119
- node.depth.should == 0
120
- end
121
-
122
- it 'returns the root node (depth 1)' do
123
- node1.root.should == node
124
- node1.should_not be_root
125
- node1.depth.should == 1
126
- end
127
-
128
- it 'returns the root node (depth 2)' do
129
- node2.root.should == node
130
- node2.should_not be_root
131
- node2.depth.should == 2
132
- end
133
-
134
- it 'returns the root node (depth 3)' do
135
- node3.root.should == node
136
- node3.should_not be_root
137
- node3.depth.should == 3
138
- end
139
- end
140
- end
141
-
142
- describe 'named child accessors' do
143
-
144
- before(:all) { Object.instance_eval { attr_children :object } }
145
-
146
- context 'when it has no children' do
147
- it 'returns an empty list by default' do
148
- Object.new.object.should be_empty
149
- end
150
- end
151
-
152
- context 'when it has children' do
153
- it 'returns a list of a single child with the matching name' do
154
- Object.new.add_children(Object.new).object.should have(1).item
155
- end
156
-
157
- it 'returns a list of all children with the matching name' do
158
- Object.new.add_children(Object.new, Object.new).object.should have(2).items
159
- end
160
- end
161
- end
162
-
163
- end