-
Notifications
You must be signed in to change notification settings - Fork 9
/
decoder_test.go
1592 lines (1469 loc) · 37.4 KB
/
decoder_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
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
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
This is free and unencumbered software released into the public domain. For more
information, see <http://unlicense.org/> or the accompanying UNLICENSE file.
*/
package gedcom
import (
"bytes"
"os"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
)
var data []byte
func init() {
var err error
data, err = os.ReadFile("testdata/allged.ged")
if err != nil {
panic(err)
}
}
func TestStructuresAreInitialized(t *testing.T) {
d := NewDecoder(bytes.NewReader(data))
g, err := d.Decode()
if err != nil {
t.Fatalf("Result of decoding gedcom gave error %v, expected no error", err)
}
if g == nil {
t.Fatalf("Result of decoding gedcom was nil, expected valid object")
}
if g.Individual == nil {
t.Fatalf("Individual list was nil, expected valid slice")
}
if g.Family == nil {
t.Fatalf("Family list was nil, expected valid slice")
}
if g.Media == nil {
t.Fatalf("Media list was nil, expected valid slice")
}
if g.Repository == nil {
t.Fatalf("Repository list was nil, expected valid slice")
}
if g.Source == nil {
t.Fatalf("Source list was nil, expected valid slice")
}
if g.Submitter == nil {
t.Fatalf("Submitter list was nil, expected valid slice")
}
}
func TestIndividual(t *testing.T) {
d := NewDecoder(bytes.NewReader(data))
g, err := d.Decode()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
// Create a comparison option that compares just names
nameOpt := cmp.Comparer(func(a, b *NameRecord) bool {
if a == nil {
return b == nil
}
if b == nil {
return a == nil
}
return a.Name == b.Name
})
individuals := []*IndividualRecord{
{
Xref: "PERSON1",
Sex: "M",
Name: []*NameRecord{
{
Name: "given name /surname/jr.",
},
{
Name: "another name /surname/",
},
},
Family: []*FamilyLinkRecord{
{
Family: &FamilyRecord{Xref: "FAMILY1"},
},
{
Family: &FamilyRecord{Xref: "FAMILY2"},
},
},
Parents: []*FamilyLinkRecord{
{
Family: &FamilyRecord{Xref: "PARENTS"},
},
{
Family: &FamilyRecord{Xref: "ADOPTIVE_PARENTS"},
},
},
Citation: []*CitationRecord{
{
Source: &SourceRecord{
Xref: "SOURCE1",
},
},
},
Change: ChangeRecord{
Date: "1 APR 1998",
Time: "12:34:56.789",
Note: []*NoteRecord{
{
Note: "A note\nNote continued here. The word TEST should not be broken!",
},
},
},
Note: []*NoteRecord{
{
Note: "A note about the inidvidual\nNote continued here. The word TEST should not be broken!",
},
},
Media: []*MediaRecord{
{
File: []*FileRecord{
{
Name: `\\network\drive\path\file name.gif`,
},
},
},
}, UserDefined: []UserDefinedTag{
{Tag: "_MYOWNTAG", Value: "This is a non-standard tag. Not recommended but allowed", Level: 1},
},
},
{
Xref: "PERSON2",
Name: []*NameRecord{
{
Name: "/Wife/",
},
},
Sex: "F",
Family: []*FamilyLinkRecord{
{
Family: &FamilyRecord{Xref: "FAMILY1"},
},
},
},
{
Xref: "PERSON3",
Name: []*NameRecord{
{
Name: "/Child 1/",
},
},
Parents: []*FamilyLinkRecord{
{
Family: &FamilyRecord{Xref: "FAMILY1"},
},
},
},
{
Xref: "PERSON4",
Name: []*NameRecord{
{
Name: "/Child 2/",
},
},
Parents: []*FamilyLinkRecord{
{
Family: &FamilyRecord{Xref: "FAMILY1"},
},
},
},
{
Xref: "PERSON5",
Sex: "M",
Name: []*NameRecord{
{
Name: "/Father/",
},
},
Family: []*FamilyLinkRecord{
{
Family: &FamilyRecord{Xref: "PARENTS"},
},
},
},
{
Xref: "PERSON6",
Name: []*NameRecord{
{
Name: "/Adoptive mother/",
},
},
Sex: "F",
Family: []*FamilyLinkRecord{
{
Family: &FamilyRecord{Xref: "ADOPTIVE_PARENTS"},
},
},
},
{
Xref: "PERSON7",
Name: []*NameRecord{
{
Name: "/Child 3/",
},
},
Parents: []*FamilyLinkRecord{
{
Family: &FamilyRecord{Xref: "FAMILY2"},
},
},
},
{
Xref: "PERSON8",
Name: []*NameRecord{
{
Name: "/2nd Wife/",
},
},
Sex: "F",
Family: []*FamilyLinkRecord{
{
Family: &FamilyRecord{Xref: "FAMILY2"},
},
},
},
}
if diff := cmp.Diff(individuals, g.Individual, nameOpt, eventIgnoreComparer, familyXrefComparer, sourceXrefComparer, mediaFileNameCompare); diff != "" {
t.Errorf("submitter mismatch (-want +got):\n%s", diff)
}
}
func TestIndividualDetail(t *testing.T) {
d := NewDecoder(bytes.NewReader(data))
g, err := d.Decode()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(g.Individual) != 8 {
t.Fatalf("Individual list length was %d, expected 8", len(g.Individual))
}
i1 := g.Individual[0]
if i1.Xref != "PERSON1" {
t.Errorf(`Individual 0 xref was "%s", expected @PERSON1@`, i1.Xref)
}
if i1.Sex != "M" {
t.Errorf(`Individual 0 sex "%s" names, expected "M"`, i1.Sex)
}
if len(i1.Name) != 2 {
t.Fatalf(`Individual 0 had %d names, expected 2`, len(i1.Name))
}
// Create a comparison option that compares sources by xref only
sourceOpt := cmp.Comparer(func(a, b *SourceRecord) bool {
if a == nil {
return b == nil
}
if b == nil {
return a == nil
}
return a.Xref == b.Xref
})
name1 := &NameRecord{
Name: "given name /surname/jr.",
Citation: []*CitationRecord{
{
Source: &SourceRecord{
Xref: "SOURCE1",
},
Page: "42",
Quay: "0",
Data: DataRecord{
Date: "BEF 1 JAN 1900",
Text: []string{
"a sample text\nSample text continued here. The word TEST should not be broken!",
},
},
Note: []*NoteRecord{
{
Note: "A note\nNote continued here. The word TEST should not be broken!",
},
},
},
},
Note: []*NoteRecord{
{
Note: "Personal Name note\nNote continued here. The word TEST should not be broken!",
},
},
}
if diff := cmp.Diff(i1.Name[0], name1, sourceOpt); diff != "" {
t.Errorf("Individual 0, name 0 mismatch (-want +got):\n%s", diff)
}
if len(i1.Event) != 24 {
t.Fatalf(`Individual 0 had %d events, expected 24`, len(i1.Event))
}
// Create a comparison option that compares families by xref
familyOpt := cmp.Comparer(func(a, b *FamilyRecord) bool {
if a == nil {
return b == nil
}
if b == nil {
return a == nil
}
return a.Xref == b.Xref
})
event1 := &EventRecord{
Tag: "BIRT",
Date: "31 DEC 1997",
Place: PlaceRecord{
Name: "The place",
},
ChildInFamily: &FamilyRecord{
Xref: "PARENTS",
},
Citation: []*CitationRecord{
{
Source: &SourceRecord{
Xref: "SOURCE1",
},
Page: "42",
Quay: "2",
Data: DataRecord{
Date: "31 DEC 1900",
Text: []string{
"a sample text\nSample text continued here. The word TEST should not be broken!",
},
},
Note: []*NoteRecord{
{
Note: "A note\nNote continued here. The word TEST should not be broken!",
},
},
},
},
Note: []*NoteRecord{
{
Note: "BIRTH event note (the event of entering into life)\nNote continued here. The word TEST should not be broken!",
},
},
}
if diff := cmp.Diff(i1.Event[0], event1, sourceOpt, familyOpt); diff != "" {
t.Errorf("Individual 0, event 0 mismatch (-want +got):\n%s", diff)
}
if len(i1.Attribute) != 14 {
t.Fatalf(`Individual 0 had %d attributes, expected 14`, len(i1.Attribute))
}
att1 := &EventRecord{
Tag: "CAST",
Value: "Cast name",
Date: "31 DEC 1997",
Place: PlaceRecord{
Name: "The place",
},
Citation: []*CitationRecord{
{
Source: &SourceRecord{
Xref: "SOURCE1",
},
Page: "42",
Quay: "3",
Data: DataRecord{
Date: "31 DEC 1900",
Text: []string{
"a sample text\nSample text continued here. The word TEST should not be broken!",
},
},
Note: []*NoteRecord{
{
Note: "A note\nNote continued here. The word TEST should not be broken!",
},
},
},
},
Note: []*NoteRecord{
{
Note: "CASTE event note (the name of an individual's rank or status in society, based on racial or religious differences, or differences in wealth, inherited rank, profession, occupation, etc)\nNote continued here. The word TEST should not be broken!",
},
},
}
if diff := cmp.Diff(att1, i1.Attribute[0], sourceOpt); diff != "" {
t.Errorf("Individual 0, attribute 0 mismatch (-want +got):\n%s", diff)
}
if len(i1.Parents) != 2 {
t.Fatalf(`Individual 0 had %d parent families, expected 2`, len(i1.Parents))
}
}
func TestSubmitter(t *testing.T) {
d := NewDecoder(bytes.NewReader(data))
g, err := d.Decode()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
submitters := []*SubmitterRecord{{Xref: "SUBMITTER"}}
if diff := cmp.Diff(submitters, g.Submitter); diff != "" {
t.Errorf("submitter mismatch (-want +got):\n%s", diff)
}
}
func TestFamily(t *testing.T) {
d := NewDecoder(bytes.NewReader(data))
g, err := d.Decode()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
// Create a comparison option that compares individuals by xref only
indOpt := cmp.Comparer(func(a, b *IndividualRecord) bool {
if a == nil {
return b == nil
}
if b == nil {
return a == nil
}
return a.Xref == b.Xref
})
// Create a comparison option that compares events by tag and date
eventOpt := cmp.Comparer(func(a, b *EventRecord) bool {
if a == nil {
return b == nil
}
if b == nil {
return a == nil
}
return a.Tag == b.Tag && a.Date == b.Date
})
// Create a comparison option that compares citations by source xref
citeOpt := cmp.Comparer(func(a, b *CitationRecord) bool {
if a == nil {
return b == nil
}
if b == nil {
return a == nil
}
if a.Source == nil {
return b.Source == nil
}
if b.Source == nil {
return a.Source == nil
}
return a.Source.Xref == b.Source.Xref
})
families := []*FamilyRecord{
{
Xref: "FAMILY1",
Husband: &IndividualRecord{Xref: "PERSON1"},
Wife: &IndividualRecord{Xref: "PERSON2"},
Child: []*IndividualRecord{
{Xref: "PERSON3"},
{Xref: "PERSON4"},
},
NumberOfChildren: "42",
Event: []*EventRecord{
{Tag: "ANUL", Date: "31 DEC 1997"},
{Tag: "CENS", Date: "31 DEC 1997"},
{Tag: "DIV", Date: "31 DEC 1997"},
{Tag: "DIVF", Date: "31 DEC 1997"},
{Tag: "ENGA", Date: "31 DEC 1997"},
{Tag: "MARR", Date: "31 DEC 1997"},
{Tag: "MARB", Date: "31 DEC 1997"},
{Tag: "MARC", Date: "31 DEC 1997"},
{Tag: "MARL", Date: "31 DEC 1997"},
{Tag: "MARS", Date: "31 DEC 1997"},
{Tag: "EVEN", Date: "31 DEC 1997"},
},
Citation: []*CitationRecord{
{
Source: &SourceRecord{Xref: "SOURCE1"},
},
},
Change: ChangeRecord{
Date: "1 APR 1998",
Time: "12:34:56.789",
Note: []*NoteRecord{
{
Note: "A note\nNote continued here. The word TEST should not be broken!",
},
},
},
Note: []*NoteRecord{
{
Note: "A note about the family\nNote continued here. The word TEST should not be broken!",
},
},
Media: []*MediaRecord{
{
File: []*FileRecord{
{
Name: `\\network\drive\path\file name.bmp`,
Format: "bmp",
},
},
Note: []*NoteRecord{
{
Note: "A note\nNote continued here. The word TEST should not be broken!",
},
},
Title: "A bmp picture",
},
},
UserDefined: []UserDefinedTag{
{Tag: "_MYOWNTAG", Value: "This is a non-standard tag. Not recommended but allowed", Level: 1},
},
},
{
Xref: "PARENTS",
Husband: &IndividualRecord{Xref: "PERSON5"},
Child: []*IndividualRecord{
{Xref: "PERSON1"},
},
},
{
Xref: "ADOPTIVE_PARENTS",
Wife: &IndividualRecord{Xref: "PERSON6"},
Child: []*IndividualRecord{
{Xref: "PERSON1"},
},
},
{
Xref: "FAMILY2",
Husband: &IndividualRecord{Xref: "PERSON1"},
Wife: &IndividualRecord{Xref: "PERSON8"},
Child: []*IndividualRecord{
{Xref: "PERSON7"},
},
},
}
if diff := cmp.Diff(families, g.Family, indOpt, eventOpt, citeOpt); diff != "" {
t.Errorf("family mismatch (-want +got):\n%s", diff)
}
}
func TestSource(t *testing.T) {
testCases := []struct {
name string
input string
want []*SourceRecord
}{
{
name: "allged",
input: string(data),
want: []*SourceRecord{
{
Xref: "SOURCE1",
Data: &SourceDataRecord{
Event: []*SourceEventRecord{
{
Kind: "BIRT, CHR",
Date: "FROM 1 JAN 1980 TO 1 FEB 1982",
Place: "Place",
},
{
Kind: "DEAT",
Date: "FROM 1 JAN 1980 TO 1 FEB 1982",
Place: "Another place",
},
},
},
Title: "Title of source\nTitle continued here. The word TEST should not be broken!",
Originator: "Author of source\nAuthor continued here. The word TEST should not be broken!",
FiledBy: "Short title",
PublicationFacts: "Source publication facts\nPublication facts continued here. The word TEST should not be broken!",
Text: "Citation from source\nCitation continued here. The word TEST should not be broken!",
Change: ChangeRecord{
Date: "1 APR 1998",
Time: "12:34:56.789",
Note: []*NoteRecord{
{
Note: "A note\nNote continued here. The word TEST should not be broken!",
},
},
},
Note: []*NoteRecord{
{
Note: "A note about the family\nNote continued here. The word TEST should not be broken!",
},
},
Media: []*MediaRecord{
{
File: []*FileRecord{
{
Name: `\\network\drive\path\file name.bmp`,
Format: "bmp",
},
},
Note: []*NoteRecord{
{
Note: "A note\nNote continued here. The word TEST should not be broken!",
},
},
Title: "A bmp picture",
},
},
UserDefined: []UserDefinedTag{
{Tag: "_MYOWNTAG", Value: "This is a non-standard tag. Not recommended but allowed", Level: 1},
},
},
},
},
{
name: "ancestry_date_place",
input: `
0 @SOURCE1@ SOUR
1 TITL 1939 England and Wales Register
1 AUTH Ancestry.com
1 PUBL Ancestry.com Operations, Inc.
2 DATE 2018
2 PLAC Lehi, UT, USA
`,
want: []*SourceRecord{
{
Xref: "SOURCE1",
Title: "1939 England and Wales Register",
Originator: "Ancestry.com",
PublicationFacts: "Ancestry.com Operations, Inc., 2018, Lehi, UT, USA",
},
},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
d := NewDecoder(strings.NewReader(tc.input))
g, err := d.Decode()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if diff := cmp.Diff(tc.want, g.Source); diff != "" {
t.Errorf("source mismatch (-want +got):\n%s", diff)
}
})
}
}
func TestHeader(t *testing.T) {
d := NewDecoder(bytes.NewReader(data))
g, err := d.Decode()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
header := &Header{
SourceSystem: SystemRecord{
Xref: "APPROVED_SOURCE_NAME",
Version: "Version number of source-program",
ProductName: "Name of source-program",
BusinessName: "Corporation name",
Address: AddressRecord{
Address: []*AddressDetail{
{
Full: "Corporation address line 1\nCorporation address line 2\nCorporation address line 3\nCorporation address line 4",
Line1: "Corporation address line 1",
Line2: "Corporation address line 2",
City: "Corporation address city",
State: "Corporation address state",
PostalCode: "Corporation address ZIP code",
Country: "Corporation address country",
},
},
Phone: []string{
"Corporation phone number 1",
"Corporation phone number 2",
"Corporation phone number 3 (last one!)",
},
},
SourceName: "Name of source data",
SourceDate: "1 JAN 1998",
SourceCopyright: "Copyright of source data",
},
Destination: "Destination of transmission",
Date: "1 JAN 1998",
Time: "13:57:24.80",
Submitter: &SubmitterRecord{Xref: "SUBMITTER"},
Submission: &SubmissionRecord{Xref: "SUBMISSION"},
Filename: "ALLGED.GED",
Copyright: "(C) 1997-2000 by H. Eichmann. You can use and distribute this file freely as long as you do not charge for it",
Version: "5.5",
Form: "LINEAGE-LINKED",
CharacterSet: "ASCII",
CharacterSetVersion: "Version number of ASCII (whatever it means) ",
Language: "language",
Note: "A general note about this file:" + "\n" +
"It demonstrates most of the data which can be submitted using GEDCOM5.5. It shows the relatives of PERSON1:" + "\n" +
"His 2 wifes (PERSON2, PERSON8), his parents (father: PERSON5, mother not given), " + "\n" +
"adoptive parents (mother: PERSON6, father not given) and his 3 children (PERSON3, PERSON4 and PERSON7)." + "\n" +
"In PERSON1, FAMILY1, SUBMITTER, SUBMISSION and SOURCE1 as many datafields as possible are used." + "\n" +
"All other individuals/families contain no data. Note, that many data tags can appear more than once" + "\n" +
"(in this transmission this is demonstrated with tags: NAME, OCCU, PLACE and NOTE. Seek the word 'another'." + "\n" +
"The data transmitted here do not make sence. Just the HEAD.DATE tag contains the date of the creation" + "\n" +
"of this file and will change in future Versions!" + "\n" +
"This file is created by H. Eichmann: h.eichmann@@gmx.de. Feel free to copy and use it for any " + "\n" +
"non-commercial purpose. For the creation the GEDCOM standard Release 5.5 (2 JAN 1996) has been used." + "\n" +
"Copyright: The church of Jesus Christ of latter-day saints, gedcom@@gedcom.org" + "\n" +
"Download it (the GEDCOM 5.5 specs) from: ftp.gedcom.com/pub/genealogy/gedcom." + "\n" +
"Some Specials: This line is very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long but not too long (255 caharcters is the limit). " + "\n" +
"This @@ (commercial at) character may only appear ONCE!" + "\n" +
"Note continued here. The word TEST should not be broken!",
UserDefined: []UserDefinedTag{
{Tag: "_MYOWNTAG", Value: "This is a non-standard tag. Not recommended but allowed", Level: 1},
},
}
if diff := cmp.Diff(header, g.Header); diff != "" {
t.Errorf("header mismatch (-want +got):\n%s", diff)
}
}
func TestIndividualAlia(t *testing.T) {
aliaData := []byte(`
0 @PERSON1@ INDI
1 SEX F
1 NAME Margaret /Smith/
1 ALIA Peggy
`)
d := NewDecoder(bytes.NewReader(aliaData))
g, err := d.Decode()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(g.Individual) == 0 {
t.Fatalf("no individual was decoded")
}
individual := &IndividualRecord{
Xref: "PERSON1",
Name: []*NameRecord{
{Name: "Margaret /Smith/"},
{Name: "Peggy"}, // alias becomes alternate name
},
Sex: "F",
}
if diff := cmp.Diff(individual, g.Individual[0]); diff != "" {
t.Errorf("individual mismatch (-want +got):\n%s", diff)
}
}
func TestFixupAncestryBadNote(t *testing.T) {
f, err := os.Open("testdata/badnote.ged")
if err != nil {
t.Fatalf("open: %v", err)
}
d := NewDecoder(f)
g, err := d.Decode()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(g.Source) == 0 {
t.Fatalf("no source was decoded")
}
want := &SourceRecord{
Xref: "S507927087",
Title: "London, England, Church of England Births and Baptisms, 1813-1917",
Originator: "Ancestry.com",
PublicationFacts: "Ancestry.com Operations, Inc.",
Note: []*NoteRecord{
{
Note: "Board of Guardian Records and Church of England Parish Registers. London Metropolitan Archives, London.\n<p>Images produced by permission of the City of London Corporation. The City of London gives no warranty as to the accuracy, completeness or fitness for the purpose of the information provided. Images may be used only for purposes of research, private study or education. Applications for any other use should be made to London Metropolitan Archives, 40 Northampton Road, London EC1R 0HB. Email - ask.lma@@cityoflondon.gov.uk. Infringement of the above condition may result in legal action.</p>",
},
},
UserDefined: []UserDefinedTag{
{Tag: "_APID", Value: "1,1558::0", Level: 1},
},
}
if diff := cmp.Diff(want, g.Source[0]); diff != "" {
t.Errorf("source mismatch (-want +got):\n%s", diff)
}
}
func TestFixupAncestryBadNote2(t *testing.T) {
f, err := os.Open("testdata/badnote2.ged")
if err != nil {
t.Fatalf("open: %v", err)
}
d := NewDecoder(f)
g, err := d.Decode()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(g.Source) == 0 {
t.Fatalf("no source was decoded")
}
want := &SourceRecord{
Xref: "S1701628864",
Title: "1939 England and Wales Register",
Originator: "Ancestry.com",
PublicationFacts: "Ancestry.com Operations, Inc.",
Note: []*NoteRecord{
{
Note: "Crown copyright images reproduced by courtesy of TNA, London England. 1939 Register (Series RG101), The National Archives, Kew, London, England.\n" +
"\n" +
"The National Archives give no warranty as to the accuracy, completeness or fitness for the purpose of the information provided. Images may be used only for purposes of research, private study or education. Applications for any other use should be made to The National Archives Image Library, Kew, Richmond, Surrey TW9 4DU, Tel: 020 8392 5225. Fax: 020 8392 5266.",
},
},
UserDefined: []UserDefinedTag{
{Tag: "_APID", Value: "1,61596::0", Level: 1},
},
}
if diff := cmp.Diff(want, g.Source[0]); diff != "" {
t.Errorf("source mismatch (-want +got):\n%s", diff)
}
}
func TestStructuredUserDefinedTags(t *testing.T) {
treeData := []byte(`
0 HEAD
1 SOUR The Source Product
2 NAME The Product Name
2 VERS The Product Version
2 _TREE The Tree Name
3 RIN The Tree Identifier
3 _ENV The Tree Environment
`)
d := NewDecoder(bytes.NewReader(treeData))
g, err := d.Decode()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
want := &Header{
SourceSystem: SystemRecord{
Xref: "The Source Product",
Version: "The Product Version",
ProductName: "The Product Name",
UserDefined: []UserDefinedTag{
{
Tag: "_TREE",
Value: "The Tree Name",
Level: 2,
UserDefined: []UserDefinedTag{
{
Tag: "RIN",
Value: "The Tree Identifier",
Level: 3,
},
{
Tag: "_ENV",
Value: "The Tree Environment",
Level: 3,
},
},
},
},
},
}
if diff := cmp.Diff(want, g.Header); diff != "" {
t.Errorf("source mismatch (-want +got):\n%s", diff)
}
}
func TestAddress(t *testing.T) {
testCases := []struct {
name string
input string
want *Header
}{
{
name: "full-5.5",
input: `
0 HEAD
1 SOUR TestSource
2 CORP TestCorp
3 ADDR Address line 1
4 CONT Address line 2
4 CONT City, State PostalCode
4 CONT Country
4 _NAME GivenName FullName
4 ADR1 Address line 1
4 ADR2 Address line 2
4 CITY City
4 STAE State
4 POST PostalCode
4 CTRY Country
3 PHON Phone
`,
want: &Header{
SourceSystem: SystemRecord{
Xref: "TestSource",
BusinessName: "TestCorp",
Address: AddressRecord{
Address: []*AddressDetail{
{
Full: "Address line 1\nAddress line 2\nCity, State PostalCode\nCountry",
Line1: "Address line 1",
Line2: "Address line 2",
City: "City",
State: "State",
PostalCode: "PostalCode",
Country: "Country",
},
},
Phone: []string{"Phone"},
},
},
},
},
{
name: "multiple-5.5",
input: `
0 HEAD
1 SOUR TestSource
2 CORP TestCorp
3 ADDR Address 1 line 1
4 CONT Address 1 line 2
4 CONT City 1, State 1 PostalCode 1
4 CONT Country 1
4 _NAME Contact 1
4 ADR1 Address 1 line 1
4 ADR2 Address 1 line 2
4 CITY City 1
4 STAE State 1
4 POST PostalCode 1
4 CTRY Country 1
3 ADDR Address 2 line 1
4 CONT Address 2 line 2
4 CONT City 2, State 2 PostalCode 2
4 CONT Country 2
4 _NAME Contact 2
4 ADR1 Address 2 line 1
4 ADR2 Address 2 line 2
4 CITY City 2
4 STAE State 2
4 POST PostalCode 2
4 CTRY Country 2
`,
want: &Header{