Skip to content

Commit

Permalink
Fix wrong format in possible transposition errors in CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
mrclmr committed Jan 3, 2024
1 parent f362858 commit 9dc0c93
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cmd/icm/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,12 +557,12 @@ func newCheckDigitInput(config *configs.Config) func() input.Input {
digitFmt = fmt.Sprintf("%d", tcn.CheckDigit)
}

contNumFmt := fmt.Sprintf(" %s%s%s%s%s%s%s",
contNumFmt := fmt.Sprintf("%s%s%s%s%s%s%s",
tcn.OwnerCode, config.SepOE(),
string(tcn.EquipCatID), config.SepES(),
serialNumberFmt, config.SepSC(),
digitFmt)
infos = append(infos, input.Info{Text: contNumFmt})
infos = append(infos, input.Info{Text: fmt.Sprintf(" %s", contNumFmt)})
builder.WriteString(contNumFmt)
if idx < len(transposedContNums)-1 {
builder.WriteString(", ")
Expand Down
29 changes: 29 additions & 0 deletions cmd/icm/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,35 @@ func Test_validateCmd(t *testing.T) {
some-city
some-country
`,
},
{
"Validate ABC U 681304 0 with fancy output",
[]string{"ABC U 681304 0"},
[]configOverride{{configs.FlagNames.Pattern, containerNumber}},
false,
`
ABC U 681304 0 ✔
↑ ↑ ↑
│ │ └─ Possible transposition errors:
│ │ ABC U 681034 0
│ │ ABC U 681340 0
│ │
│ └─ some-equip-cat-ID
└─ some-company
some-city
some-country
`,
},
{
"Validate ABC U 681304 0 with csv output",
[]string{"ABC U 681304 0"},
[]configOverride{{configs.FlagNames.Output, "csv"}},
false,
`owner-code;company;city;country;equipment-category-id;equipment-category;serial-number;check-digit;calculated-check-digit;valid-check-digit;possible-transposition-error
ABC;some-company;some-city;some-country;U;some-equip-cat-ID;681304;0;0;true;ABC U 681034 0, ABC U 681340 0
`,
},
}
Expand Down
7 changes: 6 additions & 1 deletion input/csv_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,10 @@ func (cp *CSVPrinter) Print(inputs []Input) error {
}
cp.headerPrinted = true
}
return cp.csvWriter.Write(cp.record)
err := cp.csvWriter.Write(cp.record)
if err != nil {
return err
}
cp.csvWriter.Flush()
return nil
}

0 comments on commit 9dc0c93

Please sign in to comment.