1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- # Test cases for extracting citations from lines of text
- #
- # Copyright (c) Peter Lane, 2012.
- require 'test_helper'
- describe AsciidocBib do
- it "should extract a simple citation from text" do
- cites = Citations.new
- cites.add_from_line "some text [cite:author12] more text"
- _(cites.cites_used.size).must_equal 1
- _(cites.cites_used[0]).must_equal "author12"
- end
- it "should extract combinations of citations from text" do
- cites = Citations.new
- cites.add_from_line "some text [cite:author12;another11] more text"
- _(cites.cites_used.size).must_equal 2
- _(cites.cites_used[0]).must_equal "author12"
- _(cites.cites_used[1]).must_equal "another11"
- end
- it "should extract separate groups of citations" do
- cites = Citations.new
- cites.add_from_line "some text [cite:author12;another11] more text [cite:third10]"
- _(cites.cites_used.size).must_equal 3
- _(cites.cites_used[0]).must_equal "author12"
- _(cites.cites_used[1]).must_equal "another11"
- _(cites.cites_used[2]).must_equal "third10"
- end
- it "should extract citations with page numbers" do
- cites = Citations.new
- citationdata = cites.retrieve_citations "some text [citenp:author12,1-20;another11,15]"
- _(citationdata.size).must_equal 1
- _(citationdata.first.cites.size).must_equal 2
- _(citationdata.first.cites[0].ref).must_equal "author12"
- _(citationdata.first.cites[0].pages).must_equal "1-20"
- _(citationdata.first.cites[1].ref).must_equal "another11"
- _(citationdata.first.cites[1].pages).must_equal "15"
- _(citationdata.first.cites[0].to_s).must_equal 'author12:1-20'
- end
- it "should extract page numbers as well as refs" do
- cites = Citations.new
- citationdata = cites.retrieve_citations "[citenp:author12;another11,15-30;third10,14]"
- _(citationdata.size).must_equal 1
- _(citationdata.first.cites.size).must_equal 3
- _(citationdata.first.cites[0].ref).must_equal "author12"
- _(citationdata.first.cites[0].pages).must_equal ''
- _(citationdata.first.cites[1].ref).must_equal "another11"
- _(citationdata.first.cites[1].pages).must_equal "15-30"
- _(citationdata.first.cites[2].ref).must_equal "third10"
- _(citationdata.first.cites[2].pages).must_equal "14"
- end
- it "should keep each citation once only" do
- cites = Citations.new
- cites.add_from_line "[citenp:author12;another11;author12]"
- _(cites.cites_used.size).must_equal 2
- end
- it 'should work with dash in citation' do
- cites = Citations.new
- cites.add_from_line "[cite:some-author]"
- _(cites.cites_used.size).must_equal 1
- _(cites.cites_used[0]).must_equal 'some-author'
- end
- end
|