MCPcopy
hub / github.com/bnb-chain/bsc / TestPrettyPrint

Function TestPrettyPrint

console/console_test.go:236–264  ·  view source on GitHub ↗

Tests that the JavaScript objects returned by statement executions are properly pretty printed instead of just displaying "[object]".

(t *testing.T)

Source from the content-addressed store, hash-verified

234// Tests that the JavaScript objects returned by statement executions are properly
235// pretty printed instead of just displaying "[object]".
236func TestPrettyPrint(t *testing.T) {
237 tester := newTester(t, nil)
238 defer tester.Close(t)
239
240 tester.console.Evaluate("obj = {int: 1, string: 'two', list: [3, 3, 3], obj: {null: null, func: function(){}}}")
241
242 // Define some specially formatted fields
243 var (
244 one = jsre.NumberColor("1")
245 two = jsre.StringColor("\"two\"")
246 three = jsre.NumberColor("3")
247 null = jsre.SpecialColor("null")
248 fun = jsre.FunctionColor("function()")
249 )
250 // Assemble the actual output we're after and verify
251 want := `{
252 int: ` + one + `,
253 list: [` + three + `, ` + three + `, ` + three + `],
254 obj: {
255 null: ` + null + `,
256 func: ` + fun + `
257 },
258 string: ` + two + `
259}
260`
261 if output := tester.output.String(); output != want {
262 t.Fatalf("pretty print mismatch: have %s, want %s", output, want)
263 }
264}
265
266// Tests that the JavaScript exceptions are properly formatted and colored.
267func TestPrettyError(t *testing.T) {

Callers

nothing calls this directly

Calls 5

newTesterFunction · 0.70
CloseMethod · 0.65
StringMethod · 0.65
EvaluateMethod · 0.45
FatalfMethod · 0.45

Tested by

no test coverage detected