marc 1.0.4 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +30 -0
  3. data/.github/workflows/ruby.yml +24 -0
  4. data/.gitignore +17 -0
  5. data/.standard.yml +1 -0
  6. data/{Changes → CHANGELOG.md} +106 -29
  7. data/Gemfile +15 -0
  8. data/README.md +240 -47
  9. data/Rakefile +14 -14
  10. data/bin/marc +14 -0
  11. data/bin/marc2xml +17 -0
  12. data/examples/xml2marc.rb +10 -0
  13. data/lib/marc/constants.rb +3 -3
  14. data/lib/marc/controlfield.rb +35 -23
  15. data/lib/marc/datafield.rb +70 -63
  16. data/lib/marc/dublincore.rb +59 -41
  17. data/lib/marc/exception.rb +9 -1
  18. data/lib/marc/jsonl_reader.rb +33 -0
  19. data/lib/marc/jsonl_writer.rb +44 -0
  20. data/lib/marc/marc8/map_to_unicode.rb +16417 -16420
  21. data/lib/marc/marc8/to_unicode.rb +80 -86
  22. data/lib/marc/reader.rb +119 -121
  23. data/lib/marc/record.rb +72 -62
  24. data/lib/marc/subfield.rb +12 -10
  25. data/lib/marc/unsafe_xmlwriter.rb +93 -0
  26. data/lib/marc/version.rb +1 -1
  27. data/lib/marc/writer.rb +27 -30
  28. data/lib/marc/xml_parsers.rb +222 -197
  29. data/lib/marc/xmlreader.rb +131 -114
  30. data/lib/marc/xmlwriter.rb +93 -81
  31. data/lib/marc.rb +20 -18
  32. data/marc.gemspec +23 -0
  33. data/test/marc8/tc_marc8_mapping.rb +3 -3
  34. data/test/marc8/tc_to_unicode.rb +28 -32
  35. data/test/messed_up_leader.xml +9 -0
  36. data/test/tc_controlfield.rb +37 -34
  37. data/test/tc_datafield.rb +65 -60
  38. data/test/tc_dublincore.rb +9 -11
  39. data/test/tc_hash.rb +10 -13
  40. data/test/tc_jsonl.rb +19 -0
  41. data/test/tc_marchash.rb +17 -21
  42. data/test/tc_parsers.rb +108 -144
  43. data/test/tc_reader.rb +35 -36
  44. data/test/tc_reader_char_encodings.rb +149 -169
  45. data/test/tc_record.rb +143 -148
  46. data/test/tc_subfield.rb +14 -13
  47. data/test/tc_unsafe_xml.rb +95 -0
  48. data/test/tc_writer.rb +101 -108
  49. data/test/tc_xml.rb +99 -87
  50. data/test/tc_xml_error_handling.rb +7 -8
  51. data/test/ts_marc.rb +8 -8
  52. metadata +94 -9
@@ -1,15 +1,12 @@
1
- # encoding: UTF-8
1
+ require "test/unit"
2
+ require "marc"
2
3
 
3
- require 'test/unit'
4
- require 'marc'
4
+ require "marc/marc8/to_unicode"
5
5
 
6
- require 'marc/marc8/to_unicode'
7
-
8
- require 'unf'
6
+ require "unf"
9
7
 
10
8
  if "".respond_to?(:encoding)
11
9
 
12
-
13
10
  class TestMarc8ToUnicode < Test::Unit::TestCase
14
11
  def test_empty_string
15
12
  value = MARC::Marc8::ToUnicode.new.transcode("")
@@ -35,18 +32,18 @@ if "".respond_to?(:encoding)
35
32
  # two data files, marc8 and utf8, with line-by-line correspondences.
36
33
  #
37
34
  # For now, we have NOT included proprietary III encodings in our test data!
38
- utf8_file = File.open( File.expand_path("../data/test_utf8.txt", __FILE__), "r:UTF-8")
39
- marc8_file = File.open( File.expand_path("../data/test_marc8.txt", __FILE__), "r:binary")
35
+ utf8_file = File.open(File.expand_path("../data/test_utf8.txt", __FILE__), "r:UTF-8")
36
+ marc8_file = File.open(File.expand_path("../data/test_marc8.txt", __FILE__), "r:binary")
40
37
 
41
38
  i = 0
42
39
  converter = MARC::Marc8::ToUnicode.new
43
40
 
44
41
  begin
45
- while true do
42
+ loop do
46
43
  i += 1
47
44
 
48
- utf8 = utf8_file.readline.chomp
49
- marc8 = marc8_file.readline.chomp
45
+ utf8 = utf8_file.readline.chomp
46
+ marc8 = marc8_file.readline.chomp
50
47
 
51
48
  converted = converter.transcode(marc8)
52
49
 
@@ -55,11 +52,11 @@ if "".respond_to?(:encoding)
55
52
 
56
53
  assert_equal utf8, converted, "Test data line #{i}, expected converted to match provided utf8"
57
54
  end
58
- rescue EOFError => each
55
+ rescue EOFError
59
56
  # just means the file was over, no biggie
60
57
  assert i > 1500, "Read as many lines as we expected to, at least 1500"
61
- rescue Exception => e
62
- $stderr.puts "Error at test data line #{i}"
58
+ rescue => e
59
+ warn "Error at test data line #{i}"
63
60
  raise e
64
61
  end
65
62
  end
@@ -67,23 +64,23 @@ if "".respond_to?(:encoding)
67
64
  def test_explicit_normalization
68
65
  # \xC1 is Marc8 "script small letter l", which under unicode
69
66
  # COMPAT normalization will turn into ordinary 'l'
70
- marc8 = "Conversa\xF0c\xE4ao \xC1"
71
- unicode = "Conversação \u2113"
67
+ marc8 = "Conversa\xF0c\xE4ao \xC1"
68
+ unicode = "Conversação \u2113"
72
69
 
73
- unicode_c = UNF::Normalizer.normalize(unicode, :nfc)
74
- unicode_kc = UNF::Normalizer.normalize(unicode, :nfkc)
75
- unicode_d = UNF::Normalizer.normalize(unicode, :nfd)
76
- unicode_kd = UNF::Normalizer.normalize(unicode, :nfkd)
70
+ unicode_c = UNF::Normalizer.normalize(unicode, :nfc)
71
+ unicode_kc = UNF::Normalizer.normalize(unicode, :nfkc)
72
+ unicode_d = UNF::Normalizer.normalize(unicode, :nfd)
73
+ unicode_kd = UNF::Normalizer.normalize(unicode, :nfkd)
77
74
 
78
75
  converter = MARC::Marc8::ToUnicode.new
79
76
 
80
- assert_equal unicode_c, converter.transcode(marc8, :normalization => :nfc)
81
- assert_equal unicode_kc, converter.transcode(marc8, :normalization => :nfkc)
82
- assert_equal unicode_d, converter.transcode(marc8, :normalization => :nfd)
83
- assert_equal unicode_kd, converter.transcode(marc8, :normalization => :nfkd)
77
+ assert_equal unicode_c, converter.transcode(marc8, normalization: :nfc)
78
+ assert_equal unicode_kc, converter.transcode(marc8, normalization: :nfkc)
79
+ assert_equal unicode_d, converter.transcode(marc8, normalization: :nfd)
80
+ assert_equal unicode_kd, converter.transcode(marc8, normalization: :nfkd)
84
81
 
85
82
  # disable normalization for performance or something, we won't end up with NFC.
86
- refute_equal unicode_c, converter.transcode(marc8, :normalization => nil)
83
+ refute_equal unicode_c, converter.transcode(marc8, normalization: nil)
87
84
  end
88
85
 
89
86
  def test_expand_ncr
@@ -91,7 +88,7 @@ if "".respond_to?(:encoding)
91
88
 
92
89
  marc8_ncr = "Weird &#x200F; &#xFFFD; but these aren't changed #x2000; &#200F etc."
93
90
  assert_equal "Weird \u200F \uFFFD but these aren't changed #x2000; &#200F etc.", converter.transcode(marc8_ncr)
94
- assert_equal marc8_ncr, converter.transcode(marc8_ncr, :expand_ncr => false), "should not expand NCR if disabled"
91
+ assert_equal marc8_ncr, converter.transcode(marc8_ncr, expand_ncr: false), "should not expand NCR if disabled"
95
92
  end
96
93
 
97
94
  def test_bad_byte
@@ -130,7 +127,7 @@ if "".respond_to?(:encoding)
130
127
  converter = MARC::Marc8::ToUnicode.new
131
128
 
132
129
  bad_marc8 = "\e$1!PVK7oi$N!Q1!G4i$N!0p!Q+{6924f6}\e(B"
133
- value = converter.transcode(bad_marc8, :invalid => :replace)
130
+ value = converter.transcode(bad_marc8, invalid: :replace)
134
131
 
135
132
  assert_equal "UTF-8", value.encoding.name
136
133
  assert value.valid_encoding?
@@ -145,7 +142,7 @@ if "".respond_to?(:encoding)
145
142
  converter = MARC::Marc8::ToUnicode.new
146
143
 
147
144
  bad_marc8 = "\e$1!PVK7oi$N!Q1!G4i$N!0p!Q+{6924f6}\e(B"
148
- value = converter.transcode(bad_marc8, :invalid => :replace, :replace => "")
145
+ value = converter.transcode(bad_marc8, invalid: :replace, replace: "")
149
146
 
150
147
  assert_equal "UTF-8", value.encoding.name
151
148
  assert value.valid_encoding?
@@ -169,9 +166,8 @@ if "".respond_to?(:encoding)
169
166
 
170
167
  assert_equal "La Soci\u00E9t\x1B,", value
171
168
  end
172
-
173
169
  end
174
170
  else
175
- require 'pathname'
176
- $stderr.puts "\nTests not being run in ruby 1.9.x, skipping #{Pathname.new(__FILE__).basename}\n\n"
171
+ require "pathname"
172
+ warn "\nTests not being run in ruby 1.9.x, skipping #{Pathname.new(__FILE__).basename}\n\n"
177
173
  end
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <collection xmlns="http://www.loc.gov/MARC21/slim">
3
+ <record>
4
+ <leader>01301nam a22003618&lt; 4500</leader>
5
+ <controlfield tag="005">02-26-96</controlfield>
6
+ <controlfield tag="008">960213s1996 flu 000 0 eng </controlfield>
7
+ <controlfield tag="001">991010422259705706</controlfield>
8
+ <datafield tag="010" ind1=" " ind2=" "><subfield code="a">95041713</subfield></datafield><datafield tag="020" ind1=" " ind2=" "><subfield code="a">1566700701</subfield><subfield code="q">(alk. paper)</subfield></datafield><datafield tag="020" ind1=" " ind2=" "><subfield code="a">9781566700702</subfield><subfield code="q">(alk. paper)</subfield></datafield><datafield tag="035" ind1=" " ind2=" "><subfield code="a">(NhD)b23774344-01dcl_inst</subfield></datafield><datafield tag="035" ind1=" " ind2=" "><subfield code="a">(CStRLIN)ocm33245123</subfield><subfield code="9">ExL</subfield></datafield><datafield tag="035" ind1=" " ind2=" "><subfield code="b">b23774344</subfield></datafield><datafield tag="040" ind1=" " ind2=" "><subfield code="a">DLC</subfield><subfield code="c">DLC</subfield><subfield code="d">NhD</subfield></datafield><datafield tag="050" ind1=" " ind2="4"><subfield code="a">QH545.A1</subfield><subfield code="b">R65 1996</subfield></datafield><datafield tag="100" ind1="1" ind2=" "><subfield code="a">Römbke, Jörg.</subfield><subfield code="0">http://id.loc.gov/authorities/names/n95093926.</subfield></datafield><datafield tag="245" ind1="1" ind2="0"><subfield code="a">Applied ecotoxicology /</subfield><subfield code="c">Jörg Römbke, Johann F. Moltmann.</subfield></datafield><datafield tag="260" ind1=" " ind2=" "><subfield code="a">Boca Raton, FL :</subfield><subfield code="b">CRC/Lewis Publishers,</subfield><subfield code="c">1995.</subfield></datafield><datafield tag="300" ind1=" " ind2=" "><subfield code="a">282 pages :</subfield><subfield code="b">illustrations ;</subfield><subfield code="c">24 cm.</subfield></datafield><datafield tag="336" ind1=" " ind2=" "><subfield code="a">text</subfield><subfield code="b">txt</subfield><subfield code="2">rdacontent.</subfield></datafield><datafield tag="337" ind1=" " ind2=" "><subfield code="a">unmediated</subfield><subfield code="b">n</subfield><subfield code="2">rdamedia.</subfield></datafield><datafield tag="338" ind1=" " ind2=" "><subfield code="a">volume</subfield><subfield code="b">nc</subfield><subfield code="2">rdacarrier.</subfield></datafield><datafield tag="504" ind1=" " ind2=" "><subfield code="a">Includes bibliographical references and index.</subfield></datafield><datafield tag="650" ind1=" " ind2="0"><subfield code="a">Pollution.</subfield><subfield code="0">http://id.loc.gov/authorities/subjects/sh85104530.</subfield></datafield><datafield tag="700" ind1="1" ind2=" "><subfield code="a">Moltmann, Johann Felix,</subfield><subfield code="d">1954-</subfield><subfield code="0">http://id.loc.gov/authorities/names/n91002202.</subfield></datafield><datafield tag="991" ind1=" " ind2=" "><subfield code="a">b23774344</subfield></datafield><datafield tag="906" ind1=" " ind2=" "><subfield code="a">0</subfield><subfield code="b">flu</subfield><subfield code="c">multi</subfield><subfield code="d">a</subfield><subfield code="e">r</subfield><subfield code="f">1</subfield><subfield code="g">02-09-96</subfield><subfield code="h">01-10-19</subfield><subfield code="i">20</subfield></datafield><datafield tag="955" ind1=" " ind2=" "><subfield code="u">+l</subfield></datafield><datafield tag="948" ind1=" " ind2=" "><subfield code="a">BSLW 06/11/2018</subfield></datafield><datafield tag="998" ind1=" " ind2=" "><subfield code="a">02/13/96</subfield><subfield code="t">c</subfield><subfield code="s">9110</subfield><subfield code="l">NHDG</subfield><subfield code="n">NhD</subfield><subfield code="w">DCLC9541713B</subfield><subfield code="d">02/13/96</subfield><subfield code="c">JS</subfield><subfield code="b">ACQ</subfield><subfield code="i">960213</subfield></datafield><datafield tag="995" ind1=" " ind2=" "><subfield code="a">OCLC Recl. 2008</subfield></datafield><datafield tag="903" ind1=" " ind2=" "><subfield code="f">corr./JS/2-26-96</subfield></datafield><datafield tag="903" ind1=" " ind2=" "><subfield code="a">QH545.A1</subfield><subfield code="b">R65 1995</subfield></datafield><datafield tag="852" ind1="0" ind2=" "><subfield code="b">DEPOSITORY</subfield><subfield code="c">DEPOSITORY</subfield><subfield code="h">QH545.A1 R65 1996</subfield><subfield code="8">22127176380005706</subfield></datafield><datafield tag="950" ind1=" " ind2=" "><subfield code="z">33311011074376</subfield><subfield code="e">1</subfield></datafield></record>
9
+ </collection>
@@ -1,50 +1,53 @@
1
- require 'test/unit'
2
- require 'marc'
1
+ require "test/unit"
2
+ require "marc"
3
3
 
4
4
  class TestField < Test::Unit::TestCase
5
-
6
5
  def test_control
7
- control = MARC::ControlField.new('005', 'foobarbaz')
8
- assert_equal(control.to_s, '005 foobarbaz')
6
+ control = MARC::ControlField.new("005", "foobarbaz")
7
+ assert_equal(control.to_s, "005 foobarbaz")
9
8
  end
10
9
 
11
10
  def test_field_as_control
12
- assert_raise(MARC::Exception) do
13
- # can't have a field with a tag < 010
14
- field = MARC::DataField.new('007')
15
- end
11
+ field = MARC::DataField.new("007")
12
+ assert_equal(field.valid?, false)
16
13
  end
17
14
 
18
15
  def test_alpha_control_field
19
- assert_raise(MARC::Exception) do
20
- # can't have a field with a tag < 010
21
- field = MARC::ControlField.new('DDD')
22
- end
16
+ # can't have a field with a tag < 010
17
+ field = MARC::ControlField.new("DDD")
18
+ assert_equal(field.valid?, false)
23
19
  end
24
-
20
+
25
21
  def test_extra_control_field
26
- MARC::ControlField.control_tags << 'FMT'
27
- assert_nothing_raised do
28
- field = MARC::ControlField.new('FMT')
29
- end
30
- assert_raise(MARC::Exception) do
31
- field = MARC::DataField.new('FMT')
32
- end
33
- MARC::ControlField.control_tags.delete('FMT')
34
- assert_nothing_raised do
35
- field = MARC::DataField.new('FMT')
36
- end
37
- assert_raise(MARC::Exception) do
38
- field = MARC::ControlField.new('FMT')
39
- end
40
-
22
+ MARC::ControlField.control_tags << "FMT"
23
+ field = MARC::ControlField.new("FMT")
24
+ assert_equal(field.valid?, true)
25
+ field = MARC::DataField.new("FMT")
26
+ assert_equal(field.valid?, false)
27
+ MARC::ControlField.control_tags.delete("FMT")
28
+ field = MARC::DataField.new("FMT")
29
+ assert_equal(field.valid?, true)
30
+ field = MARC::ControlField.new("FMT")
31
+ assert_equal(field.valid?, false)
41
32
  end
42
33
 
43
34
  def test_control_as_field
44
- assert_raise(MARC::Exception) do
45
- # can't have a control with a tag > 009
46
- f = MARC::ControlField.new('245')
47
- end
35
+ # can't have a control with a tag > 009
36
+ f = MARC::ControlField.new("245")
37
+ assert_equal(f.valid?, false)
48
38
  end
49
- end
50
39
 
40
+ def test_equal
41
+ f1 = MARC::ControlField.new("001", "foobarbaz")
42
+ f2 = MARC::ControlField.new("001", "foobarbaz")
43
+ assert_equal(f1, f2)
44
+
45
+ f3 = MARC::ControlField.new("001", "foobarbazqux")
46
+ assert_not_equal(f1, f3)
47
+ f4 = MARC::ControlField.new("002", "foobarbaz")
48
+ assert_not_equal(f1, f4)
49
+
50
+ assert_not_equal(f1, "001")
51
+ assert_not_equal(f2, "foobarbaz")
52
+ end
53
+ end
data/test/tc_datafield.rb CHANGED
@@ -1,71 +1,76 @@
1
- require 'test/unit'
2
- require 'marc'
1
+ require "test/unit"
2
+ require "marc"
3
3
 
4
4
  class TestField < Test::Unit::TestCase
5
+ def test_tag
6
+ f1 = MARC::DataField.new("100")
7
+ assert_equal("100", f1.tag)
8
+ f2 = MARC::DataField.new("100")
9
+ assert_equal("100", f2.tag)
10
+ assert_equal(f1, f2)
11
+ f3 = MARC::DataField.new("245")
12
+ assert_not_equal(f1, f3)
13
+ end
5
14
 
6
- def test_tag
7
- f1 = MARC::DataField.new('100')
8
- assert_equal('100', f1.tag)
9
- f2 = MARC::DataField.new(tag='100')
10
- assert_equal('100', f2.tag)
11
- assert_equal(f1, f2)
12
- f3 = MARC::DataField.new('245')
13
- assert_not_equal(f1, f3)
14
- end
15
+ def test_alphabetic_tag
16
+ alph = MARC::DataField.new("ALF")
17
+ assert_equal "ALF", alph.tag
15
18
 
16
- def test_alphabetic_tag
17
- alph = MARC::DataField.new('ALF')
18
- assert_equal 'ALF', alph.tag
19
+ alphnum = MARC::DataField.new("0D9")
20
+ assert_equal "0D9", alphnum.tag
21
+ end
19
22
 
20
- alphnum = MARC::DataField.new('0D9')
21
- assert_equal '0D9', alphnum.tag
22
- end
23
+ def test_indicators
24
+ f1 = MARC::DataField.new("100", "0", "1")
25
+ assert_equal("0", f1.indicator1)
26
+ assert_equal("1", f1.indicator2)
27
+ f2 = MARC::DataField.new("100", "0", "1")
28
+ assert_equal("0", f2.indicator1)
29
+ assert_equal("1", f2.indicator2)
30
+ assert_equal(f1, f2)
31
+ f3 = MARC::DataField.new("100", "1", "1")
32
+ assert_not_equal(f1, f3)
33
+ end
23
34
 
24
- def test_indicators
25
- f1 = MARC::DataField.new('100', '0', '1')
26
- assert_equal('0', f1.indicator1)
27
- assert_equal('1', f1.indicator2)
28
- f2 = MARC::DataField.new(tag='100',i1='0',i2='1')
29
- assert_equal('0', f2.indicator1)
30
- assert_equal('1', f2.indicator2)
31
- assert_equal(f1, f2)
32
- f3 = MARC::DataField.new(tag='100', i1='1', i2='1')
33
- assert_not_equal(f1, f3)
34
- end
35
+ def test_subfields
36
+ f1 = MARC::DataField.new("100", "0", "1",
37
+ MARC::Subfield.new("a", "Foo"),
38
+ MARC::Subfield.new("b", "Bar"))
39
+ assert_equal("100 01 $a Foo $b Bar ", f1.to_s)
40
+ assert_equal("FooBar", f1.value)
41
+ f2 = MARC::DataField.new("100", "0", "1",
42
+ MARC::Subfield.new("a", "Foo"),
43
+ MARC::Subfield.new("b", "Bar"))
44
+ assert_equal(f1, f2)
45
+ f3 = MARC::DataField.new("100", "0", "1",
46
+ MARC::Subfield.new("a", "Foo"),
47
+ MARC::Subfield.new("b", "Bez"))
48
+ assert_not_equal(f1, f3)
49
+ end
35
50
 
36
- def test_subfields
37
- f1 = MARC::DataField.new('100', '0', '1',
38
- MARC::Subfield.new('a', 'Foo'),
39
- MARC::Subfield.new('b', 'Bar') )
40
- assert_equal("100 01 $a Foo $b Bar ", f1.to_s)
41
- assert_equal("FooBar", f1.value)
42
- f2 = MARC::DataField.new('100', '0', '1',
43
- MARC::Subfield.new('a', 'Foo'),
44
- MARC::Subfield.new('b', 'Bar') )
45
- assert_equal(f1,f2)
46
- f3 = MARC::DataField.new('100', '0', '1',
47
- MARC::Subfield.new('a', 'Foo'),
48
- MARC::Subfield.new('b', 'Bez') )
49
- assert_not_equal(f1,f3)
50
- end
51
+ def test_subfield_shorthand
52
+ f = MARC::DataField.new("100", "0", "1", ["a", "Foo"], ["b", "Bar"])
53
+ assert_equal("100 01 $a Foo $b Bar ", f.to_s)
54
+ end
51
55
 
52
- def test_subfield_shorthand
53
- f = MARC::DataField.new('100', '0', '1', ['a', 'Foo'], ['b', 'Bar'])
54
- assert_equal('100 01 $a Foo $b Bar ', f.to_s)
55
- end
56
-
56
+ def test_iterator
57
+ field = MARC::DataField.new("100", "0", "1", ["a", "Foo"], ["b", "Bar"],
58
+ ["a", "Bez"])
59
+ count = 0
60
+ field.each { |x| count += 1 }
61
+ assert_equal(count, 3)
62
+ end
57
63
 
58
- def test_iterator
59
- field = MARC::DataField.new('100', '0', '1', ['a', 'Foo'],['b', 'Bar'],
60
- ['a', 'Bez'])
61
- count = 0
62
- field.each {|x| count += 1}
63
- assert_equal(count,3)
64
- end
65
-
66
- def test_lookup_shorthand
67
- f = MARC::DataField.new('100', '0', '1', ['a', 'Foo'], ['b', 'Bar'])
68
- assert_equal(f['b'], 'Bar')
69
- end
64
+ def test_lookup_shorthand
65
+ f = MARC::DataField.new("100", "0", "1", ["a", "Foo"], ["b", "Bar"])
66
+ assert_equal(f["b"], "Bar")
67
+ end
70
68
 
69
+ def test_equal_other_types
70
+ f = MARC::DataField.new("100", "0", "1",
71
+ MARC::Subfield.new("a", "Foo"),
72
+ MARC::Subfield.new("b", "Bar"))
73
+ assert_not_equal(f, "100 01 $a Foo $b Bar ")
74
+ assert_not_equal(f, f["a"])
75
+ end
71
76
  end
@@ -1,14 +1,12 @@
1
- require 'test/unit'
2
- require 'marc'
1
+ require "test/unit"
2
+ require "marc"
3
3
 
4
4
  class DublinCoreTest < Test::Unit::TestCase
5
-
6
- def test_mapping
7
- reader = MARC::Reader.new('test/batch.dat')
8
- reader.each do |record|
9
- dc = record.to_dublin_core
10
- assert dc['title'] == record['245']['a']
11
- end
5
+ def test_mapping
6
+ reader = MARC::Reader.new("test/batch.dat")
7
+ reader.each do |record|
8
+ dc = record.to_dublin_core
9
+ assert dc["title"] == record["245"]["a"]
12
10
  end
13
-
14
- end
11
+ end
12
+ end
data/test/tc_hash.rb CHANGED
@@ -1,26 +1,23 @@
1
- require 'test/unit'
2
- require 'marc'
3
- require 'rubygems'
1
+ require "test/unit"
2
+ require "marc"
3
+ require "rubygems"
4
4
 
5
5
  class TestHash < Test::Unit::TestCase
6
-
7
6
  def test_to_hash
8
- raw = IO.read('test/one.dat')
7
+ raw = IO.read("test/one.dat")
9
8
  r = MARC::Record.new_from_marc(raw)
10
9
  h = r.to_hash
11
10
  assert_kind_of(Hash, h)
12
- assert_equal(r.leader, h['leader'])
13
- assert_equal(r.fields.length, h['fields'].length)
14
- assert_equal(r.fields.first.tag, h['fields'].first.keys.first)
11
+ assert_equal(r.leader, h["leader"])
12
+ assert_equal(r.fields.length, h["fields"].length)
13
+ assert_equal(r.fields.first.tag, h["fields"].first.keys.first)
15
14
  end
16
15
 
17
16
  def test_roundtrip
18
- reader = MARC::Reader.new('test/batch.dat')
17
+ reader = MARC::Reader.new("test/batch.dat")
19
18
  reader.each do |r|
20
19
  x = MARC::Record.new_from_hash(r.to_hash)
21
- assert_equal(r,x)
20
+ assert_equal(r, x)
22
21
  end
23
22
  end
24
-
25
-
26
- end
23
+ end
data/test/tc_jsonl.rb ADDED
@@ -0,0 +1,19 @@
1
+ require "test/unit"
2
+ require "marc"
3
+
4
+ class JSONLTestCase < Test::Unit::TestCase
5
+ def test_round_trip
6
+ tempfile = "test/batch.jsonl"
7
+ records = MARC::Reader.new("test/batch.dat").to_a
8
+ jsonl_writer = MARC::JSONLWriter.new(tempfile)
9
+ records.each { |r| jsonl_writer.write(r) }
10
+ jsonl_writer.close
11
+
12
+ jsonl_reader = MARC::JSONLReader.new(tempfile)
13
+ jsonl_reader.each_with_index do |r, i|
14
+ assert_equal(records[i], r)
15
+ end
16
+ ensure
17
+ File.unlink(tempfile)
18
+ end
19
+ end
data/test/tc_marchash.rb CHANGED
@@ -1,37 +1,33 @@
1
- require 'test/unit'
2
- require 'marc'
3
- require 'rubygems'
1
+ require "test/unit"
2
+ require "marc"
3
+ require "rubygems"
4
4
 
5
5
  class TestMARCHASH < Test::Unit::TestCase
6
-
7
6
  def test_simple
8
7
  simple = {
9
- 'type' => 'marc-hash',
10
- 'version' => [1,0],
11
- 'leader' => 'LEADER',
12
- 'fields' => [
13
- ['245', '1', '0',
8
+ "type" => "marc-hash",
9
+ "version" => [1, 0],
10
+ "leader" => "LEADER",
11
+ "fields" => [
12
+ ["245", "1", "0",
14
13
  [
15
- ['a', 'TITLE'],
16
- ['b', 'SUBTITLE']
17
- ]
18
- ]
14
+ ["a", "TITLE"],
15
+ ["b", "SUBTITLE"]
16
+ ]]
19
17
  ]
20
18
  }
21
- r = MARC::Record.new()
22
- r.leader = 'LEADER'
23
- f = MARC::DataField.new('245', '1', '0', ['a', 'TITLE'], ['b', 'SUBTITLE'])
19
+ r = MARC::Record.new
20
+ r.leader = "LEADER"
21
+ f = MARC::DataField.new("245", "1", "0", ["a", "TITLE"], ["b", "SUBTITLE"])
24
22
  r << f
25
23
  assert_equal(r.to_marchash, simple)
26
24
  end
27
25
 
28
26
  def test_real
29
- reader = MARC::Reader.new('test/batch.dat')
27
+ reader = MARC::Reader.new("test/batch.dat")
30
28
  reader.each do |r|
31
29
  x = MARC::Record.new_from_marchash(r.to_marchash)
32
- assert_equal(r,x)
30
+ assert_equal(r, x)
33
31
  end
34
32
  end
35
-
36
-
37
- end
33
+ end