citeproc 1.0.0.pre12 → 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.
- checksums.yaml +7 -0
- data/.simplecov +4 -0
- data/AGPL +1 -1
- data/BSDL +2 -2
- data/Gemfile +39 -19
- data/README.md +123 -14
- data/Rakefile +22 -8
- data/cucumber.yml +1 -1
- data/features/step_definitions/processor.rb +59 -0
- data/features/support/env.rb +45 -2
- data/lib/citeproc.rb +8 -8
- data/lib/citeproc/abbreviate.rb +5 -4
- data/lib/citeproc/assets.rb +109 -109
- data/lib/citeproc/attributes.rb +11 -11
- data/lib/citeproc/bibliography.rb +107 -71
- data/lib/citeproc/citation_data.rb +175 -150
- data/lib/citeproc/compatibility.rb +5 -108
- data/lib/citeproc/date.rb +23 -12
- data/lib/citeproc/engine.rb +9 -4
- data/lib/citeproc/errors.rb +6 -6
- data/lib/citeproc/extensions.rb +66 -66
- data/lib/citeproc/item.rb +60 -2
- data/lib/citeproc/names.rb +103 -24
- data/lib/citeproc/number.rb +27 -8
- data/lib/citeproc/processor.rb +31 -41
- data/lib/citeproc/selector.rb +132 -126
- data/lib/citeproc/utilities.rb +6 -6
- data/lib/citeproc/variable.rb +5 -4
- data/lib/citeproc/version.rb +1 -1
- data/spec/citeproc/assets_spec.rb +17 -15
- data/spec/citeproc/bibliography_spec.rb +17 -17
- data/spec/citeproc/citation_data_spec.rb +90 -90
- data/spec/citeproc/engine_spec.rb +3 -4
- data/spec/citeproc/item_spec.rb +76 -68
- data/spec/citeproc/names_spec.rb +187 -148
- data/spec/citeproc/processor_spec.rb +119 -115
- data/spec/citeproc/selector_spec.rb +87 -78
- data/spec/citeproc/variable_spec.rb +30 -30
- data/spec/fixtures/locales/locales-en-US.xml +304 -0
- data/spec/spec_helper.rb +32 -1
- data/tasks/testsuite.rb +209 -0
- metadata +19 -87
- data/.gitignore +0 -6
- data/.travis.yml +0 -21
- data/citeproc.gemspec +0 -40
@@ -2,122 +2,126 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module CiteProc
|
4
4
|
describe Processor do
|
5
|
-
|
6
|
-
|
7
|
-
let(:p) { Processor.new }
|
5
|
+
let(:p) { Processor.new }
|
6
|
+
|
8
7
|
let(:palefire) { Item.new(:id => 'palefire', :type => :book, :title => 'Pale Fire') }
|
9
8
|
let(:despair) { Item.new(:id => 'despair', :type => :book, :title => 'Despair') }
|
10
|
-
|
9
|
+
|
11
10
|
it { should_not be nil }
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
11
|
+
|
12
|
+
it { p.engine.should_not be nil }
|
13
|
+
it { p.engine.name.should == 'citeproc-ruby' }
|
14
|
+
|
15
|
+
describe '#register' do
|
16
|
+
|
17
|
+
it 'adds the passed-in item to the items hash' do
|
18
|
+
expect { p.register(palefire) }.to change { p.items.length }.by(1)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'register the item with its id' do
|
22
|
+
expect { p.register(palefire) }.to change { p.has_key?('palefire') }
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#<<' do
|
28
|
+
|
29
|
+
it 'registers the passed in item' do
|
30
|
+
expect { p << palefire }.to change { p.has_key?('palefire') }
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns the processor' do
|
34
|
+
(p << palefire).should be_equal(p)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#[]' do
|
40
|
+
|
41
|
+
describe 'when there is no item with the passed-in id' do
|
42
|
+
it 'returns nil' do
|
43
|
+
p[:palefire].should be nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'when there is an item with the passed-in id' do
|
48
|
+
before(:each) { p.register(palefire) }
|
49
|
+
|
50
|
+
it 'returns the item' do
|
51
|
+
p[:palefire].should equal(palefire)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#update' do
|
57
|
+
|
58
|
+
it 'accepts a single item and adds it to the item hash' do
|
59
|
+
expect { p.update(palefire) }.to change { p.items.length }.by(1)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'registers the passed-in item with its id' do
|
63
|
+
expect { p.update(palefire) }.to change { p[:palefire] }.from(nil).to(palefire)
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'when passed a hash' do
|
67
|
+
it 'registers the value with the key as id' do
|
68
|
+
p.update(:foo => palefire)[:foo].should equal(palefire)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'converts the value to an item' do
|
72
|
+
p.update(:foo => { :title => 'The Story of Foo' })[:foo].should be_a(Item)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'adds all items in the array when passed an array' do
|
77
|
+
expect { p.update([palefire, despair]) }.to change { p.items.length }.by(2)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'adds all items in when passed multiple items' do
|
81
|
+
expect { p.update(palefire, despair) }.to change { p.items.length }.by(2)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
describe '#bibliography (generates the bibliography)' do
|
87
|
+
|
88
|
+
describe 'when no items have been processed' do
|
89
|
+
|
90
|
+
it 'returns an empty bibliography' do
|
91
|
+
p.bibliography.should be_empty
|
92
|
+
end
|
93
|
+
|
94
|
+
# it 'returns a bibliography of all registered items if invoked with :all'
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
describe 'when items have been processed' do
|
99
|
+
|
100
|
+
it 'returns a bibliography containing all cited items'
|
101
|
+
|
102
|
+
# it 'returns a bibliography of all registered items if invoked with :all'
|
103
|
+
|
104
|
+
describe 'when invoked with a block as filter' do
|
105
|
+
|
106
|
+
it 'returns an empty bibliography if the block always returns false'
|
107
|
+
|
108
|
+
it 'returns the full bibliography if the block always returns true'
|
109
|
+
|
110
|
+
it 'returns a bibliography with all items for which the block returns true'
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
describe 'when passed a hash as argument' do
|
115
|
+
|
116
|
+
it 'fails if the hash is no valid selector'
|
117
|
+
|
118
|
+
it 'creates a selector from the hash and returns a bibliography containing all matching items'
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
122
126
|
end
|
123
|
-
end
|
127
|
+
end
|
@@ -1,81 +1,90 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module CiteProc
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
end
|
4
|
+
|
5
|
+
describe Selector do
|
6
|
+
|
7
|
+
let(:select_books) { Selector.new(:all => { :type => :book }) }
|
8
|
+
|
9
|
+
it { should_not be nil }
|
10
|
+
it { should be_empty }
|
11
|
+
|
12
|
+
|
13
|
+
it 'should have no skip_condtions by default' do
|
14
|
+
Selector.new.skip_conditions.should be_empty
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should have no condtions by default' do
|
18
|
+
Selector.new.conditions.should be_empty
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'constructing' do
|
22
|
+
|
23
|
+
%w{ all none any skip }.each do |matcher|
|
24
|
+
it "accepts the ruby style matcher '#{matcher}'" do
|
25
|
+
Selector.new(matcher => {}).should_not be nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
%w{ include exclude select quash }.each do |matcher|
|
30
|
+
it "accepts the citeproc-js style matcher '#{matcher}'" do
|
31
|
+
Selector.new(matcher => {}).should_not be nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# it 'fails if the hash contains more than two elements'
|
36
|
+
# it 'fails if the hash contains unknown keys'
|
37
|
+
|
38
|
+
# it 'accepts a citeproc json style hash'
|
39
|
+
|
40
|
+
it 'accepts a json object (select)' do
|
41
|
+
Selector.new(
|
42
|
+
"select" => [
|
43
|
+
{
|
44
|
+
"field" => "type",
|
45
|
+
"value" => "book"
|
46
|
+
},
|
47
|
+
{ "field" => "categories",
|
48
|
+
"value" => "1990s"
|
49
|
+
}
|
50
|
+
]
|
51
|
+
).conditions.should have(2).items
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#to_proc' do
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#to_citeproc' do
|
59
|
+
|
60
|
+
it 'returns nil by default' do
|
61
|
+
Selector.new.to_citeproc.should be nil
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'converts all matcher to select' do
|
65
|
+
Selector.new(:all => { :a => 'b' }).to_citeproc.should == { 'select' => [{ 'field' => 'a', 'value' => 'b' }]}
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'converts any matcher to include' do
|
69
|
+
Selector.new(:any => { :a => 'b' }).to_citeproc.should == { 'include' => [{ 'field' => 'a', 'value' => 'b' }]}
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'converts none matcher to exclude' do
|
73
|
+
Selector.new(:none => { :a => 'b' }).to_citeproc.should == { 'exclude' => [{ 'field' => 'a', 'value' => 'b' }]}
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#matches?' do
|
78
|
+
it 'always matches by default' do
|
79
|
+
Selector.new.matches?(nil).should be_true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '#skip?' do
|
84
|
+
it 'never skips when by default' do
|
85
|
+
Selector.new.skip?(nil).should be_false
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
@@ -2,22 +2,22 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module CiteProc
|
4
4
|
describe Variable do
|
5
|
-
|
5
|
+
|
6
6
|
describe '.new' do
|
7
7
|
it { should be_an_instance_of(Variable) }
|
8
|
-
|
8
|
+
|
9
9
|
it 'is empty by default' do
|
10
10
|
Variable.new.should be_empty
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
it 'equals an empty string (==) by default' do
|
14
14
|
Variable.new.should == ''
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it 'matches an empty pattern by default' do
|
18
18
|
Variable.new.should =~ /^$/
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
it 'accepts a string value' do
|
22
22
|
Variable.new('test').should == 'test'
|
23
23
|
end
|
@@ -25,10 +25,10 @@ module CiteProc
|
|
25
25
|
it 'accepts a numeric value' do
|
26
26
|
Variable.new(23).should == '23'
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
it 'accepts a floating point value' do
|
30
30
|
Variable.new(23.12).should == '23.12'
|
31
|
-
end
|
31
|
+
end
|
32
32
|
end
|
33
33
|
|
34
34
|
describe '.fields' do
|
@@ -50,41 +50,41 @@ module CiteProc
|
|
50
50
|
Variable.fields[:numbers].should_not be_empty
|
51
51
|
Variable.fields[:number].should_not be_empty
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
it 'accepts either string or symbol input' do
|
55
55
|
Variable.fields[:names].should equal Variable.fields['names']
|
56
|
-
end
|
56
|
+
end
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
describe '.types' do
|
60
60
|
it 'given a field name returns the corresponding type' do
|
61
61
|
Variable.types.values_at(:author, :issued, :abstract, :issue).should == [:names, :date, :text, :number]
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
it 'accepts either string or symbol input' do
|
65
65
|
Variable.types.should have_key(:author)
|
66
66
|
Variable.types['author'].should equal Variable.types[:author]
|
67
67
|
end
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
describe '#to_s' do
|
71
71
|
it 'displays the value' do
|
72
72
|
Variable.new('test').to_s.should == 'test'
|
73
73
|
end
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
describe '#to_i' do
|
77
77
|
it 'returns zero by default' do
|
78
78
|
Variable.new.to_i.should == 0
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
context 'when the value is numeric' do
|
82
82
|
%w{ -23 -1 0 1 23 }.each do |value|
|
83
83
|
it "returns the integer value (#{value})" do
|
84
84
|
Variable.new(value).to_i.should equal(value.to_i)
|
85
85
|
end
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
it 'returns only the first numeric value if there are several' do
|
89
89
|
Variable.new('testing 1, 2, 3...').to_i.should == 1
|
90
90
|
end
|
@@ -95,24 +95,24 @@ module CiteProc
|
|
95
95
|
it 'returns zero by default' do
|
96
96
|
Variable.new.to_f.should == 0.0
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
context 'when the value is numeric' do
|
100
100
|
%w{ -23.2 -1.45 0.2 1.733 23 }.each do |value|
|
101
101
|
it "returns the integer value (#{value})" do
|
102
102
|
Variable.new(value).to_f.should == value.to_f
|
103
103
|
end
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
it 'returns only the first numeric value if there are several' do
|
107
107
|
Variable.new('testing 1, 2, 3...').to_f.should == 1.0
|
108
108
|
end
|
109
|
-
|
109
|
+
|
110
110
|
it 'works with dot and comma separators' do
|
111
111
|
Variable.new('1,23').to_f.should == Variable.new('1.23').to_f
|
112
112
|
end
|
113
113
|
end
|
114
114
|
end
|
115
|
-
|
115
|
+
|
116
116
|
describe '#numeric?' do
|
117
117
|
it 'returns false by default' do
|
118
118
|
Variable.new.should_not be_numeric
|
@@ -127,28 +127,28 @@ module CiteProc
|
|
127
127
|
it 'returns true (integer initialized)' do
|
128
128
|
Variable.new(23).should be_numeric
|
129
129
|
end
|
130
|
-
end
|
130
|
+
end
|
131
131
|
|
132
132
|
context 'variable does not contain a number' do
|
133
133
|
it 'returns false for strings' do
|
134
134
|
Variable.new('test').should_not be_numeric
|
135
135
|
end
|
136
136
|
end
|
137
|
-
|
137
|
+
|
138
138
|
context 'variable contains numbers but is not numeric' do
|
139
139
|
it 'returns false for strings' do
|
140
140
|
Variable.new('23rd test').should_not be_numeric
|
141
141
|
Variable.new('23rd, 24th & 25th edition').should_not be_numeric
|
142
142
|
end
|
143
143
|
end
|
144
|
-
|
144
|
+
|
145
145
|
context 'variable contains multiple numbers' do
|
146
146
|
it 'returns true for simple ranges' do
|
147
147
|
Variable.new('23-24').should be_numeric
|
148
148
|
Variable.new('23 - 24').should be_numeric
|
149
149
|
Variable.new('23- 24').should be_numeric
|
150
150
|
end
|
151
|
-
|
151
|
+
|
152
152
|
it 'returns true for simple lists' do
|
153
153
|
Variable.new('23,24').should be_numeric
|
154
154
|
Variable.new('23 , 24').should be_numeric
|
@@ -156,14 +156,14 @@ module CiteProc
|
|
156
156
|
Variable.new('23 ,24').should be_numeric
|
157
157
|
Variable.new('23 ,24,25 , 26, 27').should be_numeric
|
158
158
|
end
|
159
|
-
|
159
|
+
|
160
160
|
it 'returns true for complex lists' do
|
161
161
|
Variable.new('23rd, 24th & 25th').should be_numeric
|
162
162
|
Variable.new('X23, A2-49th & 25th & A1, B2').should be_numeric
|
163
163
|
end
|
164
164
|
end
|
165
165
|
end
|
166
|
-
|
166
|
+
|
167
167
|
describe '#strip_markup' do
|
168
168
|
let(:greeting) { '<h1>hello<b> world</b></h1>' }
|
169
169
|
it 'returns a string stripped of html tags' do
|
@@ -184,13 +184,13 @@ module CiteProc
|
|
184
184
|
v.should == 'hello world'
|
185
185
|
end
|
186
186
|
end
|
187
|
-
|
188
|
-
|
187
|
+
|
188
|
+
|
189
189
|
describe 'sorting' do
|
190
190
|
end
|
191
|
-
|
191
|
+
|
192
192
|
describe '#to_json' do
|
193
193
|
end
|
194
|
-
|
194
|
+
|
195
195
|
end
|
196
|
-
end
|
196
|
+
end
|