csl 1.4.5 → 1.5.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 (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,273 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module CSL
4
-
5
- describe Node do
6
-
7
- it { is_expected.not_to be nil }
8
- it { is_expected.not_to have_children }
9
- it { is_expected.to have_attributes(:attributes => {}) }
10
-
11
- describe 'given a FooBarNode with attributes :foo and :bar and a TestNode without defined attributes' do
12
- before(:all) do
13
- class FooBarNode < Node
14
- attr_struct :foo, :bar
15
- end
16
- class TestNode < Node
17
- end
18
- end
19
-
20
- it 'creates FooBarNode::Attributes' do
21
- expect(FooBarNode.const_defined?(:Attributes)).to be_truthy
22
- end
23
-
24
- it 'does not create TestNode::Attributes' do
25
- expect(TestNode.const_defined?(:Attributes)).not_to be_truthy
26
- end
27
-
28
- it 'TestNode attributes are a regular Hash' do
29
- expect(TestNode.new.attributes).to be_a(Hash)
30
- end
31
-
32
- it 'FooBarNode attributes are a Struct' do
33
- expect(FooBarNode.new.attributes).to be_a(Struct)
34
- end
35
-
36
- describe '#match?' do
37
- it 'matches an empty query' do
38
- expect(FooBarNode.new.match?({})).to be_truthy
39
- expect(FooBarNode.new(:foo => 'Foo').match?({})).to be_truthy
40
- expect(TestNode.new.match?({})).to be_truthy
41
- expect(TestNode.new(:foo => 'Foo').match?({})).to be_truthy
42
- end
43
-
44
- it 'returns true for a matching query' do
45
- expect(FooBarNode.new(:foo => 'bar').match?(:foo => 'bar')).to be_truthy
46
- expect(FooBarNode.new(:bar => 'b', :foo => 'f').match?(:foo => 'f', :bar => 'b')).to be_truthy
47
- end
48
-
49
- it 'returns false for non-matching query' do
50
- expect(FooBarNode.new.match?(:foo => 'bar')).to be_falsey
51
- expect(FooBarNode.new(:foo => 'f').match?(:foo => 'f', :bar => 'b')).to be_falsey
52
- end
53
-
54
- it 'returns false if the query contains unknown attributes' do
55
- expect(FooBarNode.new(:foo => 'f').match?(:foo => 'f', :unknown => 'u')).to be_falsey
56
- end
57
-
58
- it 'matches irrespective of order' do
59
- expect(FooBarNode.new(:bar => 'b', :foo => 'f').match?(:foo => 'f', :bar => 'b')).to be_truthy
60
- expect(FooBarNode.new(:foo => 'f', :bar => 'b').match?(:foo => 'f', :bar => 'b')).to be_truthy
61
- expect(FooBarNode.new(:foo => 'f', :bar => 'b').match?(:bar => 'b', :foo => 'f')).to be_truthy
62
- expect(FooBarNode.new(:bar => 'b', :foo => 'f').match?(:bar => 'b', :foo => 'f')).to be_truthy
63
- end
64
-
65
- it 'matches an empty query with the correct node name' do
66
- expect(FooBarNode.new.match?('foo-bar-node', {})).to be_truthy
67
- expect(FooBarNode.new(:foo => 'Foo').match?('foo-bar-node', {})).to be_truthy
68
- expect(TestNode.new.match?('test-node', {})).to be_truthy
69
- expect(TestNode.new(:foo => 'Foo').match?('test-node', {})).to be_truthy
70
- end
71
-
72
- it 'does not match other node names' do
73
- expect(FooBarNode.new.match?(:name, {})).not_to be_truthy
74
- expect(FooBarNode.new(:foo => 'Foo').match?(:name, {})).not_to be_truthy
75
- expect(TestNode.new.match?(:name, {})).not_to be_truthy
76
- expect(TestNode.new(:foo => 'Foo').match?(:name, {})).not_to be_truthy
77
- end
78
- end
79
-
80
- describe '#attributes_for' do
81
- it 'returns an empty hash when there no attributes are set' do
82
- expect(TestNode.new.attributes_for).to be_empty
83
- expect(TestNode.new.attributes_for(:x, :y)).to be_empty
84
-
85
- expect(FooBarNode.new.attributes_for).to be_empty
86
- expect(FooBarNode.new.attributes_for(:x, :y)).to be_empty
87
- expect(FooBarNode.new.attributes_for(:foo, :bar)).to be_empty
88
- end
89
-
90
- it 'returns an empty hash when no attributes match the filter' do
91
- expect(TestNode.new(:foo => 'foo').attributes_for).to be_empty
92
- expect(TestNode.new(:foo => 'foo').attributes_for(:x, :y)).to be_empty
93
-
94
- expect(FooBarNode.new(:foo => 'foo').attributes_for).to be_empty
95
- expect(FooBarNode.new(:foo => 'foo').attributes_for(:x, :y)).to be_empty
96
- end
97
-
98
- it 'returns a hash of all set attributes that match the filter' do
99
- expect(TestNode.new(:foo => 'foo', :bar => 'bar').attributes_for(:x, :foo)).to eq({ :foo => 'foo' })
100
- expect(FooBarNode.new(:foo => 'foo', :bar => 'bar').attributes_for(:x, :foo)).to eq({ :foo => 'foo' })
101
- end
102
- end
103
-
104
- describe '#formatting_options' do
105
- it 'returns an empty hash by default' do
106
- expect(TestNode.new.formatting_options).to be_empty
107
- expect(FooBarNode.new.formatting_options).to be_empty
108
- end
109
-
110
- it 'returns an empty hash if there are no formatting attributes' do
111
- expect(TestNode.new(:foo => 'foo', :bar => 'bar').formatting_options).to be_empty
112
- expect(FooBarNode.new(:foo => 'foo', :bar => 'bar').formatting_options).to be_empty
113
- end
114
-
115
- it "returns a hash of the node's formatting attributes" do
116
- expect(
117
- TestNode.new(:foo => 'foo', :'font-style' => 'italic').formatting_options
118
- ).to eq({ :'font-style' => 'italic' })
119
- end
120
- end
121
-
122
- describe '#values_at' do
123
- it 'FooBarNode accepts attribute names' do
124
- expect(FooBarNode.new(:foo => 'Foo', :bar => 'Bar').values_at(:bar, :foo))
125
- .to eq(%w{ Bar Foo })
126
-
127
- expect(FooBarNode.new(:foo => 'Foo').values_at(:bar, :foo))
128
- .to eq([nil, 'Foo'])
129
-
130
- expect(FooBarNode.new(:foo => 'Foo').values_at(:unknown, :foo))
131
- .to eq([nil, 'Foo'])
132
- end
133
-
134
- it 'TestNode accepts attribute names' do
135
- expect(TestNode.new(:foo => 'Foo', :bar => 'Bar').values_at(:bar, :foo))
136
- .to eq(%w{ Bar Foo })
137
-
138
- expect(TestNode.new(:foo => 'Foo').values_at(:bar, :foo))
139
- .to eq([nil, 'Foo'])
140
- expect(TestNode.new(:foo => 'Foo').values_at(:unknown, :foo))
141
- .to eq([nil, 'Foo'])
142
- end
143
- end
144
-
145
- describe '#to_a' do
146
- it 'returns an empty list by default' do
147
- expect(Node.new.attributes.to_a).to eq([])
148
- end
149
-
150
- it 'TestNode returns an empty list by default' do
151
- expect(TestNode.new.attributes.to_a).to eq([])
152
- end
153
-
154
- # it 'TestNode returns a list of all key/value pairs' do
155
- # TestNode.new(:foo => 'Foo', :bar => 'Bar').attributes.to_a.map(&:last).sort.should == %w{ Bar Foo }
156
- # end
157
-
158
- # it 'FooBarNode returns an empty list by default' do
159
- # FooBarNode.new.attributes.to_a.should == []
160
- # end
161
-
162
- # it 'FooBarNode returns a list of all key/value pairs' do
163
- # FooBarNode.new(:foo => 'Foo', :bar => 'Bar').attributes.to_a.map(&:last).sort.should == %w{ Bar Foo }
164
- # end
165
- end
166
-
167
- describe 'attributes.keys' do
168
- it 'returns all attribute names as symbols' do
169
- expect(TestNode.new.attributes.keys).to be_empty
170
- expect(FooBarNode.new.attributes.keys).to eq([:foo, :bar])
171
- end
172
- end
173
- end
174
-
175
- describe 'comparing nodes' do
176
- it 'empty nodes are equal' do
177
- expect(Node.new).to eq(Node.new)
178
- end
179
-
180
- it 'considers node names' do
181
- expect(Node.new).not_to eq(Node.new { |n| n.nodename = 'foo' })
182
- end
183
-
184
- it 'considers attributes' do
185
- expect(Node.new(:foo => 'bar')).to eq(Node.new(:foo => 'bar'))
186
- expect(Node.new(:foo => 'bar')).not_to eq(Node.new(:foo => 'baz'))
187
-
188
- expect(Node.new(:foo => 'bar', :baz => 'qux'))
189
- .not_to eq(Node.new(:foo => 'bar'))
190
-
191
- expect(Node.new(:foo => 'bar', :baz => 'qux'))
192
- .to eq(Node.new(:baz => 'qux', :foo => 'bar'))
193
- end
194
-
195
- it 'considers children' do
196
- n1, n2 = Node.new, Node.new
197
-
198
- n1 << Node.new
199
- expect(n1).not_to eq(n2)
200
-
201
- n2 << Node.new
202
- expect(n1).to eq(n2)
203
-
204
- n2.children[0][:foo] = 'bar'
205
- expect(n1).not_to eq(n2)
206
-
207
- n1.children[0][:foo] = 'bar'
208
- expect(n1).to eq(n2)
209
- end
210
-
211
- end
212
- end
213
-
214
- describe TextNode do
215
- it { is_expected.not_to be nil }
216
- it { is_expected.not_to have_children }
217
- it { is_expected.to have_attributes(:attributes => {}) }
218
-
219
- describe '.new' do
220
- it 'accepts a hash of attributes' do
221
- expect(TextNode.new(:foo => 'bar').attributes).to have_key(:foo)
222
- end
223
-
224
- it 'yields itself to the optional block' do
225
- expect(TextNode.new { |n| n.text = 'foo' }.text).to eq('foo')
226
- end
227
-
228
- it 'accepts hash and yields itself to the optional block' do
229
- expect(TextNode.new(:foo => 'bar') { |n| n.text = 'foo' }.to_xml)
230
- .to eq('<text-node foo="bar">foo</text-node>')
231
- end
232
- end
233
-
234
- describe '#pretty_print' do
235
- it 'prints the text node as XML' do
236
- expect(TextNode.new(:foo => 'bar') { |n| n.text = 'foo' }.pretty_print)
237
- .to eq('<text-node foo="bar">foo</text-node>')
238
- end
239
- end
240
-
241
- describe 'comparing nodes' do
242
- it 'empty nodes are equal' do
243
- expect(TextNode.new).to eq(TextNode.new)
244
- end
245
-
246
- it 'considers node names' do
247
- expect(TextNode.new).not_to eq(TextNode.new { |n| n.nodename = 'foo' })
248
- end
249
-
250
- it 'considers attributes' do
251
- expect(TextNode.new(:foo => 'bar')).to eq(TextNode.new(:foo => 'bar'))
252
- expect(TextNode.new(:foo => 'bar')).not_to eq(TextNode.new(:foo => 'baz'))
253
-
254
- expect(TextNode.new(:foo => 'bar', :baz => 'qux'))
255
- .not_to eq(TextNode.new(:foo => 'bar'))
256
-
257
- expect(TextNode.new(:foo => 'bar', :baz => 'qux'))
258
- .to eq(TextNode.new(:baz => 'qux', :foo => 'bar'))
259
- end
260
-
261
- it 'considers text' do
262
- n1, n2 = TextNode.new, TextNode.new
263
-
264
- n1.text = 'foo'
265
- expect(n1).not_to eq(n2)
266
-
267
- n2.text = 'foo'
268
- expect(n1).to eq(n2)
269
- end
270
- end
271
- end
272
-
273
- end
@@ -1,112 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module CSL
4
-
5
- describe Parser do
6
-
7
- describe '.instance' do
8
- it 'returns the parser' do
9
- expect(Parser.instance).to be_instance_of(Parser)
10
- end
11
- end
12
-
13
- Parser.engines.each_pair do |name, parser|
14
- describe "when using the #{name} parser " do
15
- before(:all) { Parser.instance.parser = parser }
16
-
17
- describe '#parse' do
18
-
19
- describe 'for <foo/>' do
20
- let(:source) { '<foo/>' }
21
-
22
- it 'returns a CSL::Node' do
23
- expect(Parser.instance.parse(source)).to be_a(Node)
24
- end
25
-
26
- it 'returns a node with nodename "foo"' do
27
- expect(Parser.instance.parse(source).nodename).to eq('foo')
28
- end
29
-
30
- it 'returns a node with no attributes' do
31
- expect(Parser.instance.parse(source).attributes).to be_empty
32
- end
33
-
34
- it 'returns a node with no children' do
35
- expect(Parser.instance.parse(source)).not_to have_children
36
- end
37
- end
38
-
39
- describe 'for an empty name node' do
40
- ['<name/>', '<name></name>', '<name> </name>'].each do |source|
41
- it "returns a Style::Name for #{source.inspect} by default" do
42
- expect(Parser.instance.parse!(source)).to be_a(Style::Name)
43
- end
44
-
45
- it "returns a Style::Name for #{source.inspect} for Style scope" do
46
- expect(Parser.instance.parse!(source, Style)).to be_a(Style::Name)
47
- end
48
-
49
- it "returns a Node for #{source.inspect} for Locale scope" do
50
- expect(Parser.instance.parse!(source, Locale)).to be_a(Node)
51
- end
52
-
53
- it "returns an Info::Name for #{source.inspect} for Info scope" do
54
- expect(Parser.instance.parse!(source, Info)).to be_a(Info::Name)
55
- end
56
- end
57
- end
58
-
59
- describe 'for <foo bar="x"/>' do
60
- let(:src) { '<foo bar="x"/>' }
61
-
62
- it 'returns a node with attributes' do
63
- expect(Parser.instance.parse(src).attributes).not_to be_empty
64
- end
65
-
66
- it 'returns a node with attribute bar' do
67
- expect(Parser.instance.parse(src).attribute?(:bar)).to be
68
- end
69
-
70
- it 'bar should be "x"' do
71
- expect(Parser.instance.parse(src)[:bar]).to eq('x')
72
- end
73
- end
74
-
75
- describe 'for <foo>Foo Bar</foo>' do
76
- let(:src) { '<foo>Foo Bar</foo>' }
77
-
78
- it 'returns text node' do
79
- expect(Parser.instance.parse(src)).to be_textnode
80
- end
81
- end
82
-
83
- it 'returns a regular node for <x>\n <y/></x>' do
84
- expect(Parser.instance.parse("<x>\n <y/></x>")).not_to be_textnode
85
- end
86
-
87
- describe 'xml comments' do
88
- it 'ignores comment-only documents' do
89
- expect(Parser.instance.parse("<!--x></x-->")).to be_nil
90
- end
91
-
92
- it 'ignores comments in normal nodes' do
93
- expect(Parser.instance.parse("<x><!-- comment --></x>")).not_to have_children
94
- end
95
-
96
- it 'ignores comments in text nodes' do
97
- node = Parser.instance.parse("<x>foo<!-- comment --></x>")
98
- expect(node).to be_textnode
99
- expect(node).not_to have_children
100
- expect(node.text).to eq('foo')
101
- end
102
-
103
- end
104
-
105
- end
106
-
107
- end
108
- end
109
-
110
- end
111
-
112
- end
@@ -1,112 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module CSL
4
- describe 'Schema' do
5
-
6
- it 'cannot be instantiated' do
7
- expect(Schema).not_to respond_to(:new)
8
- end
9
-
10
- describe '.version' do
11
- it 'returns a version string' do
12
- expect(Schema.version).to match(/^\d+\.\d+\.\d+/)
13
- end
14
-
15
- it 'is greater than 1.0' do
16
- expect(Schema.version.split(/\./)[0].to_i).to be >= 1
17
- end
18
- end
19
-
20
- describe '.variables' do
21
- it 'contains :names fields' do
22
- expect(Schema.variables[:names]).not_to be_empty
23
- expect(Schema.variables[:name]).to equal Schema.variables[:names]
24
- end
25
-
26
- it 'contains :date fields' do
27
- expect(Schema.variables[:date]).not_to be_empty
28
- expect(Schema.variables[:dates]).to equal Schema.variables[:date]
29
- end
30
-
31
- it 'contains :text fields' do
32
- expect(Schema.variables[:text]).not_to be_empty
33
- end
34
-
35
- it 'contains :number fields' do
36
- expect(Schema.variables[:numbers]).not_to be_empty
37
- expect(Schema.variables[:number]).not_to be_empty
38
- end
39
-
40
- it 'accepts either string or symbol input' do
41
- expect(Schema.variables[:names]).to equal Schema.variables['names']
42
- end
43
- end
44
-
45
- describe '.types' do
46
- it 'returns an array' do
47
- expect(Schema.types).to be_a(Array)
48
- end
49
-
50
- it 'is not empty' do
51
- expect(Schema.types).not_to be_empty
52
- end
53
-
54
- it 'includes :article' do
55
- expect(Schema.types).to include(:article)
56
- end
57
- end
58
-
59
- describe '.categories' do
60
- it 'given a field name returns the corresponding type' do
61
- expect(Schema.categories.values_at(:author, :issued, :abstract, :issue)).to eq(
62
- [:names, :date, :text, :number]
63
- )
64
- end
65
-
66
- it 'accepts either string or symbol input' do
67
- expect(Schema.categories).to have_key(:author)
68
- expect(Schema.categories['author']).to equal Schema.categories[:author]
69
- end
70
- end
71
-
72
- describe '.validate' do
73
- it 'accepts and validates a locale instance' do
74
- expect(Schema.validate(Locale.load('en-US'))).to eq([])
75
- end
76
-
77
- it 'accepts and validates a locale file path' do
78
- expect(Schema.validate(File.join(Locale.root, 'locales-en-US.xml'))).to eq([])
79
- end
80
-
81
- it 'accepts and validates a locale file' do
82
- expect(Schema.validate(File.open(File.join(Locale.root, 'locales-en-US.xml')))).to eq([])
83
- end
84
-
85
- it 'accepts and validates a locale wildcard path' do
86
- expect(Schema.validate(File.join(Locale.root, 'locales-en-*.xml'))).to eq([])
87
- end
88
-
89
- it 'accepts and validates a style file path' do
90
- expect(Schema.validate(File.join(Style.root, 'apa.csl'))).to eq([])
91
- end
92
-
93
- it 'accepts and validates the xml contents of a style instance' do
94
- expect(Schema.validate(Style.load(:apa).pretty_print)).to eq([])
95
- end
96
-
97
- it 'accepts and validates a style instance' do
98
- expect(Schema.validate(Style.load(:apa))).to eq([])
99
- end
100
-
101
- it 'does not accept invalid xml markup' do
102
- expect(Schema.validate(%Q{
103
- <style xmlns="http://purl.org/net/xbiblio/csl" class="note" version="1.0">
104
- </stle>
105
- })[0][0]).to eq(0) # error on line 0 -> parse error
106
- end
107
-
108
- # TODO fix nokogiri/jing validation
109
- end unless RUBY_PLATFORM =~ /java/i
110
-
111
- end
112
- end