3
0

Fix number sanitizer bug

This commit is contained in:
Jože Fortun
2020-07-17 13:35:53 +02:00
parent 6fa55771fb
commit dec88dcd98
2 changed files with 15 additions and 0 deletions

View File

@@ -219,6 +219,7 @@ func (sanitizer) sNumber(v *types.RecordValue, f *types.ModuleField, m *types.Mo
// In case of fractures, remove trailing 0's
if strings.Contains(v.Value, ".") {
v.Value = strings.TrimRight(v.Value, "0")
v.Value = strings.TrimRight(v.Value, ".")
}
return v

View File

@@ -143,6 +143,20 @@ func Test_sanitizer_Run(t *testing.T) {
input: "42.4",
output: "42",
},
{
name: "number precision; trailing .00",
kind: "Number",
options: map[string]interface{}{"precision": 2},
input: "42.00",
output: "42",
},
{
name: "number precision; trailing .040",
kind: "Number",
options: map[string]interface{}{"precision": 2},
input: "42.040",
output: "42.04",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {