-
Notifications
You must be signed in to change notification settings - Fork 0
/
computed_field_test.go
52 lines (43 loc) · 1.11 KB
/
computed_field_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package pgtalk
import (
"testing"
)
type hasExpressionResult struct {
m map[string]any
}
func newHasExpressionResult() *hasExpressionResult {
return &hasExpressionResult{make(map[string]any)}
}
func (r *hasExpressionResult) AddExpressionResult(key string, value any) {
r.m[key] = value
}
func (r *hasExpressionResult) GetExpressionResult(key string) any {
pv := r.m[key].(*any)
return *pv
}
func TestFieldValueToScan(t *testing.T) {
cf := new(computedField)
cf.ResultName = "one"
ent1 := newHasExpressionResult()
ent2 := newHasExpressionResult()
{
scanAddr := cf.FieldValueToScan(ent1)
// simulate scan
var newValue any = "help1"
pscanAddr := scanAddr.(*any)
*pscanAddr = newValue
}
{
scanAddr := cf.FieldValueToScan(ent2)
// simulate scan
var newValue any = "help2"
pscanAddr := scanAddr.(*any)
*pscanAddr = newValue
}
if got, want := ent1.GetExpressionResult("one"), "help1"; got != want {
t.Errorf("got [%v]:%T want [%v]:%T", got, got, want, want)
}
if got, want := ent2.GetExpressionResult("one"), "help2"; got != want {
t.Errorf("got [%v]:%T want [%v]:%T", got, got, want, want)
}
}