MCPcopy Index your code
hub / github.com/pocketbase/pocketbase / TestBindCoreToBytes

Function TestBindCoreToBytes

plugins/jsvm/binds_test.go:123–161  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

121}
122
123func TestBindCoreToBytes(t *testing.T) {
124 vm := goja.New()
125 BindCore(vm)
126 vm.Set("bytesEqual", bytes.Equal)
127 vm.Set("scenarios", []struct {
128 Name string
129 Value any
130 Expected []byte
131 }{
132 {"null", nil, []byte{}},
133 {"string", "test", []byte("test")},
134 {"number", -12.4, []byte("-12.4")},
135 {"bool", true, []byte("true")},
136 {"arr", []int{1, 2, 3}, []byte{1, 2, 3}},
137 {"jsonraw", types.JSONRaw{1, 2, 3}, []byte{1, 2, 3}},
138 {"reader", strings.NewReader("test"), []byte("test")},
139 {"obj", map[string]any{"test": 123}, []byte(`{"test":123}`)},
140 {"struct", struct {
141 Name string
142 private string
143 }{Name: "123", private: "456"}, []byte(`{"Name":"123"}`)},
144 })
145
146 _, err := vm.RunString(`
147 for (let s of scenarios) {
148 let b = toBytes(s.value)
149 if (!Array.isArray(b)) {
150 throw new Error('[' + s.name + '] Expected toBytes to return an array');
151 }
152
153 if (!bytesEqual(b, s.expected)) {
154 throw new Error('[' + s.name + '] Expected bytes ' + s.expected + ', got ' + b);
155 }
156 }
157 `)
158 if err != nil {
159 t.Fatal(err)
160 }
161}
162
163func TestBindCoreUnmarshal(t *testing.T) {
164 vm := goja.New()

Callers

nothing calls this directly

Calls 3

BindCoreFunction · 0.85
NewReaderMethod · 0.80
SetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…