aurels-rbib 1.1 → 1.2
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.
- data/README +17 -1
- data/lib/bibtex.rb +9 -0
- metadata +2 -15
- data/examples/example.bib +0 -753
- data/examples/glom_citeulike.rb +0 -21
- data/examples/tara_no_url.rb +0 -14
- data/lib/bibtex/bibliography.rb +0 -45
- data/lib/bibtex/entry.rb +0 -70
- data/lib/bibtex/field.rb +0 -17
- data/lib/bibtex/lexer.rb +0 -123
- data/lib/bibtex/parser.rb +0 -116
- data/run_unit_tests.rb +0 -12
- data/test/test_bibliography.rb +0 -76
- data/test/test_entry.rb +0 -70
- data/test/test_field.rb +0 -17
- data/test/test_lexer.rb +0 -116
- data/test/test_parser.rb +0 -27
data/test/test_entry.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'lib/bibtex/entry'
|
2
|
-
require 'test/unit'
|
3
|
-
|
4
|
-
class TestEntry < Test::Unit::TestCase
|
5
|
-
include BibTeX
|
6
|
-
|
7
|
-
def setup
|
8
|
-
@e = Entry.new(EntryType::Book, 'foo01')
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_basic
|
12
|
-
assert_equal EntryType::Book, @e.type
|
13
|
-
assert_equal 'foo01', @e.key
|
14
|
-
end
|
15
|
-
|
16
|
-
def add_default_fields
|
17
|
-
@e.add_field :author, 'C. Doof'
|
18
|
-
@e.add_field :year, 2007
|
19
|
-
@e.add_field Field.new(:url, 'www.doof.me.uk')
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_fields
|
23
|
-
add_default_fields
|
24
|
-
|
25
|
-
assert_equal 'C. Doof', @e[:author]
|
26
|
-
assert_equal 2007, @e[:year]
|
27
|
-
assert_equal 'www.doof.me.uk', @e[:url]
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_to_s
|
31
|
-
add_default_fields
|
32
|
-
|
33
|
-
expect = <<END
|
34
|
-
@book{foo01,
|
35
|
-
author = {C. Doof},
|
36
|
-
url = {www.doof.me.uk},
|
37
|
-
year = {2007}
|
38
|
-
}
|
39
|
-
|
40
|
-
END
|
41
|
-
assert_equal expect, @e.to_s
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_reject
|
45
|
-
add_default_fields
|
46
|
-
|
47
|
-
expect = <<END
|
48
|
-
@book{foo01,
|
49
|
-
author = {C. Doof},
|
50
|
-
year = {2007}
|
51
|
-
}
|
52
|
-
|
53
|
-
END
|
54
|
-
r = @e.reject_fields [:url]
|
55
|
-
assert_equal expect, r.to_s
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_select
|
59
|
-
add_default_fields
|
60
|
-
|
61
|
-
expect = <<END
|
62
|
-
@book{foo01,
|
63
|
-
url = {www.doof.me.uk}
|
64
|
-
}
|
65
|
-
|
66
|
-
END
|
67
|
-
r = @e.select_fields [:url]
|
68
|
-
assert_equal expect, r.to_s
|
69
|
-
end
|
70
|
-
end
|
data/test/test_field.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'lib/bibtex/field'
|
2
|
-
require 'test/unit'
|
3
|
-
|
4
|
-
class TestField < Test::Unit::TestCase
|
5
|
-
include BibTeX
|
6
|
-
|
7
|
-
def test_basic
|
8
|
-
f = Field.new(:author, 'C. Doof')
|
9
|
-
assert_equal :author, f.key
|
10
|
-
assert_equal 'C. Doof', f.value
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_to_s
|
14
|
-
f = Field.new(:author, 'C. Doof')
|
15
|
-
assert_equal 'author = {C. Doof}', f.to_s
|
16
|
-
end
|
17
|
-
end
|
data/test/test_lexer.rb
DELETED
@@ -1,116 +0,0 @@
|
|
1
|
-
require 'lib/bibtex/lexer'
|
2
|
-
require 'test/unit'
|
3
|
-
|
4
|
-
class TestLexer < Test::Unit::TestCase
|
5
|
-
include BibTeX
|
6
|
-
|
7
|
-
def test_basic
|
8
|
-
l = Lexer.new do |rules|
|
9
|
-
rules.match /a/, :a
|
10
|
-
rules.match /b+/, :bs
|
11
|
-
rules.match /\s+/, :space
|
12
|
-
rules.match /hello/, :hello
|
13
|
-
end
|
14
|
-
l.feed 'aabbb hello'
|
15
|
-
|
16
|
-
assert_equal :a, l.next_token!
|
17
|
-
assert_equal :a, l.next_token!
|
18
|
-
assert_equal :bs, l.next_token!
|
19
|
-
assert_equal :space, l.next_token!
|
20
|
-
assert_equal :hello, l.peek_token
|
21
|
-
assert_equal 'hello', l.peek_lval
|
22
|
-
assert_equal :hello, l.next_token!
|
23
|
-
|
24
|
-
assert (not l.more_tokens?)
|
25
|
-
assert_raise LexerError do
|
26
|
-
l.next_token!
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_prec
|
31
|
-
l = Lexer.new do |rules|
|
32
|
-
rules.match /a/, :aye
|
33
|
-
rules.match /a+/, :bad
|
34
|
-
rules.match /.*/, :other
|
35
|
-
end
|
36
|
-
l.feed 'aa'
|
37
|
-
assert_equal :aye, l.next_token!
|
38
|
-
assert_equal :aye, l.next_token!
|
39
|
-
assert (not l.more_tokens?)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_whitespace
|
43
|
-
l = Lexer.new(false) do |rules|
|
44
|
-
rules.match /\w+/, :word
|
45
|
-
end
|
46
|
-
l.feed " hello\t\n world "
|
47
|
-
|
48
|
-
assert (not l.ignore_whitespace)
|
49
|
-
l.ignore_whitespace = true
|
50
|
-
|
51
|
-
assert_equal :word, l.next_token!
|
52
|
-
assert_equal 'hello', l.lval
|
53
|
-
assert_equal :word, l.next_token!
|
54
|
-
assert_equal 'world', l.lval
|
55
|
-
assert (not l.more_tokens?)
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_src_pos
|
59
|
-
l = Lexer.new do |rules|
|
60
|
-
rules.match /a/, :a
|
61
|
-
rules.match /\n/, :newline
|
62
|
-
end
|
63
|
-
l.feed 'aaaab'
|
64
|
-
|
65
|
-
4.times { l.next_token! }
|
66
|
-
begin
|
67
|
-
l.next_token!
|
68
|
-
flunk 'No exception raised'
|
69
|
-
rescue LexerError => e
|
70
|
-
assert_kind_of SourcePos, e.src_pos
|
71
|
-
assert_equal 1, e.src_pos.line
|
72
|
-
assert_equal 4, e.src_pos.column
|
73
|
-
end
|
74
|
-
|
75
|
-
l.ignore_newlines = false
|
76
|
-
l.feed "aa\nab"
|
77
|
-
|
78
|
-
l.file_name = 'My File'
|
79
|
-
|
80
|
-
2.times { l.next_token! }
|
81
|
-
assert_equal :newline, l.next_token!
|
82
|
-
assert_equal :a, l.next_token!
|
83
|
-
begin
|
84
|
-
l.next_token!
|
85
|
-
flunk 'No error raised'
|
86
|
-
rescue LexerError => e
|
87
|
-
assert_equal 2, e.src_pos.line
|
88
|
-
assert_equal 1, e.src_pos.column
|
89
|
-
assert_equal 'My File', e.src_pos.file
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_literals
|
94
|
-
l = Lexer.new do |rules|
|
95
|
-
rules.literals [:aye, :bee]
|
96
|
-
end
|
97
|
-
l.feed 'ayebeebee'
|
98
|
-
|
99
|
-
assert_equal :aye, l.next_token!
|
100
|
-
assert_equal :bee, l.next_token!
|
101
|
-
assert_equal :bee, l.next_token!
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_refeed
|
105
|
-
l = Lexer.new do |rules|
|
106
|
-
rules.match /a/, :a
|
107
|
-
rules.match /b/, :b
|
108
|
-
end
|
109
|
-
l.feed 'aaa'
|
110
|
-
|
111
|
-
assert_equal :a, l.next_token!
|
112
|
-
l.feed 'bb'
|
113
|
-
assert l.more_tokens?
|
114
|
-
assert_equal :b, l.next_token!
|
115
|
-
end
|
116
|
-
end
|
data/test/test_parser.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'lib/bibtex/parser'
|
2
|
-
require 'test/unit'
|
3
|
-
|
4
|
-
class TestParser < Test::Unit::TestCase
|
5
|
-
include BibTeX
|
6
|
-
|
7
|
-
def test_basic
|
8
|
-
b = Parser.parse 'examples/example.bib'
|
9
|
-
|
10
|
-
ryan98 = b['ryan98']
|
11
|
-
assert_kind_of Entry, ryan98
|
12
|
-
assert_equal EntryType::Article, ryan98.type
|
13
|
-
assert_equal 1998, ryan98[:year].to_i
|
14
|
-
|
15
|
-
heys01 = b['heys01']
|
16
|
-
assert_equal "March", heys01[:month]
|
17
|
-
assert_equal 2001, heys01[:year].to_i
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_parse_reparse
|
21
|
-
fname = '/tmp/example.bib.stripped'
|
22
|
-
b = Parser.parse 'examples/example.bib'
|
23
|
-
b.save fname
|
24
|
-
Parser.parse fname
|
25
|
-
File.delete fname
|
26
|
-
end
|
27
|
-
end
|