bibtex-ruby 1.3.12 → 2.0.0pre1

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.

@@ -3,30 +3,30 @@ require 'helper.rb'
3
3
  module BibTeX
4
4
  class FiltersTest < MiniTest::Spec
5
5
 
6
- should "Filters should be singleton classes" do
6
+ it "should Filters should be singleton classes" do
7
7
  assert_equal false, Filter.respond_to?(:new)
8
8
  assert_equal Filter.instance.object_id, Filter.instance.object_id
9
9
  end
10
10
 
11
- context 'Filters.resolve' do
12
- should "return the filter if a filter is given" do
11
+ describe 'Filters.resolve' do
12
+ it "should return the filter if a filter is given" do
13
13
  assert_equal Filter.instance.object_id, Filters.resolve(Filter.instance).object_id
14
14
  end
15
15
 
16
- should "return the parameter if it quacks like a filter" do
16
+ it "should return the parameter if it quacks like a filter" do
17
17
  f = Object.new
18
18
  def f.apply; nil; end
19
19
  assert_equal f.object_id, Filters.resolve(f).object_id
20
20
  end
21
21
 
22
- should "return the filter if there is a filter by that name" do
22
+ it "should return the filter if there is a filter by that name" do
23
23
  class FooBar < Filter; end
24
24
  assert_equal FooBar.instance.object_id, Filters.resolve(:foobar).object_id
25
25
  assert_equal FooBar.instance.object_id, Filters.resolve('foobar').object_id
26
26
  Filter.subclasses.delete(FooBar)
27
27
  end
28
28
 
29
- should "return nil if there is no filter by that name" do
29
+ it "should return nil if there is no filter by that name" do
30
30
  assert_equal nil, Filters.resolve(:foobar)
31
31
  assert_equal nil, Filters.resolve('foobar')
32
32
  assert_equal nil, Filters.resolve(nil)
@@ -3,7 +3,7 @@ require 'helper.rb'
3
3
  module BibTeX
4
4
  class LexerTest < MiniTest::Spec
5
5
 
6
- should 'correctly scan a string literal' do
6
+ it 'should correctly scan a string literal' do
7
7
  assert_equal Lexer.new.analyse(%q(@string{ x = "foo" })).symbols, [:AT,:STRING,:LBRACE,:NAME,:EQ,:STRING_LITERAL,:RBRACE,false]
8
8
  end
9
9
 
@@ -3,18 +3,18 @@ require 'helper'
3
3
  module BibTeX
4
4
  class NameParserTest < MiniTest::Spec
5
5
 
6
- context "parse a number of entries having a 'van' or 'van den' name prefix" do
7
- setup do
6
+ describe "parse a number of entries having a 'van' or 'van den' name prefix" do
7
+ before do
8
8
  @a = Names.parse('van den Bout, D. E.')
9
9
  @b = Names.parse('Van den Bout, D. E.')
10
10
  end
11
11
 
12
- should "parse 'van den' part starting with lowercase letter" do
12
+ it "should parse 'van den' part starting with lowercase letter" do
13
13
  assert_equal(@a[0].to_str, "van den Bout, D. E.")
14
14
  assert_equal(@a[0].prefix, "van den")
15
15
  end
16
16
 
17
- should "parse 'Van den' part starting with uppercase letter" do
17
+ it "should parse 'Van den' part starting with uppercase letter" do
18
18
  assert_equal(@b[0].to_str, "Van den Bout, D. E.")
19
19
  assert_equal(@b[0].prefix, "Van den")
20
20
  end
@@ -3,17 +3,17 @@ require 'helper'
3
3
  module BibTeX
4
4
  class NamesTest < MiniTest::Spec
5
5
 
6
- context 'string behaviour' do
7
- setup do
6
+ describe 'string behaviour' do
7
+ before do
8
8
  @name = Name.new(:first => 'Charles Louis Xavier Joseph', :prefix => 'de la', :last => 'Vallee Poussin', :suffix => 'Jr.')
9
9
  end
10
- should 'implement upcase!' do
10
+ it 'should implement upcase!' do
11
11
  assert_equal 'DE LA VALLEE POUSSIN, JR., CHARLES LOUIS XAVIER JOSEPH', @name.upcase!.to_s
12
12
  end
13
- should 'implement downcase!' do
13
+ it 'should implement downcase!' do
14
14
  assert_equal 'de la vallee poussin, jr., charles louis xavier joseph', @name.downcase!.to_s
15
15
  end
16
- should 'implement gsub!' do
16
+ it 'should implement gsub!' do
17
17
  assert_equal 'dX la VallXX PoussXn, Jr., CharlXs LouXs XavXXr JosXph', @name.gsub!(/[ei]/, 'X').to_s
18
18
  end
19
19
 
@@ -3,36 +3,36 @@ require 'helper.rb'
3
3
  module BibTeX
4
4
  class ParserTest < MiniTest::Spec
5
5
 
6
- context 'given a set of valid @entries' do
7
- setup do
6
+ describe 'given a set of valid @entries' do
7
+ before do
8
8
  @bib = Parser.new(:debug => false).parse(File.read(Test.fixtures(:entry)))
9
9
  end
10
10
 
11
- should 'return a Bibliography' do
11
+ it 'should return a Bibliography' do
12
12
  assert @bib
13
13
  refute @bib.empty?
14
14
  end
15
15
 
16
- should 'parse all entries' do
16
+ it 'should parse all entries' do
17
17
  assert_equal 3, @bib.length
18
18
  end
19
19
 
20
- should 'parse the key values' do
21
- assert_equal %w{ key:0 key:1 foo }.map(&:to_sym), @bib.map(&:key)
20
+ it 'should parse the key values' do
21
+ assert_equal %w{ key:0 key:1 foo }, @bib.map(&:key)
22
22
  end
23
23
 
24
- should 'handle strange keys' do
24
+ it 'should handle strange keys' do
25
25
  input = "@Misc{George Martin06,title = {FEAST FOR CROWS}}"
26
26
  bib = Parser.new(:debug => false, :strict => false).parse(input)
27
- assert_equal :"George Martin06", bib.first.key
27
+ assert_equal "George Martin06", bib.first.key
28
28
  assert bib[:"George Martin06"]
29
29
  end
30
30
 
31
- should 'parse the entry types' do
31
+ it 'should parse the entry types' do
32
32
  assert_equal [:book, :article, :article], @bib.map(&:type)
33
33
  end
34
34
 
35
- should 'parse all values correctly' do
35
+ it 'should parse all values correctly' do
36
36
  assert_equal 'Poe, Edgar A.', @bib[:'key:0'].author.to_s
37
37
  assert_equal 'Hawthorne, Nathaniel', @bib[:'key:1'].author.to_s
38
38
 
@@ -47,52 +47,52 @@ module BibTeX
47
47
  end
48
48
  end
49
49
 
50
- context 'given a set of explicit and implicit comments' do
51
- setup do
50
+ describe 'given a set of explicit and implicit comments' do
51
+ before do
52
52
  @bib = Parser.new(:debug => false, :include => [:meta_content]).parse(File.read(Test.fixtures(:comment)))
53
53
  end
54
54
 
55
- should 'parses all @comments' do
55
+ it 'should parses all @comments' do
56
56
  assert_equal 2, @bib.comments.length
57
57
  end
58
58
 
59
- should 'parses all meta content' do
59
+ it 'should parses all meta content' do
60
60
  assert_equal 3, @bib.meta_contents.length
61
61
  end
62
62
 
63
- should 'parse @comment content as string' do
63
+ it 'should parse @comment content as string' do
64
64
  assert_equal ' A comment can contain pretty much anything ', @bib.comments[0].content
65
65
  assert_equal %Q[\n@string{ foo = "bar" }\n\n@string{ bar = "foo" }\n], @bib.comments[1].content
66
66
  end
67
67
  end
68
68
 
69
- context 'given a set of @preambles' do
70
- setup do
69
+ describe 'given a set of @preambles' do
70
+ before do
71
71
  @bib = Parser.new(:debug => false).parse(File.read(Test.fixtures(:preamble)))
72
72
  end
73
73
 
74
- should 'parse all @preambles' do
74
+ it 'should parse all @preambles' do
75
75
  assert_equal 3, @bib.preambles.length
76
76
  end
77
77
 
78
- should 'parse all contents' do
78
+ it 'should parse all contents' do
79
79
  assert_equal 'This bibliography was created \\today', @bib.preambles[0].value.to_s
80
80
  assert_equal 'Bib\\TeX', @bib.preambles[1].value.to_s
81
81
  assert_equal '"Maintained by " # maintainer', @bib.preambles[2].value.to_s
82
82
  end
83
83
  end
84
84
 
85
- context 'given an entry containing a multi-line literals' do
86
- setup do
85
+ describe 'given an entry containing a multi-line literals' do
86
+ before do
87
87
  @braces = %Q[@TechReport{key,\n author = {Donald,\n Duck}\n}]
88
88
  @string = %Q[@TechReport{key,\n author = "Donald,\n Duck"\n}]
89
89
  end
90
90
 
91
- should 'parse string literals' do
91
+ it 'should parse string literals' do
92
92
  refute_nil Parser.new.parse(@string)[:key]
93
93
  end
94
94
 
95
- should 'parse braced literals' do
95
+ it 'should parse braced literals' do
96
96
  refute_nil Parser.new.parse(@braces)[:key]
97
97
  end
98
98
 
@@ -3,20 +3,20 @@ require 'helper.rb'
3
3
  module BibTeX
4
4
  class StringTest < MiniTest::Spec
5
5
 
6
- context 'when parsing a simple string' do
7
- setup do
6
+ describe 'when parsing a simple string' do
7
+ before do
8
8
  @bib = BibTeX.parse('@string{ foo = "bar" }')
9
9
  end
10
- should 'should not be empty' do
10
+ it 'should should not be empty' do
11
11
  assert_equal 1, @bib.length
12
12
  end
13
- should 'have a symbol as key' do
13
+ it 'should have a symbol as key' do
14
14
  assert_equal :foo, @bib[0].key
15
15
  end
16
- should 'have a value string' do
16
+ it 'should have a value string' do
17
17
  assert_equal 'bar', @bib[0].value.to_s
18
18
  end
19
- should 'have been registered' do
19
+ it 'should have been registered' do
20
20
  refute @bib.strings[:foo].nil?
21
21
  end
22
22
  end
@@ -3,44 +3,44 @@ require 'helper.rb'
3
3
  module BibTeX
4
4
  class ValueTest < MiniTest::Spec
5
5
 
6
- context "when empty" do
7
- should "be equal to an empty string" do
6
+ describe "when empty" do
7
+ it "should be equal to an empty string" do
8
8
  assert Value.new == ''
9
9
  assert Value.new('') == ''
10
10
  end
11
- should "be empty" do
11
+ it "should be empty" do
12
12
  assert Value.new.empty?
13
13
  assert Value.new('').empty?
14
14
  end
15
- should "match an empty pattern" do
15
+ it "should match an empty pattern" do
16
16
  assert Value.new =~ //
17
17
  assert Value.new('') =~ //
18
18
  end
19
19
  end
20
20
 
21
- context "#join" do
22
- should "return empty string when empty" do
21
+ describe "#join" do
22
+ it "should return empty string when empty" do
23
23
  assert_equal '', Value.new.join.to_s
24
24
  assert_equal '', Value.new('').join.to_s
25
25
  end
26
- should "return the string if atomic" do
26
+ it "should return the string if atomic" do
27
27
  assert_equal 'foo', Value.new('foo').join.to_s
28
28
  end
29
- should "return a string concatenation of all strings when containing only strings" do
29
+ it "should return a string concatenation of all strings when containing only strings" do
30
30
  assert_equal 'foobar', Value.new('foo', 'bar').join.to_s
31
31
  assert_equal 'foobar', Value.new(['foo', 'bar']).join.to_s
32
32
  end
33
- should "should be atomic after join when containing only strings" do
33
+ it "should should be atomic after join when containing only strings" do
34
34
  refute Value.new('foo', 'bar').atomic?
35
35
  assert Value.new('foo', 'bar').join.atomic?
36
36
  end
37
- should "do nothing when containing only symbols" do
37
+ it "should do nothing when containing only symbols" do
38
38
  value = Value.new(:foo)
39
39
  assert_equal value, value.join
40
40
  value = Value.new(:foo, :bar)
41
41
  assert_equal value, value.join
42
42
  end
43
- should "do nothing when containing only symbols and a single string" do
43
+ it "should do nothing when containing only symbols and a single string" do
44
44
  value = Value.new(:foo, 'bar')
45
45
  assert_equal value, value.join
46
46
  value = Value.new('foo', :bar)
@@ -48,27 +48,27 @@ module BibTeX
48
48
  end
49
49
  end
50
50
 
51
- context "#to_s" do
52
- should "return the string if atomic" do
51
+ describe "#to_s" do
52
+ it "should return the string if atomic" do
53
53
  assert_equal 'foo bar', Value.new('foo bar').to_s
54
54
  end
55
- should "return the symbol as string when containing only a single symbol" do
55
+ it "should return the symbol as string when containing only a single symbol" do
56
56
  assert_equal 'foo', Value.new(:foo).to_s
57
57
  end
58
- should "return all string tokens concatenated by #" do
58
+ it "should return all string tokens concatenated by #" do
59
59
  assert_equal '"foo" # "bar"', Value.new('foo', 'bar').to_s
60
60
  end
61
- should "return all symbol tokens concatenated by #" do
61
+ it "should return all symbol tokens concatenated by #" do
62
62
  assert_equal 'foo # bar', Value.new(:foo, :bar).to_s
63
63
  end
64
- should "return all symbol and string tokens concatenated by #" do
64
+ it "should return all symbol and string tokens concatenated by #" do
65
65
  assert_equal 'foo # "bar"', Value.new(:foo, 'bar').to_s
66
66
  assert_equal '"foo" # bar', Value.new('foo', :bar).to_s
67
67
  end
68
68
  end
69
69
 
70
- context "conversions" do
71
- setup do
70
+ describe "conversions" do
71
+ before do
72
72
  class Upcase < BibTeX::Filter
73
73
  def apply (value)
74
74
  value.is_a?(::String) ? value.upcase : value
@@ -77,54 +77,54 @@ module BibTeX
77
77
  @values = [Value.new('foo'), Value.new('foo', :bar)]
78
78
  end
79
79
 
80
- context "#convert" do
81
- should "convert the value when given a filter instance" do
80
+ describe "#convert" do
81
+ it "should convert the value when given a filter instance" do
82
82
  assert_equal ['FOO', '"FOO" # bar'], @values.map { |v| v.convert(Upcase.instance).to_s }
83
83
  end
84
84
 
85
- should "convert the value when given a filter class" do
85
+ it "should convert the value when given a filter class" do
86
86
  assert_equal ['FOO', '"FOO" # bar'], @values.map { |v| v.convert(Upcase).to_s }
87
87
  end
88
88
 
89
- should "convert the value when given the name of a filter" do
89
+ it "should convert the value when given the name of a filter" do
90
90
  assert_equal ['FOO', '"FOO" # bar'], @values.map { |v| v.convert(:upcase).to_s }
91
91
  assert_equal ['FOO', '"FOO" # bar'], @values.map { |v| v.convert('upcase').to_s }
92
92
  end
93
93
 
94
- should "convert the value when using a ghost method" do
94
+ it "should convert the value when using a ghost method" do
95
95
  assert_equal ['FOO', '"FOO" # bar'], @values.map { |v| v.convert_upcase.to_s }
96
96
  end
97
97
 
98
- should "not alter the value when using a filter name" do
98
+ it "should not alter the value when using a filter name" do
99
99
  @values.each { |v| v.convert(:upcase) }
100
100
  assert_equal ['foo', '"foo" # bar'], @values.map(&:to_s)
101
101
  end
102
102
 
103
- should "not alter the value when using a ghost method" do
103
+ it "should not alter the value when using a ghost method" do
104
104
  @values.each { |v| v.convert_upcase }
105
105
  assert_equal ['foo', '"foo" # bar'], @values.map(&:to_s)
106
106
  end
107
107
  end
108
108
 
109
- context "#convert!" do
110
- should "convert the value when given the name of a filter" do
109
+ describe "#convert!" do
110
+ it "should convert the value when given the name of a filter" do
111
111
  assert_equal ['FOO', '"FOO" # bar'], @values.map { |v| v.convert!(:upcase).to_s }
112
112
  end
113
113
 
114
- should "alter the value when given the name of a filter" do
114
+ it "should alter the value when given the name of a filter" do
115
115
  @values.each { |v| v.convert!(:upcase) }
116
116
  assert_equal ['FOO', '"FOO" # bar'], @values.map(&:to_s)
117
117
  end
118
118
 
119
- should "alter the value when using a ghost method" do
119
+ it "should alter the value when using a ghost method" do
120
120
  @values.each { |v| v.convert_upcase! }
121
121
  assert_equal ['FOO', '"FOO" # bar'], @values.map(&:to_s)
122
122
  end
123
123
 
124
124
  end
125
125
 
126
- context "#to_s" do
127
- should 'accept a :filter option and convert the values accordingly without changing the value' do
126
+ describe "#to_s" do
127
+ it 'should accept a :filter option and convert the values accordingly without changing the value' do
128
128
  assert_equal '"FOO" # bar', @values[1].to_s(:filter => :upcase)
129
129
  assert_equal '"foo" # bar', @values[1].to_s
130
130
  end
@@ -1,5 +1,4 @@
1
1
 
2
- require 'mini_shoulda'
3
2
  require 'minitest/autorun'
4
3
  require 'redgreen'
5
4
  require 'tempfile'
@@ -27,7 +27,7 @@ module BibTeX
27
27
  bib = BibTeX::Bibliography.open(Test.fixtures(:decoret), :debug => false)
28
28
  assert_equal(15, bib.length)
29
29
  assert_equal([BibTeX::Entry,BibTeX::Comment,BibTeX::String,BibTeX::Preamble], bib.data.map(&:class).uniq)
30
- assert_equal(:py03, bib.data[0].key)
30
+ assert_equal('py03', bib.data[0].key)
31
31
  assert_equal(:article, bib[:py03].type)
32
32
  assert_equal("D\\'ecoret, Xavier", bib[:py03][:author].to_s)
33
33
  assert_equal('PyBiTex', bib[:py03][:title])
@@ -45,7 +45,7 @@ module BibTeX
45
45
  def test_bibdesk
46
46
  bib = BibTeX::Bibliography.open(Test.fixtures(:bibdesk), :debug => false)
47
47
  assert_equal 3, bib.length
48
- assert_equal :rails, bib[0].key
48
+ assert_equal 'rails', bib[0].key
49
49
  assert_equal '2010-08-05 10:06:32 +0200', bib[:dragon]['date-modified']
50
50
  end
51
51
 
@@ -75,9 +75,8 @@ module BibTeX
75
75
  end
76
76
 
77
77
  def test_parse
78
- file = File.read(Test.fixtures(:roundtrip))
79
78
  bib = BibTeX::Bibliography.new
80
- bib.add(BibTeX::Element.parse(%q( @string{ pragprog = "The Pragmatic Booksehlf" } )))
79
+ bib.add(BibTeX::Element.parse(%q( @string{ pragprog = "The Pragmatic Bookshelf" } )))
81
80
  bib.add(BibTeX::Element.parse(<<-END))
82
81
  @book{rails,
83
82
  address = {Raleigh, North Carolina},
@@ -85,7 +84,7 @@ module BibTeX
85
84
  booktitle = {Agile Web Development with Rails},
86
85
  edition = {third},
87
86
  keywords = {ruby, rails},
88
- publisher = {The Pragmatic Bookshelf},
87
+ publisher = pragprog,
89
88
  series = {The Facets of Ruby},
90
89
  title = {Agile Web Development with Rails},
91
90
  year = {2009}
@@ -95,7 +94,7 @@ module BibTeX
95
94
  assert_equal(2, bib.length)
96
95
  refute_nil(bib[:rails])
97
96
  bib.replace_strings
98
- assert_equal(file.gsub(/[\s]+/, ''), bib[:rails].to_s.gsub(/[\s]+/, ''))
97
+ assert_equal 'The Pragmatic Bookshelf', bib['rails'].publisher
99
98
  end
100
99
  end
101
100
 
@@ -1,7 +1,6 @@
1
1
  require 'helper.rb'
2
2
 
3
3
  require 'yaml'
4
- require 'json'
5
4
 
6
5
  module BibTeX
7
6
  class TestString < MiniTest::Unit::TestCase
@@ -17,13 +16,13 @@ module BibTeX
17
16
  yaml = YAML.load(bib.to_yaml)
18
17
  refute_nil(yaml)
19
18
  assert_equal(3, yaml.length)
20
- assert_equal([:dragon, :pickaxe, :rails], yaml.map { |y| y[:key] }.sort)
19
+ assert_equal(%w[ dragon pickaxe rails], yaml.map { |y| y[:key] }.sort)
21
20
  assert_equal('{The Facets of Ruby}', yaml[0][:series])
22
21
  end
23
22
 
24
23
  def test_json
25
24
  bib = BibTeX::Bibliography.open(Test.fixtures(:bibdesk), :debug => false)
26
- json = JSON.parse(bib.to_json)
25
+ json = MultiJson.decode(bib.to_json)
27
26
  refute_nil(json)
28
27
  assert_equal(3, json.length)
29
28
  assert_equal(%w[ dragon pickaxe rails], json.map { |y| y['key'] }.sort)