csl 1.0.0.pre10 → 1.0.0.pre11

Sign up to get free protection for your applications and to get access to all the features.
data/lib/csl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CSL
2
- VERSION = '1.0.0.pre10'.freeze
2
+ VERSION = '1.0.0.pre11'.freeze
3
3
  end
@@ -11,7 +11,7 @@ module CSL
11
11
 
12
12
  describe '#to_xml' do
13
13
  it 'returns <style-options punctuation-in-quote="false"/> by default' do
14
- subject.to_xml.should == '<style-options punctuation-in-quote="false"/>'
14
+ subject.to_xml.should =~ /<style-options [^\/>]+\/>/
15
15
  end
16
16
  end
17
17
 
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  module CSL
4
4
  describe Locale::Terms do
5
-
5
+
6
6
  it { should_not be nil }
7
7
 
8
8
  describe '#to_xml' do
@@ -10,9 +10,36 @@ module CSL
10
10
  subject.to_xml.should == '<terms/>'
11
11
  end
12
12
  end
13
-
13
+
14
+ describe '#ordinalize' do
15
+
16
+ describe "given standard English terms" do
17
+ let(:en) do
18
+ Locale::Terms.parse <<-EOS
19
+ <terms>
20
+ <term name="ordinal">th</term>
21
+ <term name="ordinal-01">st</term>
22
+ <term name="ordinal-02">nd</term>
23
+ <term name="ordinal-03">rd</term>
24
+ <term name="ordinal-11">th</term>
25
+ <term name="ordinal-12">th</term>
26
+ <term name="ordinal-13">th</term>
27
+ </terms>
28
+ EOS
29
+ end
30
+
31
+ %w{
32
+ ordinal ordinal-01 ordinal-02 ordinal-03 ordinal
33
+ }.each_with_index do |ordinal, number|
34
+ it "returns #{ordinal.inspect} for #{number}" do
35
+ en.ordinalize(number)[:name].should == ordinal
36
+ end
37
+ end
38
+ end
39
+ end
40
+
14
41
  end
15
-
42
+
16
43
  describe Locale::Term do
17
44
 
18
45
  it { should_not be_nil }
@@ -30,9 +57,9 @@ module CSL
30
57
  end
31
58
 
32
59
  describe 'gender attribute is set' do
33
- let(:m) { Locale::Term.new(:name => 'month-05') { |t| t.masculine!; t.text = 'Mai' } }
34
- let(:f) { Locale::Term.new(:name => 'edition') { |t| t.feminine!; t.text = 'Ausgabe' } }
35
-
60
+ let(:m) { Locale::Term.new(:name => 'month-05') { |t| t.masculine!; t.text = 'Mai' } }
61
+ let(:f) { Locale::Term.new(:name => 'edition') { |t| t.feminine!; t.text = 'Ausgabe' } }
62
+
36
63
  it 'is gendered' do
37
64
  m.should be_gendered
38
65
  f.should be_gendered
@@ -42,19 +69,19 @@ module CSL
42
69
  m.should be_masculine
43
70
  f.should be_feminine
44
71
  end
45
-
72
+
46
73
  it 'is not neutral' do
47
74
  m.should_not be_neutral
48
75
  f.should_not be_neutral
49
76
  end
50
-
77
+
51
78
  describe '#to_xml' do
52
79
  it 'contains the correct gender' do
53
80
  m.to_xml.should =~ /gender="masculine"/
54
81
  f.to_xml.should =~ /gender="feminine"/
55
82
  end
56
83
  end
57
-
84
+
58
85
  describe '#match?' do
59
86
  it 'matches the name when passed a string' do
60
87
  m.should be_match(:name => 'month-05')
@@ -63,7 +90,7 @@ module CSL
63
90
  it 'matches the name when passed a pattern' do
64
91
  m.should be_match(:name => /month-\d\d/)
65
92
  end
66
-
93
+
67
94
  it 'matches when passed a matching hash without gender' do
68
95
  f.should be_match(:name => 'edition')
69
96
  end
@@ -71,7 +98,7 @@ module CSL
71
98
  it 'does not match when passed a matching hash with wrong gender' do
72
99
  f.matches?(:name => 'edition', :gender => 'masculine').should_not be_true
73
100
  end
74
-
101
+
75
102
  it 'matches when passed a matching hash with matching gender' do
76
103
  f.matches?(:name => 'edition', :gender => 'feminine').should be_true
77
104
  end
@@ -82,22 +109,22 @@ module CSL
82
109
  f.should_not be_exact_match(:name => 'edition')
83
110
  end
84
111
  end
85
-
112
+
86
113
  describe 'attributes#to_a' do
87
114
  it 'returns an array of all attribute values of underlying struct' do
88
115
  f.attributes.to_a.should == ['edition', nil, 'feminine', nil, nil]
89
116
  end
90
117
  end
91
118
  end
92
-
119
+
93
120
  describe '#to_s' do
94
121
  it 'returns an empty string by default' do
95
122
  Locale::Term.new.to_s.should == ''
96
123
  end
97
-
124
+
98
125
  describe 'given a simple term' do
99
126
  let(:node) { Locale::Term.new { |t| t.text = 'foo' } }
100
-
127
+
101
128
  it "returns the term's text" do
102
129
  node.to_s.should == node.text
103
130
  end
@@ -109,7 +136,7 @@ module CSL
109
136
  it "returns the term's singular form by default" do
110
137
  node.to_s.should == node.singularize
111
138
  end
112
-
139
+
113
140
  it "returns the term's plural form when passed :number => :plural" do
114
141
  node.to_s(:number => :plural).should == node.pluralize
115
142
  end
@@ -128,12 +155,12 @@ module CSL
128
155
 
129
156
  end
130
157
  end
131
-
158
+
132
159
  describe '#to_xml' do
133
160
  it 'returns <term/> by default' do
134
161
  subject.to_xml.should == '<term/>'
135
162
  end
136
-
163
+
137
164
  it 'returns <term>foo</term> when the text is "foo"' do
138
165
  Locale::Term.new { |t| t.text = 'foo' }.to_xml.should == '<term>foo</term>'
139
166
  end
@@ -141,7 +168,7 @@ module CSL
141
168
  it 'returns <term><multiple>foo</multiple></term> when multiple is "foo"' do
142
169
  Locale::Term.new { |t| t.multiple = 'foo' }.to_xml.should == '<term><multiple>foo</multiple></term>'
143
170
  end
144
-
171
+
145
172
  end
146
173
  end
147
174
  end
@@ -9,29 +9,42 @@ module CSL
9
9
  let(:locale) { Locale.new }
10
10
 
11
11
  let(:en) { Locale.new('en-US') }
12
+ let(:gb) { Locale.new('en-GB') }
12
13
  let(:de) { Locale.new('de-DE') }
13
- let(:fr) { Locale.new('fr-FR') }
14
14
 
15
15
  describe '.regions' do
16
-
16
+
17
17
  it 'returns the default region when passed a language symbol' do
18
18
  Locale.regions[:en].should == :US
19
19
  end
20
-
20
+
21
21
  end
22
-
22
+
23
23
  describe '.languages' do
24
-
24
+
25
25
  describe 'the language hash' do
26
26
  it 'returns the default language when passed a region string' do
27
27
  %w{ US en GB en AT de DE de }.map(&:to_sym).each_slice(2) do |region, language|
28
28
  Locale.languages[region].should == language
29
29
  end
30
30
  end
31
- end
32
-
31
+ end
32
+
33
33
  end
34
-
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
+ Locale.normalize(tag).should == expected
44
+ end
45
+ end
46
+ end
47
+
35
48
  describe '.new' do
36
49
  it { should_not be_nil }
37
50
 
@@ -50,18 +63,18 @@ module CSL
50
63
  it 'contains no terms by default' do
51
64
  Locale.new.terms.should be_nil
52
65
  end
53
-
66
+
54
67
  end
55
68
 
56
69
  describe '.load' do
57
-
70
+
58
71
  describe 'when called with "en-GB" ' do
59
72
  let(:locale) { Locale.load('en-GB') }
60
-
73
+
61
74
  it 'the returned locale has the correct IETF tag' do
62
75
  locale.to_s.should == 'en-GB'
63
76
  end
64
-
77
+
65
78
  it 'the locale has language :en' do
66
79
  locale.language.should == :en
67
80
  end
@@ -69,13 +82,13 @@ module CSL
69
82
  it 'the locale has region :GB' do
70
83
  locale.region.should == :GB
71
84
  end
72
-
85
+
73
86
  end
74
-
87
+
75
88
  end
76
89
 
77
- describe '#set' do
78
-
90
+ describe '#set' do
91
+
79
92
  it 'when passed "en-GB" sets language to :en and region to :GB' do
80
93
  locale.set('en-GB')
81
94
  [locale.language, locale.region].should == [:en, :GB]
@@ -90,39 +103,64 @@ module CSL
90
103
  locale.set('-AT')
91
104
  [locale.language, locale.region].should == [:de, :AT]
92
105
  end
93
-
106
+
94
107
  end
95
-
108
+
109
+ describe '#merge!' do
110
+ let(:locale_with_options) { Locale.new('en', :foo => 'bar') }
111
+
112
+ describe 'style options' do
113
+ it 'does not change the options if none are set on either locale' do
114
+ expect { locale.merge!(en) }.not_to change { locale.options }
115
+ end
116
+
117
+ it 'creates a duplicate option element if the first locale has no options' do
118
+ locale.should_not have_options
119
+ locale.merge!(locale_with_options)
120
+ locale.should have_options
121
+ locale.options[:foo].should == 'bar'
122
+ locale.options.should_not equal(locale_with_options.options)
123
+ end
124
+
125
+ it 'merges the options if both locales have options' do
126
+ locale << Locale::StyleOptions.new(:bar => 'foo')
127
+
128
+ expect { locale.merge!(locale_with_options) }.not_to change { locale.options.object_id }
129
+
130
+ locale.options[:foo].should == 'bar'
131
+ locale.options[:bar].should == 'foo'
132
+ end
133
+
134
+ it 'overrides the options with those in the other locale' do
135
+ locale << Locale::StyleOptions.new(:bar => 'foo', :foo => 'foo')
136
+ locale.merge!(locale_with_options)
137
+ locale.options[:foo].should == 'bar'
138
+ locale.options[:bar].should == 'foo'
139
+ end
140
+ end
141
+
142
+ describe 'dates' do
143
+ it 'does not change the dates if none are set on either locale' do
144
+ expect { locale.merge!(en) }.not_to change { locale.dates }
145
+ end
146
+
147
+ it 'creates duplicate date elements if the first locale has no options' do
148
+ locale.merge!(Locale.load('en-US'))
149
+ locale.should have_dates
150
+ end
151
+ end
152
+ end
153
+
96
154
  describe '#legacy?' do
97
155
  it 'returns false by default' do
98
156
  locale.should_not be_legacy
99
157
  end
100
-
158
+
101
159
  it 'returns true if the version is less than 1.0.1' do
102
- locale.version = '1.0'
160
+ locale.version = '0.8'
103
161
  locale.should be_legacy
104
162
  end
105
163
  end
106
-
107
- describe '#ordinalize_query_for' do
108
-
109
- it 'returns { :name => "ordinal-%02d" } by default' do
110
- locale.send(:ordinalize_query_for, nil).should == { :name => "ordinal-%02d" }
111
- end
112
-
113
- it 'returns { :name => "ordinal-%02d" } for { :form => :short }' do
114
- locale.send(:ordinalize_query_for, { :form => :short }).should == { :name => "ordinal-%02d" }
115
- end
116
164
 
117
- it 'returns { :name => "long-ordinal-%02d" } for { :form => :long }' do
118
- locale.send(:ordinalize_query_for, { :form => :long }).should == { :name => "long-ordinal-%02d" }
119
- end
120
-
121
- it 'returns { :name => "ordinal-%02d", :"gender-form" => "feminine" } for { :gender => :feminine }' do
122
- locale.send(:ordinalize_query_for, { :gender => :feminine }).should == { :name => "ordinal-%02d", :'gender-form' => 'feminine' }
123
- end
124
-
125
- end
126
-
127
165
  end
128
166
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre10
4
+ version: 1.0.0.pre11
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-05 00:00:00.000000000 Z
12
+ date: 2012-10-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: namae
16
- requirement: &70315294433280 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0.3'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70315294433280
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.3'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: cucumber
27
- requirement: &70315294432260 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '1.1'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70315294432260
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.1'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rspec
38
- requirement: &70315294431720 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '2.7'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70315294431720
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.7'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rake
49
- requirement: &70315294431000 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ~>
@@ -54,7 +69,12 @@ dependencies:
54
69
  version: '0.9'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70315294431000
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '0.9'
58
78
  description: ! "\n\t\tA Ruby parser and library for the Citation Style Language (CSL),
59
79
  an open\n\t\tXML-based language to describe the formatting of citations and\n\t\tbibliographies.\n\t\t"
60
80
  email:
@@ -65,7 +85,6 @@ extra_rdoc_files: []
65
85
  files:
66
86
  - .document
67
87
  - .gitignore
68
- - .gitmodules
69
88
  - .rspec
70
89
  - .simplecov
71
90
  - .travis.yml
@@ -164,7 +183,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
183
  version: '0'
165
184
  segments:
166
185
  - 0
167
- hash: -2344357487878349673
186
+ hash: -1272288240557992685
168
187
  required_rubygems_version: !ruby/object:Gem::Requirement
169
188
  none: false
170
189
  requirements:
@@ -173,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
192
  version: 1.3.1
174
193
  requirements: []
175
194
  rubyforge_project:
176
- rubygems_version: 1.8.10
195
+ rubygems_version: 1.8.24
177
196
  signing_key:
178
197
  specification_version: 3
179
198
  summary: A Ruby CSL parser and library