asciidoctor-bibliography 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +23 -4
- data/asciidoctor-bibliography.gemspec +8 -8
- data/lib/asciidoctor-bibliography.rb +6 -0
- data/lib/asciidoctor-bibliography/asciidoctor/bibliographer_preprocessor.rb +35 -23
- data/lib/asciidoctor-bibliography/bibliographer.rb +0 -15
- data/lib/asciidoctor-bibliography/citation.rb +29 -22
- data/lib/asciidoctor-bibliography/databases/bibtex.rb +4 -1
- data/lib/asciidoctor-bibliography/formatter.rb +28 -0
- data/lib/asciidoctor-bibliography/index.rb +24 -16
- data/lib/asciidoctor-bibliography/options.rb +65 -32
- data/lib/asciidoctor-bibliography/version.rb +1 -1
- data/lib/citeproc/ruby/formats/adoc.rb +36 -0
- data/lib/csl/styles/tex-citealp-authoryear.csl +117 -0
- data/lib/csl/styles/tex-citealp-numeric.csl +116 -0
- data/lib/csl/styles/tex-citealps-authoryear.csl +117 -0
- data/lib/csl/styles/tex-citealps-numeric.csl +116 -0
- data/lib/csl/styles/tex-citealt-authoryear.csl +119 -0
- data/lib/csl/styles/tex-citealt-numeric.csl +119 -0
- data/lib/csl/styles/tex-citealts-authoryear.csl +119 -0
- data/lib/csl/styles/tex-citealts-numeric.csl +119 -0
- data/lib/csl/styles/tex-citeauthor-authoryear.csl +116 -0
- data/lib/csl/styles/tex-citeauthor-numeric.csl +116 -0
- data/lib/csl/styles/tex-citeauthors-authoryear.csl +116 -0
- data/lib/csl/styles/tex-citeauthors-numeric.csl +116 -0
- data/lib/csl/styles/tex-citep-authoryear.csl +117 -0
- data/lib/csl/styles/tex-citep-numeric.csl +116 -0
- data/lib/csl/styles/tex-citeps-authoryear.csl +117 -0
- data/lib/csl/styles/tex-citeps-numeric.csl +116 -0
- data/lib/csl/styles/tex-citet-authoryear.csl +119 -0
- data/lib/csl/styles/tex-citet-numeric.csl +119 -0
- data/lib/csl/styles/tex-citets-authoryear.csl +119 -0
- data/lib/csl/styles/tex-citets-numeric.csl +119 -0
- data/lib/csl/styles/tex-citeyear-authoryear.csl +116 -0
- data/lib/csl/styles/tex-citeyear-numeric.csl +116 -0
- data/lib/csl/styles/tex-citeyearpar-authoryear.csl +116 -0
- data/lib/csl/styles/tex-citeyearpar-numeric.csl +116 -0
- data/samples/tex/sample-numbers.adoc +1 -1
- data/samples/tex/sample-sort.adoc +1 -1
- data/spec/citation_helper.rb +46 -0
- data/spec/citation_item_spec.rb +0 -2
- data/spec/csl/styles/tex_citealp_authoryear_spec.rb +42 -0
- data/spec/csl/styles/tex_citealp_numeric_spec.rb +42 -0
- data/spec/csl/styles/tex_citealps_authoryear_spec.rb +42 -0
- data/spec/csl/styles/tex_citealps_numeric_spec.rb +42 -0
- data/spec/csl/styles/tex_citealt_authoryear_spec.rb +42 -0
- data/spec/csl/styles/tex_citealt_numeric_spec.rb +42 -0
- data/spec/csl/styles/tex_citealts_authoryear_spec.rb +42 -0
- data/spec/csl/styles/tex_citealts_numeric_spec.rb +42 -0
- data/spec/csl/styles/tex_citeauthor_authoryear_spec.rb +42 -0
- data/spec/csl/styles/tex_citeauthor_numeric_spec.rb +42 -0
- data/spec/csl/styles/tex_citeauthors_authoryear_spec.rb +42 -0
- data/spec/csl/styles/tex_citeauthors_numeric_spec.rb +42 -0
- data/spec/csl/styles/tex_citep_authoryear_spec.rb +42 -0
- data/spec/csl/styles/tex_citep_numeric_spec.rb +42 -0
- data/spec/csl/styles/tex_citeps_authoryear_spec.rb +42 -0
- data/spec/csl/styles/tex_citeps_numeric_spec.rb +42 -0
- data/spec/csl/styles/tex_citet_authoryear_spec.rb +42 -0
- data/spec/csl/styles/tex_citet_numeric_spec.rb +42 -0
- data/spec/csl/styles/tex_citets_authoryear_spec.rb +42 -0
- data/spec/csl/styles/tex_citets_numeric_spec.rb +42 -0
- data/spec/csl/styles/tex_citeyear_authoryear_spec.rb +42 -0
- data/spec/csl/styles/tex_citeyear_numeric_spec.rb +42 -0
- data/spec/csl/styles/tex_citeyearpar_authoryear_spec.rb +42 -0
- data/spec/csl/styles/tex_citeyearpar_numeric_spec.rb +42 -0
- data/spec/database_spec.rb +20 -1
- data/spec/macros_spec.rb +21 -0
- data/spec/options_spec.rb +105 -1
- metadata +72 -24
- data/lib/asciidoctor-bibliography/formatters/csl.rb +0 -28
- data/lib/asciidoctor-bibliography/formatters/tex.rb +0 -187
- data/lib/asciidoctor-bibliography/helpers.rb +0 -41
- data/spec/helpers_spec.rb +0 -73
@@ -0,0 +1,42 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require_relative "../../citation_helper"
|
4
|
+
|
5
|
+
describe "citet macro with numeric style" do
|
6
|
+
let(:options) { { "bibliography-tex-style" => "numeric" } }
|
7
|
+
|
8
|
+
it "formats a single citation" do
|
9
|
+
expect(formatted_citation("citet:[Erdos65]", options: options)).
|
10
|
+
to eq "Erdős et al. [1]"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "formats a grouped citation" do
|
14
|
+
expect(formatted_citation("citet:[Erdos65]+[Einstein35]", options: options)).
|
15
|
+
to eq "Erdős et al. [1], Einstein et al. [2]"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "formats a single citation with a prefix" do
|
19
|
+
expect(formatted_citation("citet:[Erdos65, prefix=see]", options: options)).
|
20
|
+
to eq "Erdős et al. [see 1]"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "formats a single citation with a suffix" do
|
24
|
+
expect(formatted_citation("citet:[Erdos65, suffix=new edition]", options: options)).
|
25
|
+
to eq "Erdős et al. [1, new edition]"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "formats a single citation with both a prefix and a suffix" do
|
29
|
+
expect(formatted_citation("citet:[Erdos65, prefix=see, suffix=new edition]", options: options)).
|
30
|
+
to eq "Erdős et al. [see 1, new edition]"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "formats a single citation with a standard locator" do
|
34
|
+
expect(formatted_citation("citet:[Erdos65, page=41-43]", options: options)).
|
35
|
+
to eq "Erdős et al. [1, pp. 41-43]"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "formats a single citation with a custom locator" do
|
39
|
+
expect(formatted_citation("citet:[Erdos65, locator=somewhere]", options: options)).
|
40
|
+
to eq "Erdős et al. [1, somewhere]"
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require_relative "../../citation_helper"
|
4
|
+
|
5
|
+
describe "citet* macro with authoryear style" do
|
6
|
+
let(:options) { { "bibliography-tex-style" => "authoryear" } }
|
7
|
+
|
8
|
+
it "formats a single citation" do
|
9
|
+
expect(formatted_citation("citet*:[Erdos65]", options: options)).
|
10
|
+
to eq "Erdős, Heyting, and Brouwer (1965)"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "formats a grouped citation" do
|
14
|
+
expect(formatted_citation("citet*:[Erdos65]+[Einstein35]", options: options)).
|
15
|
+
to eq "Erdős, Heyting, and Brouwer (1965); Einstein, Podolsky, and Rosen (1935)"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "formats a single citation with a prefix" do
|
19
|
+
expect(formatted_citation("citet*:[Erdos65, prefix=see]", options: options)).
|
20
|
+
to eq "Erdős, Heyting, and Brouwer (see 1965)"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "formats a single citation with a suffix" do
|
24
|
+
expect(formatted_citation("citet*:[Erdos65, suffix=new edition]", options: options)).
|
25
|
+
to eq "Erdős, Heyting, and Brouwer (1965, new edition)"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "formats a single citation with both a prefix and a suffix" do
|
29
|
+
expect(formatted_citation("citet*:[Erdos65, prefix=see, suffix=new edition]", options: options)).
|
30
|
+
to eq "Erdős, Heyting, and Brouwer (see 1965, new edition)"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "formats a single citation with a standard locator" do
|
34
|
+
expect(formatted_citation("citet*:[Erdos65, page=41-43]", options: options)).
|
35
|
+
to eq "Erdős, Heyting, and Brouwer (1965, pp. 41-43)"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "formats a single citation with a custom locator" do
|
39
|
+
expect(formatted_citation("citet*:[Erdos65, locator=somewhere]", options: options)).
|
40
|
+
to eq "Erdős, Heyting, and Brouwer (1965, somewhere)"
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require_relative "../../citation_helper"
|
4
|
+
|
5
|
+
describe "citet* macro with numeric style" do
|
6
|
+
let(:options) { { "bibliography-tex-style" => "numeric" } }
|
7
|
+
|
8
|
+
it "formats a single citation" do
|
9
|
+
expect(formatted_citation("citet*:[Erdos65]", options: options)).
|
10
|
+
to eq "Erdős, Heyting, and Brouwer [1]"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "formats a grouped citation" do
|
14
|
+
expect(formatted_citation("citet*:[Erdos65]+[Einstein35]", options: options)).
|
15
|
+
to eq "Erdős, Heyting, and Brouwer [1], Einstein, Podolsky, and Rosen [2]"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "formats a single citation with a prefix" do
|
19
|
+
expect(formatted_citation("citet*:[Erdos65, prefix=see]", options: options)).
|
20
|
+
to eq "Erdős, Heyting, and Brouwer [see 1]"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "formats a single citation with a suffix" do
|
24
|
+
expect(formatted_citation("citet*:[Erdos65, suffix=new edition]", options: options)).
|
25
|
+
to eq "Erdős, Heyting, and Brouwer [1, new edition]"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "formats a single citation with both a prefix and a suffix" do
|
29
|
+
expect(formatted_citation("citet*:[Erdos65, prefix=see, suffix=new edition]", options: options)).
|
30
|
+
to eq "Erdős, Heyting, and Brouwer [see 1, new edition]"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "formats a single citation with a standard locator" do
|
34
|
+
expect(formatted_citation("citet*:[Erdos65, page=41-43]", options: options)).
|
35
|
+
to eq "Erdős, Heyting, and Brouwer [1, pp. 41-43]"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "formats a single citation with a custom locator" do
|
39
|
+
expect(formatted_citation("citet*:[Erdos65, locator=somewhere]", options: options)).
|
40
|
+
to eq "Erdős, Heyting, and Brouwer [1, somewhere]"
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require_relative "../../citation_helper"
|
4
|
+
|
5
|
+
describe "citeyear macro with authoryear style" do
|
6
|
+
let(:options) { { "bibliography-tex-style" => "authoryear" } }
|
7
|
+
|
8
|
+
it "formats a single citation" do
|
9
|
+
expect(formatted_citation("citeyear:[Erdos65]", options: options)).
|
10
|
+
to eq "1965"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "formats a grouped citation" do
|
14
|
+
expect(formatted_citation("citeyear:[Erdos65]+[Einstein35]", options: options)).
|
15
|
+
to eq "1965; 1935"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "formats a single citation with a prefix" do
|
19
|
+
expect(formatted_citation("citeyear:[Erdos65, prefix=see]", options: options)).
|
20
|
+
to eq "see 1965"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "formats a single citation with a suffix" do
|
24
|
+
expect(formatted_citation("citeyear:[Erdos65, suffix=new edition]", options: options)).
|
25
|
+
to eq "1965, new edition"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "formats a single citation with both a prefix and a suffix" do
|
29
|
+
expect(formatted_citation("citeyear:[Erdos65, prefix=see, suffix=new edition]", options: options)).
|
30
|
+
to eq "see 1965, new edition"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "formats a single citation with a standard locator" do
|
34
|
+
expect(formatted_citation("citeyear:[Erdos65, page=41-43]", options: options)).
|
35
|
+
to eq "1965, pp. 41-43"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "formats a single citation with a custom locator" do
|
39
|
+
expect(formatted_citation("citeyear:[Erdos65, locator=somewhere]", options: options)).
|
40
|
+
to eq "1965, somewhere"
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require_relative "../../citation_helper"
|
4
|
+
|
5
|
+
describe "citeyear macro with numeric style" do
|
6
|
+
let(:options) { { "bibliography-tex-style" => "numeric" } }
|
7
|
+
|
8
|
+
it "formats a single citation" do
|
9
|
+
expect(formatted_citation("citeyear:[Erdos65]", options: options)).
|
10
|
+
to eq "1965"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "formats a grouped citation" do
|
14
|
+
expect(formatted_citation("citeyear:[Erdos65]+[Einstein35]", options: options)).
|
15
|
+
to eq "1965, 1935"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "formats a single citation with a prefix" do
|
19
|
+
expect(formatted_citation("citeyear:[Erdos65, prefix=see]", options: options)).
|
20
|
+
to eq "see 1965"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "formats a single citation with a suffix" do
|
24
|
+
expect(formatted_citation("citeyear:[Erdos65, suffix=new edition]", options: options)).
|
25
|
+
to eq "1965, new edition"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "formats a single citation with both a prefix and a suffix" do
|
29
|
+
expect(formatted_citation("citeyear:[Erdos65, prefix=see, suffix=new edition]", options: options)).
|
30
|
+
to eq "see 1965, new edition"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "formats a single citation with a standard locator" do
|
34
|
+
expect(formatted_citation("citeyear:[Erdos65, page=41-43]", options: options)).
|
35
|
+
to eq "1965, pp. 41-43"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "formats a single citation with a custom locator" do
|
39
|
+
expect(formatted_citation("citeyear:[Erdos65, locator=somewhere]", options: options)).
|
40
|
+
to eq "1965, somewhere"
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require_relative "../../citation_helper"
|
4
|
+
|
5
|
+
describe "citeyearpar macro with authoryear style" do
|
6
|
+
let(:options) { { "bibliography-tex-style" => "authoryear" } }
|
7
|
+
|
8
|
+
it "formats a single citation" do
|
9
|
+
expect(formatted_citation("citeyearpar:[Erdos65]", options: options)).
|
10
|
+
to eq "(1965)"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "formats a grouped citation" do
|
14
|
+
expect(formatted_citation("citeyearpar:[Erdos65]+[Einstein35]", options: options)).
|
15
|
+
to eq "(1965; 1935)"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "formats a single citation with a prefix" do
|
19
|
+
expect(formatted_citation("citeyearpar:[Erdos65, prefix=see]", options: options)).
|
20
|
+
to eq "(see 1965)"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "formats a single citation with a suffix" do
|
24
|
+
expect(formatted_citation("citeyearpar:[Erdos65, suffix=new edition]", options: options)).
|
25
|
+
to eq "(1965, new edition)"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "formats a single citation with both a prefix and a suffix" do
|
29
|
+
expect(formatted_citation("citeyearpar:[Erdos65, prefix=see, suffix=new edition]", options: options)).
|
30
|
+
to eq "(see 1965, new edition)"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "formats a single citation with a standard locator" do
|
34
|
+
expect(formatted_citation("citeyearpar:[Erdos65, page=41-43]", options: options)).
|
35
|
+
to eq "(1965, pp. 41-43)"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "formats a single citation with a custom locator" do
|
39
|
+
expect(formatted_citation("citeyearpar:[Erdos65, locator=somewhere]", options: options)).
|
40
|
+
to eq "(1965, somewhere)"
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require_relative "../../citation_helper"
|
4
|
+
|
5
|
+
describe "citeyearpar macro with numeric style" do
|
6
|
+
let(:options) { { "bibliography-tex-style" => "numeric" } }
|
7
|
+
|
8
|
+
it "formats a single citation" do
|
9
|
+
expect(formatted_citation("citeyearpar:[Erdos65]", options: options)).
|
10
|
+
to eq "[1965]"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "formats a grouped citation" do
|
14
|
+
expect(formatted_citation("citeyearpar:[Erdos65]+[Einstein35]", options: options)).
|
15
|
+
to eq "[1965, 1935]"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "formats a single citation with a prefix" do
|
19
|
+
expect(formatted_citation("citeyearpar:[Erdos65, prefix=see]", options: options)).
|
20
|
+
to eq "[see 1965]"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "formats a single citation with a suffix" do
|
24
|
+
expect(formatted_citation("citeyearpar:[Erdos65, suffix=new edition]", options: options)).
|
25
|
+
to eq "[1965, new edition]"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "formats a single citation with both a prefix and a suffix" do
|
29
|
+
expect(formatted_citation("citeyearpar:[Erdos65, prefix=see, suffix=new edition]", options: options)).
|
30
|
+
to eq "[see 1965, new edition]"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "formats a single citation with a standard locator" do
|
34
|
+
expect(formatted_citation("citeyearpar:[Erdos65, page=41-43]", options: options)).
|
35
|
+
to eq "[1965, pp. 41-43]"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "formats a single citation with a custom locator" do
|
39
|
+
expect(formatted_citation("citeyearpar:[Erdos65, locator=somewhere]", options: options)).
|
40
|
+
to eq "[1965, somewhere]"
|
41
|
+
end
|
42
|
+
end
|
data/spec/database_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# coding: utf-8
|
2
2
|
|
3
3
|
describe AsciidoctorBibliography::Database do
|
4
4
|
describe ".new" do
|
@@ -15,6 +15,25 @@ describe AsciidoctorBibliography::Database do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
describe "#find_entry_by_id" do
|
19
|
+
subject { described_class.new("spec/fixtures/database.bib") }
|
20
|
+
|
21
|
+
it "finds an existing id" do
|
22
|
+
expect { subject.find_entry_by_id("foo") }.
|
23
|
+
to raise_exception AsciidoctorBibliography::Errors::Database::IdNotFound
|
24
|
+
end
|
25
|
+
|
26
|
+
it "raises error if asked to retrieve unexisting id" do
|
27
|
+
expect(subject.find_entry_by_id("Lane12a")).
|
28
|
+
to eq("author" => [{ "family" => "Lane", "given" => "P." }],
|
29
|
+
"title" => "Book title",
|
30
|
+
"publisher" => "Publisher",
|
31
|
+
"id" => "Lane12a",
|
32
|
+
"issued" => { "date-parts" => [[2000]] },
|
33
|
+
"type" => "book")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
18
37
|
describe "#append" do
|
19
38
|
let(:db) { described_class.new }
|
20
39
|
|
data/spec/macros_spec.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require_relative "citation_helper"
|
4
|
+
|
5
|
+
describe "cite macro with apa style" do
|
6
|
+
it "formats a complex citation" do
|
7
|
+
expect(formatted_citation("cite:[Erdos65, prefix=see]+[Einstein35, page=41-43]",
|
8
|
+
options: { "bibliography-style" => "apa",
|
9
|
+
"bibliography-hyperlinks" => "true" })).
|
10
|
+
to eq "(xref:bibliography-Einstein35[Einstein, Podolsky, & Rosen, 1935, pp. 41-43]; " +
|
11
|
+
"xref:bibliography-Erdos65[seeErdős, Heyting, & Brouwer, 1965])"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "fullcite macro with apa style" do
|
16
|
+
it "formats a complex citation" do
|
17
|
+
expect(formatted_citation("fullcite:[Erdos65]",
|
18
|
+
options: { "bibliography-style" => "apa" })).
|
19
|
+
to eq "Erdős, P., Heyting, A., & Brouwer, L. E. (1965). Some very hard sums. _Difficult Maths Today_, 30."
|
20
|
+
end
|
21
|
+
end
|
data/spec/options_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require "asciidoctor
|
1
|
+
require "asciidoctor"
|
2
2
|
|
3
3
|
describe AsciidoctorBibliography::Options do
|
4
4
|
describe "#database" do
|
@@ -31,6 +31,36 @@ describe AsciidoctorBibliography::Options do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
describe "#locale" do
|
35
|
+
it "defaults to en-US" do
|
36
|
+
expect(described_class.new.locale).to eq "en-US"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns the provided option when set" do
|
40
|
+
expect(described_class.new.merge("bibliography-locale" => "it-IT").locale).to eq "it-IT"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "raises an error when provided option is invalid" do
|
44
|
+
expect { described_class.new.merge("bibliography-locale" => "foo").locale }.
|
45
|
+
to raise_exception AsciidoctorBibliography::Errors::Options::Invalid
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#tex_style" do
|
50
|
+
it "defaults to en-US" do
|
51
|
+
expect(described_class.new.tex_style).to eq "authoryear"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "returns the provided option when set" do
|
55
|
+
expect(described_class.new.merge("bibliography-tex-style" => "numeric").tex_style).to eq "numeric"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "raises an error when provided option is invalid" do
|
59
|
+
expect { described_class.new.merge("bibliography-tex-style" => "foo").tex_style }.
|
60
|
+
to raise_exception AsciidoctorBibliography::Errors::Options::Invalid
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
34
64
|
describe "#style" do
|
35
65
|
it "defaults to apa" do
|
36
66
|
expect(described_class.new.style).to eq "apa"
|
@@ -40,4 +70,78 @@ describe AsciidoctorBibliography::Options do
|
|
40
70
|
expect(described_class.new.merge("bibliography-style" => "foobar").style).to eq("foobar")
|
41
71
|
end
|
42
72
|
end
|
73
|
+
|
74
|
+
describe "#sort" do
|
75
|
+
it "defaults to nil" do
|
76
|
+
expect(described_class.new.sort).to be nil
|
77
|
+
end
|
78
|
+
|
79
|
+
it "parses and returns an empty array" do
|
80
|
+
expect(described_class.new.merge("bibliography-sort" => "[]").sort).
|
81
|
+
to eq([])
|
82
|
+
end
|
83
|
+
|
84
|
+
it "parses and returns a naked hash" do
|
85
|
+
expect(described_class.new.merge("bibliography-sort" => "macro: author").sort).
|
86
|
+
to eq([{ "macro" => "author" }])
|
87
|
+
end
|
88
|
+
|
89
|
+
it "parses and returns a hash" do
|
90
|
+
expect(described_class.new.merge("bibliography-sort" => "{macro: author, sort: descending}").sort).
|
91
|
+
to eq([{ "macro" => "author", "sort" => "descending" }])
|
92
|
+
end
|
93
|
+
|
94
|
+
it "parses and returns multiple hashes" do
|
95
|
+
expect(described_class.new.merge("bibliography-sort" => "[{macro: author}, {variable: issued}]").sort).
|
96
|
+
to eq([{ "macro" => "author" }, { "variable" => "issued" }])
|
97
|
+
end
|
98
|
+
|
99
|
+
it "raises an error when provided option is invalid (type)" do
|
100
|
+
expect { described_class.new.merge("bibliography-sort" => "foo").sort }.
|
101
|
+
to raise_exception AsciidoctorBibliography::Errors::Options::Invalid
|
102
|
+
end
|
103
|
+
|
104
|
+
it "raises an error when provided option is invalid (key)" do
|
105
|
+
expect { described_class.new.merge("bibliography-sort" => "[{something: wrong}]").sort }.
|
106
|
+
to raise_exception AsciidoctorBibliography::Errors::Options::Invalid
|
107
|
+
end
|
108
|
+
|
109
|
+
it "raises an error when provided option is invalid (syntax)" do
|
110
|
+
expect { described_class.new.merge("bibliography-sort" => "foo: bar:").sort }.
|
111
|
+
to raise_exception AsciidoctorBibliography::Errors::Options::Invalid
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe ".new_from_reader" do
|
116
|
+
let(:reader) do
|
117
|
+
::Asciidoctor::PreprocessorReader.new(::Asciidoctor::Document.new, <<~SOURCE.lines)
|
118
|
+
= This is the document title
|
119
|
+
:bibliography-database: foo
|
120
|
+
:bibliography-locale: bar
|
121
|
+
:bibliography-style: baz
|
122
|
+
:bibliography-hyperlinks: quz
|
123
|
+
:bibliography-order: zod
|
124
|
+
:bibliography-tex-style: lep
|
125
|
+
:bibliography-sort: kan
|
126
|
+
:bibliography-bogus: pow
|
127
|
+
SOURCE
|
128
|
+
end
|
129
|
+
|
130
|
+
subject { described_class.new_from_reader reader }
|
131
|
+
|
132
|
+
it "extracts all bibliography options ignoring others" do
|
133
|
+
expect(subject).to eq("bibliography-database" => "foo",
|
134
|
+
"bibliography-locale" => "bar",
|
135
|
+
"bibliography-style" => "baz",
|
136
|
+
"bibliography-hyperlinks" => "quz",
|
137
|
+
"bibliography-order" => "zod",
|
138
|
+
"bibliography-tex-style" => "lep",
|
139
|
+
"bibliography-sort" => "kan")
|
140
|
+
end
|
141
|
+
|
142
|
+
it "acts non-destructively on reader" do
|
143
|
+
expect { subject }.to_not(change { reader.lines })
|
144
|
+
expect { subject }.to_not(change { reader.cursor.lineno })
|
145
|
+
end
|
146
|
+
end
|
43
147
|
end
|