Skip to content

Commit

Permalink
Handle values on RESI attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
iand committed Jul 28, 2024
1 parent f174119 commit 901ca91
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 4 deletions.
20 changes: 17 additions & 3 deletions decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,24 @@ func makeIndividualParser(d *Decoder, i *IndividualRecord, minLevel int) parser
if value == "Y" && (tag == "BIRT" || tag == "CHR" || tag == "DEAT") {
e.Value = "Y"
} else {
// any event other value is invalid and added as a note instead
// event value is invalid and added as a note instead
r := &NoteRecord{Note: value}
e.Note = append(i.Note, r)
}
}
i.Event = append(i.Event, e)
d.pushParser(makeEventParser(d, tag, e, level))
case "CAST", "DSCR", "EDUC", "IDNO", "NATI", "NCHI", "NMR", "OCCU", "PROP", "RELI", "RESI", "SSN", "TITL", "FACT":
e := &EventRecord{Tag: tag, Value: value}
e := &EventRecord{Tag: tag}
if value != "" {
if tag == "RESI" {
// event value is invalid and added as a note instead
r := &NoteRecord{Note: value}
e.Note = append(i.Note, r)
} else {
e.Value = value
}
}
i.Attribute = append(i.Attribute, e)
d.pushParser(makeEventParser(d, tag, e, level))
case "FAMC":
Expand Down Expand Up @@ -864,7 +873,12 @@ func makeFamilyParser(d *Decoder, f *FamilyRecord, minLevel int) parser {
case "CHIL":
f.Child = append(f.Child, d.individual(stripXref(value)))
case "ANUL", "CENS", "DIV", "DIVF", "ENGA", "MARR", "MARB", "MARC", "MARL", "MARS", "EVEN", "RESI":
e := &EventRecord{Tag: tag, Value: value}
e := &EventRecord{Tag: tag}
if value != "" {
// any event other value is invalid and added as a note instead
r := &NoteRecord{Note: value}
e.Note = append(e.Note, r)
}
f.Event = append(f.Event, e)
d.pushParser(makeEventParser(d, tag, e, level))
case "NCHI":
Expand Down
85 changes: 84 additions & 1 deletion decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,7 @@ func TestPlace(t *testing.T) {
}
}

func TestEvent(t *testing.T) {
func TestIndividualEvent(t *testing.T) {
testCases := []struct {
name string
input string
Expand Down Expand Up @@ -1575,3 +1575,86 @@ func TestEvent(t *testing.T) {
})
}
}

func TestIndividualAttribute(t *testing.T) {
testCases := []struct {
name string
input string
want *EventRecord
}{
{
name: "even_value_to_note",
input: `
1 RESI Marital Status: MarriedRelation to Head of House: Head
2 DATE 1 Jun 1921
`,
want: &EventRecord{
Tag: "RESI",
Date: "1 Jun 1921",
Note: []*NoteRecord{
{Note: "Marital Status: MarriedRelation to Head of House: Head"},
},
},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
tc.input = "0 @test@ INDI\n" + tc.input
d := NewDecoder(bytes.NewReader([]byte(tc.input)))

g, err := d.Decode()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

if diff := cmp.Diff(tc.want, g.Individual[0].Attribute[0]); diff != "" {
t.Errorf("event mismatch (-want +got):\n%s", diff)
}
})
}
}

func TestFamilyEvent(t *testing.T) {
testCases := []struct {
name string
input string
want *EventRecord
}{
{
// findmypast uses the note as the value of the EVEN
name: "even_value_to_note",
input: `
1 EVEN was age 10 and the daughter of the head of the household
2 TYPE Census UK 1881
2 _PRIM Y
2 DATE 3 Apr 1881
`,
want: &EventRecord{
Tag: "EVEN",
Type: "Census UK 1881",
Date: "3 Apr 1881",
Note: []*NoteRecord{
{Note: "was age 10 and the daughter of the head of the household"},
},
UserDefined: []UserDefinedTag{{Tag: "_PRIM", Value: "Y", Level: 2}},
},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
tc.input = "0 @test@ FAM\n" + tc.input
d := NewDecoder(bytes.NewReader([]byte(tc.input)))

g, err := d.Decode()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

if diff := cmp.Diff(tc.want, g.Family[0].Event[0]); diff != "" {
t.Errorf("event mismatch (-want +got):\n%s", diff)
}
})
}
}

0 comments on commit 901ca91

Please sign in to comment.