csl 1.2.1 → 1.2.2
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.
- checksums.yaml +4 -4
- data/features/step_definitions/locale_steps.rb +7 -5
- data/features/step_definitions/parser_steps.rb +8 -8
- data/features/step_definitions/style_steps.rb +3 -3
- data/lib/csl/loader.rb +3 -3
- data/lib/csl/node.rb +5 -0
- data/lib/csl/style/group.rb +1 -6
- data/lib/csl/version.rb +1 -1
- data/spec/csl/info_spec.rb +50 -50
- data/spec/csl/locale/date_spec.rb +13 -13
- data/spec/csl/locale/style_options_spec.rb +3 -3
- data/spec/csl/locale/term_spec.rb +51 -51
- data/spec/csl/locale_spec.rb +36 -36
- data/spec/csl/node_spec.rb +64 -62
- data/spec/csl/parser_spec.rb +19 -19
- data/spec/csl/schema_spec.rb +27 -26
- data/spec/csl/style/choose_spec.rb +8 -8
- data/spec/csl/style/date_spec.rb +2 -2
- data/spec/csl/style/label_spec.rb +8 -8
- data/spec/csl/style/names_spec.rb +2 -2
- data/spec/csl/style/number_spec.rb +17 -17
- data/spec/csl/style/sort_spec.rb +1 -1
- data/spec/csl/style_spec.rb +27 -27
- data/spec/csl/treelike_spec.rb +20 -20
- metadata +2 -2
data/spec/csl/node_spec.rb
CHANGED
@@ -4,9 +4,9 @@ module CSL
|
|
4
4
|
|
5
5
|
describe Node do
|
6
6
|
|
7
|
-
it {
|
8
|
-
it {
|
9
|
-
it {
|
7
|
+
it { is_expected.not_to be nil }
|
8
|
+
it { is_expected.not_to have_children }
|
9
|
+
it { is_expected.not_to have_attributes }
|
10
10
|
|
11
11
|
describe 'given a FooBarNode with attributes :foo and :bar and a TestNode without defined attributes' do
|
12
12
|
before(:all) do
|
@@ -18,126 +18,126 @@ module CSL
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'creates FooBarNode::Attributes' do
|
21
|
-
FooBarNode.const_defined?(:Attributes).
|
21
|
+
expect(FooBarNode.const_defined?(:Attributes)).to be_truthy
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'does not create TestNode::Attributes' do
|
25
|
-
TestNode.const_defined?(:Attributes).
|
25
|
+
expect(TestNode.const_defined?(:Attributes)).not_to be_truthy
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'TestNode attributes are a regular Hash' do
|
29
|
-
TestNode.new.attributes.
|
29
|
+
expect(TestNode.new.attributes).to be_a(Hash)
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'FooBarNode attributes are a Struct' do
|
33
|
-
FooBarNode.new.attributes.
|
33
|
+
expect(FooBarNode.new.attributes).to be_a(Struct)
|
34
34
|
end
|
35
35
|
|
36
36
|
describe '#match?' do
|
37
37
|
it 'matches an empty query' do
|
38
|
-
FooBarNode.new.match?({}).
|
39
|
-
FooBarNode.new(:foo => 'Foo').match?({}).
|
40
|
-
TestNode.new.match?({}).
|
41
|
-
TestNode.new(:foo => 'Foo').match?({}).
|
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
42
|
end
|
43
43
|
|
44
44
|
it 'returns true for a matching query' do
|
45
|
-
FooBarNode.new(:foo => 'bar').match?(:foo => 'bar').
|
46
|
-
FooBarNode.new(:bar => 'b', :foo => 'f').match?(:foo => 'f', :bar => 'b').
|
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
47
|
end
|
48
48
|
|
49
49
|
it 'returns false for non-matching query' do
|
50
|
-
FooBarNode.new.match?(:foo => 'bar').
|
51
|
-
FooBarNode.new(:foo => 'f').match?(:foo => 'f', :bar => 'b').
|
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
52
|
end
|
53
53
|
|
54
54
|
it 'returns false if the query contains unknown attributes' do
|
55
|
-
FooBarNode.new(:foo => 'f').match?(:foo => 'f', :unknown => 'u').
|
55
|
+
expect(FooBarNode.new(:foo => 'f').match?(:foo => 'f', :unknown => 'u')).to be_falsey
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'matches irrespective of order' do
|
59
|
-
FooBarNode.new(:bar => 'b', :foo => 'f').match?(:foo => 'f', :bar => 'b').
|
60
|
-
FooBarNode.new(:foo => 'f', :bar => 'b').match?(:foo => 'f', :bar => 'b').
|
61
|
-
FooBarNode.new(:foo => 'f', :bar => 'b').match?(:bar => 'b', :foo => 'f').
|
62
|
-
FooBarNode.new(:bar => 'b', :foo => 'f').match?(:bar => 'b', :foo => 'f').
|
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
63
|
end
|
64
64
|
|
65
65
|
it 'matches an empty query with the correct node name' do
|
66
|
-
FooBarNode.new.match?('foo-bar-node', {}).
|
67
|
-
FooBarNode.new(:foo => 'Foo').match?('foo-bar-node', {}).
|
68
|
-
TestNode.new.match?('test-node', {}).
|
69
|
-
TestNode.new(:foo => 'Foo').match?('test-node', {}).
|
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
70
|
end
|
71
71
|
|
72
72
|
it 'does not match other node names' do
|
73
|
-
FooBarNode.new.match?(:name, {}).
|
74
|
-
FooBarNode.new(:foo => 'Foo').match?(:name, {}).
|
75
|
-
TestNode.new.match?(:name, {}).
|
76
|
-
TestNode.new(:foo => 'Foo').match?(:name, {}).
|
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
77
|
end
|
78
78
|
end
|
79
79
|
|
80
80
|
describe '#attributes_for' do
|
81
81
|
it 'returns an empty hash when there no attributes are set' do
|
82
|
-
TestNode.new.attributes_for.
|
83
|
-
TestNode.new.attributes_for(:x, :y).
|
82
|
+
expect(TestNode.new.attributes_for).to be_empty
|
83
|
+
expect(TestNode.new.attributes_for(:x, :y)).to be_empty
|
84
84
|
|
85
|
-
FooBarNode.new.attributes_for.
|
86
|
-
FooBarNode.new.attributes_for(:x, :y).
|
87
|
-
FooBarNode.new.attributes_for(:foo, :bar).
|
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
88
|
end
|
89
89
|
|
90
90
|
it 'returns an empty hash when no attributes match the filter' do
|
91
|
-
TestNode.new(:foo => 'foo').attributes_for.
|
92
|
-
TestNode.new(:foo => 'foo').attributes_for(:x, :y).
|
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
93
|
|
94
|
-
FooBarNode.new(:foo => 'foo').attributes_for.
|
95
|
-
FooBarNode.new(:foo => 'foo').attributes_for(:x, :y).
|
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
96
|
end
|
97
97
|
|
98
98
|
it 'returns a hash of all set attributes that match the filter' do
|
99
|
-
TestNode.new(:foo => 'foo', :bar => 'bar').attributes_for(:x, :foo).
|
100
|
-
FooBarNode.new(:foo => 'foo', :bar => 'bar').attributes_for(:x, :foo).
|
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
101
|
end
|
102
102
|
end
|
103
103
|
|
104
104
|
describe '#formatting_options' do
|
105
105
|
it 'returns an empty hash by default' do
|
106
|
-
TestNode.new.formatting_options.
|
107
|
-
FooBarNode.new.formatting_options.
|
106
|
+
expect(TestNode.new.formatting_options).to be_empty
|
107
|
+
expect(FooBarNode.new.formatting_options).to be_empty
|
108
108
|
end
|
109
109
|
|
110
110
|
it 'returns an empty hash if there are no formatting attributes' do
|
111
|
-
TestNode.new(:foo => 'foo', :bar => 'bar').formatting_options.
|
112
|
-
FooBarNode.new(:foo => 'foo', :bar => 'bar').formatting_options.
|
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
113
|
end
|
114
114
|
|
115
115
|
it "returns a hash of the node's formatting attributes" do
|
116
|
-
TestNode.new(:foo => 'foo', :'font-style' => 'italic').formatting_options.
|
116
|
+
expect(TestNode.new(:foo => 'foo', :'font-style' => 'italic').formatting_options).to eq({ :'font-style' => 'italic' })
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
120
|
describe '#values_at' do
|
121
121
|
it 'FooBarNode accepts attribute names' do
|
122
|
-
FooBarNode.new(:foo => 'Foo', :bar => 'Bar').values_at(:bar, :foo).
|
123
|
-
FooBarNode.new(:foo => 'Foo').values_at(:bar, :foo).
|
124
|
-
FooBarNode.new(:foo => 'Foo').values_at(:unknown, :foo).
|
122
|
+
expect(FooBarNode.new(:foo => 'Foo', :bar => 'Bar').values_at(:bar, :foo)).to eq(%w{ Bar Foo })
|
123
|
+
expect(FooBarNode.new(:foo => 'Foo').values_at(:bar, :foo)).to eq([nil, 'Foo'])
|
124
|
+
expect(FooBarNode.new(:foo => 'Foo').values_at(:unknown, :foo)).to eq([nil, 'Foo'])
|
125
125
|
end
|
126
126
|
|
127
127
|
it 'TestNode accepts attribute names' do
|
128
|
-
TestNode.new(:foo => 'Foo', :bar => 'Bar').values_at(:bar, :foo).
|
129
|
-
TestNode.new(:foo => 'Foo').values_at(:bar, :foo).
|
130
|
-
TestNode.new(:foo => 'Foo').values_at(:unknown, :foo).
|
128
|
+
expect(TestNode.new(:foo => 'Foo', :bar => 'Bar').values_at(:bar, :foo)).to eq(%w{ Bar Foo })
|
129
|
+
expect(TestNode.new(:foo => 'Foo').values_at(:bar, :foo)).to eq([nil, 'Foo'])
|
130
|
+
expect(TestNode.new(:foo => 'Foo').values_at(:unknown, :foo)).to eq([nil, 'Foo'])
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
134
|
describe '#to_a' do
|
135
135
|
it 'returns an empty list by default' do
|
136
|
-
Node.new.attributes.to_a.
|
136
|
+
expect(Node.new.attributes.to_a).to eq([])
|
137
137
|
end
|
138
138
|
|
139
139
|
it 'TestNode returns an empty list by default' do
|
140
|
-
TestNode.new.attributes.to_a.
|
140
|
+
expect(TestNode.new.attributes.to_a).to eq([])
|
141
141
|
end
|
142
142
|
|
143
143
|
# it 'TestNode returns a list of all key/value pairs' do
|
@@ -155,8 +155,8 @@ module CSL
|
|
155
155
|
|
156
156
|
describe 'attributes.keys' do
|
157
157
|
it 'returns all attribute names as symbols' do
|
158
|
-
TestNode.new.attributes.keys.
|
159
|
-
FooBarNode.new.attributes.keys.
|
158
|
+
expect(TestNode.new.attributes.keys).to be_empty
|
159
|
+
expect(FooBarNode.new.attributes.keys).to eq([:foo, :bar])
|
160
160
|
end
|
161
161
|
end
|
162
162
|
end
|
@@ -164,27 +164,29 @@ module CSL
|
|
164
164
|
|
165
165
|
describe TextNode do
|
166
166
|
|
167
|
-
it {
|
168
|
-
it {
|
169
|
-
it {
|
167
|
+
it { is_expected.not_to be nil }
|
168
|
+
it { is_expected.not_to have_children }
|
169
|
+
it { is_expected.not_to have_attributes }
|
170
170
|
|
171
171
|
describe '.new' do
|
172
172
|
it 'accepts a hash of attributes' do
|
173
|
-
TextNode.new(:foo => 'bar').
|
173
|
+
expect(TextNode.new(:foo => 'bar')).to have_attributes
|
174
174
|
end
|
175
175
|
|
176
176
|
it 'yields itself to the optional block' do
|
177
|
-
TextNode.new { |n| n.text = 'foo' }.text.
|
177
|
+
expect(TextNode.new { |n| n.text = 'foo' }.text).to eq('foo')
|
178
178
|
end
|
179
179
|
|
180
180
|
it 'accepts hash and yields itself to the optional block' do
|
181
|
-
TextNode.new(:foo => 'bar') { |n| n.text = 'foo' }.to_xml.
|
181
|
+
expect(TextNode.new(:foo => 'bar') { |n| n.text = 'foo' }.to_xml).to eq('<text-node foo="bar">foo</text-node>')
|
182
182
|
end
|
183
183
|
end
|
184
184
|
|
185
185
|
describe '#pretty_print' do
|
186
|
-
|
186
|
+
it 'prints the text node as XML' do
|
187
|
+
expect(TextNode.new(:foo => 'bar') { |n| n.text = 'foo' }.pretty_print).to eq('<text-node foo="bar">foo</text-node>')
|
188
|
+
end
|
187
189
|
end
|
188
190
|
end
|
189
191
|
|
190
|
-
end
|
192
|
+
end
|
data/spec/csl/parser_spec.rb
CHANGED
@@ -6,7 +6,7 @@ module CSL
|
|
6
6
|
|
7
7
|
describe '.instance' do
|
8
8
|
it 'returns the parser' do
|
9
|
-
Parser.instance.
|
9
|
+
expect(Parser.instance).to be_instance_of(Parser)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -20,38 +20,38 @@ module CSL
|
|
20
20
|
let(:source) { '<foo/>' }
|
21
21
|
|
22
22
|
it 'returns a CSL::Node' do
|
23
|
-
Parser.instance.parse(source).
|
23
|
+
expect(Parser.instance.parse(source)).to be_a(Node)
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'returns a node with nodename "foo"' do
|
27
|
-
Parser.instance.parse(source).nodename.
|
27
|
+
expect(Parser.instance.parse(source).nodename).to eq('foo')
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'returns a node with no attributes' do
|
31
|
-
Parser.instance.parse(source).
|
31
|
+
expect(Parser.instance.parse(source)).not_to have_attributes
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'returns a node with no children' do
|
35
|
-
Parser.instance.parse(source).
|
35
|
+
expect(Parser.instance.parse(source)).not_to have_children
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
describe 'for an empty name node' do
|
40
40
|
['<name/>', '<name></name>', '<name> </name>'].each do |source|
|
41
41
|
it "returns a Style::Name for #{source.inspect} by default" do
|
42
|
-
Parser.instance.parse!(source).
|
42
|
+
expect(Parser.instance.parse!(source)).to be_a(Style::Name)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "returns a Style::Name for #{source.inspect} for Style scope" do
|
46
|
-
Parser.instance.parse!(source, Style).
|
46
|
+
expect(Parser.instance.parse!(source, Style)).to be_a(Style::Name)
|
47
47
|
end
|
48
48
|
|
49
49
|
it "returns a Node for #{source.inspect} for Locale scope" do
|
50
|
-
Parser.instance.parse!(source, Locale).
|
50
|
+
expect(Parser.instance.parse!(source, Locale)).to be_a(Node)
|
51
51
|
end
|
52
52
|
|
53
53
|
it "returns an Info::Name for #{source.inspect} for Info scope" do
|
54
|
-
Parser.instance.parse!(source, Info).
|
54
|
+
expect(Parser.instance.parse!(source, Info)).to be_a(Info::Name)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -60,15 +60,15 @@ module CSL
|
|
60
60
|
let(:source) { '<foo bar="x"/>' }
|
61
61
|
|
62
62
|
it 'returns a node with attributes' do
|
63
|
-
Parser.instance.parse(source).
|
63
|
+
expect(Parser.instance.parse(source)).to have_attributes
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'returns a node with attribute bar' do
|
67
|
-
Parser.instance.parse(source).attribute?(:bar).
|
67
|
+
expect(Parser.instance.parse(source).attribute?(:bar)).to be
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'bar should be "x"' do
|
71
|
-
Parser.instance.parse(source)[:bar].
|
71
|
+
expect(Parser.instance.parse(source)[:bar]).to eq('x')
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -76,28 +76,28 @@ module CSL
|
|
76
76
|
let(:source) { '<foo>Foo Bar</foo>' }
|
77
77
|
|
78
78
|
it 'returns text node' do
|
79
|
-
Parser.instance.parse(source).
|
79
|
+
expect(Parser.instance.parse(source)).to be_textnode
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
83
|
it 'returns a regular node for <x>\n <y/></x>' do
|
84
|
-
Parser.instance.parse("<x>\n <y/></x>").
|
84
|
+
expect(Parser.instance.parse("<x>\n <y/></x>")).not_to be_textnode
|
85
85
|
end
|
86
86
|
|
87
87
|
describe 'xml comments' do
|
88
88
|
it 'ignores comment-only documents' do
|
89
|
-
Parser.instance.parse("<!--x></x-->").
|
89
|
+
expect(Parser.instance.parse("<!--x></x-->")).to be_nil
|
90
90
|
end
|
91
91
|
|
92
92
|
it 'ignores comments in normal nodes' do
|
93
|
-
Parser.instance.parse("<x><!-- comment --></x>").
|
93
|
+
expect(Parser.instance.parse("<x><!-- comment --></x>")).not_to have_children
|
94
94
|
end
|
95
95
|
|
96
96
|
it 'ignores comments in text nodes' do
|
97
97
|
node = Parser.instance.parse("<x>foo<!-- comment --></x>")
|
98
|
-
node.
|
99
|
-
node.
|
100
|
-
node.text.
|
98
|
+
expect(node).to be_textnode
|
99
|
+
expect(node).not_to have_children
|
100
|
+
expect(node.text).to eq('foo')
|
101
101
|
end
|
102
102
|
|
103
103
|
end
|
data/spec/csl/schema_spec.rb
CHANGED
@@ -4,104 +4,105 @@ module CSL
|
|
4
4
|
describe 'Schema' do
|
5
5
|
|
6
6
|
it 'cannot be instantiated' do
|
7
|
-
Schema.
|
7
|
+
expect(Schema).not_to respond_to(:new)
|
8
8
|
end
|
9
9
|
|
10
10
|
describe '.version' do
|
11
11
|
it 'returns a version string' do
|
12
|
-
Schema.version.
|
12
|
+
expect(Schema.version).to match(/^\d+\.\d+\.\d+/)
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'is greater than 1.0' do
|
16
|
-
Schema.version.split(/\./)[0].to_i.
|
16
|
+
expect(Schema.version.split(/\./)[0].to_i).to be >= 1
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
describe '.variables' do
|
21
21
|
it 'contains :names fields' do
|
22
|
-
Schema.variables[:names].
|
23
|
-
Schema.variables[:name].
|
22
|
+
expect(Schema.variables[:names]).not_to be_empty
|
23
|
+
expect(Schema.variables[:name]).to equal Schema.variables[:names]
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'contains :date fields' do
|
27
|
-
Schema.variables[:date].
|
28
|
-
Schema.variables[:dates].
|
27
|
+
expect(Schema.variables[:date]).not_to be_empty
|
28
|
+
expect(Schema.variables[:dates]).to equal Schema.variables[:date]
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'contains :text fields' do
|
32
|
-
Schema.variables[:text].
|
32
|
+
expect(Schema.variables[:text]).not_to be_empty
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'contains :number fields' do
|
36
|
-
Schema.variables[:numbers].
|
37
|
-
Schema.variables[:number].
|
36
|
+
expect(Schema.variables[:numbers]).not_to be_empty
|
37
|
+
expect(Schema.variables[:number]).not_to be_empty
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'accepts either string or symbol input' do
|
41
|
-
Schema.variables[:names].
|
41
|
+
expect(Schema.variables[:names]).to equal Schema.variables['names']
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
describe '.types' do
|
46
46
|
it 'returns an array' do
|
47
|
-
Schema.types.
|
47
|
+
expect(Schema.types).to be_a(Array)
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'is not empty' do
|
51
|
-
Schema.types.
|
51
|
+
expect(Schema.types).not_to be_empty
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'includes :article' do
|
55
|
-
Schema.types.
|
55
|
+
expect(Schema.types).to include(:article)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
describe '.categories' do
|
60
60
|
it 'given a field name returns the corresponding type' do
|
61
|
-
Schema.categories.values_at(:author, :issued, :abstract, :issue).
|
61
|
+
expect(Schema.categories.values_at(:author, :issued, :abstract, :issue)).to eq(
|
62
62
|
[:names, :date, :text, :number]
|
63
|
+
)
|
63
64
|
end
|
64
65
|
|
65
66
|
it 'accepts either string or symbol input' do
|
66
|
-
Schema.categories.
|
67
|
-
Schema.categories['author'].
|
67
|
+
expect(Schema.categories).to have_key(:author)
|
68
|
+
expect(Schema.categories['author']).to equal Schema.categories[:author]
|
68
69
|
end
|
69
70
|
end
|
70
71
|
|
71
72
|
describe '.validate' do
|
72
73
|
it 'accepts and validates a locale instance' do
|
73
|
-
Schema.validate(Locale.load('en-US')).
|
74
|
+
expect(Schema.validate(Locale.load('en-US'))).to eq([])
|
74
75
|
end
|
75
76
|
|
76
77
|
it 'accepts and validates a locale file path' do
|
77
|
-
Schema.validate(File.join(Locale.root, 'locales-en-US.xml')).
|
78
|
+
expect(Schema.validate(File.join(Locale.root, 'locales-en-US.xml'))).to eq([])
|
78
79
|
end
|
79
80
|
|
80
81
|
it 'accepts and validates a locale file' do
|
81
|
-
Schema.validate(File.open(File.join(Locale.root, 'locales-en-US.xml'))).
|
82
|
+
expect(Schema.validate(File.open(File.join(Locale.root, 'locales-en-US.xml')))).to eq([])
|
82
83
|
end
|
83
84
|
|
84
85
|
it 'accepts and validates a locale wildcard path' do
|
85
|
-
Schema.validate(File.join(Locale.root, 'locales-en-*.xml')).
|
86
|
+
expect(Schema.validate(File.join(Locale.root, 'locales-en-*.xml'))).to eq([])
|
86
87
|
end
|
87
88
|
|
88
89
|
it 'accepts and validates a style file path' do
|
89
|
-
Schema.validate(File.join(Style.root, 'apa.csl')).
|
90
|
+
expect(Schema.validate(File.join(Style.root, 'apa.csl'))).to eq([])
|
90
91
|
end
|
91
92
|
|
92
93
|
it 'accepts and validates the xml contents of a style instance' do
|
93
|
-
Schema.validate(Style.load(:apa).pretty_print).
|
94
|
+
expect(Schema.validate(Style.load(:apa).pretty_print)).to eq([])
|
94
95
|
end
|
95
96
|
|
96
97
|
it 'accepts and validates a style instance' do
|
97
|
-
Schema.validate(Style.load(:apa)).
|
98
|
+
expect(Schema.validate(Style.load(:apa))).to eq([])
|
98
99
|
end
|
99
100
|
|
100
101
|
it 'does not accept invalid xml markup' do
|
101
|
-
Schema.validate(%Q{
|
102
|
+
expect(Schema.validate(%Q{
|
102
103
|
<style xmlns="http://purl.org/net/xbiblio/csl" class="note" version="1.0">
|
103
104
|
</stle>
|
104
|
-
})[0][0].
|
105
|
+
})[0][0]).to eq(0) # error on line 0 -> parse error
|
105
106
|
end
|
106
107
|
|
107
108
|
# TODO fix nokogiri/jing validation
|