Skip to content

Commit 2cd5808

Browse files
committed
Generator: Tests: Fix handling of int/float
(cherry picked from commit 76170c7) (cherry picked from commit 2e880d2)
1 parent eacc993 commit 2cd5808

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

internal/cmd/generate/commands/gentests/generator.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,16 @@ func (g *Generator) genAction(a Action, skipBody ...bool) {
10261026
re := regexp.MustCompile("^(\\d+).*")
10271027
value = re.ReplaceAllString(fmt.Sprintf("%d", v), "$1")
10281028
case "*int":
1029-
g.w(`esapi.IntPtr(` + fmt.Sprintf("%d", v) + `)`)
1029+
switch v.(type) {
1030+
case int:
1031+
g.w(`esapi.IntPtr(` + fmt.Sprintf("%d", v) + `)`)
1032+
case float64:
1033+
if vv, ok := v.(float64); ok {
1034+
g.w(`esapi.IntPtr(` + fmt.Sprintf("%d", int(vv)) + `)`)
1035+
}
1036+
default:
1037+
panic(fmt.Sprintf("Unexpected type [%T] for [%s]", v, k))
1038+
}
10301039
default:
10311040
value = fmt.Sprintf("%v", v)
10321041
}

0 commit comments

Comments
 (0)