Skip to content

Commit cd1a23f

Browse files
committed
新增reflection bool类型测试用例
1 parent c0e5213 commit cd1a23f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/reflection_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,33 @@ func printTableInfo(table *reflection.StructInfo) {
319319
fmt.Printf("origin : %s, map %s\n", k, v)
320320
}
321321
}
322+
323+
func TestSetInt2Bool(t *testing.T) {
324+
t.Run("true", func(t *testing.T) {
325+
var i int64 = 1
326+
var b bool = false
327+
328+
set := reflection.SetValue(reflection.ReflectValue(&b), i)
329+
if !set {
330+
t.Fatal("not set")
331+
}
332+
333+
if !b {
334+
t.Fatal("b is false, expect true")
335+
}
336+
})
337+
338+
t.Run("false", func(t *testing.T) {
339+
var i int64 = 0
340+
var b bool = true
341+
342+
set := reflection.SetValue(reflection.ReflectValue(&b), i)
343+
if !set {
344+
t.Fatal("not set")
345+
}
346+
347+
if b {
348+
t.Fatal("b is true, expect false")
349+
}
350+
})
351+
}

0 commit comments

Comments
 (0)