-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmarc21_test.go
534 lines (506 loc) · 19.8 KB
/
marc21_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
package marc21
/*
Go Language MARC21 Library
Copyright (C) 2011 William Waites
This program is free software: you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License and the GNU General Public License along with this program
(the files COPYING and GPL3 respectively). If not, see
<http://www.gnu.org/licenses/>.
*/
import (
"bytes"
"fmt"
"io"
"log"
"os"
"strings"
"testing"
)
// TestReadEmpty tests readings a record without fields.
func TestReadEmpty(t *testing.T) {
file, err := os.Open("fixtures/r0.mrc")
if err != nil {
t.Error(err)
}
record, err := ReadRecord(file)
if err != nil {
t.Error(err)
}
if len(record.Fields) != 0 {
t.Errorf("record.Fields, got %v, want %v", len(record.Fields), 0)
}
if record.Leader.Length != 26 {
t.Errorf("record.Leader.Length, got %v, want %v", record.Leader.Length, 0)
}
}
func TestWhitespaceIdentifier(t *testing.T) {
file, err := os.Open("fixtures/r1.mrc")
if err != nil {
t.Error(err)
}
record, err := ReadRecord(file)
if err != nil {
t.Error(err)
}
if len(record.Fields) != 1 {
t.Errorf("record.Fields, got %v, want %v", len(record.Fields), 1)
}
if record.Fields[0].GetTag() != "001" {
t.Errorf("record.Fields.GetTag, got %v, want %v", record.Fields[0].GetTag(), "001")
}
if record.Identifier() != "with ws" {
t.Errorf("record.Fields.Identifier, got %v, want %v", record.Identifier(), "with ws")
}
if record.Leader.Length != 46 {
t.Errorf("record.Leader.Length, got %v, want %v", record.Leader.Length, 46)
}
}
// TestEmptyWrongLength tests an empty record with wrong length.
func TestEmptyWrongLength(t *testing.T) {
file, err := os.Open("fixtures/r2.mrc")
if err != nil {
t.Error(err)
}
record, err := ReadRecord(file)
if err != nil {
t.Error(err)
}
if len(record.Fields) != 0 {
t.Errorf("record.Fields, got %v, want %v", len(record.Fields), 0)
}
if record.Leader.Length != 21 {
t.Errorf("record.Leader.Length, got %v, want %v", record.Leader.Length, 0)
}
}
// TestNonNumericLength tests a record with a nonnumeric length. Note: This could
// be mitigated by ignoring the length field and just read up to the next record
// separator.
func TestNonNumericLength(t *testing.T) {
file, err := os.Open("fixtures/r3.mrc")
if err != nil {
t.Error(err)
}
_, err = ReadRecord(file)
if err == nil {
t.Errorf("ReadRecord, got %v, want %v", err, "some error")
}
}
func openTestMARC(t *testing.T) (data *os.File) {
data, err := os.Open("fixtures/test.mrc")
if err != nil {
t.Fatal(err)
}
return
}
func TestReader(t *testing.T) {
exp := 85
data := openTestMARC(t)
defer data.Close()
count := 0
for {
_, err := ReadRecord(data)
if err == io.EOF {
break
}
if err != nil {
t.Fatal(err)
}
count++
/*
r.XML(os.Stdout)
log.Print(record)
buf := &bytes.Buffer{}
err = record.XML(buf)
if err != nil {
log.Fatal(err)
}
log.Print(string(buf.Bytes()))
break
*/
}
if count != exp {
t.Errorf("Expected to read %d records, got %d", exp, count)
}
log.Printf("%d records", count)
}
func TestString(t *testing.T) {
const exp = `001 50001
005 20010903131819.0
008 701012s1970 moua b 001 0 eng
010 [ ] [(a) 73117956 ]
035 [ ] [(a) ocm00094426 ]
035 [ ] [(9) 7003024381]
040 [ ] [(a) DLC], [(c) DLC], [(d) OKO]
020 [ ] [(a) 0801657024]
050 [00] [(a) RC78.7.C9], [(b) Z83]
060 [ ] [(a) QS 504 Z94d 1970]
082 [00] [(a) 616.07/583]
049 [ ] [(a) CUDA]
100 [1 ] [(a) Zugibe, Frederick T.], [(q) (Frederick Thomas),], [(d) 1928-]
245 [10] [(a) Diagnostic histochemistry], [(c) [by] Frederick T. Zugibe.]
260 [ ] [(a) Saint Louis,], [(b) Mosby,], [(c) 1970.]
300 [ ] [(a) xiv, 366 p.], [(b) illus.], [(c) 25 cm.]
504 [ ] [(a) Bibliography: p. 332-349.]
650 [ 0] [(a) Cytodiagnosis.]
650 [ 0] [(a) Histochemistry], [(x) Technique.]
650 [ 2] [(a) Histocytochemistry.]
650 [ 2] [(a) Histological Techniques.]
994 [ ] [(a) 92], [(b) CUD]`
data := openTestMARC(t)
defer data.Close()
r, _ := ReadRecord(data)
out := r.String()
if out != exp {
t.Errorf("Output record string %s did not match expected string", out)
}
log.Printf("Record.String()")
}
func TestWriteTo(t *testing.T) {
const exp = `<record><leader>00819cam a2200289 4500</leader><controlfield tag="001">50001</controlfield><controlfield tag="005">20010903131819.0</controlfield><controlfield tag="008">701012s1970 moua b 001 0 eng </controlfield><datafield tag="010" ind1="32" ind2="32"><subfield code="97"> 73117956 </subfield></datafield><datafield tag="035" ind1="32" ind2="32"><subfield code="97">ocm00094426 </subfield></datafield><datafield tag="035" ind1="32" ind2="32"><subfield code="57">7003024381</subfield></datafield><datafield tag="040" ind1="32" ind2="32"><subfield code="97">DLC</subfield><subfield code="99">DLC</subfield><subfield code="100">OKO</subfield></datafield><datafield tag="020" ind1="32" ind2="32"><subfield code="97">0801657024</subfield></datafield><datafield tag="050" ind1="48" ind2="48"><subfield code="97">RC78.7.C9</subfield><subfield code="98">Z83</subfield></datafield><datafield tag="060" ind1="32" ind2="32"><subfield code="97">QS 504 Z94d 1970</subfield></datafield><datafield tag="082" ind1="48" ind2="48"><subfield code="97">616.07/583</subfield></datafield><datafield tag="049" ind1="32" ind2="32"><subfield code="97">CUDA</subfield></datafield><datafield tag="100" ind1="49" ind2="32"><subfield code="97">Zugibe, Frederick T.</subfield><subfield code="113">(Frederick Thomas),</subfield><subfield code="100">1928-</subfield></datafield><datafield tag="245" ind1="49" ind2="48"><subfield code="97">Diagnostic histochemistry</subfield><subfield code="99">[by] Frederick T. Zugibe.</subfield></datafield><datafield tag="260" ind1="32" ind2="32"><subfield code="97">Saint Louis,</subfield><subfield code="98">Mosby,</subfield><subfield code="99">1970.</subfield></datafield><datafield tag="300" ind1="32" ind2="32"><subfield code="97">xiv, 366 p.</subfield><subfield code="98">illus.</subfield><subfield code="99">25 cm.</subfield></datafield><datafield tag="504" ind1="32" ind2="32"><subfield code="97">Bibliography: p. 332-349.</subfield></datafield><datafield tag="650" ind1="32" ind2="48"><subfield code="97">Cytodiagnosis.</subfield></datafield><datafield tag="650" ind1="32" ind2="48"><subfield code="97">Histochemistry</subfield><subfield code="120">Technique.</subfield></datafield><datafield tag="650" ind1="32" ind2="50"><subfield code="97">Histocytochemistry.</subfield></datafield><datafield tag="650" ind1="32" ind2="50"><subfield code="97">Histological Techniques.</subfield></datafield><datafield tag="994" ind1="32" ind2="32"><subfield code="97">92</subfield><subfield code="98">CUD</subfield></datafield></record>`
data := openTestMARC(t)
defer data.Close()
r, err := ReadRecord(data)
buf := &bytes.Buffer{}
_, err = r.WriteTo(buf)
if err != nil {
t.Fatal(err)
}
if exp != string(buf.Bytes()) {
t.Errorf("Output XML did not match expected XML, got: %s", string(buf.Bytes()))
}
log.Printf("XML output")
}
func TestGetFields(t *testing.T) {
const exp = `Record: 1
650 [ 0] [(a) Cytodiagnosis.]
650 [ 0] [(a) Histochemistry], [(x) Technique.]
650 [ 2] [(a) Histocytochemistry.]
650 [ 2] [(a) Histological Techniques.]
Record: 2
650 [ 0] [(a) Logic, Symbolic and mathematical.]
Record: 4
650 [ 0] [(a) Landscape drawing.]
650 [ 0] [(a) Colors.]
Record: 5
650 [ 0] [(a) Musicals], [(z) United States], [(x) History and criticism.]
650 [ 0] [(a) Musicals], [(x) Discography.]
Record: 6
650 [ 0] [(a) Opioid abuse.]
Record: 7
650 [ 4] [(a) Taxation], [(z) England], [(y) 1991.]
650 [ 4] [(a) England], [(x) Taxation], [(y) 1991.]
650 [ 0] [(a) Taxation], [(z) Great Britain.]
Record: 8
650 [ 0] [(a) Dragons], [(z) China.]
650 [ 0] [(a) Dragons in art.]
650 [ 0] [(a) Art, Chinese.]
Record: 12
650 [ 0] [(a) Navies], [(x) Insignia.]
Record: 13
650 [ 0] [(a) Real property tax], [(z) England], [(x) History.]
Record: 14
650 [ 0] [(a) Nuclear reactors], [(x) Control.]
650 [ 0] [(a) Neutron flux.]
Record: 17
650 [ 0] [(a) Psychopharmacology.]
650 [ 0] [(a) Psychotropic drugs.]
Record: 18
650 [ 0] [(a) Advertising.]
Record: 19
650 [ 0] [(a) God], [(x) History of doctrines.]
650 [ 0] [(a) Secularization.]
Record: 20
650 [ 0] [(a) Germans], [(z) Czechoslovakia], [(x) History.]
650 [ 0] [(a) Minorities], [(z) Czechoslovakia], [(x) History.]
Record: 22
650 [ 0] [(a) Homeopathy], [(x) Materia medica and therapeutics.]
Record: 23
650 [ 0] [(a) Songs with piano.]
650 [ 0] [(a) Patriotic music.]
Record: 24
650 [ 0] [(a) Acoustical engineering.]
650 [ 0] [(a) Noise control.]
Record: 26
650 [ 0] [(a) Judaism], [(x) Liturgy.]
650 [ 0] [(a) Judaism], [(x) Customs and practices.]
650 [ 0] [(a) Fasts and feasts], [(x) Judaism.]
Record: 27
650 [ 0] [(a) Electronic monitoring of parolees and probationers.]
Record: 29
650 [ 0] [(a) Tourism.]
Record: 30
650 [ 0] [(a) Computers and civilization], [(v) Humor.]
Record: 31
650 [ 0] [(a) Authors, Slovak], [(v) Diaries.]
650 [ 0] [(a) World War, 1939-1945], [(x) Personal narratives, Slovak.]
Record: 32
650 [ 0] [(a) Latin language, Medieval and modern], [(x) Study and teaching], [(v) Congresses.]
Record: 33
650 [ 0] [(a) Missions], [(z) South Africa.]
650 [ 0] [(a) Zulu (African people)], [(x) Missions.]
Record: 35
650 [ 0] [(a) Novelists, English], [(y) 20th century], [(v) Biography.]
Record: 37
650 [ 0] [(a) Negotiation in business.]
Record: 38
650 [ 0] [(a) Land reform], [(z) Zimbabwe.]
650 [ 0] [(a) Land use], [(x) Government policy], [(z) Zimbabwe.]
650 [ 0] [(a) Democracy], [(z) Zimbabwe.]
Record: 39
650 [ 0] [(a) Prints], [(y) 19th century], [(z) England], [(v) Exhibitions.]
650 [ 0] [(a) Prints, English], [(v) Exhibitions.]
Record: 40
650 [ 0] [(a) Germans], [(z) Czechoslovakia], [(x) History.]
650 [ 0] [(a) Minorities], [(z) Czechoslovakia], [(x) History.]
Record: 42
650 [ 0] [(a) Upper class], [(z) England], [(v) Humor.]
650 [ 0] [(a) Etiquette], [(z) England], [(v) Humor.]
650 [ 0] [(a) Eccentrics and eccentricities], [(z) England], [(v) Humor.]
Record: 43
650 [ 0] [(a) Conduct of life.]
650 [ 0] [(a) Prostitution], [(z) Great Britain], [(x) History], [(y) 19th century], [(v) Sources.]
650 [ 0] [(a) Women], [(z) Great Britain], [(x) Social conditions.]
Record: 44
650 [ 0] [(a) Authors, English], [(y) 17th century], [(v) Biography.]
650 [ 0] [(a) Authors, English], [(y) 18th century], [(v) Biography.]
Record: 58
650 [ 0] [(a) Beauty operators], [(z) England], [(v) Biography.]
Record: 59
650 [ 0] [(a) Greek language, Modern.]
650 [ 0] [(a) Mythology, Greek.]
650 [ 0] [(a) Greek poetry, Modern], [(x) History and criticism.]
Record: 62
650 [ 0] [(a) Education], [(x) Philosophy.]
650 [ 0] [(a) Art], [(x) Philosophy.]
Record: 63
650 [ 0] [(a) Inland navigation], [(z) Balkan Peninsula.]
Record: 64
650 [ 0] [(a) Exhumation], [(z) Saint Helena.]
650 [ 0] [(a) Emperors], [(z) France], [(x) Death.]
Record: 65
650 [ 0] [(a) Catechisms, Greek.]
Record: 66
650 [ 0] [(a) History], [(x) Methodology.]
650 [ 0] [(a) Linguistics.]
Record: 68
650 [ 0] [(a) Clothing and dress], [(z) Japan], [(x) History.]
650 [ 0] [(a) Used clothing industry], [(z) Japan], [(x) History.]
Record: 70
650 [ 0] [(a) Painting, German.]
650 [ 0] [(a) Painting, Flemish.]
650 [ 0] [(a) Painting, Dutch.]
Record: 71
650 [ 0] [(a) Repudiation.]
650 [ 0] [(a) State bankruptcy.]
Record: 72
650 [ 0] [(a) Slavic philology.]
Record: 73
650 [ 0] [(a) Victims of state-sponsored terrorism], [(z) Northern Ireland.]
650 [ 0] [(a) Political violence], [(z) Northern Ireland.]
650 [ 0] [(a) Violent deaths], [(z) Northern Ireland.]
650 [ 0] [(a) Civil rights], [(z) Northern Ireland.]
Record: 74
650 [ 0] [(a) Slavery and the church], [(z) Southern States], [(x) History.]
650 [ 0] [(a) Slavery], [(x) Moral and ethical aspects], [(z) Southern States], [(x) History.]
650 [ 0] [(a) Slavery], [(z) Southern States], [(x) History.]
650 [ 0] [(a) Christianity and culture], [(z) Southern States], [(x) History.]
650 [ 0] [(a) Culture conflict], [(z) Southern States], [(x) History.]
Record: 75
650 [ 0] [(a) Songs with piano.]
Record: 78
650 [ 0] [(a) Symphonies], [(v) Excerpts], [(v) Scores.]
Record: 79
650 [ 0] [(a) Astronomy in literature.]
650 [ 0] [(a) Cosmology in literature.]
650 [ 0] [(a) Literature and science], [(x) History.]
Record: 80
650 [ 0] [(a) Sermons, Scottish], [(y) 19th century.]`
data := openTestMARC(t)
defer data.Close()
count := 0
subjects := []string{}
for {
r, err := ReadRecord(data)
if err == io.EOF {
break
}
if err != nil {
t.Fatal(err)
}
count++
t := r.GetFields("650")
if len(t) != 0 {
subjects = append(subjects, fmt.Sprintf("Record: %d", count))
for _, f := range t {
subjects = append(subjects, fmt.Sprintf("%s", f))
}
}
}
out := strings.Join(subjects, "\n")
if out != exp {
t.Error("Returned fields did not match expected fields")
}
log.Printf("GetFields()")
}
func TestGetSubFields(t *testing.T) {
const exp = `Record 1: (a) Diagnostic histochemistry
Record 2: (a) Elements of mathematical logic :
Record 3: (a) The Narren-motifs in the works of Georg Büchner.
Record 4: (a) The way to sketch,
Record 5: (a) The American musical theater;
Record 6: (a) Opioids :
Record 7: (a) Mayson on revenue law.
Record 8: (a) Céleste dragon :
Record 9: (a) The Geography of Lograire /
Record 10: (a) Forskarbiografin :
Record 11: (a) Swedish imprints 1731-1833 :
Record 12: (a) Naval and Marine badges and insignia of World War 2 /
Record 13: (a) Land tax assessments c.1690-c.1950 /
Record 14: (a) Upravlenie neĭtronnym polem i︠a︡dernogo reaktora /
Record 15: (a) The final analysis of Dr Stark /
Record 16: (a) Érintések /
Record 17: (a) Clinical pharmacology of psychotherapeutic drugs /
Record 18: (a) Behind the scenes in advertising /
Record 19: (a) The way of transcendence :
Record 20: (a) Integration oder Ausgrenzung :
Record 21: (a) Saunders Lewis /
Record 22: (a) A materia medica of homeopathic formulas.
Record 23: (a) Our monarch, the Prince and the nation :
Record 24: (a) Acoustics and noise control /
Record 25: (a) A letter to Dr. Bentley :
Record 26: (a) Sefer Moreh be-ʾeṣbaʻ /
Record 27: (a) Electronic tagging :
Record 28: (a) The ebbing of the kraft /
Record 29: (a) The business of tourism /
Record 30: (a) The devouring fungus :
Record 31: (a) Surová býva vše pravda života ...
Record 32: (a) Vocabulary of teaching and research between Middle Ages and Renaissance :
Record 33: (a) Umfundisi :
Record 34: (a) Country life, and Society and solitude :
Record 35: (a) My road :
Record 36: (a) Nienasycenie /
Record 37: (a) The outstanding negotiator :
Record 38: (a) Land and democracy in Zimbabwe /
Record 39: (a) Berufskünstler und Amateure, Whistler, Haden und die Blüte der Graphik in England :
Record 40: (a) Integration oder Ausgrenzung :
Record 41: (a) Saunders Lewis /
Record 42: (a) The English gentleman /
Record 43: (a) Social purity /
Record 44: (a) Lives of Dryden and Pope /
Record 45: (a) A system of medicine... Vol.5 /
Record 46: (a) Parley's present for all seasons /
Record 47: (a) An act for dividing and inclosing the open and common fields, meadows, and common fen within the parishes of Billingborough and Birthorpe, in the county of Lincoln, and for draining and improving the said fen.
Record 48: (a) [Versus Christianismus, edur Sannur Christen̄domur, i fiorum Bokum... Saman̄skrifadur af Johanne Arndt... En̄ nu...wtlagdur a Islensku af...Þorleife Arnaysyne.
Record 49: (a) Zhong hua da zang jing (Han wen bu fen).
Record 50: (a) Sôgyokushi :
Record 51: (a) Newsletter, An Foras Riarachain.
Record 52: (a) Coop Developer.
Record 53: (a) The Institute's professional qualifying examination and membership regulations /
Record 54: (a) [The New Testament].
Record 55: (a) In der Sprache der Sagas :
Record 56: (a) The book of Psalms :
Record 57: (a) Histoire sommaire de la civilisation depuis l'origine jusqu'à nos jours /
Record 58: (a) My life (as I remember it) /
Record 59: (a) Horae Hellenicæ :
Record 60: (a) The Dance of death /
Record 61: (a) Blaise Cendrars, une étude par Louis Parrot, un choix de poèmes et de textes, une bibliographie établie par J. H. Levesque, des inédits, des manuscrits, des dessins, des portraits.
Record 62: (a) Plato's ideas on art and education /
Record 63: (a) The Danube-Aegean waterway project :
Record 64: (a) Journal du retour des cendres, 1840 :
Record 65: (a) [Katēchēseis tēs Christianikēs pisteōs,] :
Record 66: (a) Histoire et linguistique.
Record 67: (a) The infallibility of the church. A course of lectures delivered in the Divinity School of the University of Dublin.
Record 68: (a) Furugi /
Record 69: (a) The Royal River: the Thames, from source to sea. Descriptive, historical, pictorial /
Record 70: (a) Handbook of painting :
Record 71: (a) The repudiation of state debts :
Record 72: (a) Slavi︠a︡nskai︠a︡ filologii︠a︡:
Record 73: (a) Unfinished business :
Record 74: (a) Black & tan :
Record 75: (a) Fem sang =
Record 76: (a) The Church of St. Edward, King and Martyr, Corfe Castle.
Record 77: (a) Four Thrilling Adventure Novels. Hearts of Three, by Jack London. The Crystal Skull, by Jack McLaren. The Master of Merripit, by Eden Phillpotts. Shadows by the Sea, by J. Jefferson Farjeon. [With illustrations.]
Record 78: (a) [Symphony] :
Record 79: (a) Thomas Hardy's novel universe :
Record 80: (a) Our present hope and our future home :
Record 81: (a) The paradox of prosperity :
Record 82: (a) The Lancashire local historian and his theme.
Record 83: (a) Business and government :
Record 84: (a) Gamma rays from isotopes produced by (n, gamma) - reactions /
Record 85: (a) Dante - the Divine comedy :`
data := openTestMARC(t)
defer data.Close()
count := 0
titles := []string{}
for {
r, err := ReadRecord(data)
if err == io.EOF {
break
}
if err != nil {
t.Fatal(err)
}
count++
t := r.GetSubFields("245", 'a')
if len(t) != 0 {
for _, f := range t {
titles = append(titles, fmt.Sprintf("Record %d: %s", count, f))
}
}
}
out := strings.Join(titles, "\n")
if out != exp {
t.Errorf("Returned subfields %s did not match expected subfields", out)
}
log.Printf("GetSubFields()")
}
// Basic example of how to modify a record
func TestAppendField(t *testing.T) {
const exp = `001 50001
005 20010903131819.0
008 701012s1970 moua b 001 0 eng
010 [ ] [(a) 73117956 ]
035 [ ] [(a) ocm00094426 ]
035 [ ] [(9) 7003024381]
040 [ ] [(a) DLC], [(c) DLC], [(d) OKO]
020 [ ] [(a) 0801657024]
050 [00] [(a) RC78.7.C9], [(b) Z83]
060 [ ] [(a) QS 504 Z94d 1970]
082 [00] [(a) 616.07/583]
049 [ ] [(a) CUDA]
100 [1 ] [(a) Zugibe, Frederick T.], [(q) (Frederick Thomas),], [(d) 1928-]
245 [10] [(a) Diagnostic histochemistry], [(c) [by] Frederick T. Zugibe.]
260 [ ] [(a) Saint Louis,], [(b) Mosby,], [(c) 1970.]
300 [ ] [(a) xiv, 366 p.], [(b) illus.], [(c) 25 cm.]
504 [ ] [(a) Bibliography: p. 332-349.]
650 [ 0] [(a) Cytodiagnosis.]
650 [ 0] [(a) Histochemistry], [(x) Technique.]
650 [ 2] [(a) Histocytochemistry.]
650 [ 2] [(a) Histological Techniques.]
994 [ ] [(a) 92], [(b) CUD]
650 [ 0] [(a) Unit testing.]`
data := openTestMARC(t)
defer data.Close()
r, _ := ReadRecord(data)
// Build a subfield first
s := &SubField{Code: 'a', Value: `Unit testing.`}
// Wrap the subfield in a slice
sf := make([]*SubField, 0)
sf = append(sf, s)
// Create a datafield containing the subfield slice
df := &DataField{Tag: `650`, Ind1: ' ', Ind2: '0', SubFields: sf}
// Append the datafield to the record
r.Fields = append(r.Fields, df)
out := r.String()
if out != exp {
t.Errorf("Output record string %s did not match expected string", out)
}
}