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
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module BibTeX
|
4
|
+
|
5
|
+
class PreambleTest < MiniTest::Spec
|
6
|
+
|
7
|
+
context 'a new preamble instance' do
|
8
|
+
setup do
|
9
|
+
@preamble = Preamble.new
|
10
|
+
end
|
11
|
+
|
12
|
+
should 'not be nil' do
|
13
|
+
assert @preamble
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'given a set of @preambles' do
|
18
|
+
setup do
|
19
|
+
@bib = BibTeX.open(Test.fixtures(:preamble))
|
20
|
+
@preambles = @bib.preambles
|
21
|
+
end
|
22
|
+
|
23
|
+
should 'support round-trips of all parsed preambles' do
|
24
|
+
assert_equal %q[@preamble{ "This bibliography was created \today" }], @preambles[0].to_s
|
25
|
+
assert_equal %q[@preamble{ "Bib\TeX" }], @preambles[1].to_s
|
26
|
+
assert_equal %q[@preamble{ "Maintained by " # maintainer }], @preambles[2].to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
should 'support string replacement of preamble contents' do
|
30
|
+
assert_equal %q["Maintained by " # maintainer], @preambles[2].value.to_s
|
31
|
+
@bib.replace_strings
|
32
|
+
assert_equal %q["Maintained by " # "Myself"], @preambles[2].value.to_s
|
33
|
+
@bib.join_strings
|
34
|
+
assert_equal 'Maintained by Myself', @preambles[2].value.to_s
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'helper.rb'
|
2
|
+
|
3
|
+
module BibTeX
|
4
|
+
class EntryTest < MiniTest::Spec
|
5
|
+
|
6
|
+
context 'a new Entry' do
|
7
|
+
should 'not be nil' do
|
8
|
+
assert Entry.new
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_simple
|
13
|
+
bib = BibTeX::Bibliography.open(Test.fixtures(:entry), :debug => false)
|
14
|
+
refute_nil(bib)
|
15
|
+
assert_equal(BibTeX::Bibliography, bib.class)
|
16
|
+
assert_equal(3, bib.data.length)
|
17
|
+
assert_equal([BibTeX::Entry], bib.data.map(&:class).uniq)
|
18
|
+
assert_equal(:'key:0', bib.data[0].key)
|
19
|
+
assert_equal(:'key:1', bib.data[1].key)
|
20
|
+
assert_equal(:'foo', bib.data[2].key)
|
21
|
+
assert_equal(:book, bib.data[0].type)
|
22
|
+
assert_equal(:article, bib.data[1].type)
|
23
|
+
assert_equal(:article, bib.data[2].type)
|
24
|
+
assert_equal('Poe, Edgar A.', bib.data[0][:author])
|
25
|
+
assert_equal('Hawthorne, Nathaniel', bib.data[1][:author])
|
26
|
+
assert_equal('2003', bib.data[0][:year])
|
27
|
+
assert_equal('2001', bib.data[1][:year])
|
28
|
+
assert_equal('American Library', bib.data[0][:publisher])
|
29
|
+
assert_equal('American Library', bib.data[1][:publisher])
|
30
|
+
assert_equal('Selected \\emph{Poetry} and `Tales\'', bib.data[0].title)
|
31
|
+
assert_equal('Tales and Sketches', bib.data[1].title)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_ghost_methods
|
35
|
+
bib = BibTeX::Bibliography.open(Test.fixtures(:entry), :debug => false)
|
36
|
+
|
37
|
+
assert_equal 'Poe, Edgar A.', bib[0].author
|
38
|
+
|
39
|
+
expected = 'Poe, Edgar Allen'
|
40
|
+
bib.data[0].author = expected
|
41
|
+
|
42
|
+
assert_equal expected, bib[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 [: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
|
99
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module BibTeX
|
4
|
+
class NamesTest < MiniTest::Spec
|
5
|
+
|
6
|
+
context 'string behaviour' do
|
7
|
+
setup do
|
8
|
+
@name = Name.new(:first => 'Charles Louis Xavier Joseph', :prefix => 'de la', :last => 'Vallee Poussin', :suffix => 'Jr.')
|
9
|
+
end
|
10
|
+
should 'implement upcase!' do
|
11
|
+
assert_equal 'DE LA VALLEE POUSSIN, JR., CHARLES LOUIS XAVIER JOSEPH', @name.upcase!.to_s
|
12
|
+
end
|
13
|
+
should 'implement downcase!' do
|
14
|
+
assert_equal 'de la vallee poussin, jr., charles louis xavier joseph', @name.downcase!.to_s
|
15
|
+
end
|
16
|
+
should 'implement gsub!' do
|
17
|
+
assert_equal 'dX la VallXX PoussXn, Jr., CharlXs LouXs XavXXr JosXph', @name.gsub!(/[ei]/, 'X').to_s
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'helper.rb'
|
2
|
+
|
3
|
+
module BibTeX
|
4
|
+
class ParserTest < MiniTest::Spec
|
5
|
+
|
6
|
+
context 'given a set of valid @entries' do
|
7
|
+
setup do
|
8
|
+
@bib = Parser.new(:debug => false).parse(File.read(Test.fixtures(:entry)))
|
9
|
+
end
|
10
|
+
|
11
|
+
should 'return a Bibliography' do
|
12
|
+
assert @bib
|
13
|
+
refute @bib.empty?
|
14
|
+
end
|
15
|
+
|
16
|
+
should 'parse all entries' do
|
17
|
+
assert_equal 3, @bib.length
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'parse the key values' do
|
21
|
+
assert_equal %w{ key:0 key:1 foo }.map(&:to_sym), @bib.map(&:key)
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'parse the entry types' do
|
25
|
+
assert_equal [:book, :article, :article], @bib.map(&:type)
|
26
|
+
end
|
27
|
+
|
28
|
+
should 'parse all values correctly' do
|
29
|
+
assert_equal 'Poe, Edgar A.', @bib[:'key:0'].author
|
30
|
+
assert_equal 'Hawthorne, Nathaniel', @bib[:'key:1'].author
|
31
|
+
|
32
|
+
assert_equal '2003', @bib[:'key:0'].year
|
33
|
+
assert_equal '2001', @bib[:'key:1'].year
|
34
|
+
|
35
|
+
assert_equal 'American Library', @bib[:'key:0'].publisher
|
36
|
+
assert_equal 'American Library', @bib[:'key:1'].publisher
|
37
|
+
|
38
|
+
assert_equal %q[Selected \emph{Poetry} and `Tales'], @bib[:'key:0'].title
|
39
|
+
assert_equal 'Tales and Sketches', @bib[:'key:1'].title
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'given a set of explicit and implicit comments' do
|
44
|
+
setup do
|
45
|
+
@bib = Parser.new(:debug => false, :include => [:meta_content]).parse(File.read(Test.fixtures(:comment)))
|
46
|
+
end
|
47
|
+
|
48
|
+
should 'parses all @comments' do
|
49
|
+
assert_equal 2, @bib.comments.length
|
50
|
+
end
|
51
|
+
|
52
|
+
should 'parses all meta content' do
|
53
|
+
assert_equal 3, @bib.meta_contents.length
|
54
|
+
end
|
55
|
+
|
56
|
+
should 'parse @comment content as string' do
|
57
|
+
assert_equal ' A comment can contain pretty much anything ', @bib.comments[0].content
|
58
|
+
assert_equal %Q[\n@string{ foo = "bar" }\n\n@string{ bar = "foo" }\n], @bib.comments[1].content
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'given a set of @preambles' do
|
63
|
+
setup do
|
64
|
+
@bib = Parser.new(:debug => false).parse(File.read(Test.fixtures(:preamble)))
|
65
|
+
end
|
66
|
+
|
67
|
+
should 'parse all @preambles' do
|
68
|
+
assert_equal 3, @bib.preambles.length
|
69
|
+
end
|
70
|
+
|
71
|
+
should 'parse all contents' do
|
72
|
+
assert_equal 'This bibliography was created \\today', @bib.preambles[0].value.to_s
|
73
|
+
assert_equal 'Bib\\TeX', @bib.preambles[1].value.to_s
|
74
|
+
assert_equal '"Maintained by " # maintainer', @bib.preambles[2].value.to_s
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'helper.rb'
|
2
|
+
|
3
|
+
module BibTeX
|
4
|
+
class StringTest < MiniTest::Spec
|
5
|
+
|
6
|
+
context 'when parsing a simple string' do
|
7
|
+
setup do
|
8
|
+
@bib = BibTeX.parse('@string{ foo = "bar" }')
|
9
|
+
end
|
10
|
+
should 'should not be empty' do
|
11
|
+
assert_equal 1, @bib.length
|
12
|
+
end
|
13
|
+
should 'have a symbol as key' do
|
14
|
+
assert_equal :foo, @bib[0].key
|
15
|
+
end
|
16
|
+
should 'have a value string' do
|
17
|
+
assert_equal 'bar', @bib[0].value.to_s
|
18
|
+
end
|
19
|
+
should 'have been registered' do
|
20
|
+
refute @bib.strings[:foo].nil?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# def test_replacement
|
26
|
+
# bib = BibTeX::Bibliography.open(Test.fixtures(:string_replacement), :debug => false)
|
27
|
+
# refute_nil(bib)
|
28
|
+
# assert(bib.kind_of?(BibTeX::Bibliography))
|
29
|
+
# refute(bib.empty?)
|
30
|
+
# assert_equal(7,bib.length)
|
31
|
+
# assert_equal([BibTeX::String,BibTeX::Preamble,BibTeX::Entry], bib.data.map(&:class).uniq)
|
32
|
+
# assert_equal(["foo"], bib.strings[:foo])
|
33
|
+
# assert_equal(["bar"], bib.strings[:bar])
|
34
|
+
# assert_equal([:foo, "bar"], bib.strings[:foobar])
|
35
|
+
# assert_equal([:foobar, :foo], bib.strings[:foobarfoo])
|
36
|
+
# assert_equal([:bar, "foo", :bar], bib.strings[:barfoobar])
|
37
|
+
# assert_equal('"foo" # foo # foobarfoo # "bar"', bib.preambles[0].content)
|
38
|
+
# assert_equal('"foo" # barfoobar', bib[:'manual:1'].title)
|
39
|
+
#
|
40
|
+
# bib.replace_strings({ :filter => [:preamble]})
|
41
|
+
# assert_equal(["foo"], bib.strings[:foo])
|
42
|
+
# assert_equal(["bar"], bib.strings[:bar])
|
43
|
+
# assert_equal([:foo, "bar"], bib.strings[:foobar])
|
44
|
+
# assert_equal([:foobar, :foo], bib.strings[:foobarfoo])
|
45
|
+
# assert_equal([:bar, "foo", :bar], bib.strings[:barfoobar])
|
46
|
+
# assert_equal('"foo" # "foo" # foobar # foo # "bar"', bib.preambles[0].content)
|
47
|
+
# assert_equal('"foo" # barfoobar', bib[:'manual:1'].title)
|
48
|
+
#
|
49
|
+
# bib.replace_strings({ :filter => [:string]})
|
50
|
+
# assert_equal(['foo','bar'], bib.strings[:foobar])
|
51
|
+
# assert_equal(['foo', 'bar','foo'], bib.strings[:foobarfoo])
|
52
|
+
# assert_equal(['bar','foo','bar'], bib.strings[:barfoobar])
|
53
|
+
# assert_equal('"foo" # "foo" # foobar # foo # "bar"', bib.preambles[0].content)
|
54
|
+
# assert_equal('"foo" # barfoobar', bib[:'manual:1'].title)
|
55
|
+
#
|
56
|
+
# bib.replace_strings({ :filter => [:preamble,:entry]})
|
57
|
+
# assert_equal('"foo" # "foo" # "foo" # "bar" # "foo" # "bar"', bib.preambles[0].content)
|
58
|
+
# assert_equal('"foo" # "bar" # "foo" # "bar"', bib[:'manual:1'].title)
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
# def test_roundtrip
|
62
|
+
# bib = BibTeX::Bibliography.open(Test.fixtures(:string_replacement), :debug => false)
|
63
|
+
# refute_nil(bib)
|
64
|
+
# assert_equal('@string{ foo = "foo" }', bib.data[0].to_s)
|
65
|
+
# assert_equal('@string{ bar = "bar" }', bib.data[1].to_s)
|
66
|
+
# assert_equal('@string{ foobar = foo # "bar" }', bib.data[2].to_s)
|
67
|
+
# assert_equal('@string{ foobarfoo = foobar # foo }', bib.data[3].to_s)
|
68
|
+
# assert_equal('@string{ barfoobar = bar # "foo" # bar }', bib.data[4].to_s)
|
69
|
+
# bib.replace_strings
|
70
|
+
# assert_equal('@string{ foo = "foo" }', bib.data[0].to_s)
|
71
|
+
# assert_equal('@string{ bar = "bar" }', bib.data[1].to_s)
|
72
|
+
# assert_equal('@string{ foobar = "foo" # "bar" }', bib.data[2].to_s)
|
73
|
+
# assert_equal('@string{ foobarfoo = "foo" # "bar" # "foo" }', bib.data[3].to_s)
|
74
|
+
# assert_equal('@string{ barfoobar = "bar" # "foo" # "bar" }', bib.data[4].to_s)
|
75
|
+
# bib.join_strings
|
76
|
+
# assert_equal('@string{ foo = "foo" }', bib.data[0].to_s)
|
77
|
+
# assert_equal('@string{ bar = "bar" }', bib.data[1].to_s)
|
78
|
+
# assert_equal('@string{ foobar = "foobar" }', bib.data[2].to_s)
|
79
|
+
# assert_equal('@string{ foobarfoo = "foobarfoo" }', bib.data[3].to_s)
|
80
|
+
# assert_equal('@string{ barfoobar = "barfoobar" }', bib.data[4].to_s)
|
81
|
+
# end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'helper.rb'
|
2
|
+
|
3
|
+
module BibTeX
|
4
|
+
|
5
|
+
class TestBibtex < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
def test_empty?
|
8
|
+
assert BibTeX.open(Test.fixtures(:empty)).empty?
|
9
|
+
refute BibTeX.open(Test.fixtures(:bibdesk)).empty?
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_parse
|
13
|
+
bib = BibTeX.parse %q[ @book{ id, author = {Poe, Edgar Allen}, title = "Ligeia" } ]
|
14
|
+
assert_equal 1, bib.length
|
15
|
+
assert_equal 'Ligeia', bib[:id].title
|
16
|
+
assert_equal 'Poe, Edgar Allen', bib[:id].author
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_validation
|
20
|
+
log_level = BibTeX.log.level
|
21
|
+
BibTeX.log.level = Logger::ERROR
|
22
|
+
|
23
|
+
refute BibTeX.parse(%q[ @book{ id, author = {Poe, Edgar Allen}, title = "Ligeia" } ]).valid?
|
24
|
+
assert BibTeX.parse(%q[ @book{ id, author = {Poe, Edgar Allen}, title = "Ligeia", publisher = "Penguin", year = 1996 } ]).valid?
|
25
|
+
assert BibTeX.parse(%q[ @book{ id, editor = {Poe, Edgar Allen}, title = "Ligeia", publisher = "Penguin", year = 1996 } ]).valid?
|
26
|
+
refute BibTeX.parse(%q[ @book{ id, xxxxxx = {Poe, Edgar Allen}, title = "Ligeia", publisher = "Penguin", year = 1996 } ]).valid?
|
27
|
+
refute BibTeX.parse(%q[ @book{ id, author = {Poe, Edgar Allen}, title = "Lig"eia", publisher = "Penguin", year = 1996 } ]).valid?
|
28
|
+
assert BibTeX.valid?(Test.fixtures(:bibdesk))
|
29
|
+
|
30
|
+
BibTeX.log.level = log_level
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'helper.rb'
|
2
|
+
|
3
|
+
module BibTeX
|
4
|
+
class ValueTest < MiniTest::Spec
|
5
|
+
|
6
|
+
context "when empty" do
|
7
|
+
should "be equal to an empty string" do
|
8
|
+
assert Value.new == ''
|
9
|
+
assert Value.new('') == ''
|
10
|
+
end
|
11
|
+
should "be empty" do
|
12
|
+
assert Value.new.empty?
|
13
|
+
assert Value.new('').empty?
|
14
|
+
end
|
15
|
+
should "match an empty pattern" do
|
16
|
+
assert Value.new =~ //
|
17
|
+
assert Value.new('') =~ //
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "#join" do
|
22
|
+
should "return empty string when empty" do
|
23
|
+
assert_equal '', Value.new.join.to_s
|
24
|
+
assert_equal '', Value.new('').join.to_s
|
25
|
+
end
|
26
|
+
should "return the string if atomic" do
|
27
|
+
assert_equal 'foo', Value.new('foo').join.to_s
|
28
|
+
end
|
29
|
+
should "return a string concatenation of all strings when containing only strings" do
|
30
|
+
assert_equal 'foobar', Value.new('foo', 'bar').join.to_s
|
31
|
+
assert_equal 'foobar', Value.new(['foo', 'bar']).join.to_s
|
32
|
+
end
|
33
|
+
should "should be atomic after join when containing only strings" do
|
34
|
+
refute Value.new('foo', 'bar').atomic?
|
35
|
+
assert Value.new('foo', 'bar').join.atomic?
|
36
|
+
end
|
37
|
+
should "do nothing when containing only symbols" do
|
38
|
+
value = Value.new(:foo)
|
39
|
+
assert_equal value, value.join
|
40
|
+
value = Value.new(:foo, :bar)
|
41
|
+
assert_equal value, value.join
|
42
|
+
end
|
43
|
+
should "do nothing when containing only symbols and a single string" do
|
44
|
+
value = Value.new(:foo, 'bar')
|
45
|
+
assert_equal value, value.join
|
46
|
+
value = Value.new('foo', :bar)
|
47
|
+
assert_equal value, value.join
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "#to_s" do
|
52
|
+
should "return the string if atomic" do
|
53
|
+
assert_equal 'foo bar', Value.new('foo bar').to_s
|
54
|
+
end
|
55
|
+
should "return the symbol as string when containing only a single symbol" do
|
56
|
+
assert_equal 'foo', Value.new(:foo).to_s
|
57
|
+
end
|
58
|
+
should "return all string tokens concatenated by #" do
|
59
|
+
assert_equal '"foo" # "bar"', Value.new('foo', 'bar').to_s
|
60
|
+
end
|
61
|
+
should "return all symbol tokens concatenated by #" do
|
62
|
+
assert_equal 'foo # bar', Value.new(:foo, :bar).to_s
|
63
|
+
end
|
64
|
+
should "return all symbol and string tokens concatenated by #" do
|
65
|
+
assert_equal 'foo # "bar"', Value.new(:foo, 'bar').to_s
|
66
|
+
assert_equal '"foo" # bar', Value.new('foo', :bar).to_s
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
12
|
@book{rails,
|
13
13
|
Address = {Raleigh, North Carolina},
|
14
|
-
Author = {Ruby, Sam, and Thomas, Dave, and Hansson, David
|
14
|
+
Author = {Ruby, Sam, and Thomas, Dave, and Hansson Heinemeier, David},
|
15
15
|
Booktitle = {Agile Web Development with Rails},
|
16
16
|
Date-Added = {2010-08-05 10:01:36 +0200},
|
17
17
|
Date-Modified = {2010-08-05 10:06:46 +0200},
|
File without changes
|