bibtex-ruby 1.2.1 → 1.3.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.
Potentially problematic release.
This version of bibtex-ruby might be problematic. Click here for more details.
- data/Gemfile +6 -1
 - data/Gemfile.lock +48 -5
 - data/History.txt +16 -1
 - data/Manifest +43 -19
 - data/README.md +178 -167
 - data/Rakefile +26 -5
 - data/auto.watchr +6 -0
 - data/bibtex-ruby.gemspec +8 -5
 - data/examples/bib2html.rb +28 -18
 - data/features/bibtex.feature +96 -0
 - data/features/entries.feature +67 -0
 - data/features/issues/slash_keys.feature +21 -0
 - data/features/names.feature +72 -0
 - data/features/preambles.feature +27 -0
 - data/features/query.feature +56 -0
 - data/features/replacement.feature +68 -0
 - data/features/step_definitions/bibtex_steps.rb +74 -0
 - data/features/step_definitions/name_steps.rb +13 -0
 - data/features/strings.feature +52 -0
 - data/features/support/env.rb +7 -0
 - data/lib/bibtex.rb +5 -1
 - data/lib/bibtex/bibliography.rb +218 -95
 - data/lib/bibtex/bibtex.y +18 -15
 - data/lib/bibtex/elements.rb +130 -136
 - data/lib/bibtex/entry.rb +133 -69
 - data/lib/bibtex/extensions.rb +0 -35
 - data/lib/bibtex/lexer.rb +9 -9
 - data/lib/bibtex/name_parser.output +464 -0
 - data/lib/bibtex/name_parser.rb +490 -0
 - data/lib/bibtex/names.rb +162 -0
 - data/lib/bibtex/names.y +196 -0
 - data/lib/bibtex/parser.output +5 -5
 - data/lib/bibtex/parser.rb +19 -16
 - data/lib/bibtex/replaceable.rb +52 -0
 - data/lib/bibtex/utilities.rb +23 -5
 - data/lib/bibtex/value.rb +201 -0
 - data/lib/bibtex/version.rb +1 -1
 - data/test/benchmark.rb +52 -0
 - data/test/bibtex/test_bibliography.rb +141 -0
 - data/test/bibtex/test_elements.rb +40 -0
 - data/test/bibtex/test_entry.rb +99 -0
 - data/test/bibtex/test_names.rb +23 -0
 - data/test/bibtex/test_parser.rb +79 -0
 - data/test/bibtex/test_string.rb +83 -0
 - data/test/bibtex/test_utilities.rb +34 -0
 - data/test/bibtex/test_value.rb +70 -0
 - data/test/{bib/10_bibdesk.bib → fixtures/bibdesk.bib} +1 -1
 - data/test/{bib/05_comment.bib → fixtures/comment.bib} +0 -0
 - data/test/{bib/08_decoret.bib → fixtures/decoret.bib} +0 -0
 - data/test/{bib/00_empty.bib → fixtures/empty.bib} +0 -0
 - data/test/{bib/07_entry.bib → fixtures/entry.bib} +0 -0
 - data/test/{bib/09_errors.bib → fixtures/errors.bib} +0 -0
 - data/test/{bib/01_no_bibtex.bib → fixtures/no_bibtex.bib} +0 -0
 - data/test/{bib/06_preamble.bib → fixtures/preamble.bib} +1 -1
 - data/test/{bib/11_roundtrip.bib → fixtures/roundtrip.bib} +1 -1
 - data/test/helper.rb +17 -2
 - data/test/test_bibtex.rb +87 -93
 - data/test/test_export.rb +18 -22
 - metadata +85 -30
 - data/test/bib/02_string.bib +0 -1
 - data/test/bib/03_string.bib +0 -25
 - data/test/bib/04_string_replacement.bib +0 -16
 - data/test/test_comment.rb +0 -21
 - data/test/test_entry.rb +0 -98
 - data/test/test_preamble.rb +0 -39
 - data/test/test_string.rb +0 -97
 - data/test/test_utilities.rb +0 -36
 
    
        data/test/bib/02_string.bib
    DELETED
    
    | 
         @@ -1 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            @string{ foo = "bar" }
         
     | 
    
        data/test/bib/03_string.bib
    DELETED
    
    | 
         @@ -1,25 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            %%
         
     | 
| 
       2 
     | 
    
         
            -
            %% This is a valid BibTeX file
         
     | 
| 
       3 
     | 
    
         
            -
            %% String assignments Test
         
     | 
| 
       4 
     | 
    
         
            -
            %%
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
            @string{foo="bar"}
         
     | 
| 
       7 
     | 
    
         
            -
            @ string{foo="bar"}
         
     | 
| 
       8 
     | 
    
         
            -
            @string {foo="bar"}
         
     | 
| 
       9 
     | 
    
         
            -
            @string{ foo="bar"}
         
     | 
| 
       10 
     | 
    
         
            -
            @string{foo ="bar"}
         
     | 
| 
       11 
     | 
    
         
            -
            @string{foo= "bar"}
         
     | 
| 
       12 
     | 
    
         
            -
            @string{foo="bar" }
         
     | 
| 
       13 
     | 
    
         
            -
            @ string { foo = "bar" }
         
     | 
| 
       14 
     | 
    
         
            -
            @string   { foo=   "bar"}
         
     | 
| 
       15 
     | 
    
         
            -
            @string{ foo = "bar" }
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
            @string{foo="bar"}
         
     | 
| 
       18 
     | 
    
         
            -
            @string{foo="'bar'"}
         
     | 
| 
       19 
     | 
    
         
            -
            @string{foo="{"}bar{"}"}
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
            Using some interesting symbols
         
     | 
| 
       22 
     | 
    
         
            -
            @string{foo="@bar@"}
         
     | 
| 
       23 
     | 
    
         
            -
            @string{foo="'bar'"}
         
     | 
| 
       24 
     | 
    
         
            -
            @string{foo="{"}bar{"}"}
         
     | 
| 
       25 
     | 
    
         
            -
            @string{foo="{bar}"}
         
     | 
| 
         @@ -1,16 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            %%
         
     | 
| 
       2 
     | 
    
         
            -
            %% A valid BibTeX file
         
     | 
| 
       3 
     | 
    
         
            -
            %% String assignment and replacement
         
     | 
| 
       4 
     | 
    
         
            -
            %%
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
            @string{ foo = "foo" }
         
     | 
| 
       7 
     | 
    
         
            -
            @string{ bar = "bar" }
         
     | 
| 
       8 
     | 
    
         
            -
            @string{ foobar = foo # "bar" }
         
     | 
| 
       9 
     | 
    
         
            -
            @string{ foobarfoo = foobar # foo }
         
     | 
| 
       10 
     | 
    
         
            -
            @string{ barfoobar = bar # "foo" # bar }
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
            @preamble { "foo" # foo # foobarfoo # "bar" }
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
            @manual {manual:1,
         
     | 
| 
       15 
     | 
    
         
            -
            	title = "foo" # barfoobar
         
     | 
| 
       16 
     | 
    
         
            -
            }
         
     | 
    
        data/test/test_comment.rb
    DELETED
    
    | 
         @@ -1,21 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'helper.rb'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            class TestComment < MiniTest::Unit::TestCase
         
     | 
| 
       4 
     | 
    
         
            -
              
         
     | 
| 
       5 
     | 
    
         
            -
              def setup
         
     | 
| 
       6 
     | 
    
         
            -
              end
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
              def teardown
         
     | 
| 
       9 
     | 
    
         
            -
              end
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
              def test_explicit
         
     | 
| 
       12 
     | 
    
         
            -
                bib = BibTeX::Bibliography.open('test/bib/05_comment.bib', :debug => true)
         
     | 
| 
       13 
     | 
    
         
            -
                refute_nil(bib)
         
     | 
| 
       14 
     | 
    
         
            -
                assert_equal(BibTeX::Bibliography, bib.class)
         
     | 
| 
       15 
     | 
    
         
            -
                assert_equal(2, bib.data.length)
         
     | 
| 
       16 
     | 
    
         
            -
                assert_equal([BibTeX::Comment], bib.data.map(&:class).uniq)
         
     | 
| 
       17 
     | 
    
         
            -
                assert_equal(' A comment can contain pretty much anything ', bib.data[0].content)
         
     | 
| 
       18 
     | 
    
         
            -
                assert_equal("\n@string{ foo = \"bar\" }\n\n@string{ bar = \"foo\" }\n", bib.data[1].content)
         
     | 
| 
       19 
     | 
    
         
            -
              end
         
     | 
| 
       20 
     | 
    
         
            -
              
         
     | 
| 
       21 
     | 
    
         
            -
            end
         
     | 
    
        data/test/test_entry.rb
    DELETED
    
    | 
         @@ -1,98 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'helper.rb'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            class TestEntry < MiniTest::Unit::TestCase
         
     | 
| 
       4 
     | 
    
         
            -
              
         
     | 
| 
       5 
     | 
    
         
            -
              def setup
         
     | 
| 
       6 
     | 
    
         
            -
              end
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
              def teardown
         
     | 
| 
       9 
     | 
    
         
            -
              end
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
              def test_simple
         
     | 
| 
       12 
     | 
    
         
            -
                bib = BibTeX::Bibliography.open('test/bib/07_entry.bib', :debug => true)
         
     | 
| 
       13 
     | 
    
         
            -
                refute_nil(bib)
         
     | 
| 
       14 
     | 
    
         
            -
                assert_equal(BibTeX::Bibliography, bib.class)
         
     | 
| 
       15 
     | 
    
         
            -
                assert_equal(3, bib.data.length)
         
     | 
| 
       16 
     | 
    
         
            -
                assert_equal([BibTeX::Entry], bib.data.map(&:class).uniq)
         
     | 
| 
       17 
     | 
    
         
            -
                assert_equal('key:0', bib.data[0].key)
         
     | 
| 
       18 
     | 
    
         
            -
                assert_equal('key:1', bib.data[1].key)
         
     | 
| 
       19 
     | 
    
         
            -
                assert_equal('foo', bib.data[2].key)
         
     | 
| 
       20 
     | 
    
         
            -
                assert_equal(:book, bib.data[0].type)
         
     | 
| 
       21 
     | 
    
         
            -
                assert_equal(:article, bib.data[1].type)
         
     | 
| 
       22 
     | 
    
         
            -
                assert_equal(:article, bib.data[2].type)
         
     | 
| 
       23 
     | 
    
         
            -
                assert_equal('Poe, Edgar A.', bib.data[0][:author])
         
     | 
| 
       24 
     | 
    
         
            -
                assert_equal('Hawthorne, Nathaniel', bib.data[1][:author])
         
     | 
| 
       25 
     | 
    
         
            -
                assert_equal('2003', bib.data[0][:year])
         
     | 
| 
       26 
     | 
    
         
            -
                assert_equal('2001', bib.data[1][:year])
         
     | 
| 
       27 
     | 
    
         
            -
                assert_equal('American Library', bib.data[0][:publisher])
         
     | 
| 
       28 
     | 
    
         
            -
                assert_equal('American Library', bib.data[1][:publisher])
         
     | 
| 
       29 
     | 
    
         
            -
                assert_equal('Selected \\emph{Poetry} and `Tales\'', bib.data[0].title)
         
     | 
| 
       30 
     | 
    
         
            -
                assert_equal('Tales and Sketches', bib.data[1].title)
         
     | 
| 
       31 
     | 
    
         
            -
              end
         
     | 
| 
       32 
     | 
    
         
            -
              
         
     | 
| 
       33 
     | 
    
         
            -
              def test_ghost_methods
         
     | 
| 
       34 
     | 
    
         
            -
                bib = BibTeX::Bibliography.open('test/bib/07_entry.bib', :debug => true)
         
     | 
| 
       35 
     | 
    
         
            -
                refute_nil(bib)
         
     | 
| 
       36 
     | 
    
         
            -
                assert_equal(BibTeX::Bibliography, bib.class)
         
     | 
| 
       37 
     | 
    
         
            -
                assert_equal('Poe, Edgar A.', bib.data[0].author)
         
     | 
| 
       38 
     | 
    
         
            -
                
         
     | 
| 
       39 
     | 
    
         
            -
                expected = 'Poe, Edgar Allen'
         
     | 
| 
       40 
     | 
    
         
            -
                bib.data[0].author = expected
         
     | 
| 
       41 
     | 
    
         
            -
                
         
     | 
| 
       42 
     | 
    
         
            -
                assert_equal(expected, bib.data[0].author)
         
     | 
| 
       43 
     | 
    
         
            -
              end
         
     | 
| 
       44 
     | 
    
         
            -
              
         
     | 
| 
       45 
     | 
    
         
            -
              def test_creation_simple
         
     | 
| 
       46 
     | 
    
         
            -
                expected = "@book{raven,\n  author = {Poe, Edgar A.},\n  title = {The Raven}\n}\n"
         
     | 
| 
       47 
     | 
    
         
            -
                
         
     | 
| 
       48 
     | 
    
         
            -
                entry = BibTeX::Entry.new
         
     | 
| 
       49 
     | 
    
         
            -
                entry.type = :book
         
     | 
| 
       50 
     | 
    
         
            -
                entry.key = 'raven'
         
     | 
| 
       51 
     | 
    
         
            -
                entry.author = 'Poe, Edgar A.'
         
     | 
| 
       52 
     | 
    
         
            -
                entry.title = 'The Raven'
         
     | 
| 
       53 
     | 
    
         
            -
                
         
     | 
| 
       54 
     | 
    
         
            -
                assert_equal(expected, entry.to_s)
         
     | 
| 
       55 
     | 
    
         
            -
              end
         
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
              def test_creation_from_hash
         
     | 
| 
       58 
     | 
    
         
            -
                expected = "@book{raven,\n  author = {Poe, Edgar A.},\n  title = {The Raven}\n}\n"
         
     | 
| 
       59 
     | 
    
         
            -
                
         
     | 
| 
       60 
     | 
    
         
            -
                entry = BibTeX::Entry.new({
         
     | 
| 
       61 
     | 
    
         
            -
                  :type => 'book',
         
     | 
| 
       62 
     | 
    
         
            -
                  :key => 'raven',
         
     | 
| 
       63 
     | 
    
         
            -
                  :author => 'Poe, Edgar A.',
         
     | 
| 
       64 
     | 
    
         
            -
                  :title => 'The Raven'
         
     | 
| 
       65 
     | 
    
         
            -
                })
         
     | 
| 
       66 
     | 
    
         
            -
                
         
     | 
| 
       67 
     | 
    
         
            -
                assert_equal(expected, entry.to_s)
         
     | 
| 
       68 
     | 
    
         
            -
              end
         
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
              def test_creation_from_block
         
     | 
| 
       71 
     | 
    
         
            -
                expected = "@book{raven,\n  author = {Poe, Edgar A.},\n  title = {The Raven}\n}\n"
         
     | 
| 
       72 
     | 
    
         
            -
                
         
     | 
| 
       73 
     | 
    
         
            -
                entry = BibTeX::Entry.new do |e|
         
     | 
| 
       74 
     | 
    
         
            -
                  e.type = :book
         
     | 
| 
       75 
     | 
    
         
            -
                  e.key = 'raven'
         
     | 
| 
       76 
     | 
    
         
            -
                  e.author = 'Poe, Edgar A.'
         
     | 
| 
       77 
     | 
    
         
            -
                  e.title = 'The Raven'
         
     | 
| 
       78 
     | 
    
         
            -
                end
         
     | 
| 
       79 
     | 
    
         
            -
                
         
     | 
| 
       80 
     | 
    
         
            -
                assert_equal(expected, entry.to_s)
         
     | 
| 
       81 
     | 
    
         
            -
              end
         
     | 
| 
       82 
     | 
    
         
            -
              
         
     | 
| 
       83 
     | 
    
         
            -
              def test_sorting
         
     | 
| 
       84 
     | 
    
         
            -
                entries = []
         
     | 
| 
       85 
     | 
    
         
            -
                entries << BibTeX::Entry.new({ :type => 'book', :key => 'raven3', :author => 'Poe, Edgar A.', :title => 'The Raven'})
         
     | 
| 
       86 
     | 
    
         
            -
                entries << BibTeX::Entry.new({ :type => 'book', :key => 'raven2', :author => 'Poe, Edgar A.', :title => 'The Raven'})
         
     | 
| 
       87 
     | 
    
         
            -
                entries << BibTeX::Entry.new({ :type => 'book', :key => 'raven1', :author => 'Poe, Edgar A.', :title => 'The Raven'})
         
     | 
| 
       88 
     | 
    
         
            -
                entries << BibTeX::Entry.new({ :type => 'book', :key => 'raven1', :author => 'Poe, Edgar A.', :title => 'The Aven'})
         
     | 
| 
       89 
     | 
    
         
            -
                
         
     | 
| 
       90 
     | 
    
         
            -
                entries.sort!
         
     | 
| 
       91 
     | 
    
         
            -
                
         
     | 
| 
       92 
     | 
    
         
            -
                assert_equal(%w{ raven1 raven1 raven2 raven3 }, entries.map(&:key))
         
     | 
| 
       93 
     | 
    
         
            -
                assert_equal([ 'The Aven', 'The Raven' ], entries.map(&:title)[0,2])
         
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
              end
         
     | 
| 
       96 
     | 
    
         
            -
              
         
     | 
| 
       97 
     | 
    
         
            -
              
         
     | 
| 
       98 
     | 
    
         
            -
            end
         
     | 
    
        data/test/test_preamble.rb
    DELETED
    
    | 
         @@ -1,39 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'helper.rb'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            class TestPreamble < MiniTest::Unit::TestCase
         
     | 
| 
       4 
     | 
    
         
            -
              
         
     | 
| 
       5 
     | 
    
         
            -
              def setup
         
     | 
| 
       6 
     | 
    
         
            -
                @bib = BibTeX::Bibliography.open('test/bib/06_preamble.bib', :debug => true, :strict => false)
         
     | 
| 
       7 
     | 
    
         
            -
              end
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
              def teardown
         
     | 
| 
       10 
     | 
    
         
            -
              end
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
              def test_simple
         
     | 
| 
       13 
     | 
    
         
            -
                refute_nil(@bib)
         
     | 
| 
       14 
     | 
    
         
            -
                assert_equal(BibTeX::Bibliography, @bib.class)
         
     | 
| 
       15 
     | 
    
         
            -
                assert_equal(4, @bib.data.length)
         
     | 
| 
       16 
     | 
    
         
            -
                assert_equal([BibTeX::Preamble,BibTeX::String], @bib.data.map(&:class).uniq)
         
     | 
| 
       17 
     | 
    
         
            -
                assert_equal('"This bibliography was created \\today"', @bib.data[0].content)
         
     | 
| 
       18 
     | 
    
         
            -
                assert_equal('"Bib\\TeX"', @bib.data[1].content)
         
     | 
| 
       19 
     | 
    
         
            -
                assert_equal('"Maintained by " # maintainer', @bib.data[3].content)
         
     | 
| 
       20 
     | 
    
         
            -
              end
         
     | 
| 
       21 
     | 
    
         
            -
              
         
     | 
| 
       22 
     | 
    
         
            -
              def test_roundtrip
         
     | 
| 
       23 
     | 
    
         
            -
                assert_equal(%q[@preamble{ "This bibliography was created \today" }], @bib.data[0].to_s)
         
     | 
| 
       24 
     | 
    
         
            -
                assert_equal(%q[@preamble{ "Bib\TeX" }], @bib.data[1].to_s)
         
     | 
| 
       25 
     | 
    
         
            -
                assert_equal(%q[@string{ maintainer = "Myself" }], @bib.data[2].to_s)
         
     | 
| 
       26 
     | 
    
         
            -
                assert_equal(%q[@preamble{ "Maintained by " # maintainer }], @bib.data[3].to_s)
         
     | 
| 
       27 
     | 
    
         
            -
              end
         
     | 
| 
       28 
     | 
    
         
            -
              
         
     | 
| 
       29 
     | 
    
         
            -
              def test_replacement
         
     | 
| 
       30 
     | 
    
         
            -
                bib = BibTeX::Bibliography.open('test/bib/06_preamble.bib', :debug => true, :strict => false)
         
     | 
| 
       31 
     | 
    
         
            -
                refute_nil(bib)
         
     | 
| 
       32 
     | 
    
         
            -
                assert_equal(%q[@preamble{ "Maintained by " # maintainer }], bib.data[3].to_s)
         
     | 
| 
       33 
     | 
    
         
            -
                bib.replace_strings
         
     | 
| 
       34 
     | 
    
         
            -
                assert_equal('"Maintained by " # "Myself"', bib.data[3].content)
         
     | 
| 
       35 
     | 
    
         
            -
                assert_equal(%q[@preamble{ "Maintained by " # "Myself" }], bib.data[3].to_s)    
         
     | 
| 
       36 
     | 
    
         
            -
                bib.join_strings
         
     | 
| 
       37 
     | 
    
         
            -
                assert_equal(%q[@preamble{ "Maintained by Myself" }], bib.data[3].to_s)    
         
     | 
| 
       38 
     | 
    
         
            -
              end
         
     | 
| 
       39 
     | 
    
         
            -
            end
         
     | 
    
        data/test/test_string.rb
    DELETED
    
    | 
         @@ -1,97 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'helper.rb'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            class TestString < MiniTest::Unit::TestCase
         
     | 
| 
       4 
     | 
    
         
            -
              
         
     | 
| 
       5 
     | 
    
         
            -
              def setup
         
     | 
| 
       6 
     | 
    
         
            -
              end
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
              def teardown
         
     | 
| 
       9 
     | 
    
         
            -
              end
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
              def test_simple
         
     | 
| 
       12 
     | 
    
         
            -
                bib = BibTeX::Bibliography.open('test/bib/02_string.bib', :debug => true)
         
     | 
| 
       13 
     | 
    
         
            -
                refute_nil(bib)
         
     | 
| 
       14 
     | 
    
         
            -
                assert(bib.kind_of? BibTeX::Bibliography)
         
     | 
| 
       15 
     | 
    
         
            -
                refute(bib.empty?)
         
     | 
| 
       16 
     | 
    
         
            -
                assert_equal(bib.data.length,1)
         
     | 
| 
       17 
     | 
    
         
            -
                assert(bib.data.first.is_a?(BibTeX::String))
         
     | 
| 
       18 
     | 
    
         
            -
                assert_equal(:foo, bib.data.first.key)
         
     | 
| 
       19 
     | 
    
         
            -
                assert_equal('"bar"', bib.data.first.value)
         
     | 
| 
       20 
     | 
    
         
            -
                assert_equal(["bar"], bib.strings[:foo])
         
     | 
| 
       21 
     | 
    
         
            -
              end
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
              def test_assignment
         
     | 
| 
       24 
     | 
    
         
            -
                bib = BibTeX::Bibliography.open('test/bib/03_string.bib', :debug => true)
         
     | 
| 
       25 
     | 
    
         
            -
                refute_nil(bib)
         
     | 
| 
       26 
     | 
    
         
            -
                assert(bib.kind_of? BibTeX::Bibliography)
         
     | 
| 
       27 
     | 
    
         
            -
                refute(bib.empty?)
         
     | 
| 
       28 
     | 
    
         
            -
                assert_equal(bib.data.length,17)
         
     | 
| 
       29 
     | 
    
         
            -
                assert_equal(bib.data.map(&:class).uniq, [BibTeX::String]) 
         
     | 
| 
       30 
     | 
    
         
            -
                assert_equal(bib.data.map(&:key).uniq, [:foo]) 
         
     | 
| 
       31 
     | 
    
         
            -
                (0..10).each { |i| assert_equal( '"bar"', bib.data[i].value) }
         
     | 
| 
       32 
     | 
    
         
            -
                assert_equal(bib.data[11].value, '"\'bar\'"')
         
     | 
| 
       33 
     | 
    
         
            -
                assert_equal(bib.data[12].value, '"{"}bar{"}"')
         
     | 
| 
       34 
     | 
    
         
            -
                assert_equal(bib.data[13].value, '"@bar@"')
         
     | 
| 
       35 
     | 
    
         
            -
                assert_equal(bib.data[14].value, '"\'bar\'"')
         
     | 
| 
       36 
     | 
    
         
            -
                assert_equal(bib.data[15].value, '"{"}bar{"}"')
         
     | 
| 
       37 
     | 
    
         
            -
                assert_equal(bib.data[16].value, '"{bar}"')
         
     | 
| 
       38 
     | 
    
         
            -
              end
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
              def test_replacement
         
     | 
| 
       41 
     | 
    
         
            -
                bib = BibTeX::Bibliography.open('test/bib/04_string_replacement.bib', :debug => true)
         
     | 
| 
       42 
     | 
    
         
            -
                refute_nil(bib)
         
     | 
| 
       43 
     | 
    
         
            -
                assert(bib.kind_of?(BibTeX::Bibliography))
         
     | 
| 
       44 
     | 
    
         
            -
                refute(bib.empty?)
         
     | 
| 
       45 
     | 
    
         
            -
                assert_equal(7,bib.length)
         
     | 
| 
       46 
     | 
    
         
            -
                assert_equal([BibTeX::String,BibTeX::Preamble,BibTeX::Entry], bib.data.map(&:class).uniq) 
         
     | 
| 
       47 
     | 
    
         
            -
                assert_equal(["foo"], bib.strings[:foo])
         
     | 
| 
       48 
     | 
    
         
            -
                assert_equal(["bar"], bib.strings[:bar])
         
     | 
| 
       49 
     | 
    
         
            -
                assert_equal([:foo, "bar"], bib.strings[:foobar])
         
     | 
| 
       50 
     | 
    
         
            -
                assert_equal([:foobar, :foo], bib.strings[:foobarfoo])
         
     | 
| 
       51 
     | 
    
         
            -
                assert_equal([:bar, "foo", :bar], bib.strings[:barfoobar])
         
     | 
| 
       52 
     | 
    
         
            -
                assert_equal('"foo" # foo # foobarfoo # "bar"', bib.preamble[0].content)
         
     | 
| 
       53 
     | 
    
         
            -
                assert_equal('"foo" # barfoobar', bib['manual:1'].title)
         
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
                bib.replace_strings({ :include => [BibTeX::Preamble]})
         
     | 
| 
       56 
     | 
    
         
            -
                assert_equal(["foo"], bib.strings[:foo])
         
     | 
| 
       57 
     | 
    
         
            -
                assert_equal(["bar"], bib.strings[:bar])
         
     | 
| 
       58 
     | 
    
         
            -
                assert_equal([:foo, "bar"], bib.strings[:foobar])
         
     | 
| 
       59 
     | 
    
         
            -
                assert_equal([:foobar, :foo], bib.strings[:foobarfoo])
         
     | 
| 
       60 
     | 
    
         
            -
                assert_equal([:bar, "foo", :bar], bib.strings[:barfoobar])
         
     | 
| 
       61 
     | 
    
         
            -
                assert_equal('"foo" # "foo" # foobar # foo # "bar"', bib.preamble[0].content)
         
     | 
| 
       62 
     | 
    
         
            -
                assert_equal('"foo" # barfoobar', bib['manual:1'].title)
         
     | 
| 
       63 
     | 
    
         
            -
                
         
     | 
| 
       64 
     | 
    
         
            -
                bib.replace_strings({ :include => [BibTeX::String]})
         
     | 
| 
       65 
     | 
    
         
            -
                assert_equal(['foo','bar'], bib.strings[:foobar])
         
     | 
| 
       66 
     | 
    
         
            -
                assert_equal(['foo', 'bar','foo'], bib.strings[:foobarfoo])
         
     | 
| 
       67 
     | 
    
         
            -
                assert_equal(['bar','foo','bar'], bib.strings[:barfoobar])
         
     | 
| 
       68 
     | 
    
         
            -
                assert_equal('"foo" # "foo" # foobar # foo # "bar"', bib.preamble[0].content)
         
     | 
| 
       69 
     | 
    
         
            -
                assert_equal('"foo" # barfoobar', bib['manual:1'].title)
         
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
                bib.replace_strings({ :include => [BibTeX::Preamble,BibTeX::Entry]})
         
     | 
| 
       72 
     | 
    
         
            -
                assert_equal('"foo" # "foo" # "foo" # "bar" # "foo" # "bar"', bib.preamble[0].content)
         
     | 
| 
       73 
     | 
    
         
            -
                assert_equal('"foo" # "bar" # "foo" # "bar"', bib['manual:1'].title)
         
     | 
| 
       74 
     | 
    
         
            -
              end
         
     | 
| 
       75 
     | 
    
         
            -
              
         
     | 
| 
       76 
     | 
    
         
            -
              def test_roundtrip
         
     | 
| 
       77 
     | 
    
         
            -
                bib = BibTeX::Bibliography.open('test/bib/04_string_replacement.bib', :debug => true)
         
     | 
| 
       78 
     | 
    
         
            -
                refute_nil(bib)
         
     | 
| 
       79 
     | 
    
         
            -
                assert_equal('@string{ foo = "foo" }', bib.data[0].to_s)
         
     | 
| 
       80 
     | 
    
         
            -
                assert_equal('@string{ bar = "bar" }', bib.data[1].to_s)
         
     | 
| 
       81 
     | 
    
         
            -
                assert_equal('@string{ foobar = foo # "bar" }', bib.data[2].to_s)
         
     | 
| 
       82 
     | 
    
         
            -
                assert_equal('@string{ foobarfoo = foobar # foo }', bib.data[3].to_s)
         
     | 
| 
       83 
     | 
    
         
            -
                assert_equal('@string{ barfoobar = bar # "foo" # bar }', bib.data[4].to_s)
         
     | 
| 
       84 
     | 
    
         
            -
                bib.replace_strings
         
     | 
| 
       85 
     | 
    
         
            -
                assert_equal('@string{ foo = "foo" }', bib.data[0].to_s)
         
     | 
| 
       86 
     | 
    
         
            -
                assert_equal('@string{ bar = "bar" }', bib.data[1].to_s)
         
     | 
| 
       87 
     | 
    
         
            -
                assert_equal('@string{ foobar = "foo" # "bar" }', bib.data[2].to_s)
         
     | 
| 
       88 
     | 
    
         
            -
                assert_equal('@string{ foobarfoo = "foo" # "bar" # "foo" }', bib.data[3].to_s)
         
     | 
| 
       89 
     | 
    
         
            -
                assert_equal('@string{ barfoobar = "bar" # "foo" # "bar" }', bib.data[4].to_s)
         
     | 
| 
       90 
     | 
    
         
            -
                bib.join_strings
         
     | 
| 
       91 
     | 
    
         
            -
                assert_equal('@string{ foo = "foo" }', bib.data[0].to_s)
         
     | 
| 
       92 
     | 
    
         
            -
                assert_equal('@string{ bar = "bar" }', bib.data[1].to_s)
         
     | 
| 
       93 
     | 
    
         
            -
                assert_equal('@string{ foobar = "foobar" }', bib.data[2].to_s)
         
     | 
| 
       94 
     | 
    
         
            -
                assert_equal('@string{ foobarfoo = "foobarfoo" }', bib.data[3].to_s)
         
     | 
| 
       95 
     | 
    
         
            -
                assert_equal('@string{ barfoobar = "barfoobar" }', bib.data[4].to_s)
         
     | 
| 
       96 
     | 
    
         
            -
              end
         
     | 
| 
       97 
     | 
    
         
            -
            end
         
     | 
    
        data/test/test_utilities.rb
    DELETED
    
    | 
         @@ -1,36 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'helper.rb'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            class TestBibtex < MiniTest::Unit::TestCase
         
     | 
| 
       4 
     | 
    
         
            -
              
         
     | 
| 
       5 
     | 
    
         
            -
              def setup
         
     | 
| 
       6 
     | 
    
         
            -
              end
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
              def teardown
         
     | 
| 
       9 
     | 
    
         
            -
              end
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
              def test_empty
         
     | 
| 
       12 
     | 
    
         
            -
                bib = BibTeX.open('test/bib/00_empty.bib', :debug => true)
         
     | 
| 
       13 
     | 
    
         
            -
                refute_nil(bib)
         
     | 
| 
       14 
     | 
    
         
            -
                assert_equal(BibTeX::Bibliography, bib.class)
         
     | 
| 
       15 
     | 
    
         
            -
                assert(bib.empty?)
         
     | 
| 
       16 
     | 
    
         
            -
              end
         
     | 
| 
       17 
     | 
    
         
            -
              
         
     | 
| 
       18 
     | 
    
         
            -
              def test_parse
         
     | 
| 
       19 
     | 
    
         
            -
                bib = BibTeX.parse %q[ @book{ id, author = {Poe, Edgar Allen}, title = "Ligeia" } ]
         
     | 
| 
       20 
     | 
    
         
            -
                refute_nil(bib)
         
     | 
| 
       21 
     | 
    
         
            -
                assert_equal(BibTeX::Bibliography, bib.class)
         
     | 
| 
       22 
     | 
    
         
            -
                [
         
     | 
| 
       23 
     | 
    
         
            -
                  [1, bib.length],
         
     | 
| 
       24 
     | 
    
         
            -
                  ['Ligeia', bib[:id].title],
         
     | 
| 
       25 
     | 
    
         
            -
                  ['Poe, Edgar Allen', bib[:id].author]
         
     | 
| 
       26 
     | 
    
         
            -
                ].each { |a| assert_equal(a[0], a[1]) }
         
     | 
| 
       27 
     | 
    
         
            -
              end
         
     | 
| 
       28 
     | 
    
         
            -
              
         
     | 
| 
       29 
     | 
    
         
            -
              def test_validate
         
     | 
| 
       30 
     | 
    
         
            -
                refute BibTeX.parse(%q[ @book{ id, author = {Poe, Edgar Allen}, title = "Ligeia" } ]).valid?
         
     | 
| 
       31 
     | 
    
         
            -
                assert BibTeX.parse(%q[ @book{ id, author = {Poe, Edgar Allen}, title = "Ligeia", publisher = "Penguin", year = 1996 } ]).valid?
         
     | 
| 
       32 
     | 
    
         
            -
                refute BibTeX.parse(%q[ @book{ id, author = {Poe, Edgar Allen}, title = "Lig"eia", publisher = "Penguin", year = 1996 } ]).valid?
         
     | 
| 
       33 
     | 
    
         
            -
                assert BibTeX.valid?('test/bib/10_bibdesk.bib')
         
     | 
| 
       34 
     | 
    
         
            -
              end
         
     | 
| 
       35 
     | 
    
         
            -
              
         
     | 
| 
       36 
     | 
    
         
            -
            end
         
     |