csl 1.4.5 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +10 -30
  3. data/Rakefile +1 -1
  4. data/csl.gemspec +10 -13
  5. data/lib/csl/locale/term.rb +1 -1
  6. data/lib/csl/version.rb +1 -1
  7. metadata +11 -88
  8. data/.rspec +0 -3
  9. data/.simplecov +0 -4
  10. data/Guardfile +0 -15
  11. data/features/locales/loading.feature +0 -57
  12. data/features/locales/ordinalize.feature +0 -713
  13. data/features/parser/choose.feature +0 -16
  14. data/features/parser/info.feature +0 -27
  15. data/features/parser/localized_dates.feature +0 -35
  16. data/features/parser/terms.feature +0 -28
  17. data/features/step_definitions/locale_steps.rb +0 -36
  18. data/features/step_definitions/parser_steps.rb +0 -40
  19. data/features/step_definitions/style_steps.rb +0 -16
  20. data/features/style/loading.feature +0 -53
  21. data/features/support/env.rb +0 -24
  22. data/spec/csl/info_spec.rb +0 -278
  23. data/spec/csl/locale/date_spec.rb +0 -63
  24. data/spec/csl/locale/style_options_spec.rb +0 -19
  25. data/spec/csl/locale/term_spec.rb +0 -255
  26. data/spec/csl/locale_spec.rb +0 -245
  27. data/spec/csl/node_spec.rb +0 -273
  28. data/spec/csl/parser_spec.rb +0 -112
  29. data/spec/csl/schema_spec.rb +0 -112
  30. data/spec/csl/style/bibliography_spec.rb +0 -7
  31. data/spec/csl/style/choose_spec.rb +0 -66
  32. data/spec/csl/style/citation_spec.rb +0 -7
  33. data/spec/csl/style/date_spec.rb +0 -21
  34. data/spec/csl/style/group_spec.rb +0 -7
  35. data/spec/csl/style/label_spec.rb +0 -44
  36. data/spec/csl/style/layout_spec.rb +0 -7
  37. data/spec/csl/style/macro_spec.rb +0 -7
  38. data/spec/csl/style/names_spec.rb +0 -36
  39. data/spec/csl/style/number_spec.rb +0 -85
  40. data/spec/csl/style/sort_spec.rb +0 -11
  41. data/spec/csl/style/text_spec.rb +0 -7
  42. data/spec/csl/style_spec.rb +0 -137
  43. data/spec/csl/treelike_spec.rb +0 -151
  44. data/spec/fixtures/locales/locales-de-DE.xml +0 -298
  45. data/spec/fixtures/locales/locales-en-GB.xml +0 -304
  46. data/spec/fixtures/locales/locales-en-US.xml +0 -304
  47. data/spec/fixtures/styles/apa.csl +0 -443
  48. data/spec/spec_helper.rb +0 -57
@@ -1,63 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module CSL
4
-
5
- describe Locale::Date do
6
-
7
- let(:date) { Locale::Date.new }
8
-
9
- it { is_expected.not_to be_nil }
10
-
11
- it { is_expected.to be_text }
12
- it { is_expected.not_to be_numeric }
13
-
14
- describe '#parts' do
15
-
16
- it 'returns nil by default' do
17
- expect(date.parts).to be_empty
18
- end
19
-
20
- end
21
-
22
- describe '#to_xml' do
23
-
24
- it 'returns <date/> by default' do
25
- expect(Locale::Date.new.to_xml).to eq('<date/>')
26
- end
27
-
28
- it 'returns <date form="numeric"/> for an empty numeric date' do
29
- expect(Locale::Date.new(:form => 'numeric').to_xml).to eq('<date form="numeric"/>')
30
- end
31
-
32
- end
33
-
34
- end
35
-
36
- describe Locale::DatePart do
37
-
38
- it { is_expected.not_to be_nil }
39
-
40
- it { is_expected.not_to be_day }
41
- it { is_expected.not_to be_month }
42
- it { is_expected.not_to be_year }
43
-
44
- describe '#to_xml' do
45
-
46
- it 'returns <date-part/> by default' do
47
- expect(Locale::DatePart.new.to_xml).to eq("<date-part/>")
48
- end
49
-
50
- it 'returns <date-part name="year"/> when the name is "year"' do
51
- expect(Locale::DatePart.new(:name => 'year').to_xml).to eq('<date-part name="year"/>')
52
- end
53
-
54
- it 'returns <date-part name="month" form="numeric" prefix="-"/> for a numeric month with prefix "-"' do
55
- expect(Locale::DatePart.new(:name => 'month', :form => 'numeric', :prefix => '-').to_xml).to match(/(\s(name|form|prefix)="[^"]+"){3}/)
56
- end
57
-
58
- end
59
-
60
- end
61
-
62
-
63
- end
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module CSL
4
- describe Locale::StyleOptions do
5
-
6
- it { is_expected.not_to be nil }
7
-
8
- it 'punctuation-in-quote is false by default' do
9
- expect(subject[:'punctuation-in-quote']).to be false
10
- end
11
-
12
- describe '#to_xml' do
13
- it 'returns <style-options punctuation-in-quote="false"/> by default' do
14
- expect(subject.to_xml).to match(/<style-options\/>/)
15
- end
16
- end
17
-
18
- end
19
- end
@@ -1,255 +0,0 @@
1
- # coding: utf-8
2
- require 'spec_helper'
3
-
4
- module CSL
5
- describe Locale::Terms do
6
-
7
- it { is_expected.not_to be nil }
8
-
9
- describe '#to_xml' do
10
- it 'returns <terms/> by default' do
11
- expect(subject.to_xml).to eq('<terms/>')
12
- end
13
- end
14
-
15
- describe '.specialize' do
16
- it 'filters the passed in hash to contain only match-able entries' do
17
- expect(Locale::Term.specialize({ :form => 'short', :foo => 'bar' })).to eq({ :form => 'short' })
18
- end
19
- end
20
-
21
- describe '#ordinalize' do
22
-
23
- describe "given standard English terms" do
24
- let(:en) do
25
- Locale::Terms.parse <<-EOS
26
- <terms>
27
- <term name="ordinal">th</term>
28
- <term name="ordinal-01">st</term>
29
- <term name="ordinal-02">nd</term>
30
- <term name="ordinal-03">rd</term>
31
- <term name="ordinal-11">th</term>
32
- <term name="ordinal-12">th</term>
33
- <term name="ordinal-13">th</term>
34
- </terms>
35
- EOS
36
- end
37
-
38
- %w{
39
- ordinal ordinal-01 ordinal-02 ordinal-03 ordinal
40
- }.each_with_index do |ordinal, number|
41
- it "returns #{ordinal.inspect} for #{number}" do
42
- expect(en.ordinalize(number)[:name]).to eq(ordinal)
43
- end
44
- end
45
- end
46
-
47
- end
48
-
49
- describe '#lookup' do
50
-
51
- describe "given standard English terms" do
52
- let(:en) do
53
- Locale::Terms.parse <<-EOS
54
- <terms>
55
- <term name="page" form="short">
56
- <single>p.</single>
57
- <multiple>pp.</multiple>
58
- </term>
59
- <term name="page">
60
- <single>page</single>
61
- <multiple>pages</multiple>
62
- </term>
63
- <term name="section">
64
- <single>section</single>
65
- <multiple>sections</multiple>
66
- </term>
67
- <term name="section" form="short">sec.</term>
68
- <term name="section" form="symbol">
69
- <single>§</single>
70
- <multiple>§§</multiple>
71
- </term>
72
- <term name="editor">
73
- <single>editor</single>
74
- <multiple>editors</multiple>
75
- </term>
76
- <term name="editor" form="short">
77
- <single>ed.</single>
78
- <multiple>eds.</multiple>
79
- </term>
80
- <term name="editor" form="verb">edited by</term>
81
- <term name="editor" form="verb-short">ed.</term>
82
- </terms>
83
- EOS
84
- end
85
-
86
- it 'returns nil if there is no matching term' do
87
- expect(en.lookup(:foo)).to be_nil
88
- end
89
-
90
- it 'returns the long form by default' do
91
- expect(en.lookup(:page)).to be_long
92
- end
93
-
94
- it 'returns the term in the passed-in form if available' do
95
- expect(en.lookup(:section, :form => 'long')).to be_long
96
- expect(en.lookup(:section, :form => 'short')).to be_short
97
- expect(en.lookup(:section, :form => 'symbol')).to be_symbol
98
-
99
- expect(en.lookup(:editor)).to be_long
100
- expect(en.lookup(:editor, :form => 'long')).to be_long
101
- expect(en.lookup(:editor, :form => 'verb')).to be_verb
102
- expect(en.lookup(:editor, :form => 'verb-short')).to be_verb_short
103
- end
104
-
105
- it 'returns the right fallback form if the passed-in form is not available' do
106
- expect(en.lookup(:page, :form => 'verb')).to be_long
107
- expect(en.lookup(:page, :form => 'verb-short')).to be_long
108
- expect(en.lookup(:page, :form => 'symbol')).to be_short
109
- end
110
-
111
- it 'ignores irrelevant options' do
112
- expect(en.lookup(:page, :plural => true)).not_to be_nil
113
- end
114
- end
115
-
116
- end
117
- end
118
-
119
- describe Locale::Term do
120
-
121
- it { is_expected.not_to be_nil }
122
-
123
- it { is_expected.not_to be_gendered }
124
- it { is_expected.to be_neutral }
125
-
126
- it { is_expected.to be_long }
127
-
128
- it { is_expected.not_to be_ordinal }
129
- it { is_expected.not_to be_short_ordinal }
130
- it { is_expected.not_to be_long_ordinal }
131
-
132
- it 'is not a textnode by default' do
133
- expect(subject).not_to be_textnode
134
- end
135
-
136
- it 'is a textnode when the text is "foo"' do
137
- expect(Locale::Term.new { |t| t.text = 'foo' }).to be_textnode
138
- end
139
-
140
- describe 'gender attribute is set' do
141
- let(:m) { Locale::Term.new(:name => 'month-05') { |t| t.masculine!; t.text = 'Mai' } }
142
- let(:f) { Locale::Term.new(:name => 'edition') { |t| t.feminine!; t.text = 'Ausgabe' } }
143
-
144
- it 'is gendered' do
145
- expect(m).to be_gendered
146
- expect(f).to be_gendered
147
- end
148
-
149
- it 'is feminine or masculine' do
150
- expect(m).to be_masculine
151
- expect(f).to be_feminine
152
- end
153
-
154
- it 'is not neutral' do
155
- expect(m).not_to be_neutral
156
- expect(f).not_to be_neutral
157
- end
158
-
159
- describe '#to_xml' do
160
- it 'contains the correct gender' do
161
- expect(m.to_xml).to match(/gender="masculine"/)
162
- expect(f.to_xml).to match(/gender="feminine"/)
163
- end
164
- end
165
-
166
- describe '#match?' do
167
- it 'matches the name when passed a string' do
168
- expect(m).to be_match(:name => 'month-05')
169
- end
170
-
171
- it 'matches the name when passed a pattern' do
172
- expect(m).to be_match(:name => /month-\d\d/)
173
- end
174
-
175
- it 'matches when passed a matching hash without gender' do
176
- expect(f).to be_match(:name => 'edition')
177
- end
178
-
179
- it 'does not match when passed a matching hash with wrong gender' do
180
- expect(f.matches?(:name => 'edition', :gender => 'masculine')).not_to be_truthy
181
- end
182
-
183
- it 'matches when passed a matching hash with matching gender' do
184
- expect(f.matches?(:name => 'edition', :gender => 'feminine')).to be_truthy
185
- end
186
- end
187
-
188
- describe '#exact_match?' do
189
- it 'does not match when passed a matching hash without gender' do
190
- expect(f).not_to be_exact_match(:name => 'edition')
191
- end
192
- end
193
-
194
- describe 'attributes#to_a' do
195
- it 'returns an array of all attribute values of underlying struct' do
196
- expect(f.attributes.to_a).to eq(['edition', 'long', 'feminine', nil, nil])
197
- end
198
- end
199
- end
200
-
201
- describe '#to_s' do
202
- it 'returns an empty string by default' do
203
- expect(Locale::Term.new.to_s).to eq('')
204
- end
205
-
206
- describe 'given a simple term' do
207
- let(:node) { Locale::Term.new { |t| t.text = 'foo' } }
208
-
209
- it "returns the term's text" do
210
- expect(node.to_s).to eq(node.text)
211
- end
212
- end
213
-
214
- describe 'given a compound term' do
215
- let(:node) { Locale::Term.new { |t| t.single = 'shoe'; t.multiple = 'shoes' } }
216
-
217
- it "returns the term's singular form by default" do
218
- expect(node.to_s).to eq(node.singularize)
219
- end
220
-
221
- it "returns the term's plural form when passed :number => :plural" do
222
- expect(node.to_s(:number => :plural)).to eq(node.pluralize)
223
- end
224
-
225
- it "returns the term's plural form when passed :number => 2" do
226
- expect(node.to_s(:number => 2)).to eq(node.pluralize)
227
- end
228
-
229
- it "returns the term's singular form when passed :number => 1" do
230
- expect(node.to_s(:number => 1)).to eq(node.singularize)
231
- end
232
-
233
- it "returns the term's plural form when passed :plural => true" do
234
- expect(node.to_s(:plural => true)).to eq(node.pluralize)
235
- end
236
-
237
- end
238
- end
239
-
240
- describe '#to_xml' do
241
- it 'returns <term/> by default' do
242
- expect(subject.to_xml).to eq('<term/>')
243
- end
244
-
245
- it 'returns <term>foo</term> when the text is "foo"' do
246
- expect(Locale::Term.new { |t| t.text = 'foo' }.to_xml).to eq('<term>foo</term>')
247
- end
248
-
249
- it 'returns <term><multiple>foo</multiple></term> when multiple is "foo"' do
250
- expect(Locale::Term.new { |t| t.multiple = 'foo' }.to_xml).to eq('<term><multiple>foo</multiple></term>')
251
- end
252
-
253
- end
254
- end
255
- end
@@ -1,245 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- require 'spec_helper'
4
-
5
- module CSL
6
-
7
- describe Locale do
8
-
9
- let(:locale) { Locale.new }
10
-
11
- let(:en) { Locale.new('en-US') }
12
- let(:gb) { Locale.new('en-GB') }
13
- let(:de) { Locale.new('de-DE') }
14
-
15
- describe '.regions' do
16
-
17
- it 'returns the default region when passed a language symbol' do
18
- expect(Locale.regions[:en]).to eq(:US)
19
- end
20
-
21
- end
22
-
23
- describe '.languages' do
24
-
25
- describe 'the language hash' do
26
- it 'returns the default language when passed a region string' do
27
- %w{ US en GB en AT de DE de }.map(&:to_sym).each_slice(2) do |region, language|
28
- expect(Locale.languages[region]).to eq(language)
29
- end
30
- end
31
- end
32
-
33
- end
34
-
35
- describe '.normalize' do
36
- {
37
- 'en' => 'en-US',
38
- '-GB' => 'en-GB',
39
- '-BR' => 'pt-BR',
40
- 'de-AT' => 'de-AT'
41
- }.each_pair do |tag, expected|
42
- it "converts #{tag.inspect} to #{expected.inspect}" do
43
- expect(Locale.normalize(tag)).to eq(expected)
44
- end
45
- end
46
- end
47
-
48
- describe '.new' do
49
- it { is_expected.not_to be_nil }
50
-
51
- it 'has no language' do
52
- expect(Locale.new.language).to be_nil
53
- end
54
-
55
- it 'has no region' do
56
- expect(Locale.new.region).to be_nil
57
- end
58
-
59
- it 'contains no dates by default' do
60
- expect(Locale.new.dates).to be_nil
61
- end
62
-
63
- it 'contains no terms by default' do
64
- expect(Locale.new.terms).to be_nil
65
- end
66
-
67
- end
68
-
69
- describe '.load' do
70
-
71
- describe 'when called with "en-GB" ' do
72
- let(:locale) { Locale.load('en-GB') }
73
-
74
- it 'the returned locale has the correct IETF tag' do
75
- expect(locale.to_s).to eq('en-GB')
76
- end
77
-
78
- it 'the locale has language :en' do
79
- expect(locale.language).to eq(:en)
80
- end
81
-
82
- it 'the locale has region :GB' do
83
- expect(locale.region).to eq(:GB)
84
- end
85
-
86
- end
87
-
88
- end
89
-
90
- describe '.parse' do
91
- it 'does not set a default language' do
92
- expect(Locale.parse('<locale/>').language).to be_nil
93
- end
94
- end
95
-
96
- describe '#set' do
97
-
98
- it 'when passed "en-GB" sets language to :en and region to :GB' do
99
- locale.set('en-GB')
100
- expect([locale.language, locale.region]).to eq([:en, :GB])
101
- end
102
-
103
- it 'when passed "de" sets language to :de and region to :DE' do
104
- locale.set('de')
105
- expect([locale.language, locale.region]).to eq([:de, :DE])
106
- end
107
-
108
- it 'when passed "-AT" sets language to :de and region to :AT' do
109
- locale.set('-AT')
110
- expect([locale.language, locale.region]).to eq([:de, :AT])
111
- end
112
-
113
- end
114
-
115
- describe '#merge!' do
116
- let(:locale_with_options) { Locale.new('en', :foo => 'bar') }
117
-
118
- describe 'style options' do
119
- it 'does not change the options if none are set on either locale' do
120
- expect { locale.merge!(en) }.not_to change { locale.options }
121
- end
122
-
123
- it 'creates a duplicate option element if the first locale has no options' do
124
- expect(locale).not_to have_options
125
- locale.merge!(locale_with_options)
126
- expect(locale).to have_options
127
- expect(locale.options[:foo]).to eq('bar')
128
- expect(locale.options).not_to equal(locale_with_options.options)
129
- end
130
-
131
- it 'merges the options if both locales have options' do
132
- locale << Locale::StyleOptions.new(:bar => 'foo')
133
-
134
- expect { locale.merge!(locale_with_options) }.not_to change { locale.options.object_id }
135
-
136
- expect(locale.options[:foo]).to eq('bar')
137
- expect(locale.options[:bar]).to eq('foo')
138
- end
139
-
140
- it 'overrides the options with those in the other locale' do
141
- locale << Locale::StyleOptions.new(:bar => 'foo', :foo => 'foo')
142
- locale.merge!(locale_with_options)
143
- expect(locale.options[:foo]).to eq('bar')
144
- expect(locale.options[:bar]).to eq('foo')
145
- end
146
- end
147
-
148
- describe 'dates' do
149
- it 'does not change the dates if none are set on either locale' do
150
- expect { locale.merge!(en) }.not_to change { locale.dates }
151
- end
152
-
153
- it 'creates duplicate date elements if the first locale has no options' do
154
- locale.merge!(Locale.load('en-US'))
155
- expect(locale).to have_dates
156
- end
157
-
158
- it 'merges dates of both locales' do
159
- locale << Locale::Date.new(:form => 'numeric')
160
-
161
- other = Locale.load('en-US')
162
- locale.merge! other
163
-
164
- expect(locale.dates.length).to eq(other.dates.length)
165
- end
166
- end
167
-
168
- describe 'terms' do
169
- let(:us) { Locale.load('en-US') }
170
-
171
- it 'does not change the terms if none are set on either locale' do
172
- expect { locale.merge!(Locale.new) }.not_to change { locale.terms.to_s }
173
- end
174
-
175
- it 'overrides terms with those of the other locale' do
176
- expect(locale).not_to have_terms
177
-
178
- locale.merge! us
179
- expect(locale).to have_terms
180
- end
181
-
182
- it 'makes copies of the terms' do
183
- locale.merge! us
184
- expect(locale).to have_terms
185
-
186
- expect(locale.terms.first).to eq(us.terms.first)
187
- expect(locale.terms.first).not_to be(us.terms.first)
188
- end
189
- end
190
- end
191
-
192
- describe '#legacy?' do
193
- it 'returns false by default' do
194
- expect(locale).not_to be_legacy
195
- end
196
-
197
- it 'returns true if the version is less than 1.0.1' do
198
- locale.version = '0.8'
199
- expect(locale).to be_legacy
200
- end
201
- end
202
-
203
- describe '#quote' do
204
-
205
- it 'quotes the passed-in string' do
206
- locale.store 'open-quote', '»'
207
- locale.store 'close-quote', '«'
208
-
209
- expect(locale.quote('foo')).to eq('»foo«')
210
- end
211
-
212
- it 'does not alter the string if there are no quotes in the locale' do
213
- expect(locale.quote('foo')).to eq('foo')
214
- end
215
-
216
- it 'adds quotes inside final punctuation if punctuation-in-quote option is set' do
217
- locale.store 'open-quote', '»'
218
- locale.store 'close-quote', '«'
219
-
220
- expect(locale.quote('foo.')).to eq('»foo«.')
221
- expect(locale.quote('foo,')).to eq('»foo«,')
222
-
223
- expect(locale.quote('foo!')).to eq('»foo!«')
224
- expect(locale.quote('foo?')).to eq('»foo?«')
225
-
226
- locale.punctuation_in_quotes!
227
-
228
- expect(locale.quote('foo.')).to eq('»foo.«')
229
- expect(locale.quote('foo,')).to eq('»foo,«')
230
-
231
- expect(locale.quote('foo!')).to eq('»foo!«')
232
- expect(locale.quote('foo?')).to eq('»foo?«')
233
- end
234
-
235
- it 'replaces existing quotes with inner quotes' do
236
- locale.store 'open-quote', '“'
237
- locale.store 'close-quote', '”'
238
- locale.store 'open-inner-quote', '‘'
239
- locale.store 'close-inner-quote', '’'
240
-
241
- expect(locale.quote('“foo”')).to eq('“‘foo’”')
242
- end
243
- end
244
- end
245
- end