citeproc 1.0.1 → 1.0.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/Gemfile +11 -5
- data/features/step_definitions/processor.rb +9 -9
- data/features/support/env.rb +6 -4
- data/lib/citeproc/item.rb +5 -0
- data/lib/citeproc/version.rb +1 -1
- data/spec/citeproc/abbreviate_spec.rb +5 -5
- data/spec/citeproc/assets_spec.rb +8 -8
- data/spec/citeproc/attributes_spec.rb +3 -3
- data/spec/citeproc/bibliography_spec.rb +10 -10
- data/spec/citeproc/citation_data_spec.rb +12 -12
- data/spec/citeproc/date_spec.rb +89 -89
- data/spec/citeproc/engine_spec.rb +2 -2
- data/spec/citeproc/extensions_spec.rb +20 -20
- data/spec/citeproc/item_spec.rb +15 -15
- data/spec/citeproc/names_spec.rb +130 -130
- data/spec/citeproc/processor_spec.rb +8 -8
- data/spec/citeproc/selector_spec.rb +12 -12
- data/spec/citeproc/utilities_spec.rb +1 -1
- data/spec/citeproc/variable_spec.rb +46 -46
- data/spec/spec_helper.rb +3 -2
- data/tasks/testsuite.rb +0 -3
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66ce4e398cb9a4ab393a5f4baf0bbb08b54b053c
|
4
|
+
data.tar.gz: 222b8101e61b1aac744082a5155106cc15e49499
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07a7857820062116708c5f0716471016b065eafb460da34d07b8e401030fac0e5207e2b314a7cfbd1ca26caa53ccbf47ed7888d61831abb5454a13c80197d53a
|
7
|
+
data.tar.gz: c67fcd016def1e8664b42651848549ab3fc2355e1945e5ac6f8e5c260a2c2db152057828729be5903fd60ffd1548f8ab149155adcefe32f6c7a7b98f9aadba33
|
data/Gemfile
CHANGED
@@ -2,10 +2,16 @@ source 'https://rubygems.org'
|
|
2
2
|
gemspec
|
3
3
|
|
4
4
|
group :debug do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
if RUBY_VERSION >= '2.0'
|
6
|
+
gem 'byebug', :require => false, :platforms => :mri
|
7
|
+
else
|
8
|
+
gem 'debugger', :require => false, :platforms => :mri
|
9
|
+
end
|
10
|
+
|
11
|
+
gem 'ruby-debug', :require => false, :platforms => :jruby
|
12
|
+
|
13
|
+
gem 'rubinius-debugger', :require => false, :platforms => :rbx
|
14
|
+
gem 'rubinius-compiler', :require => false, :platforms => :rbx
|
9
15
|
end
|
10
16
|
|
11
17
|
group :optional do
|
@@ -30,7 +36,7 @@ end
|
|
30
36
|
group :development do
|
31
37
|
gem 'rake'
|
32
38
|
gem 'cucumber'
|
33
|
-
gem 'rspec'
|
39
|
+
gem 'rspec', '~>2.0'
|
34
40
|
gem 'simplecov', '~>0.8', :require => false
|
35
41
|
gem 'rubinius-coverage', :platform => :rbx
|
36
42
|
gem 'coveralls', :require => false
|
@@ -4,32 +4,32 @@ end
|
|
4
4
|
|
5
5
|
Given(/^the following input:$/) do |string|
|
6
6
|
@input = JSON.parse(string)
|
7
|
-
@input.
|
7
|
+
expect(@input).not_to be_nil
|
8
8
|
|
9
9
|
processor.import @input
|
10
10
|
end
|
11
11
|
|
12
12
|
Given(/^the following abbreviations:$/) do |string|
|
13
13
|
processor.abbreviations = JSON.parse(string)
|
14
|
-
processor.abbreviations[:default].
|
14
|
+
expect(processor.abbreviations[:default]).not_to be_empty
|
15
15
|
end
|
16
16
|
|
17
17
|
When(/^I render the entire bibliography$/) do
|
18
18
|
@bibliography = processor.bibliography
|
19
|
-
@bibliography.errors.
|
19
|
+
expect(@bibliography.errors).to eq([])
|
20
20
|
end
|
21
21
|
|
22
22
|
When(/^I render the following bibliography selection:$/) do |string|
|
23
23
|
selection = JSON.parse(string)
|
24
|
-
selection.
|
24
|
+
expect(selection).not_to be_nil
|
25
25
|
|
26
26
|
@bibliography = processor.bibliography(selection)
|
27
|
-
@bibliography.errors.
|
27
|
+
expect(@bibliography.errors).to eq([])
|
28
28
|
end
|
29
29
|
|
30
30
|
Then(/^the bibliography should be:$/) do |string|
|
31
31
|
string.gsub!(/\n\s*/m, '') # strip newlines
|
32
|
-
@bibliography.join.
|
32
|
+
expect(@bibliography.join).to eq(string)
|
33
33
|
end
|
34
34
|
|
35
35
|
When(/^I cite the following items:$/) do |string|
|
@@ -46,14 +46,14 @@ Then(/^the bibliography's options should match:$/) do |table|
|
|
46
46
|
headers = table.headers.map(&:to_sym)
|
47
47
|
expected = table.rows[0]
|
48
48
|
|
49
|
-
@bibliography.options.values_at(*headers).
|
49
|
+
expect(@bibliography.options.values_at(*headers)).to eq(expected)
|
50
50
|
end
|
51
51
|
|
52
52
|
Then(/^the results should be:$/) do |table|
|
53
|
-
@results.
|
53
|
+
expect(@results).to eq(table.raw.map(&:first))
|
54
54
|
end
|
55
55
|
|
56
56
|
Then(/^the result should be:$/) do |string|
|
57
|
-
@result.
|
57
|
+
expect(@result).to eq(string)
|
58
58
|
end
|
59
59
|
|
data/features/support/env.rb
CHANGED
@@ -6,13 +6,15 @@ end
|
|
6
6
|
|
7
7
|
begin
|
8
8
|
case
|
9
|
-
when RUBY_PLATFORM
|
10
|
-
require 'debug'
|
11
|
-
Debugger.start
|
9
|
+
when RUBY_PLATFORM == 'java'
|
10
|
+
# require 'debug'
|
11
|
+
# Debugger.start
|
12
12
|
when defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
|
13
13
|
require 'rubinius/debugger'
|
14
|
-
|
14
|
+
when RUBY_VERSION < '2.0'
|
15
15
|
require 'debugger'
|
16
|
+
else
|
17
|
+
require 'byebug'
|
16
18
|
end
|
17
19
|
rescue LoadError
|
18
20
|
# ignore
|
data/lib/citeproc/item.rb
CHANGED
@@ -108,6 +108,11 @@ module CiteProc
|
|
108
108
|
notify_observers :read, key, value
|
109
109
|
end
|
110
110
|
|
111
|
+
def simulate_read_attribute(key, value)
|
112
|
+
changed
|
113
|
+
notify_observers :read, key, value
|
114
|
+
end
|
115
|
+
|
111
116
|
alias original_read_attribute read_attribute
|
112
117
|
alias unobservable_read_attribute read_attribute
|
113
118
|
|
data/lib/citeproc/version.rb
CHANGED
@@ -11,8 +11,8 @@ module CiteProc
|
|
11
11
|
let(:abbrev) { Hash[:foo, :bar] }
|
12
12
|
it 'uses the hash as the new set of abbreviations' do
|
13
13
|
subject.abbreviations = abbrev
|
14
|
-
subject.abbreviations.
|
15
|
-
subject.abbreviations.
|
14
|
+
expect(subject.abbreviations).to eq(abbrev)
|
15
|
+
expect(subject.abbreviations).not_to equal(abbrev)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -20,16 +20,16 @@ module CiteProc
|
|
20
20
|
let(:abbrev) { '{"foo":"bar"}' }
|
21
21
|
it 'uses the hash as the new set of abbreviations' do
|
22
22
|
subject.abbreviations = abbrev
|
23
|
-
subject.abbreviations.
|
23
|
+
expect(subject.abbreviations).to eq(Hash[:foo,'bar'])
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
describe '#abbreviate' do
|
29
29
|
it 'looks up abbreviations in the default namespace by default' do
|
30
|
-
subject.abbreviate(:title, 'foo').
|
30
|
+
expect(subject.abbreviate(:title, 'foo')).to eq(nil)
|
31
31
|
subject.abbreviations[:default][:title] = { 'foo' => 'bar' }
|
32
|
-
subject.abbreviate(:title, 'foo').
|
32
|
+
expect(subject.abbreviate(:title, 'foo')).to eq('bar')
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -30,40 +30,40 @@ module CiteProc
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'should not be open by default' do
|
33
|
-
Style.new.
|
33
|
+
expect(Style.new).not_to be_open
|
34
34
|
end
|
35
35
|
|
36
36
|
describe '.open' do
|
37
37
|
|
38
38
|
it 'accepts an absolute file name' do
|
39
|
-
Style.open(@file.path).to_s.
|
39
|
+
expect(Style.open(@file.path).to_s).to eq("asset content\n")
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'accepts a file name' do
|
43
|
-
Style.open(@name).to_s.
|
43
|
+
expect(Style.open(@name).to_s).to eq("asset content\n")
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'accepts a file name without extension' do
|
47
|
-
Style.open(@name.sub(/#{@extension}$/,'')).to_s.
|
47
|
+
expect(Style.open(@name.sub(/#{@extension}$/,'')).to_s).to eq("asset content\n")
|
48
48
|
end
|
49
49
|
|
50
50
|
|
51
51
|
it 'accepts an io object' do
|
52
|
-
Style.open(@file.open).to_s.
|
52
|
+
expect(Style.open(@file.open).to_s).to eq("asset content\n")
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'returns the given string if it looks like XML' do
|
56
|
-
Style.open('<b>foo bar!</b>').to_s.
|
56
|
+
expect(Style.open('<b>foo bar!</b>').to_s).to eq('<b>foo bar!</b>')
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
60
|
describe '.extend_name' do
|
61
61
|
it 'adds the default extension if the file does not already end with it' do
|
62
|
-
Style.extend_name(@name.sub(/#{@extension}$/,'')).
|
62
|
+
expect(Style.extend_name(@name.sub(/#{@extension}$/,''))).to eq(@name)
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'does not add the default extension if the file already ends with it' do
|
66
|
-
Style.extend_name(@name).
|
66
|
+
expect(Style.extend_name(@name)).to eq(@name)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
@@ -33,18 +33,18 @@ module CiteProc
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'generates no other setters' do
|
36
|
-
|
36
|
+
expect { A.new.some_other_value }.to raise_error
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
describe '#merge' do
|
41
41
|
|
42
42
|
it 'merges non-existent values from other object' do
|
43
|
-
A.new.merge(other)[:foo].
|
43
|
+
expect(A.new.merge(other)[:foo]).to eq('bar')
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'does not overwrite existing values when merging other object' do
|
47
|
-
instance.merge(other)[:bar].
|
47
|
+
expect(instance.merge(other)[:bar]).to eq('foo')
|
48
48
|
end
|
49
49
|
|
50
50
|
end
|
@@ -10,29 +10,29 @@ module CiteProc
|
|
10
10
|
describe '#to_citeproc conversion' do
|
11
11
|
|
12
12
|
it 'returns an array' do
|
13
|
-
subject.to_citeproc.
|
13
|
+
expect(subject.to_citeproc).to be_a(Array)
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'returns exactly two elements' do
|
17
|
-
subject.to_citeproc.
|
17
|
+
expect(subject.to_citeproc.size).to eq(2)
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'returns formatting options as the first element' do
|
21
|
-
subject.to_citeproc.first.
|
21
|
+
expect(subject.to_citeproc.first).to be_a(Hash)
|
22
22
|
end
|
23
23
|
|
24
24
|
describe 'the formatting options' do
|
25
25
|
let(:options) { subject.to_citeproc[0] }
|
26
26
|
|
27
27
|
it 'contains a the error list' do
|
28
|
-
options.
|
29
|
-
options['bibliography_errors'].
|
28
|
+
expect(options).to have_key('bibliography_errors')
|
29
|
+
expect(options['bibliography_errors']).to be_empty
|
30
30
|
end
|
31
31
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'returns the list of references as the second element' do
|
35
|
-
subject.to_citeproc.last.
|
35
|
+
expect(subject.to_citeproc.last).to be_a(Array)
|
36
36
|
end
|
37
37
|
|
38
38
|
end
|
@@ -59,10 +59,10 @@ module CiteProc
|
|
59
59
|
|
60
60
|
it 'parses citeproc/json strings' do
|
61
61
|
b = Bibliography.create!(js)
|
62
|
-
b.
|
63
|
-
b.
|
64
|
-
b.
|
65
|
-
b.options[:'second-field-align'].
|
62
|
+
expect(b).to be_a(Bibliography)
|
63
|
+
expect(b.references.size).to eq(2)
|
64
|
+
expect(b).not_to have_errors
|
65
|
+
expect(b.options[:'second-field-align']).to be true
|
66
66
|
end
|
67
67
|
|
68
68
|
end
|
@@ -25,25 +25,25 @@ module CiteProc
|
|
25
25
|
it { should be_empty }
|
26
26
|
|
27
27
|
it 'has not been processed by default' do
|
28
|
-
CitationData.new.
|
28
|
+
expect(CitationData.new).not_to be_processed
|
29
29
|
end
|
30
30
|
|
31
31
|
describe '.new' do
|
32
32
|
|
33
33
|
it 'accepts a citeproc hash' do
|
34
34
|
d = CitationData.new(hash)
|
35
|
-
d.
|
36
|
-
d.
|
37
|
-
d[0].
|
38
|
-
d.index.
|
35
|
+
expect(d).to be_footnote
|
36
|
+
expect(d).not_to be_empty
|
37
|
+
expect(d[0]).to be_a(CitationItem)
|
38
|
+
expect(d.index).to eq(1)
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'accepts an array of items' do
|
42
|
-
CitationData.new([CitationItem.new(:id => 'id')]).
|
42
|
+
expect(CitationData.new([CitationItem.new(:id => 'id')]).items.size).to eq(1)
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'accepts an array of hashes' do
|
46
|
-
CitationData.new([{:id => 'id'}])[0].
|
46
|
+
expect(CitationData.new([{:id => 'id'}])[0]).to be_a(CitationItem)
|
47
47
|
end
|
48
48
|
|
49
49
|
end
|
@@ -51,7 +51,7 @@ module CiteProc
|
|
51
51
|
describe '#to_citeproc' do
|
52
52
|
|
53
53
|
it 'returns empty an empty/default citation data element by default' do
|
54
|
-
CitationData.new.to_citeproc.
|
54
|
+
expect(CitationData.new.to_citeproc).to eq({ 'citationItems' => [], 'properties' => { 'noteIndex' => 0}})
|
55
55
|
end
|
56
56
|
|
57
57
|
|
@@ -67,7 +67,7 @@ module CiteProc
|
|
67
67
|
describe '.new' do
|
68
68
|
|
69
69
|
it 'accepts a hash as input' do
|
70
|
-
CitationItem.new(:label => 'chapter').
|
70
|
+
expect(CitationItem.new(:label => 'chapter')).to have_label
|
71
71
|
end
|
72
72
|
|
73
73
|
end
|
@@ -75,15 +75,15 @@ module CiteProc
|
|
75
75
|
describe '#to_citeproc' do
|
76
76
|
|
77
77
|
it 'returns empty citation data by default' do
|
78
|
-
CitationItem.new.to_citeproc.
|
78
|
+
expect(CitationItem.new.to_citeproc).to eq({})
|
79
79
|
end
|
80
80
|
|
81
81
|
it 'returns a hash with stringified keys' do
|
82
|
-
CitationItem.new(:type => :article).to_citeproc.
|
82
|
+
expect(CitationItem.new(:type => :article).to_citeproc).to have_key('type')
|
83
83
|
end
|
84
84
|
|
85
85
|
it 'returns a hash with stringified values' do
|
86
|
-
CitationItem.new(:type => :article).to_citeproc.
|
86
|
+
expect(CitationItem.new(:type => :article).to_citeproc).to have_value('article')
|
87
87
|
end
|
88
88
|
|
89
89
|
end
|
data/spec/citeproc/date_spec.rb
CHANGED
@@ -10,31 +10,31 @@ module CiteProc
|
|
10
10
|
|
11
11
|
describe 'sorting' do
|
12
12
|
it 'treats [2003] as less than [2003,1]' do
|
13
|
-
DateParts.new(2003).
|
13
|
+
expect(DateParts.new(2003)).to be < DateParts.new(2003,1)
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'treats [1992,9,23] as less than [1993,8,22]' do
|
17
|
-
DateParts.new(1992,9,23).
|
17
|
+
expect(DateParts.new(1992,9,23)).to be < DateParts.new(1993,8,22)
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'treats [1992,9,23] as less than [1992,10,22]' do
|
21
|
-
DateParts.new(1992,9,23).
|
21
|
+
expect(DateParts.new(1992,9,23)).to be < DateParts.new(1992,10,22)
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'treats [1992,9,23] as less than [1992,9,24]' do
|
25
|
-
DateParts.new(1992,9,23).
|
25
|
+
expect(DateParts.new(1992,9,23)).to be < DateParts.new(1992,9,24)
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'treats [-50] as less than [-25]' do
|
29
|
-
DateParts.new(-50).
|
29
|
+
expect(DateParts.new(-50)).to be < DateParts.new(-25)
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'treats [-50] as less than [-50,12]' do
|
33
|
-
DateParts.new(-50).
|
33
|
+
expect(DateParts.new(-50)).to be < DateParts.new(-50,12)
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'treats [1994,1,23] as less than today' do
|
37
|
-
DateParts.new(1994,1,23).
|
37
|
+
expect(DateParts.new(1994,1,23)).to be < ::Date.today
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -42,56 +42,56 @@ module CiteProc
|
|
42
42
|
let(:date) { DateParts.new(1991,8,22) }
|
43
43
|
|
44
44
|
it 'creates a copy that contains the same parts' do
|
45
|
-
date.dup.to_a.
|
45
|
+
expect(date.dup.to_a).to eq([1991,8,22])
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'does not return self' do
|
49
|
-
date.dup.
|
50
|
-
date.dup.
|
49
|
+
expect(date.dup).not_to equal(date)
|
50
|
+
expect(date.dup).to eq(date)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
describe '#update' do
|
55
55
|
it 'accepts a hash' do
|
56
|
-
DateParts.new.update(:month => 2, :year => 80).to_a.
|
56
|
+
expect(DateParts.new.update(:month => 2, :year => 80).to_a).to eq([80,2,nil])
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'accepts an array' do
|
60
|
-
DateParts.new.update([80,2]).to_a.
|
60
|
+
expect(DateParts.new.update([80,2]).to_a).to eq([80,2,nil])
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
64
|
describe '#strftime' do
|
65
65
|
it 'formats the date parts according to the format string' do
|
66
|
-
DateParts.new(1998,2,4).strftime('FOO %0m%0d%y').
|
66
|
+
expect(DateParts.new(1998,2,4).strftime('FOO %0m%0d%y')).to eq('FOO 020498')
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
70
|
describe 'to_citeproc' do
|
71
71
|
it 'returns an empty list by default' do
|
72
|
-
DateParts.new.to_citeproc.
|
72
|
+
expect(DateParts.new.to_citeproc).to eq([])
|
73
73
|
end
|
74
74
|
|
75
75
|
it 'returns a list with the year if only the year is set' do
|
76
|
-
DateParts.new(2001).to_citeproc.
|
76
|
+
expect(DateParts.new(2001).to_citeproc).to eq([2001])
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'supports zero parts' do
|
80
|
-
DateParts.new(0,0).to_citeproc.
|
80
|
+
expect(DateParts.new(0,0).to_citeproc).to eq([0,0])
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
84
|
describe '#open?' do
|
85
85
|
it 'returns false by default' do
|
86
|
-
DateParts.new.
|
86
|
+
expect(DateParts.new).not_to be_open
|
87
87
|
end
|
88
88
|
|
89
89
|
it 'returns false for [1999,8,24]' do
|
90
|
-
DateParts.new(1999, 8, 24).
|
90
|
+
expect(DateParts.new(1999, 8, 24)).not_to be_open
|
91
91
|
end
|
92
92
|
|
93
93
|
it 'returns true for [0]' do
|
94
|
-
DateParts.new(0).
|
94
|
+
expect(DateParts.new(0)).to be_open
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|
@@ -113,80 +113,80 @@ module CiteProc
|
|
113
113
|
|
114
114
|
describe '.new' do
|
115
115
|
it 'accepts a hash as input' do
|
116
|
-
Date.new(:literal => 'Summer').to_s.
|
116
|
+
expect(Date.new(:literal => 'Summer').to_s).to eq('Summer')
|
117
117
|
end
|
118
118
|
|
119
119
|
it 'accepts a hash as input and converts date parts' do
|
120
|
-
Date.new(:'date-parts' => [[2003,2]]).parts[0].
|
120
|
+
expect(Date.new(:'date-parts' => [[2003,2]]).parts[0]).to be_a(Date::DateParts)
|
121
121
|
end
|
122
122
|
|
123
123
|
it 'accepts a fixnum and treats it as the year' do
|
124
|
-
Date.new(1666).year.
|
124
|
+
expect(Date.new(1666).year).to eq(1666)
|
125
125
|
end
|
126
126
|
|
127
127
|
it 'accepts a date' do
|
128
|
-
Date.new(::Date.new(1980,4)).month.
|
128
|
+
expect(Date.new(::Date.new(1980,4)).month).to eq(4)
|
129
129
|
end
|
130
130
|
|
131
131
|
it 'accepts a date and creates date parts' do
|
132
|
-
Date.new(::Date.new(1980,4)).parts[0].to_citeproc.
|
132
|
+
expect(Date.new(::Date.new(1980,4)).parts[0].to_citeproc).to eq([1980,4,1])
|
133
133
|
end
|
134
134
|
|
135
135
|
it 'is empty by default' do
|
136
|
-
Date.new.
|
136
|
+
expect(Date.new).to be_empty
|
137
137
|
end
|
138
138
|
|
139
139
|
it 'accepts date strings' do
|
140
|
-
Date.new('2009-03-19').day.
|
140
|
+
expect(Date.new('2009-03-19').day).to eq(19)
|
141
141
|
end
|
142
142
|
|
143
143
|
it 'accepts JSON strings' do
|
144
|
-
Date.new('{ "date-parts": [[2001,1,19]]}').day.
|
144
|
+
expect(Date.new('{ "date-parts": [[2001,1,19]]}').day).to eq(19)
|
145
145
|
end
|
146
146
|
|
147
147
|
it 'accepts date parts in an array' do
|
148
|
-
Date.new([2009,3]).month.
|
148
|
+
expect(Date.new([2009,3]).month).to eq(3)
|
149
149
|
end
|
150
150
|
|
151
151
|
it 'accepts ranges as an array' do
|
152
|
-
Date.new([[2009],[2012]]).
|
152
|
+
expect(Date.new([[2009],[2012]])).to be_range
|
153
153
|
end
|
154
154
|
|
155
155
|
it 'accepts year ranges' do
|
156
|
-
Date.new(2009..2012).
|
156
|
+
expect(Date.new(2009..2012)).to be_range
|
157
157
|
end
|
158
158
|
|
159
159
|
it 'accepts exclusive date ranges' do
|
160
|
-
Date.new(::Date.new(2009) ... ::Date.new(2011)).end_date.year.
|
160
|
+
expect(Date.new(::Date.new(2009) ... ::Date.new(2011)).end_date.year).to eq(2010)
|
161
161
|
end
|
162
162
|
|
163
163
|
it 'accepts inclusive date ranges' do
|
164
|
-
Date.new(::Date.new(2009) .. ::Date.new(2011)).end_date.year.
|
164
|
+
expect(Date.new(::Date.new(2009) .. ::Date.new(2011)).end_date.year).to eq(2011)
|
165
165
|
end
|
166
166
|
|
167
167
|
it 'accepts EDTF date strings' do
|
168
|
-
Date.new('2009?-03-19').
|
168
|
+
expect(Date.new('2009?-03-19')).to be_uncertain
|
169
169
|
end
|
170
170
|
|
171
171
|
it 'accepts EDTF intervals' do
|
172
|
-
Date.new('2009-03-19/2010-11-21').parts.map(&:to_citeproc).
|
172
|
+
expect(Date.new('2009-03-19/2010-11-21').parts.map(&:to_citeproc)).to eq([[2009,3,19],[2010,11,21]])
|
173
173
|
end
|
174
174
|
end
|
175
175
|
|
176
176
|
describe '.parse' do
|
177
177
|
it 'returns nil by default' do
|
178
|
-
Date.parse('').
|
179
|
-
Date.parse(nil).
|
178
|
+
expect(Date.parse('')).to be nil
|
179
|
+
expect(Date.parse(nil)).to be nil
|
180
180
|
end
|
181
181
|
|
182
182
|
it 'parses date strings' do
|
183
|
-
Date.parse('2004-10-26').year.
|
183
|
+
expect(Date.parse('2004-10-26').year).to eq(2004)
|
184
184
|
end
|
185
185
|
end
|
186
186
|
|
187
187
|
describe '.create' do
|
188
188
|
it 'should accept parameters and return a new instance' do
|
189
|
-
Date.create('date-parts' => [[2001, 1]]).year.
|
189
|
+
expect(Date.create('date-parts' => [[2001, 1]]).year).to eq(2001)
|
190
190
|
end
|
191
191
|
end
|
192
192
|
|
@@ -194,12 +194,12 @@ module CiteProc
|
|
194
194
|
let(:date) { Date.new([1991,8]) }
|
195
195
|
|
196
196
|
it 'creates a copy that contains the same parts' do
|
197
|
-
date.dup.parts.map(&:to_citeproc).
|
197
|
+
expect(date.dup.parts.map(&:to_citeproc)).to eq([[1991,8]])
|
198
198
|
end
|
199
199
|
|
200
200
|
it 'copies uncertainty' do
|
201
|
-
date.dup.
|
202
|
-
date.uncertain!.dup.
|
201
|
+
expect(date.dup).not_to be_uncertain
|
202
|
+
expect(date.uncertain!.dup).to be_uncertain
|
203
203
|
end
|
204
204
|
|
205
205
|
it 'makes a deep copy of attributes' do
|
@@ -211,95 +211,95 @@ module CiteProc
|
|
211
211
|
end
|
212
212
|
|
213
213
|
it 'does not return self' do
|
214
|
-
date.dup.
|
215
|
-
date.dup.
|
214
|
+
expect(date.dup).not_to equal(date)
|
215
|
+
expect(date.dup).to eq(date)
|
216
216
|
end
|
217
217
|
end
|
218
218
|
|
219
219
|
describe 'literal dates' do
|
220
220
|
it 'is not literal by default' do
|
221
|
-
Date.new.
|
221
|
+
expect(Date.new).not_to be_literal
|
222
222
|
end
|
223
223
|
|
224
224
|
it 'is literal if it contains only a literal field' do
|
225
|
-
Date.create(:literal => 'foo').
|
225
|
+
expect(Date.create(:literal => 'foo')).to be_literal
|
226
226
|
end
|
227
227
|
|
228
228
|
it 'is literal if it contains a literal field' do
|
229
|
-
Date.create('date-parts' => [[2000]], :literal => 'foo').
|
229
|
+
expect(Date.create('date-parts' => [[2000]], :literal => 'foo')).to be_literal
|
230
230
|
end
|
231
231
|
end
|
232
232
|
|
233
233
|
describe 'seasons' do
|
234
234
|
it 'is no season by default' do
|
235
|
-
Date.new.
|
235
|
+
expect(Date.new).not_to be_season
|
236
236
|
end
|
237
237
|
|
238
238
|
it 'is a season if contains only a season field' do
|
239
|
-
Date.new(:season => 'Winter').
|
239
|
+
expect(Date.new(:season => 'Winter')).to be_season
|
240
240
|
end
|
241
241
|
|
242
242
|
it 'is a season if contains a season field' do
|
243
|
-
Date.new(:'date-parts' => [[2001]], :season => 'Winter').
|
243
|
+
expect(Date.new(:'date-parts' => [[2001]], :season => 'Winter')).to be_season
|
244
244
|
end
|
245
245
|
end
|
246
246
|
|
247
247
|
describe 'uncertain dates' do
|
248
248
|
it 'are uncertain' do
|
249
|
-
Date.new({ 'date-parts' => [[-225]], 'circa' => '1' }).
|
250
|
-
Date.new { |d| d.parts = [[-225]]; d.uncertain! }.
|
249
|
+
expect(Date.new({ 'date-parts' => [[-225]], 'circa' => '1' })).to be_uncertain
|
250
|
+
expect(Date.new { |d| d.parts = [[-225]]; d.uncertain! }).not_to be_certain
|
251
251
|
end
|
252
252
|
|
253
253
|
describe '#(un)certain!' do
|
254
254
|
it 'returns self' do
|
255
|
-
ad2k.uncertain
|
256
|
-
ad2k.certain
|
255
|
+
expect(ad2k.uncertain!).to equal(ad2k)
|
256
|
+
expect(ad2k.certain!).to equal(ad2k)
|
257
257
|
end
|
258
258
|
end
|
259
259
|
end
|
260
260
|
|
261
261
|
describe 'sorting' do
|
262
262
|
it 'dates with more date-parts will come after those with fewer parts' do
|
263
|
-
(ad2k < may && may < first_of_may).
|
263
|
+
expect(ad2k < may && may < first_of_may).to be true
|
264
264
|
end
|
265
265
|
|
266
266
|
it 'negative years are sorted inversely' do
|
267
|
-
[ad50, bc100, bc50, ad100].sort.map(&:year).
|
267
|
+
expect([ad50, bc100, bc50, ad100].sort.map(&:year)).to eq([-100, -50, 50, 100])
|
268
268
|
end
|
269
269
|
|
270
270
|
it 'can be compared to dates' do
|
271
|
-
ad50.
|
272
|
-
ad50.
|
271
|
+
expect(ad50).to be < ::Date.new(50,2)
|
272
|
+
expect(ad50).to be > ::Date.new(49)
|
273
273
|
end
|
274
274
|
end
|
275
275
|
|
276
276
|
describe '#start_date' do
|
277
277
|
it 'returns nil by default' do
|
278
|
-
Date.new.start_date.
|
278
|
+
expect(Date.new.start_date).to be_nil
|
279
279
|
end
|
280
280
|
|
281
281
|
it 'returns a ruby date when date-parts are set' do
|
282
|
-
Date.new(1999).start_date.year.
|
282
|
+
expect(Date.new(1999).start_date.year).to eq(1999)
|
283
283
|
end
|
284
284
|
end
|
285
285
|
|
286
286
|
describe '#end_date' do
|
287
287
|
it 'returns nil by default' do
|
288
|
-
Date.new.end_date.
|
288
|
+
expect(Date.new.end_date).to be_nil
|
289
289
|
end
|
290
290
|
|
291
291
|
it 'returns nil when there is a single date-parts set' do
|
292
|
-
Date.new(1312).end_date.
|
292
|
+
expect(Date.new(1312).end_date).to be_nil
|
293
293
|
end
|
294
294
|
|
295
295
|
it 'returns a ruby date when date-parts are a closed range' do
|
296
|
-
Date.new(1999..2000).end_date.year.
|
296
|
+
expect(Date.new(1999..2000).end_date.year).to eq(2000)
|
297
297
|
end
|
298
298
|
end
|
299
299
|
|
300
300
|
describe '#-@' do
|
301
301
|
it 'inverts the year' do
|
302
|
-
(-ad50).
|
302
|
+
expect(-ad50).to eq(bc50)
|
303
303
|
end
|
304
304
|
end
|
305
305
|
|
@@ -312,112 +312,112 @@ module CiteProc
|
|
312
312
|
describe 'b.c. and a.d.' do
|
313
313
|
|
314
314
|
it 'the year 993 is a.d.' do
|
315
|
-
Date.new(993).
|
315
|
+
expect(Date.new(993)).to be_ad
|
316
316
|
end
|
317
317
|
|
318
318
|
it 'the year 1000 is not a.d.' do
|
319
|
-
Date.new(1000).
|
319
|
+
expect(Date.new(1000)).not_to be_ad
|
320
320
|
end
|
321
321
|
|
322
322
|
it 'the year 993 is not b.c.' do
|
323
|
-
Date.new(993).
|
323
|
+
expect(Date.new(993)).not_to be_bc
|
324
324
|
end
|
325
325
|
|
326
326
|
it 'the year 0 is a.d.' do
|
327
|
-
Date.new(0).
|
327
|
+
expect(Date.new(0)).to be_ad
|
328
328
|
end
|
329
329
|
|
330
330
|
it 'the year 0 is not b.c.' do
|
331
|
-
Date.new(0).
|
331
|
+
expect(Date.new(0)).not_to be_bc
|
332
332
|
end
|
333
333
|
|
334
334
|
it 'the year -33 is not a.d.' do
|
335
|
-
Date.new(-33).
|
335
|
+
expect(Date.new(-33)).not_to be_ad
|
336
336
|
end
|
337
337
|
|
338
338
|
it 'the year -33 is b.c.' do
|
339
|
-
Date.new(-33).
|
339
|
+
expect(Date.new(-33)).to be_bc
|
340
340
|
end
|
341
341
|
|
342
342
|
it 'today is not a.d.' do
|
343
|
-
Date.today.
|
343
|
+
expect(Date.today).not_to be_ad
|
344
344
|
end
|
345
345
|
|
346
346
|
it 'today is not b.c.' do
|
347
|
-
Date.today.
|
347
|
+
expect(Date.today).not_to be_bc
|
348
348
|
end
|
349
349
|
|
350
350
|
it 'the year 2000 is not a.d.' do
|
351
|
-
ad2k.
|
351
|
+
expect(ad2k).not_to be_ad
|
352
352
|
end
|
353
353
|
|
354
354
|
end
|
355
355
|
|
356
356
|
describe '#empty?' do
|
357
357
|
it 'returns true by default' do
|
358
|
-
Date.new.
|
358
|
+
expect(Date.new).to be_empty
|
359
359
|
end
|
360
360
|
|
361
361
|
it 'returns true when it contains no date parts' do
|
362
|
-
Date.new({}).
|
362
|
+
expect(Date.new({})).to be_empty
|
363
363
|
end
|
364
364
|
|
365
365
|
it 'returns false for today' do
|
366
|
-
Date.today.
|
366
|
+
expect(Date.today).not_to be_empty
|
367
367
|
end
|
368
368
|
|
369
369
|
it 'returns false for literal dates' do
|
370
|
-
Date.new(:literal => 'foo').
|
370
|
+
expect(Date.new(:literal => 'foo')).not_to be_empty
|
371
371
|
end
|
372
372
|
|
373
373
|
it 'returns false for seasons' do
|
374
|
-
Date.new(:season => 'Summer').
|
374
|
+
expect(Date.new(:season => 'Summer')).not_to be_empty
|
375
375
|
end
|
376
376
|
end
|
377
377
|
|
378
378
|
describe '#to_json' do
|
379
379
|
it 'supports simple parts' do
|
380
|
-
Date.new(%w{2000 1 15}).to_json.
|
380
|
+
expect(Date.new(%w{2000 1 15}).to_json).to eq('{"date-parts":[[2000,1,15]]}')
|
381
381
|
end
|
382
382
|
|
383
383
|
it 'supports string parts' do
|
384
|
-
Date.new(['2000', '1', '15']).to_json.
|
384
|
+
expect(Date.new(['2000', '1', '15']).to_json).to eq('{"date-parts":[[2000,1,15]]}')
|
385
385
|
end
|
386
386
|
|
387
387
|
it 'supports integer parts' do
|
388
|
-
Date.new([2000, 1, 15]).to_json.
|
388
|
+
expect(Date.new([2000, 1, 15]).to_json).to eq('{"date-parts":[[2000,1,15]]}')
|
389
389
|
end
|
390
390
|
|
391
391
|
it 'supports mixed parts' do
|
392
|
-
Date.new(['2000', 1, '15']).to_json.
|
392
|
+
expect(Date.new(['2000', 1, '15']).to_json).to eq('{"date-parts":[[2000,1,15]]}')
|
393
393
|
end
|
394
394
|
|
395
395
|
it 'supports negative years' do
|
396
|
-
Date.new(-200).to_json.
|
396
|
+
expect(Date.new(-200).to_json).to eq('{"date-parts":[[-200]]}')
|
397
397
|
end
|
398
398
|
|
399
399
|
it 'treats seasons as a strings' do
|
400
|
-
Date.create({:season => '1', 'date-parts' => [[1950]]}).to_json.
|
400
|
+
expect(Date.create({:season => '1', 'date-parts' => [[1950]]}).to_json).to match(/"season":"1"/)
|
401
401
|
end
|
402
402
|
|
403
403
|
it 'supports seasons' do
|
404
|
-
Date.create({:season => 'Trinity', 'date-parts' => [[1975]]}).to_json.
|
404
|
+
expect(Date.create({:season => 'Trinity', 'date-parts' => [[1975]]}).to_json).to match(/"season":"Trinity"/)
|
405
405
|
end
|
406
406
|
|
407
407
|
it 'supports string literals' do
|
408
|
-
Date.new(:literal => '13th century').to_json.
|
408
|
+
expect(Date.new(:literal => '13th century').to_json).to eq('{"literal":"13th century"}')
|
409
409
|
end
|
410
410
|
|
411
411
|
it 'supports raw strings' do
|
412
|
-
Date.new(:raw => '23 May 1955').to_json.
|
412
|
+
expect(Date.new(:raw => '23 May 1955').to_json).to eq('{"date-parts":[[1955,5,23]]}')
|
413
413
|
end
|
414
414
|
|
415
415
|
it 'supports closed ranges' do
|
416
|
-
Date.new([[2000,11],[2000,12]]).to_json.
|
416
|
+
expect(Date.new([[2000,11],[2000,12]]).to_json).to eq('{"date-parts":[[2000,11],[2000,12]]}')
|
417
417
|
end
|
418
418
|
|
419
419
|
it 'supports open ranges' do
|
420
|
-
Date.new([[2000,11],[0,0]]).to_json.
|
420
|
+
expect(Date.new([[2000,11],[0,0]]).to_json).to eq('{"date-parts":[[2000,11],[0,0]]}')
|
421
421
|
end
|
422
422
|
end
|
423
423
|
|