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,101 +0,0 @@
1
- module CiteProc
2
- describe Formatter do
3
-
4
- it { should_not be_nil }
5
-
6
- describe '#format' do
7
- it 'returns the current format by default' do
8
- Formatter.new.format.should be_a_kind_of(Format::Default)
9
- end
10
-
11
- it 'applies the current format if arguments are given' do
12
- Formatter.new.format('foo').should == 'foo'
13
- end
14
- end
15
-
16
- describe '#apply' do
17
-
18
- it 'returns an empty string by default' do
19
- Formatter.new.apply.should == ''
20
- end
21
-
22
- context 'using the default style' do
23
-
24
- let(:format) { Formatter.new }
25
-
26
- it 'returns the given string if there are no attributes' do
27
- format.apply('foo') == 'foo'
28
- end
29
-
30
- it 'returns the formatted string (prefix)' do
31
- format.apply('foo', 'prefix' => '@').should == '@foo'
32
- end
33
-
34
- it 'returns the formatted string (suffix)' do
35
- format.apply('foo', 'suffix' => '@').should == 'foo@'
36
- end
37
-
38
- it 'returns the formatted string (affixes)' do
39
- format.apply('foo', 'prefix' => '@', 'suffix' => '@').should == '@foo@'
40
- end
41
-
42
- it 'returns the formatted string (display)' do
43
- format.apply('foo', 'display' => 'block').should == 'foo'
44
- format.apply('foo', 'display' => 'inline').should == 'foo'
45
- format.apply('foo', 'display' => 'right-inline').should == 'foo'
46
- format.apply('foo', 'display' => 'left-margin').should == 'foo'
47
- end
48
-
49
- it 'returns the formatted string (strip periods)' do
50
- format.apply('foo', 'strip-periods' => 'true').should == 'foo'
51
- format.apply('foo.', 'strip-periods' => 'true').should == 'foo'
52
- format.apply('f.oo.', 'strip-periods' => 'true').should == 'f oo'
53
- format.apply('.foo.', 'strip-periods' => 'true').should == 'foo'
54
- format.apply('foo...', 'strip-periods' => 'true').should == 'foo'
55
- end
56
-
57
- it 'returns the formatted string (font-style)' do
58
- format.apply('foo', 'font-style' => 'normal').should == 'foo'
59
- format.apply('foo', 'font-style' => 'italic').should == 'foo'
60
- format.apply('foo', 'font-style' => 'italics').should == 'foo'
61
- format.apply('foo', 'font-style' => 'oblique').should == 'foo'
62
- end
63
-
64
- it 'returns the formatted string (font-variant)' do
65
- format.apply('foo', 'font-variant' => 'normal').should == 'foo'
66
- format.apply('foo', 'font-variant' => 'small-caps').should == 'foo'
67
- end
68
-
69
- it 'returns the formatted string (font-weight)' do
70
- format.apply('foo', 'font-weight' => 'normal').should == 'foo'
71
- format.apply('foo', 'font-weight' => 'bold').should == 'foo'
72
- format.apply('foo', 'font-weight' => 'light').should == 'foo'
73
- end
74
-
75
- it 'returns the formatted string (text-decoration)' do
76
- format.apply('foo', 'text-decoration' => 'none').should == 'foo'
77
- format.apply('foo', 'text-decoration' => 'underline').should == 'foo'
78
- end
79
-
80
- it 'returns the formatted string (vertical-align)' do
81
- format.apply('foo', 'vertical-align' => 'baseline').should == 'foo'
82
- format.apply('foo', 'vertical-align' => 'sub').should == 'foo'
83
- format.apply('foo', 'vertical-align' => 'sup').should == 'foo'
84
- end
85
-
86
- it 'returns the formatted string (text-case)' do
87
- format.apply('foo', 'text-case' => 'none').should == 'foo'
88
- format.apply('foo Foo FOO', 'text-case' => 'lowercase').should == 'foo foo foo'
89
- format.apply('foo Foo FoO', 'text-case' => 'uppercase').should == 'FOO FOO FOO'
90
- format.apply('foo foo foo', 'text-case' => 'capitalize-first').should == 'Foo foo foo'
91
- format.apply('foo FOO fOo', 'text-case' => 'capitalize-all').should == 'Foo Foo Foo'
92
- format.apply('the short story of foo and bar', 'text-case' => 'title').should == 'The Short Story of Foo and Bar'
93
- format.apply('the short story of FOO and BAR', 'text-case' => 'title').should == 'The Short Story of FOO and BAR'
94
- format.apply('the short story of foo and bar', 'text-case' => 'sentence').should == 'The short story of foo and bar'
95
- end
96
-
97
- end
98
-
99
- end
100
- end
101
- end
@@ -1,71 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module CiteProc
4
- describe Item do
5
-
6
- let(:item) { Item.new }
7
-
8
- describe '#new' do
9
- it { should_not be_nil }
10
- end
11
-
12
- describe '.create' do
13
- it 'accepts parameters and returns a new item containing the parameters' do
14
- pending #Item.new(:author => 'Poe, Edgar A.').author.family == 'Poe'
15
- end
16
- end
17
-
18
- describe '#add_observers' do
19
- it 'adds a new observer to the empty list of observers' do
20
- expect {
21
- item.add_observer(stub('observer', :update => nil))
22
- }.to change { item.count_observers }.from(0).to(1)
23
- end
24
-
25
- it 'adds a new observers to the internal list of observers' do
26
- expect {
27
- item.add_observer(stub('observer1', :update => nil))
28
- item.add_observer(stub('observer2', :update => nil))
29
- item.add_observer(stub('observer3', :update => nil))
30
- }.to change { item.count_observers }.from(0).to(3)
31
- end
32
- end
33
-
34
- describe '#delete_observers' do
35
- let(:observer) { stub('observer', :update => nil) }
36
-
37
- it 'raises no error if the list of observers is empty' do
38
- item.delete_observer(observer)
39
- end
40
-
41
- it 'does not alter the list of observers if the given observer is not currently observing the item' do
42
- item.add_observer(observer)
43
- item.count_observers.should == 1
44
- item.delete_observer(stub('observer2'))
45
- item.count_observers.should == 1
46
- end
47
-
48
- it 'removes the given observer from the list of observers' do
49
- item.add_observer(observer)
50
- expect {
51
- item.delete_observer(observer)
52
- }.to change { item.count_observers }.from(1).to(0)
53
- end
54
- end
55
-
56
- describe '#[]' do
57
- it 'returns the value for the given key' do
58
- item['foo'] = 'foo'
59
- item['foo'].should == 'foo'
60
- end
61
-
62
- it 'notifies observers on every variable access' do
63
- observer = stub('observer')
64
- observer.should_receive(:update).once
65
- item.add_observer(observer)
66
- item['foo']
67
- end
68
- end
69
-
70
- end
71
- end
@@ -1,30 +0,0 @@
1
- module CiteProc
2
-
3
- describe Name do
4
- Test::Fixtures::Names.keys.each do |feature|
5
- describe feature do
6
-
7
- Test::Fixtures::Names[feature].each do |test|
8
-
9
- it test['it'] do
10
- names = test['names'].map { |name| Name.new(name) }
11
- expected = test['expected']
12
- options = test['options']
13
-
14
- result = case feature
15
- when 'sort'
16
- names.sort.map(&:to_s)
17
- else
18
- names.map { |name| name.send(feature, options) }
19
- end
20
-
21
- result.should == expected
22
- end
23
-
24
- end
25
-
26
- end
27
- end
28
- end
29
-
30
- end
@@ -1,61 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module CiteProc
4
-
5
- describe Processor do
6
-
7
- let(:processor) { Processor.new }
8
- let(:item) { Hash['author', [{ 'given' => 'Edgar A.', 'family' => 'Poe' }], 'title', 'The Raven', 'type', 'book', 'issued', { 'date-parts' => [[1996]] }, 'publisher', 'Library of America', 'publisher-place', 'New York' ] }
9
-
10
- describe '.process' do
11
- it 'returns an empty string by default' do
12
- Processor.process({}).should == ''
13
- end
14
-
15
- it 'returns a formatted citation' do
16
- Processor.process(item, :mode => :citation, :style => :apa)[0].should == '(Poe, 1996)'
17
- Processor.process(item, :mode => :citation, :style => :mla)[0].should == '(Poe)'
18
- end
19
-
20
- it 'returns a formatted bibliographic entry' do
21
- Processor.process(item, :mode => :bibliography, :style => :apa).should == 'Poe, E. A. (1996). The Raven. New York: Library of America.'
22
- end
23
- end
24
-
25
- describe '#style' do
26
- it 'accepts a style name' do
27
- processor.style = 'apa'
28
- processor.style.should_not be_nil
29
- end
30
- end
31
-
32
- describe '#abbreviations' do
33
- it 'can be set and records new abbreviations' do
34
- expected = { 'default' => { 'container-title' => { 'long' => 'short' } } }
35
- processor.abbreviations = expected
36
- processor.abbreviations.should == expected
37
-
38
- alternate = { 'alternate' => { 'container-title' => { 'long' => 'short' } } }
39
- processor.add_abbreviations(alternate)
40
- processor.abbreviations.should == expected.merge(alternate)
41
-
42
- result = processor.abbreviate('container-title', 'long')
43
- result.should == 'short'
44
-
45
- result = processor.abbreviate('container-title', 'long', 'alternate')
46
- result.should == 'short'
47
-
48
- result = processor.abbreviate('container-title', 'new')
49
- result.should == 'new'
50
-
51
- result = processor.abbreviate('container-title', 'new', 'alternate')
52
- result.should == 'new'
53
-
54
- result = processor.abbreviate('hereinafter', 'new')
55
- result.should == 'new'
56
- end
57
- end
58
-
59
- end
60
-
61
- end
@@ -1,82 +0,0 @@
1
- module CiteProc
2
- describe Selector do
3
- describe '#new' do
4
- it { should_not be_nil }
5
-
6
- %w{ all any none select include exclude }.each do |mode|
7
- it "accepts string/symbol values (#{mode})" do
8
- Selector.new(mode).type.should_not be_nil
9
- # Selector.new(mode.to_sym).type.should_not be_nil
10
- end
11
- end
12
-
13
- describe 'json API support' do
14
-
15
- it 'accepts a json object (select)' do
16
- Selector.new(
17
- "select" => [
18
- {
19
- "field" => "type",
20
- "value" => "book"
21
- },
22
- { "field" => "categories",
23
- "value" => "1990s"
24
- }
25
- ]
26
- ).select.should have(2).items
27
- end
28
-
29
- it 'accepts a json string (select)' do
30
- Selector.new('{
31
- "select" : [
32
- {
33
- "field" : "type",
34
- "value" : "book"
35
- },
36
- { "field" : "categories",
37
- "value" : "1990s"
38
- }
39
- ]
40
- }
41
- ').select.should have(2).items
42
- end
43
-
44
- end
45
- end
46
-
47
- describe '#conditions' do
48
-
49
- let(:condition) { {'field' => 'type', 'value' => 'book'} }
50
-
51
- %w{ select include exclude }.each do |mode|
52
- it "returns the conditions (#{mode})" do
53
- Selector.new(mode => [condition]).conditions.should == [condition]
54
- end
55
- end
56
-
57
- end
58
-
59
- describe '#to_proc' do
60
-
61
- let(:books) { Selector.new('select' => [{'field' => 'type', 'value' => 'book'}]) }
62
- let(:english_books) { Selector.new('select' => [{'field' => 'type', 'value' => 'book'}, {'field' => 'language', 'value' => 'en'}]) }
63
-
64
-
65
- it 'can be used as a block to Array#select' do
66
- [{ 'type' => 'book'}, { 'type' => 'article'}].select(&books).should have(1).item
67
- end
68
-
69
- it 'does not filter out anything by default' do
70
- [1,2,3].select(&Selector.new).should == [1,2,3]
71
- end
72
-
73
- describe 'when the type is :select' do
74
- it 'selects items that match all conditions' do
75
- [{ 'type' => 'book'}, { 'type' => 'article'}, { 'type' => 'book', 'language' => 'en'}].select(&english_books).should have(1).item
76
- end
77
- end
78
-
79
- end
80
-
81
- end
82
- end
@@ -1,69 +0,0 @@
1
- module CiteProc
2
-
3
- describe Variable do
4
-
5
- describe '#new' do
6
- it { should_not be_nil }
7
-
8
- it 'accepts a string value' do
9
- Variable.new('test').value.should == 'test'
10
- end
11
-
12
- it 'accepts an attributes hash' do
13
- Variable.new('value' => 'test').value.should == 'test'
14
- end
15
-
16
- it 'supports self yielding block' do
17
- Variable.new { |v| v.value = 'test' }.value.should == 'test'
18
- end
19
- end
20
-
21
- describe '#to_s' do
22
- it 'displays the value' do
23
- Variable.new('test').to_s.should == 'test'
24
- end
25
- end
26
-
27
- describe '#to_i' do
28
- it 'returns zero by default' do
29
- Variable.new.to_i.should == 0
30
- end
31
-
32
- context 'when the value is numeric' do
33
- %w{ -23 -1 0 1 23 }.each do |value|
34
- it "returns the integer value (#{value})" do
35
- Variable.new(value).to_i.should == value.to_i
36
- end
37
- end
38
-
39
- it 'returns only the first numeric value if there are several' do
40
- Variable.new('testing 1, 2, 3...').to_i.should == 1
41
- end
42
- end
43
- end
44
-
45
-
46
- describe '#numeric?' do
47
- it 'returns false by default' do
48
- Variable.new.should_not be_numeric
49
- end
50
-
51
- context 'variable contains a number' do
52
- it 'returns true (string initialized)' do
53
- Variable.new('23').should be_numeric
54
- Variable.new('foo 23').should be_numeric
55
- end
56
- it 'returns true (integer initialized)' do
57
- Variable.new(23).should be_numeric
58
- end
59
- end
60
-
61
- context 'variable does not contain a number' do
62
- it 'returns false for strings' do
63
- Variable.new('test').should_not be_numeric
64
- end
65
- end
66
- end
67
-
68
- end
69
- end
@@ -1,208 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- module CSL
4
-
5
- describe Locale do
6
-
7
- let(:locale) { Locale.new }
8
-
9
- let(:en) { Locale.new('en-US') }
10
- let(:de) { Locale.new('de-DE') }
11
- let(:fr) { Locale.new('fr-FR') }
12
-
13
- describe '#new' do
14
- it { should_not be_nil }
15
-
16
- it 'defaults to empty language' do
17
- locale.language.should be_nil
18
- end
19
-
20
- it 'defaults to empty region' do
21
- locale.region.should be_nil
22
- end
23
-
24
- it 'contains no terms, date, and options content by default' do
25
- [:terms, :date, :options].each do |m|
26
- locale.send(m).should_not be_nil
27
- locale.send(m).should be_empty
28
- end
29
- end
30
-
31
- it 'parses an XML string' do
32
- locale = Locale.new <<-END
33
- <locale xml:lang="en">
34
- <terms>
35
- <term name="editortranslator" form="short">
36
- <single>ed. &amp; trans.</single>
37
- <multiple>eds. &amp; trans.</multiple>
38
- </term>
39
- </terms>
40
- </locale>
41
- END
42
-
43
- locale.language.should == 'en'
44
- locale.options.should be_empty
45
- locale.terms['editortranslator'].pluralize('form' => 'short').should == 'eds. & trans.'
46
- end
47
- end
48
-
49
- describe '#set' do
50
- it 'sets a new language' do
51
- language = 'de'
52
- locale.language = language
53
- locale.language.should == language
54
- locale.region.should == 'DE'
55
- end
56
-
57
- it 'sets a new language and region' do
58
- language = 'de'
59
- region = 'DE'
60
-
61
- locale.region = region
62
- locale.language.should == language
63
- locale.region.should == region
64
- end
65
-
66
- end
67
-
68
- describe '#terms' do
69
- it 'contains common terms by default' do
70
- en['book'].should_not be_nil
71
- end
72
-
73
- it 'contains variants for form and number' do
74
- en['page']['long'].values.should == ['page', 'pages']
75
- en['page']['short'].values.should == ['p.', 'pp.']
76
- end
77
-
78
- it 'returns different values for different languages' do
79
- [en, de, fr].map do |l|
80
- l['editor'].to_s
81
- end.uniq.length.should == 3
82
- end
83
- end
84
-
85
- describe '#ordinalize' do
86
- context 'in English' do
87
- it 'works' do
88
- result = (1..13).map do |i|
89
- en.ordinalize(i)
90
- end
91
-
92
- expected = %w{ 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th }
93
-
94
- result.should == expected
95
-
96
- result = [20, 21, 22, 23, 24, 100, 101, 102, 103, 104, 113, 123].map do |i|
97
- en.ordinalize(i)
98
- end
99
-
100
- expected = %w{ 20th 21st 22nd 23rd 24th 100th 101st 102nd 103rd 104th 113th 123rd }
101
-
102
- result.should == expected
103
-
104
- end
105
-
106
- it 'long-forms work in English' do
107
- result = (1..13).map do |i|
108
- en.ordinalize(i, 'form' => 'long-ordinal')
109
- end
110
-
111
- expected = %w{ first second third fourth fifth sixth seventh eighth ninth tenth 11th 12th 13th }
112
-
113
- result.should == expected
114
- end
115
- end
116
-
117
- context 'in German' do
118
- it 'works' do
119
- result = (1..13).map do |i|
120
- de.ordinalize(i)
121
- end
122
-
123
- expected = %w{ 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. }
124
-
125
- result.should == expected
126
-
127
- result = [20, 21, 22, 23, 24, 100, 101, 102, 103, 104, 113, 123].map do |i|
128
- de.ordinalize(i)
129
- end
130
-
131
- expected = %w{ 20. 21. 22. 23. 24. 100. 101. 102. 103. 104. 113. 123. }
132
-
133
- result.should == expected
134
-
135
- end
136
-
137
- it 'long-forms work' do
138
- result = (1..13).map do |i|
139
- de.ordinalize(i, 'form' => 'long-ordinal')
140
- end
141
-
142
- expected = %w{ erster zweiter dritter vierter fünfter sechster siebter achter neunter zehnter 11. 12. 13. }
143
-
144
- result.should == expected
145
- end
146
-
147
- it 'female long-forms work' do
148
- result = (1..13).map do |i|
149
- de.ordinalize(i, 'form' => 'long-ordinal', 'gender-form' => 'feminine')
150
- end
151
-
152
- expected = %w{ erste zweite dritte vierte fünfte sechste siebte achte neunte zehnte 11. 12. 13. }
153
-
154
- result.should == expected
155
- end
156
-
157
- end
158
-
159
- end
160
-
161
- describe 'sorting' do
162
-
163
- context 'default priority' do
164
- [['da-DK', 'de-DE'], ['ar-AR', 'el-GR'], ['en-US', 'it-IT'], ['en-US', 'ar-AR'], ['en-US', 'de-DE']].each do |a,b|
165
- it "sorts by default and alphabetically by language (#{a} < #{b})" do
166
- (Locale.new(a) < Locale.new(b)).should be true
167
- end
168
- end
169
-
170
- [['de-AT', 'de-CH'], ['de-DE', 'de-CH'], ['de-DE', 'de-AT'], ['pt-PT', 'pt-BR'], ['zh-CN', 'zh-TW']].each do |a,b|
171
- it "sorts by default and alphabetically by region (#{a} < #{b})" do
172
- (Locale.new(a) < Locale.new(b)).should be true
173
- end
174
- end
175
-
176
- it 'sorts nil languages last' do
177
- [Locale.new, Locale.new('de'), Locale.new('sv-SE')].sort.last.language.should be_nil
178
- end
179
-
180
- it 'sorts nil regions as default' do
181
- %w{ de de-AT de-DE de-CH }.map { |lc| Locale.new(lc) }.sort.map(&:tag).should == %w{ de-DE de-DE de-AT de-CH }
182
- end
183
- end
184
-
185
- context 'language priority (de)' do
186
- [['de-DE', 'da-DK'], ['ar-AR', 'el-GR'], ['en-US', 'it-IT'], ['en-US', 'ar-AR'], ['de-DE', 'en-US']].each do |a,b|
187
- it "sorts by default and alphabetically by language (#{a} < #{b})" do
188
- [Locale.new(a), Locale.new(b)].sort(&Locale.sort('de')).map(&:tag).should == [a,b]
189
- end
190
- end
191
-
192
- [['de-DE', 'de-AT'], ['de-AT', 'ar-AR'], ['en-US', 'ar-AR'], ['de-CH', 'en-US']].each do |a,b|
193
- it "sorts by default and alphabetically by region (#{a} < #{b})" do
194
- [Locale.new(a), Locale.new(b)].sort(&Locale.sort('de')).map(&:tag).should == [a,b]
195
- end
196
- end
197
- end
198
-
199
- context 'regional priority (CH)' do
200
- it 'sorts by default and alphabetically' do
201
- %w{ de-AT de-DE de-CH }.map { |lc| Locale.new(lc) }.sort(&Locale.sort(nil, 'CH')).map(&:tag).should == %w{ de-CH de-DE de-AT }
202
- end
203
- end
204
-
205
- end
206
-
207
- end
208
- end