citations_test.rb 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Test cases for extracting citations from lines of text
  2. #
  3. # Copyright (c) Peter Lane, 2012.
  4. require 'test_helper'
  5. describe AsciidocBib do
  6. it "should extract a simple citation from text" do
  7. cites = Citations.new
  8. cites.add_from_line "some text [cite:author12] more text"
  9. _(cites.cites_used.size).must_equal 1
  10. _(cites.cites_used[0]).must_equal "author12"
  11. end
  12. it "should extract combinations of citations from text" do
  13. cites = Citations.new
  14. cites.add_from_line "some text [cite:author12;another11] more text"
  15. _(cites.cites_used.size).must_equal 2
  16. _(cites.cites_used[0]).must_equal "author12"
  17. _(cites.cites_used[1]).must_equal "another11"
  18. end
  19. it "should extract separate groups of citations" do
  20. cites = Citations.new
  21. cites.add_from_line "some text [cite:author12;another11] more text [cite:third10]"
  22. _(cites.cites_used.size).must_equal 3
  23. _(cites.cites_used[0]).must_equal "author12"
  24. _(cites.cites_used[1]).must_equal "another11"
  25. _(cites.cites_used[2]).must_equal "third10"
  26. end
  27. it "should extract citations with page numbers" do
  28. cites = Citations.new
  29. citationdata = cites.retrieve_citations "some text [citenp:author12,1-20;another11,15]"
  30. _(citationdata.size).must_equal 1
  31. _(citationdata.first.cites.size).must_equal 2
  32. _(citationdata.first.cites[0].ref).must_equal "author12"
  33. _(citationdata.first.cites[0].pages).must_equal "1-20"
  34. _(citationdata.first.cites[1].ref).must_equal "another11"
  35. _(citationdata.first.cites[1].pages).must_equal "15"
  36. _(citationdata.first.cites[0].to_s).must_equal 'author12:1-20'
  37. end
  38. it "should extract page numbers as well as refs" do
  39. cites = Citations.new
  40. citationdata = cites.retrieve_citations "[citenp:author12;another11,15-30;third10,14]"
  41. _(citationdata.size).must_equal 1
  42. _(citationdata.first.cites.size).must_equal 3
  43. _(citationdata.first.cites[0].ref).must_equal "author12"
  44. _(citationdata.first.cites[0].pages).must_equal ''
  45. _(citationdata.first.cites[1].ref).must_equal "another11"
  46. _(citationdata.first.cites[1].pages).must_equal "15-30"
  47. _(citationdata.first.cites[2].ref).must_equal "third10"
  48. _(citationdata.first.cites[2].pages).must_equal "14"
  49. end
  50. it "should keep each citation once only" do
  51. cites = Citations.new
  52. cites.add_from_line "[citenp:author12;another11;author12]"
  53. _(cites.cites_used.size).must_equal 2
  54. end
  55. it 'should work with dash in citation' do
  56. cites = Citations.new
  57. cites.add_from_line "[cite:some-author]"
  58. _(cites.cites_used.size).must_equal 1
  59. _(cites.cites_used[0]).must_equal 'some-author'
  60. end
  61. end