marc 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +30 -0
- data/.github/workflows/ruby.yml +24 -0
- data/.gitignore +17 -0
- data/.standard.yml +1 -0
- data/{Changes → CHANGELOG.md} +102 -30
- data/Gemfile +15 -0
- data/README.md +239 -46
- data/Rakefile +14 -14
- data/bin/marc +14 -0
- data/bin/marc2xml +17 -0
- data/examples/xml2marc.rb +10 -0
- data/lib/marc/constants.rb +3 -3
- data/lib/marc/controlfield.rb +35 -23
- data/lib/marc/datafield.rb +70 -63
- data/lib/marc/dublincore.rb +59 -41
- data/lib/marc/exception.rb +9 -1
- data/lib/marc/jsonl_reader.rb +33 -0
- data/lib/marc/jsonl_writer.rb +44 -0
- data/lib/marc/marc8/map_to_unicode.rb +16417 -16420
- data/lib/marc/marc8/to_unicode.rb +80 -86
- data/lib/marc/reader.rb +117 -123
- data/lib/marc/record.rb +72 -62
- data/lib/marc/subfield.rb +12 -10
- data/lib/marc/unsafe_xmlwriter.rb +93 -0
- data/lib/marc/version.rb +1 -1
- data/lib/marc/writer.rb +27 -30
- data/lib/marc/xml_parsers.rb +222 -197
- data/lib/marc/xmlreader.rb +131 -114
- data/lib/marc/xmlwriter.rb +93 -82
- data/lib/marc.rb +20 -18
- data/marc.gemspec +23 -0
- data/test/marc8/tc_marc8_mapping.rb +3 -3
- data/test/marc8/tc_to_unicode.rb +28 -32
- data/test/messed_up_leader.xml +9 -0
- data/test/tc_controlfield.rb +37 -34
- data/test/tc_datafield.rb +65 -60
- data/test/tc_dublincore.rb +9 -11
- data/test/tc_hash.rb +10 -13
- data/test/tc_jsonl.rb +19 -0
- data/test/tc_marchash.rb +17 -21
- data/test/tc_parsers.rb +108 -144
- data/test/tc_reader.rb +35 -36
- data/test/tc_reader_char_encodings.rb +149 -169
- data/test/tc_record.rb +143 -148
- data/test/tc_subfield.rb +14 -13
- data/test/tc_unsafe_xml.rb +95 -0
- data/test/tc_writer.rb +101 -108
- data/test/tc_xml.rb +101 -94
- data/test/tc_xml_error_handling.rb +7 -8
- data/test/ts_marc.rb +8 -8
- metadata +80 -9
data/test/tc_parsers.rb
CHANGED
@@ -1,180 +1,154 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "test/unit"
|
2
|
+
require "marc"
|
3
|
+
require "warning"
|
3
4
|
|
4
5
|
class ParsersTest < Test::Unit::TestCase
|
6
|
+
LOADABLE_PARSERS = {
|
7
|
+
libxml: "xml",
|
8
|
+
nokogiri: "nokogiri",
|
9
|
+
}
|
10
|
+
|
11
|
+
@@parsers = LOADABLE_PARSERS.keys.each_with_object({}) do |label, h|
|
12
|
+
begin
|
13
|
+
require LOADABLE_PARSERS[label]
|
14
|
+
h[label] = true
|
15
|
+
rescue LoadError
|
16
|
+
warn "#{label} unavailable: skipping its tests"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.jstax_available?
|
21
|
+
require "java"
|
22
|
+
java.lang.Class.forName("javax.xml.stream.XMLInputFactory")
|
23
|
+
true
|
24
|
+
rescue LoadError, java.lang.ClassNotFoundException
|
25
|
+
warn "jstax unavailable: skipping its tests"
|
26
|
+
false
|
27
|
+
end
|
28
|
+
|
29
|
+
@@parsers[:jstax] = jstax_available?
|
30
|
+
|
5
31
|
def test_parser_default
|
6
32
|
assert_equal("rexml", MARC::XMLReader.parser)
|
7
|
-
reader = MARC::XMLReader.new(
|
33
|
+
reader = MARC::XMLReader.new("test/one.xml")
|
8
34
|
assert_kind_of(REXML::Parsers::PullParser, reader.parser)
|
9
35
|
end
|
10
|
-
|
36
|
+
|
11
37
|
def test_set_nokogiri
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
assert_kind_of(Nokogiri::XML::SAX::Parser, reader.parser)
|
31
|
-
rescue LoadError
|
32
|
-
puts "\nNokogiri not available, skipping 'test_set_nokogiri'.\n"
|
33
|
-
end
|
38
|
+
return unless @@parsers[:nokogiri]
|
39
|
+
assert_equal("rexml", MARC::XMLReader.parser)
|
40
|
+
reader = MARC::XMLReader.new("test/one.xml")
|
41
|
+
assert_kind_of(REXML::Parsers::PullParser, reader.parser)
|
42
|
+
reader = MARC::XMLReader.new("test/one.xml", parser: MARC::XMLReader::USE_NOKOGIRI)
|
43
|
+
assert_kind_of(Nokogiri::XML::SAX::Parser, reader.parser)
|
44
|
+
assert_equal("rexml", MARC::XMLReader.parser)
|
45
|
+
reader = MARC::XMLReader.new("test/one.xml", parser: "nokogiri")
|
46
|
+
assert_kind_of(Nokogiri::XML::SAX::Parser, reader.parser)
|
47
|
+
assert_equal("rexml", MARC::XMLReader.parser)
|
48
|
+
MARC::XMLReader.parser = MARC::XMLReader::USE_NOKOGIRI
|
49
|
+
assert_equal("nokogiri", MARC::XMLReader.parser)
|
50
|
+
reader = MARC::XMLReader.new("test/one.xml")
|
51
|
+
assert_kind_of(Nokogiri::XML::SAX::Parser, reader.parser)
|
52
|
+
MARC::XMLReader.parser = "nokogiri"
|
53
|
+
assert_equal("nokogiri", MARC::XMLReader.parser)
|
54
|
+
reader = MARC::XMLReader.new("test/one.xml")
|
55
|
+
assert_kind_of(Nokogiri::XML::SAX::Parser, reader.parser)
|
34
56
|
end
|
35
|
-
|
36
|
-
def
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
57
|
-
else
|
58
|
-
puts "\nTest not being run from JRuby, skipping 'test_set_jrexml'.\n"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_set_jstax
|
63
|
-
if defined? JRUBY_VERSION
|
64
|
-
begin
|
65
|
-
assert_equal("rexml", MARC::XMLReader.parser)
|
66
|
-
reader = MARC::XMLReader.new('test/one.xml')
|
67
|
-
assert_kind_of(REXML::Parsers::PullParser, reader.parser)
|
68
|
-
|
69
|
-
reader = MARC::XMLReader.new('test/one.xml', :parser=>MARC::XMLReader::USE_JSTAX)
|
70
|
-
assert_kind_of(Java::ComSunOrgApacheXercesInternalImpl::XMLStreamReaderImpl, reader.parser)
|
71
|
-
assert_equal("rexml", MARC::XMLReader.parser)
|
72
|
-
reader = MARC::XMLReader.new('test/one.xml', :parser=>'jstax')
|
73
|
-
assert_kind_of(Java::ComSunOrgApacheXercesInternalImpl::XMLStreamReaderImpl, reader.parser)
|
74
|
-
assert_equal("rexml", MARC::XMLReader.parser)
|
75
|
-
MARC::XMLReader.parser=MARC::XMLReader::USE_JSTAX
|
76
|
-
assert_equal("jstax", MARC::XMLReader.parser)
|
77
|
-
reader = MARC::XMLReader.new('test/one.xml')
|
78
|
-
assert_kind_of(Java::ComSunOrgApacheXercesInternalImpl::XMLStreamReaderImpl, reader.parser)
|
79
|
-
MARC::XMLReader.parser="jstax"
|
80
|
-
assert_equal("jstax", MARC::XMLReader.parser)
|
81
|
-
reader = MARC::XMLReader.new('test/one.xml')
|
82
|
-
assert_kind_of(Java::ComSunOrgApacheXercesInternalImpl::XMLStreamReaderImpl, reader.parser)
|
83
|
-
rescue java.lang.ClassNotFoundException
|
84
|
-
puts "\njavax.xml.stream not available, skipping 'test_set_jstax'.\n"
|
85
|
-
end
|
86
|
-
else
|
87
|
-
puts "\nTest not being run from JRuby, skipping 'test_set_jstax'.\n"
|
57
|
+
|
58
|
+
def test_set_jstax
|
59
|
+
return unless @@parsers[:jstax]
|
60
|
+
assert_equal("rexml", MARC::XMLReader.parser)
|
61
|
+
reader = MARC::XMLReader.new("test/one.xml")
|
62
|
+
assert_kind_of(REXML::Parsers::PullParser, reader.parser)
|
63
|
+
|
64
|
+
reader = MARC::XMLReader.new("test/one.xml", parser: MARC::XMLReader::USE_JSTAX)
|
65
|
+
assert_kind_of(Java::ComSunOrgApacheXercesInternalImpl::XMLStreamReaderImpl, reader.parser)
|
66
|
+
assert_equal("rexml", MARC::XMLReader.parser)
|
67
|
+
reader = MARC::XMLReader.new("test/one.xml", parser: "jstax")
|
68
|
+
assert_kind_of(Java::ComSunOrgApacheXercesInternalImpl::XMLStreamReaderImpl, reader.parser)
|
69
|
+
assert_equal("rexml", MARC::XMLReader.parser)
|
70
|
+
MARC::XMLReader.parser = MARC::XMLReader::USE_JSTAX
|
71
|
+
assert_equal("jstax", MARC::XMLReader.parser)
|
72
|
+
reader = MARC::XMLReader.new("test/one.xml")
|
73
|
+
assert_kind_of(Java::ComSunOrgApacheXercesInternalImpl::XMLStreamReaderImpl, reader.parser)
|
74
|
+
MARC::XMLReader.parser = "jstax"
|
75
|
+
assert_equal("jstax", MARC::XMLReader.parser)
|
76
|
+
reader = MARC::XMLReader.new("test/one.xml")
|
77
|
+
assert_kind_of(Java::ComSunOrgApacheXercesInternalImpl::XMLStreamReaderImpl, reader.parser)
|
88
78
|
end
|
89
|
-
|
90
|
-
|
79
|
+
|
91
80
|
def test_set_rexml
|
92
|
-
reader = MARC::XMLReader.new(
|
81
|
+
reader = MARC::XMLReader.new("test/one.xml", parser: MARC::XMLReader::USE_REXML)
|
93
82
|
assert_kind_of(REXML::Parsers::PullParser, reader.parser)
|
94
83
|
assert_equal("rexml", MARC::XMLReader.parser)
|
95
|
-
reader = MARC::XMLReader.new(
|
84
|
+
reader = MARC::XMLReader.new("test/one.xml", parser: "rexml")
|
96
85
|
assert_kind_of(REXML::Parsers::PullParser, reader.parser)
|
97
|
-
assert_equal("rexml", MARC::XMLReader.parser)
|
98
|
-
MARC::XMLReader.parser=MARC::XMLReader::USE_REXML
|
99
86
|
assert_equal("rexml", MARC::XMLReader.parser)
|
100
|
-
|
87
|
+
MARC::XMLReader.parser = MARC::XMLReader::USE_REXML
|
88
|
+
assert_equal("rexml", MARC::XMLReader.parser)
|
89
|
+
reader = MARC::XMLReader.new("test/one.xml")
|
101
90
|
assert_kind_of(REXML::Parsers::PullParser, reader.parser)
|
102
|
-
MARC::XMLReader.parser="rexml"
|
91
|
+
MARC::XMLReader.parser = "rexml"
|
103
92
|
assert_equal("rexml", MARC::XMLReader.parser)
|
104
|
-
reader = MARC::XMLReader.new(
|
105
|
-
assert_kind_of(REXML::Parsers::PullParser, reader.parser)
|
93
|
+
reader = MARC::XMLReader.new("test/one.xml")
|
94
|
+
assert_kind_of(REXML::Parsers::PullParser, reader.parser)
|
106
95
|
end
|
107
|
-
|
96
|
+
|
108
97
|
def test_set_magic
|
109
98
|
best = choose_best_available_parser
|
110
99
|
magic_parser = best[:parser]
|
111
|
-
|
112
|
-
reader = MARC::XMLReader.new('test/one.xml', :parser=>MARC::XMLReader::USE_BEST_AVAILABLE)
|
100
|
+
reader = MARC::XMLReader.new("test/one.xml", parser: MARC::XMLReader::USE_BEST_AVAILABLE)
|
113
101
|
assert_kind_of(magic_parser, reader.parser)
|
114
102
|
assert_equal("rexml", MARC::XMLReader.parser)
|
115
|
-
reader = MARC::XMLReader.new(
|
103
|
+
reader = MARC::XMLReader.new("test/one.xml", parser: "magic")
|
116
104
|
assert_kind_of(magic_parser, reader.parser)
|
117
|
-
assert_equal("rexml", MARC::XMLReader.parser)
|
118
|
-
MARC::XMLReader.parser=MARC::XMLReader::USE_BEST_AVAILABLE
|
105
|
+
assert_equal("rexml", MARC::XMLReader.parser)
|
106
|
+
MARC::XMLReader.parser = MARC::XMLReader::USE_BEST_AVAILABLE
|
119
107
|
assert_equal("magic", MARC::XMLReader.parser)
|
120
|
-
reader = MARC::XMLReader.new(
|
108
|
+
reader = MARC::XMLReader.new("test/one.xml")
|
121
109
|
assert_kind_of(magic_parser, reader.parser)
|
122
|
-
MARC::XMLReader.parser="magic"
|
110
|
+
MARC::XMLReader.parser = "magic"
|
123
111
|
assert_equal("magic", MARC::XMLReader.parser)
|
124
|
-
reader = MARC::XMLReader.new(
|
125
|
-
assert_kind_of(magic_parser, reader.parser)
|
126
|
-
end
|
127
|
-
|
112
|
+
reader = MARC::XMLReader.new("test/one.xml")
|
113
|
+
assert_kind_of(magic_parser, reader.parser)
|
114
|
+
end
|
115
|
+
|
128
116
|
def test_parser_set_convenience_methods
|
129
117
|
best = choose_best_available_parser
|
130
118
|
parser = best[:parser]
|
131
119
|
parser_name = best[:parser_name]
|
132
120
|
assert_equal(parser_name, MARC::XMLReader.best_available)
|
133
121
|
MARC::XMLReader.best_available!
|
134
|
-
reader = MARC::XMLReader.new(
|
122
|
+
reader = MARC::XMLReader.new("test/one.xml")
|
135
123
|
assert_kind_of(parser, reader.parser)
|
136
124
|
MARC::XMLReader.rexml!
|
137
|
-
reader = MARC::XMLReader.new(
|
138
|
-
assert_kind_of(REXML::Parsers::PullParser, reader.parser)
|
139
|
-
if parser_name ==
|
125
|
+
reader = MARC::XMLReader.new("test/one.xml")
|
126
|
+
assert_kind_of(REXML::Parsers::PullParser, reader.parser)
|
127
|
+
if parser_name == "nokogiri"
|
140
128
|
MARC::XMLReader.nokogiri!
|
141
|
-
reader = MARC::XMLReader.new(
|
142
|
-
assert_kind_of(Nokogiri::XML::SAX::Parser, reader.parser)
|
143
|
-
else
|
144
|
-
puts "\nNokogiri not loaded, skipping convenience method test.\n"
|
145
|
-
end
|
146
|
-
if defined? JRUBY_VERSION
|
147
|
-
begin
|
148
|
-
require 'jrexml'
|
149
|
-
MARC::XMLReader.jrexml!
|
150
|
-
reader = MARC::XMLReader.new('test/one.xml')
|
151
|
-
assert_kind_of(REXML::Parsers::PullParser, reader.parser)
|
152
|
-
rescue LoadError
|
153
|
-
puts "\njrexml not available, skipping convenience method test.\n"
|
154
|
-
end
|
155
|
-
else
|
156
|
-
puts "\nTest not being run from JRuby, skipping jrexml convenience method test.\n"
|
129
|
+
reader = MARC::XMLReader.new("test/one.xml")
|
130
|
+
assert_kind_of(Nokogiri::XML::SAX::Parser, reader.parser)
|
157
131
|
end
|
158
132
|
end
|
159
|
-
|
133
|
+
|
160
134
|
def teardown
|
161
|
-
MARC::XMLReader.parser=MARC::XMLReader::USE_REXML
|
135
|
+
MARC::XMLReader.parser = MARC::XMLReader::USE_REXML
|
162
136
|
end
|
163
|
-
|
137
|
+
|
164
138
|
def choose_best_available_parser
|
165
139
|
parser_name = nil
|
166
140
|
parser = nil
|
167
|
-
unless parser
|
141
|
+
unless parser
|
168
142
|
begin
|
169
|
-
require
|
170
|
-
parser_name =
|
143
|
+
require "nokogiri"
|
144
|
+
parser_name = "nokogiri"
|
171
145
|
parser = Nokogiri::XML::SAX::Parser
|
172
146
|
rescue LoadError
|
173
147
|
end
|
174
148
|
end
|
175
149
|
unless parser
|
176
150
|
if defined? JRUBY_VERSION
|
177
|
-
require
|
151
|
+
require "java"
|
178
152
|
begin
|
179
153
|
java.lang.Class.forName("javax.xml.stream.XMLInputFactory")
|
180
154
|
parser_name = "jstax"
|
@@ -186,27 +160,17 @@ end
|
|
186
160
|
unless parser
|
187
161
|
if !defined? JRUBY_VERSION
|
188
162
|
begin
|
189
|
-
require
|
190
|
-
parser_name =
|
163
|
+
require "xml"
|
164
|
+
parser_name = "libxml"
|
191
165
|
parser = LibXML::XML::Reader
|
192
166
|
rescue LoadError
|
193
167
|
end
|
194
|
-
else
|
195
|
-
if defined? JRUBY_VERSION
|
196
|
-
begin
|
197
|
-
require 'jrexml'
|
198
|
-
parser_name = 'jrexml'
|
199
|
-
parser = REXML::Parsers::PullParser
|
200
|
-
rescue LoadError
|
201
|
-
end
|
202
|
-
end
|
203
168
|
end
|
204
169
|
unless parser
|
205
170
|
parser = REXML::Parsers::PullParser
|
206
|
-
parser_name =
|
171
|
+
parser_name = "rexml"
|
207
172
|
end
|
208
|
-
end
|
209
|
-
|
173
|
+
end
|
174
|
+
{parser: parser, parser_name: parser_name}
|
210
175
|
end
|
211
|
-
|
212
|
-
end
|
176
|
+
end
|
data/test/tc_reader.rb
CHANGED
@@ -1,92 +1,92 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require 'marc'
|
1
|
+
require "test/unit"
|
2
|
+
require "marc"
|
5
3
|
|
6
4
|
class ReaderTest < Test::Unit::TestCase
|
7
|
-
|
8
5
|
def test_batch
|
9
|
-
reader = MARC::Reader.new(
|
6
|
+
reader = MARC::Reader.new("test/batch.dat")
|
10
7
|
count = 0
|
11
8
|
reader.each { count += 1 }
|
12
9
|
assert_equal(count, 10)
|
13
10
|
end
|
14
11
|
|
15
12
|
def test_loose
|
16
|
-
reader = MARC::ForgivingReader.new(
|
13
|
+
reader = MARC::ForgivingReader.new("test/batch.dat")
|
17
14
|
count = 0
|
18
15
|
reader.each { count += 1 }
|
19
16
|
assert_equal(10, count)
|
20
17
|
end
|
21
|
-
|
18
|
+
|
22
19
|
def test_loose_utf8
|
23
|
-
# This isn't actually a corrupt file, but it is utf8,
|
20
|
+
# This isn't actually a corrupt file, but it is utf8,
|
24
21
|
# and I have some reason to believe forgiving reader isn't
|
25
|
-
# working properly with UTF8 in ruby 1.9, so testing it.
|
26
|
-
reader = MARC::ForgivingReader.new(
|
22
|
+
# working properly with UTF8 in ruby 1.9, so testing it.
|
23
|
+
reader = MARC::ForgivingReader.new("test/utf8.marc")
|
27
24
|
count = 0
|
28
25
|
reader.each { count += 1 }
|
29
26
|
assert_equal(1, count)
|
30
27
|
end
|
31
|
-
|
28
|
+
|
32
29
|
def test_loose_unimarc
|
33
|
-
# Unimarc might use a different record seperator? Let's make sure it works.
|
34
|
-
reader = MARC::Reader.new(File.open(
|
30
|
+
# Unimarc might use a different record seperator? Let's make sure it works.
|
31
|
+
reader = MARC::Reader.new(File.open("test/cp866_unimarc.marc", "r:cp866"))
|
35
32
|
count = 0
|
36
|
-
reader.each {|a| count += 1 }
|
33
|
+
reader.each { |a| count += 1 }
|
37
34
|
assert_equal(1, count)
|
38
35
|
end
|
39
36
|
|
40
37
|
def test_non_numeric_tags
|
41
|
-
reader = MARC::Reader.new(
|
38
|
+
reader = MARC::Reader.new("test/non-numeric.dat")
|
42
39
|
count = 0
|
43
40
|
record = nil
|
44
|
-
reader.each do |
|
41
|
+
reader.each do |rec|
|
45
42
|
count += 1
|
46
43
|
record = rec
|
47
44
|
end
|
48
45
|
assert_equal(1, count)
|
49
|
-
assert_equal(
|
50
|
-
assert_equal(
|
46
|
+
assert_equal("9780061317842", record["ISB"]["a"])
|
47
|
+
assert_equal("1", record["LOC"]["9"])
|
51
48
|
end
|
52
49
|
|
53
50
|
def test_bad_marc
|
54
|
-
reader = MARC::Reader.new(
|
55
|
-
assert_raises(MARC::Exception) {reader.entries[0]}
|
51
|
+
reader = MARC::Reader.new("test/tc_reader.rb")
|
52
|
+
assert_raises(MARC::Exception) { reader.entries[0] }
|
56
53
|
end
|
57
54
|
|
58
55
|
def test_search
|
59
|
-
reader = MARC::Reader.new(
|
56
|
+
reader = MARC::Reader.new("test/batch.dat")
|
60
57
|
records = reader.find_all { |r| r =~ /Perl/ }
|
61
58
|
assert_equal(10, records.length)
|
62
59
|
|
63
|
-
reader = MARC::Reader.new(
|
64
|
-
records = reader.find_all { |r| r[
|
60
|
+
reader = MARC::Reader.new("test/batch.dat")
|
61
|
+
records = reader.find_all { |r| r["245"] =~ /Perl/ }
|
65
62
|
assert_equal(10, records.length)
|
66
63
|
|
67
|
-
reader = MARC::Reader.new(
|
68
|
-
records = reader.find_all { |r| r[
|
64
|
+
reader = MARC::Reader.new("test/batch.dat")
|
65
|
+
records = reader.find_all { |r| r["245"]["a"] =~ /Perl/ }
|
69
66
|
assert_equal(10, records.length)
|
70
67
|
|
71
|
-
reader = MARC::Reader.new(
|
68
|
+
reader = MARC::Reader.new("test/batch.dat")
|
72
69
|
records = reader.find_all { |r| r =~ /Foo/ }
|
73
70
|
assert_equal(0, records.length)
|
74
71
|
end
|
75
|
-
|
72
|
+
|
76
73
|
def test_binary_enumerator
|
77
|
-
reader = MARC::Reader.new(
|
74
|
+
reader = MARC::Reader.new("test/batch.dat")
|
78
75
|
iter = reader.each
|
79
76
|
r = iter.next
|
80
77
|
assert_instance_of(MARC::Record, r)
|
81
|
-
9.times {iter.next} # total of ten records
|
82
|
-
assert_raises(StopIteration) { iter.next }
|
78
|
+
9.times { iter.next } # total of ten records
|
79
|
+
assert_raises(StopIteration) { iter.next }
|
83
80
|
end
|
84
81
|
|
85
82
|
def test_each_raw
|
86
|
-
reader = MARC::Reader.new(
|
83
|
+
reader = MARC::Reader.new("test/batch.dat")
|
87
84
|
count = 0
|
88
85
|
raw = nil
|
89
|
-
reader.each_raw { |r|
|
86
|
+
reader.each_raw { |r|
|
87
|
+
count += 1
|
88
|
+
raw = r
|
89
|
+
}
|
90
90
|
assert_equal(count, 10)
|
91
91
|
assert_instance_of(String, raw)
|
92
92
|
|
@@ -95,7 +95,7 @@ class ReaderTest < Test::Unit::TestCase
|
|
95
95
|
end
|
96
96
|
|
97
97
|
def test_each_raw_enum
|
98
|
-
reader = MARC::Reader.new(
|
98
|
+
reader = MARC::Reader.new("test/batch.dat")
|
99
99
|
enum = reader.each_raw
|
100
100
|
r = enum.next
|
101
101
|
assert_instance_of(String, r)
|
@@ -103,8 +103,7 @@ class ReaderTest < Test::Unit::TestCase
|
|
103
103
|
record = MARC::Reader.decode(r)
|
104
104
|
assert_instance_of(MARC::Record, record)
|
105
105
|
|
106
|
-
9.times {enum.next} # total of ten records
|
106
|
+
9.times { enum.next } # total of ten records
|
107
107
|
assert_raises(StopIteration) { enum.next }
|
108
108
|
end
|
109
|
-
|
110
109
|
end
|