MCPcopy Create free account
hub / github.com/buke/quickjs-go / TestContextNewStringUTF16

Function TestContextNewStringUTF16

context_test.go:121–155  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

119}
120
121func TestContextNewStringUTF16(t *testing.T) {
122 useStableOwnerHooksForLegacySubtests(t)
123
124 rt := NewRuntime()
125 defer rt.Close()
126 ctx := rt.NewContext()
127 defer ctx.Close()
128
129 ascii := ctx.NewStringUTF16([]uint16{'o', 'k'})
130 require.NotNil(t, ascii)
131 defer ascii.Free()
132 require.True(t, ascii.IsString())
133 require.Equal(t, "ok", ascii.ToString())
134
135 empty := ctx.NewStringUTF16(nil)
136 require.NotNil(t, empty)
137 defer empty.Free()
138 require.Equal(t, "", empty.ToString())
139
140 wide := ctx.NewStringUTF16([]uint16{0xD800})
141 require.NotNil(t, wide)
142 defer wide.Free()
143 utf16, err := wide.ToStringUTF16()
144 require.NoError(t, err)
145 require.Equal(t, []uint16{0xD800}, utf16)
146
147 var nilCtx *Context
148 require.Nil(t, nilCtx.NewStringUTF16([]uint16{'x'}))
149
150 closedRT := NewRuntime()
151 closedCtx := closedRT.NewContext()
152 closedCtx.Close()
153 require.Nil(t, closedCtx.NewStringUTF16([]uint16{'x'}))
154 closedRT.Close()
155}
156
157func TestContextExceptionPrimitiveFallback(t *testing.T) {
158 useStableOwnerHooksForLegacySubtests(t)

Callers

nothing calls this directly

Calls 11

CloseMethod · 0.95
NewContextMethod · 0.95
CloseMethod · 0.95
NewStringUTF16Method · 0.95
NewRuntimeFunction · 0.85
IsStringMethod · 0.80
EqualMethod · 0.80
ToStringUTF16Method · 0.80
FreeMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected