-
Notifications
You must be signed in to change notification settings - Fork 20
/
script_integration_test.go
102 lines (75 loc) · 2.48 KB
/
script_integration_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package overflow
import (
"testing"
"github.com/hexops/autogold"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type AwesomeStruct struct {
First struct {
Nested string `json:"nested"`
} `json:"first"`
}
func TestScriptIntegrationNew(t *testing.T) {
o, err := OverflowTesting()
require.NoError(t, err)
require.NotNil(t, o)
mapScript := o.ScriptFileNameFN(`access(all) fun main() : {String: {String: String}} {
return { "first" : { "nested" : "nestedvalue"}}
}`)
t.Run("Get length from pointer", func(t *testing.T) {
mapScript().AssertLengthWithPointer(t, "/first/nested", 11)
})
t.Run("Get length from pointer map", func(t *testing.T) {
mapScript().AssertLengthWithPointer(t, "/first", 23)
})
t.Run("Get value from pointer", func(t *testing.T) {
mapScript().AssertWithPointer(t, "/first/nested", "nestedvalue")
})
t.Run("Get error from pointer", func(t *testing.T) {
mapScript().AssertWithPointerError(t, "/first/nested2", "Object has no key 'nested2'")
})
t.Run("Get value using want", func(t *testing.T) {
mapScript().AssertWithPointerWant(t, "/first/nested", autogold.Want("nested", "nestedvalue"))
})
t.Run("Get value using want map", func(t *testing.T) {
//Note that wants must have a unique name
mapScript().AssertWithPointerWant(t, "/first", autogold.Want("nestedMap", map[string]interface{}{"nested": "nestedvalue"}))
})
t.Run("Marhal result using pointer", func(t *testing.T) {
var result map[string]string
//Note that wants must have a unique name
err := mapScript().MarshalPointerAs("/first", &result)
assert.NoError(t, err)
assert.Equal(t, "nestedvalue", result["nested"])
})
t.Run("Marhal result", func(t *testing.T) {
var result AwesomeStruct
err := mapScript().MarshalAs(&result)
assert.NoError(t, err)
assert.Equal(t, "nestedvalue", result.First.Nested)
})
t.Run("Get assert with want", func(t *testing.T) {
mapScript().AssertWant(t, autogold.Want("assertWant", map[string]interface{}{"first": map[string]interface{}{"nested": "nestedvalue"}}))
})
t.Run("Use relative import", func(t *testing.T) {
res := o.Script(`
import Debug from "../contracts/Debug.cdc"
access(all) fun main() : AnyStruct {
return "foo"
}
`)
require.NoError(t, res.Err)
assert.Equal(t, "foo", res.Output)
})
t.Run("Use new import syntax", func(t *testing.T) {
res := o.Script(`
import "Debug"
access(all) fun main() : AnyStruct {
return "foo"
}
`)
require.NoError(t, res.Err)
assert.Equal(t, "foo", res.Output)
})
}