Skip to content

Commit

Permalink
Handle event values
Browse files Browse the repository at this point in the history
  • Loading branch information
iand committed Jul 28, 2024
1 parent 0c40194 commit f174119
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 2 deletions.
11 changes: 10 additions & 1 deletion decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,16 @@ func makeIndividualParser(d *Decoder, i *IndividualRecord, minLevel int) parser
case "SEX":
i.Sex = value
case "BIRT", "CHR", "DEAT", "BURI", "CREM", "ADOP", "BAPM", "BARM", "BASM", "BLES", "CHRA", "CONF", "FCOM", "ORDN", "NATU", "EMIG", "IMMI", "CENS", "PROB", "WILL", "GRAD", "RETI", "EVEN":
e := &EventRecord{Tag: tag, Value: value}
e := &EventRecord{Tag: tag}
if value != "" {
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
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":
Expand Down
90 changes: 89 additions & 1 deletion decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,95 @@ func TestPlace(t *testing.T) {
}

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

func TestEvent(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}},
},
},
{
// A Y after a DEAT, BIRT or CHR is allowed, indicating the event is known to have happened
name: "death_known",
input: `
1 DEAT Y
`,
want: &EventRecord{
Tag: "DEAT",
Value: "Y",
},
},
{
// A Y after a DEAT, BIRT or CHR is allowed, indicating the event is known to have happened
name: "birt_known",
input: `
1 BIRT Y
`,
want: &EventRecord{
Tag: "BIRT",
Value: "Y",
},
},
{
// A Y after a DEAT, BIRT or CHR is allowed, indicating the event is known to have happened
name: "chr_known",
input: `
1 CHR Y
`,
want: &EventRecord{
Tag: "CHR",
Value: "Y",
},
},
{
name: "death_standard",
input: `
1 DEAT
2 DATE 2 OCT 1937
`,
want: &EventRecord{
Tag: "DEAT",
Date: "2 OCT 1937",
},
},
}

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].Event[0]); diff != "" {
t.Errorf("event mismatch (-want +got):\n%s", diff)
}
})
}
Expand Down

0 comments on commit f174119

Please sign in to comment.