mrrc 0.7.6

A Rust library for reading, writing, and manipulating MARC bibliographic records in ISO 2709 binary format
Documentation
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
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
//! BIBFRAME integration tests.
//!
//! These tests verify conversion of complete bibliographic records with
//! multiple field types and format variations (books, serials, music, maps, etc.)

use mrrc::bibframe::{marc_to_bibframe, BibframeConfig, RdfFormat};
use mrrc::leader::Leader;
use mrrc::record::{Field, Record};

fn make_test_leader() -> Leader {
    Leader {
        record_length: 1000,
        record_status: 'n',
        record_type: 'a',
        bibliographic_level: 'm',
        control_record_type: ' ',
        character_coding: 'a',
        indicator_count: 2,
        subfield_code_count: 2,
        data_base_address: 100,
        encoding_level: ' ',
        cataloging_form: 'a',
        multipart_level: ' ',
        reserved: "4500".to_string(),
    }
}

fn make_config() -> BibframeConfig {
    BibframeConfig::new().with_base_uri("http://example.org/")
}

// ============================================================================
// Integration Tests: Book Records
// ============================================================================

#[test]
fn test_integration_simple_book() {
    let mut record = Record::new(make_test_leader());

    // Control fields
    record.add_control_field("001".to_string(), "book-001".to_string());
    record.add_control_field(
        "008".to_string(),
        "040520s2001    xxu           000 0 eng  ".to_string(),
    );

    // ISBN
    let mut f020 = Field::new("020".to_string(), ' ', ' ');
    f020.add_subfield('a', "0123456789".to_string());
    record.add_field(f020);

    // LCCN
    let mut f010 = Field::new("010".to_string(), ' ', ' ');
    f010.add_subfield('a', "2001234567".to_string());
    record.add_field(f010);

    // Title
    let mut f245 = Field::new("245".to_string(), '1', '0');
    f245.add_subfield('a', "Introduction to Computer Science /".to_string());
    f245.add_subfield('c', "by Jane Doe.".to_string());
    record.add_field(f245);

    // Creator
    let mut f100 = Field::new("100".to_string(), '1', ' ');
    f100.add_subfield('a', "Doe, Jane,".to_string());
    f100.add_subfield('d', "1960-".to_string());
    f100.add_subfield('4', "aut".to_string());
    record.add_field(f100);

    // Publication
    let mut f260 = Field::new("260".to_string(), ' ', ' ');
    f260.add_subfield('a', "New York :".to_string());
    f260.add_subfield('b', "Academic Press,".to_string());
    f260.add_subfield('c', "2001.".to_string());
    record.add_field(f260);

    // Physical description
    let mut f300 = Field::new("300".to_string(), ' ', ' ');
    f300.add_subfield('a', "500 pages :".to_string());
    f300.add_subfield('b', "illustrations ;".to_string());
    f300.add_subfield('c', "24 cm.".to_string());
    record.add_field(f300);

    // Subject
    let mut f650 = Field::new("650".to_string(), ' ', '0');
    f650.add_subfield('a', "Computer science".to_string());
    f650.add_subfield('x', "Textbooks.".to_string());
    record.add_field(f650);

    // Notes
    let mut f500 = Field::new("500".to_string(), ' ', ' ');
    f500.add_subfield('a', "Includes index.".to_string());
    record.add_field(f500);

    let graph = marc_to_bibframe(&record, &make_config());
    let rdf = graph.serialize(RdfFormat::RdfXml).unwrap();

    // Verify all major elements are present
    assert!(
        rdf.contains("0123456789") || rdf.contains("Isbn"),
        "ISBN should be present"
    );
    assert!(
        rdf.contains("Introduction to Computer Science") || rdf.contains("mainTitle"),
        "Title should be present"
    );
    assert!(
        rdf.contains("Doe, Jane") || rdf.contains("Person"),
        "Creator should be present"
    );
    assert!(
        rdf.contains("New York") || rdf.contains("Academic Press"),
        "Publication info should be present"
    );
    assert!(
        rdf.contains("Computer science") || rdf.contains("Topic"),
        "Subject should be present"
    );
    assert!(
        rdf.contains("Text") || rdf.contains("bf:Text"),
        "Book should be typed as Text"
    );
}

#[test]
fn test_integration_book_with_translator() {
    let mut record = Record::new(make_test_leader());

    record.add_control_field("001".to_string(), "trans-001".to_string());
    record.add_control_field(
        "008".to_string(),
        "040520s2001    xxu           000 0 eng  ".to_string(),
    );

    // Title
    let mut f245 = Field::new("245".to_string(), '1', '0');
    f245.add_subfield('a', "The Book /".to_string());
    f245.add_subfield(
        'c',
        "by Original Author ; translated by Jane Translator.".to_string(),
    );
    record.add_field(f245);

    // Original author
    let mut f100 = Field::new("100".to_string(), '1', ' ');
    f100.add_subfield('a', "Author, Original,".to_string());
    f100.add_subfield('4', "aut".to_string());
    record.add_field(f100);

    // Translator as contributor
    let mut f700 = Field::new("700".to_string(), '1', ' ');
    f700.add_subfield('a', "Translator, Jane,".to_string());
    f700.add_subfield('e', "translator.".to_string());
    f700.add_subfield('4', "trl".to_string());
    record.add_field(f700);

    let graph = marc_to_bibframe(&record, &make_config());
    let rdf = graph.serialize(RdfFormat::RdfXml).unwrap();

    assert!(
        rdf.contains("Author, Original") || rdf.contains("Translator, Jane"),
        "Should contain both author and translator"
    );
}

// ============================================================================
// Integration Tests: Serial Records
// ============================================================================

#[test]
fn test_integration_serial_record() {
    let mut leader = make_test_leader();
    leader.record_type = 'a';
    leader.bibliographic_level = 's'; // serial
    let mut record = Record::new(leader);

    record.add_control_field("001".to_string(), "serial-001".to_string());
    record.add_control_field(
        "008".to_string(),
        "040520c2001    xxu          0eng  ".to_string(),
    );

    // ISSN
    let mut f022 = Field::new("022".to_string(), ' ', ' ');
    f022.add_subfield('a', "1234-5678".to_string());
    record.add_field(f022);

    // Title
    let mut f245 = Field::new("245".to_string(), '1', '0');
    f245.add_subfield('a', "Journal of Computer Science.".to_string());
    record.add_field(f245);

    // Publication
    let mut f260 = Field::new("260".to_string(), ' ', ' ');
    f260.add_subfield('a', "New York :".to_string());
    f260.add_subfield('b', "Scientific Press,".to_string());
    f260.add_subfield('c', "2001-".to_string());
    record.add_field(f260);

    // Frequency
    let mut f310 = Field::new("310".to_string(), ' ', ' ');
    f310.add_subfield('a', "Monthly".to_string());
    record.add_field(f310);

    let graph = marc_to_bibframe(&record, &make_config());
    let rdf = graph.serialize(RdfFormat::RdfXml).unwrap();

    assert!(
        rdf.contains("Serial") || rdf.contains("bf:Serial"),
        "Serial record should be typed as Serial"
    );
    assert!(
        rdf.contains("1234-5678") || rdf.contains("Issn"),
        "Should contain ISSN"
    );
}

#[test]
fn test_integration_serial_with_linking_entries() {
    let mut leader = make_test_leader();
    leader.record_type = 'a';
    leader.bibliographic_level = 's';
    let mut record = Record::new(leader);

    record.add_control_field("001".to_string(), "link-serial".to_string());
    record.add_control_field(
        "008".to_string(),
        "040520c2001    xxu          0eng  ".to_string(),
    );

    // Title
    let mut f245 = Field::new("245".to_string(), '1', '0');
    f245.add_subfield('a', "Current Journal.".to_string());
    record.add_field(f245);

    // Earlier title (780 with $t and $x)
    let mut f780 = Field::new("780".to_string(), '0', '0');
    f780.add_subfield('t', "Previous Title".to_string());
    f780.add_subfield('x', "0000-0000".to_string());
    record.add_field(f780);

    // Later title (785)
    let mut f785 = Field::new("785".to_string(), '0', '0');
    f785.add_subfield('t', "Future Title".to_string());
    f785.add_subfield('x', "9999-9999".to_string());
    record.add_field(f785);

    let graph = marc_to_bibframe(&record, &make_config());
    let rdf = graph.serialize(RdfFormat::RdfXml).unwrap();

    // Should reference linking entries
    assert!(
        rdf.contains("Previous")
            || rdf.contains("Future")
            || rdf.contains("precededBy")
            || rdf.contains("succeededBy"),
        "Should contain linking entry information"
    );
}

// ============================================================================
// Integration Tests: Music Records
// ============================================================================

#[test]
fn test_integration_music_score() {
    let mut leader = make_test_leader();
    leader.record_type = 'c'; // notated music
    let mut record = Record::new(leader);

    record.add_control_field("001".to_string(), "music-001".to_string());
    record.add_control_field(
        "008".to_string(),
        "040520s2001    xxu  n       000 0 eng  ".to_string(),
    );

    // Title
    let mut f245 = Field::new("245".to_string(), '1', '0');
    f245.add_subfield('a', "Symphony No. 5 /".to_string());
    f245.add_subfield('c', "Beethoven.".to_string());
    record.add_field(f245);

    // Creator
    let mut f100 = Field::new("100".to_string(), '1', ' ');
    f100.add_subfield('a', "Beethoven, Ludwig van,".to_string());
    f100.add_subfield('d', "1770-1827.".to_string());
    f100.add_subfield('4', "cmp".to_string());
    record.add_field(f100);

    // Publication
    let mut f260 = Field::new("260".to_string(), ' ', ' ');
    f260.add_subfield('a', "Vienna :".to_string());
    f260.add_subfield('b', "Music Publisher,".to_string());
    f260.add_subfield('c', "1808.".to_string());
    record.add_field(f260);

    // Physical description (music-specific)
    let mut f300 = Field::new("300".to_string(), ' ', ' ');
    f300.add_subfield('a', "1 score (150 pages) :".to_string());
    f300.add_subfield('b', "choral.".to_string());
    record.add_field(f300);

    let graph = marc_to_bibframe(&record, &make_config());
    let rdf = graph.serialize(RdfFormat::RdfXml).unwrap();

    assert!(
        rdf.contains("NotatedMusic") || rdf.contains("bf:NotatedMusic"),
        "Music score should be typed as NotatedMusic"
    );
    assert!(
        rdf.contains("Beethoven") || rdf.contains("Person"),
        "Should contain composer"
    );
}

#[test]
fn test_integration_music_recording() {
    let mut leader = make_test_leader();
    leader.record_type = 'i'; // nonmusical sound recording
    let mut record = Record::new(leader);

    record.add_control_field("001".to_string(), "audio-001".to_string());
    record.add_control_field(
        "008".to_string(),
        "040520s2001    xxu           000 0 eng  ".to_string(),
    );

    // Title
    let mut f245 = Field::new("245".to_string(), '1', '0');
    f245.add_subfield('a', "Symphony No. 5 /".to_string());
    f245.add_subfield(
        'c',
        "[London Symphony Orchestra, conductor: Simon Rattle].".to_string(),
    );
    record.add_field(f245);

    // Performer
    let mut f700 = Field::new("700".to_string(), '1', ' ');
    f700.add_subfield('a', "Rattle, Simon,".to_string());
    f700.add_subfield('d', "1955-".to_string());
    f700.add_subfield('e', "conductor.".to_string());
    record.add_field(f700);

    let graph = marc_to_bibframe(&record, &make_config());
    let rdf = graph.serialize(RdfFormat::RdfXml).unwrap();

    assert!(
        rdf.contains("Audio") || rdf.contains("MusicAudio") || rdf.contains("bf:Audio"),
        "Audio recording should be typed as Audio or MusicAudio"
    );
}

// ============================================================================
// Integration Tests: Map Records
// ============================================================================

#[test]
fn test_integration_map_record() {
    let mut leader = make_test_leader();
    leader.record_type = 'e'; // cartographic
    let mut record = Record::new(leader);

    record.add_control_field("001".to_string(), "map-001".to_string());
    record.add_control_field(
        "008".to_string(),
        "040520s2001    xxu           000 0 eng  ".to_string(),
    );

    // Title
    let mut f245 = Field::new("245".to_string(), '1', '0');
    f245.add_subfield('a', "Map of North America.".to_string());
    record.add_field(f245);

    // Scale and coordinates
    let mut f034 = Field::new("034".to_string(), '1', ' ');
    f034.add_subfield('b', "2000000".to_string());
    record.add_field(f034);

    // Geographic area (651)
    let mut f651 = Field::new("651".to_string(), ' ', '0');
    f651.add_subfield('a', "North America".to_string());
    f651.add_subfield('x', "Maps.".to_string());
    record.add_field(f651);

    // Physical description
    let mut f300 = Field::new("300".to_string(), ' ', ' ');
    f300.add_subfield('a', "1 map :".to_string());
    f300.add_subfield('b', "color ;".to_string());
    f300.add_subfield('c', "50 x 40 cm.".to_string());
    record.add_field(f300);

    let graph = marc_to_bibframe(&record, &make_config());
    let rdf = graph.serialize(RdfFormat::RdfXml).unwrap();

    assert!(
        rdf.contains("Cartography") || rdf.contains("bf:Cartography"),
        "Map should be typed as Cartography"
    );
    assert!(
        rdf.contains("North America") || rdf.contains("Place"),
        "Should contain geographic subject"
    );
}

// ============================================================================
// Integration Tests: Visual Materials
// ============================================================================

#[test]
fn test_integration_video_record() {
    let mut leader = make_test_leader();
    leader.record_type = 'g'; // projected medium
    let mut record = Record::new(leader);

    record.add_control_field("001".to_string(), "video-001".to_string());
    record.add_control_field(
        "008".to_string(),
        "040520s2001    xxu           000 0 eng  ".to_string(),
    );

    // Title
    let mut f245 = Field::new("245".to_string(), '1', '0');
    f245.add_subfield('a', "Great Documentary Film /".to_string());
    f245.add_subfield('c', "directed by Someone.".to_string());
    record.add_field(f245);

    // Director as creator
    let mut f100 = Field::new("100".to_string(), '1', ' ');
    f100.add_subfield('a', "Someone, Director,".to_string());
    f100.add_subfield('4', "drt".to_string());
    record.add_field(f100);

    // Physical description
    let mut f300 = Field::new("300".to_string(), ' ', ' ');
    f300.add_subfield('a', "1 videodisc (95 min.) :".to_string());
    f300.add_subfield('b', "sound, color ;".to_string());
    f300.add_subfield('c', "4 3/4 in.".to_string());
    record.add_field(f300);

    let graph = marc_to_bibframe(&record, &make_config());
    let rdf = graph.serialize(RdfFormat::RdfXml).unwrap();

    assert!(
        rdf.contains("MovingImage") || rdf.contains("bf:MovingImage"),
        "Video should be typed as MovingImage"
    );
    assert!(
        rdf.contains("videodisc"),
        "Should contain video format information"
    );
}

#[test]
fn test_integration_photograph_record() {
    let mut leader = make_test_leader();
    leader.record_type = 'k'; // two-dimensional nonprojectable graphic
    let mut record = Record::new(leader);

    record.add_control_field("001".to_string(), "photo-001".to_string());
    record.add_control_field(
        "008".to_string(),
        "040520s2001    xxu           000 0 eng  ".to_string(),
    );

    // Title
    let mut f245 = Field::new("245".to_string(), '0', '0');
    f245.add_subfield('a', "Portrait of the artist as a young person.".to_string());
    record.add_field(f245);

    // Subject
    let mut f650 = Field::new("650".to_string(), ' ', '0');
    f650.add_subfield('a', "Photographs".to_string());
    record.add_field(f650);

    let graph = marc_to_bibframe(&record, &make_config());
    let rdf = graph.serialize(RdfFormat::RdfXml).unwrap();

    assert!(
        rdf.contains("StillImage") || rdf.contains("bf:StillImage"),
        "Photograph should be typed as StillImage"
    );
}

// ============================================================================
// Integration Tests: Multi-Script Records (880 Linked Fields)
// ============================================================================

#[test]
fn test_integration_alternate_script_record() {
    let mut record = Record::new(make_test_leader());

    record.add_control_field("001".to_string(), "script-001".to_string());
    record.add_control_field(
        "008".to_string(),
        "040520s2001    xxu           000 0 eng  ".to_string(),
    );

    // Latin script title
    let mut f245 = Field::new("245".to_string(), '1', '0');
    f245.add_subfield('a', "Test Title.".to_string());
    record.add_field(f245);

    // Alternate script (880 field with $6 linkage)
    let mut f880 = Field::new("880".to_string(), '1', '0');
    f880.add_subfield('6', "245-01".to_string()); // Links to field 245
    f880.add_subfield('a', "テストタイトル。".to_string()); // Japanese
    record.add_field(f880);

    let graph = marc_to_bibframe(&record, &make_config());
    let rdf = graph.serialize(RdfFormat::RdfXml).unwrap();

    // Should handle both scripts
    assert!(
        rdf.contains("Test Title") || rdf.contains("title"),
        "Should contain Latin script title"
    );
    // Alternate script handling is implementation-dependent
}

// ============================================================================
// Integration Tests: Authority-Controlled Records
// ============================================================================

#[test]
fn test_integration_lcsh_headings() {
    let mut record = Record::new(make_test_leader());

    record.add_control_field("001".to_string(), "lcsh-001".to_string());
    record.add_control_field(
        "008".to_string(),
        "040520s2001    xxu           000 0 eng  ".to_string(),
    );

    // Title
    let mut f245 = Field::new("245".to_string(), '1', '0');
    f245.add_subfield('a', "Book about History.".to_string());
    record.add_field(f245);

    // LCSH topical heading with subdivisions
    let mut f650 = Field::new("650".to_string(), ' ', '0');
    f650.add_subfield('a', "United States".to_string());
    f650.add_subfield('x', "History".to_string());
    f650.add_subfield('y', "19th century.".to_string());
    record.add_field(f650);

    // LCSH name heading with relationship
    let mut f700 = Field::new("700".to_string(), '1', ' ');
    f700.add_subfield('a', "Lincoln, Abraham,".to_string());
    f700.add_subfield('d', "1809-1865.".to_string());
    f700.add_subfield('e', "subject.".to_string());
    f700.add_subfield('0', "(OCoLC)12345678".to_string());
    record.add_field(f700);

    let graph = marc_to_bibframe(&record, &make_config());
    let rdf = graph.serialize(RdfFormat::RdfXml).unwrap();

    assert!(
        rdf.contains("United States") || rdf.contains("History"),
        "Should contain subject headings with subdivisions"
    );
    assert!(
        rdf.contains("Lincoln") || rdf.contains("Person"),
        "Should contain name subject"
    );
}

// ============================================================================
// Integration Tests: Complex Records with Multiple Identifiers
// ============================================================================

#[test]
fn test_integration_record_with_multiple_identifiers() {
    let mut record = Record::new(make_test_leader());

    record.add_control_field("001".to_string(), "ids-001".to_string());
    record.add_control_field(
        "008".to_string(),
        "040520s2001    xxu           000 0 eng  ".to_string(),
    );

    // LCCN
    let mut f010 = Field::new("010".to_string(), ' ', ' ');
    f010.add_subfield('a', "2001234567".to_string());
    record.add_field(f010);

    // ISBN
    let mut f020 = Field::new("020".to_string(), ' ', ' ');
    f020.add_subfield('a', "0123456789".to_string());
    f020.add_subfield('q', "(hardcover)".to_string());
    record.add_field(f020);

    // System number
    let mut f035 = Field::new("035".to_string(), ' ', ' ');
    f035.add_subfield('a', "(OCoLC)12345678".to_string());
    record.add_field(f035);

    // Title
    let mut f245 = Field::new("245".to_string(), '1', '0');
    f245.add_subfield('a', "Highly Identifiable Book.".to_string());
    record.add_field(f245);

    let graph = marc_to_bibframe(&record, &make_config());
    let rdf = graph.serialize(RdfFormat::RdfXml).unwrap();

    // All identifiers should be present
    assert!(
        rdf.contains("2001234567") || rdf.contains("Lccn") || rdf.contains("bf:Lccn"),
        "Should contain LCCN"
    );
    assert!(
        rdf.contains("0123456789") || rdf.contains("Isbn") || rdf.contains("bf:Isbn"),
        "Should contain ISBN"
    );
    assert!(
        rdf.contains("12345678") || rdf.contains("OCoLC"),
        "Should contain system number"
    );
}

// ============================================================================
// Integration Tests: Record Types Completeness
// ============================================================================

#[test]
fn test_integration_all_format_types() {
    let test_cases = vec![
        ('a', 'm', "Text"),         // language material, monograph
        ('a', 's', "Serial"),       // language material, serial
        ('c', ' ', "NotatedMusic"), // notated music
        ('d', ' ', "NotatedMusic"), // manuscript music
        ('e', ' ', "Cartography"),  // cartographic material
        ('f', ' ', "Cartography"),  // manuscript cartography
        ('g', ' ', "MovingImage"),  // projected medium
        ('i', ' ', "Audio"),        // nonmusical sound recording
        ('j', ' ', "MusicAudio"),   // musical sound recording
        ('k', ' ', "StillImage"),   // two-dimensional nonprojectable graphic
        ('o', ' ', "Electronic"),   // kit
        ('p', ' ', "Text"),         // mixed materials
        ('r', ' ', "Text"),         // three-dimensional object/artifact
        ('t', ' ', "Text"),         // manuscript language material
    ];

    for (record_type, bib_level, _expected_bf_type) in test_cases {
        let mut leader = make_test_leader();
        leader.record_type = record_type;
        if bib_level != ' ' {
            leader.bibliographic_level = bib_level;
        }
        let mut record = Record::new(leader);
        record.add_control_field(
            "001".to_string(),
            format!("test-{record_type}-{}", bib_level as u32),
        );
        record.add_control_field(
            "008".to_string(),
            "040520s2001    xxu           000 0 eng  ".to_string(),
        );

        let graph = marc_to_bibframe(&record, &make_config());
        let rdf = graph
            .serialize(RdfFormat::RdfXml)
            .unwrap_or_else(|_| String::new());

        assert!(
            !rdf.is_empty(),
            "Record type {record_type} should produce RDF output"
        );
        // Type assertions are lenient - implementation may vary
    }
}

// ============================================================================
// Integration Tests: Edge Cases in Complete Records
// ============================================================================

#[test]
fn test_integration_record_with_missing_245() {
    // Some records may be missing main title (rare but possible)
    let mut record = Record::new(make_test_leader());

    record.add_control_field("001".to_string(), "no-245".to_string());
    record.add_control_field(
        "008".to_string(),
        "040520s2001    xxu           000 0 eng  ".to_string(),
    );

    // Only ISBN and publication info, no title
    let mut f020 = Field::new("020".to_string(), ' ', ' ');
    f020.add_subfield('a', "0123456789".to_string());
    record.add_field(f020);

    let graph = marc_to_bibframe(&record, &make_config());
    // Should not crash and should produce some output
    assert!(!graph.is_empty(), "Should produce RDF even without 245");
}

#[test]
fn test_integration_record_with_only_control_fields() {
    let mut record = Record::new(make_test_leader());

    record.add_control_field("001".to_string(), "minimal".to_string());
    record.add_control_field(
        "008".to_string(),
        "040520s2001    xxu           000 0 eng  ".to_string(),
    );

    let graph = marc_to_bibframe(&record, &make_config());
    let rdf = graph.serialize(RdfFormat::RdfXml).unwrap();

    // Even minimal record should produce Work and Instance
    assert!(
        rdf.contains("Work") || rdf.contains("Instance"),
        "Minimal record should produce Work/Instance"
    );
}

#[test]
fn test_integration_record_with_many_fields() {
    let mut record = Record::new(make_test_leader());

    record.add_control_field("001".to_string(), "many-fields".to_string());
    record.add_control_field(
        "008".to_string(),
        "040520s2001    xxu           000 0 eng  ".to_string(),
    );

    // Title
    let mut f245 = Field::new("245".to_string(), '1', '0');
    f245.add_subfield('a', "Complex Record.".to_string());
    record.add_field(f245);

    // Add multiple subjects
    for i in 0..5 {
        let mut f650 = Field::new("650".to_string(), ' ', '0');
        f650.add_subfield('a', format!("Subject {i}"));
        record.add_field(f650);
    }

    // Add multiple contributors
    for i in 0..3 {
        let mut f700 = Field::new("700".to_string(), '1', ' ');
        f700.add_subfield('a', format!("Contributor {i}, Person {i}"));
        record.add_field(f700);
    }

    // Add multiple notes
    for i in 0..4 {
        let mut f500 = Field::new("500".to_string(), ' ', ' ');
        f500.add_subfield('a', format!("Note {i}"));
        record.add_field(f500);
    }

    let graph = marc_to_bibframe(&record, &make_config());
    let rdf = graph.serialize(RdfFormat::RdfXml).unwrap();

    // Should handle all fields without crashing
    assert!(
        rdf.contains("Complex Record") || rdf.contains("Subject"),
        "Should contain record data"
    );
    assert!(
        graph.len() > 10,
        "Complex record should produce many triples"
    );
}