Tests that the JavaScript objects returned by statement executions are properly pretty printed instead of just displaying "[object]".
(t *testing.T)
| 234 | // Tests that the JavaScript objects returned by statement executions are properly |
| 235 | // pretty printed instead of just displaying "[object]". |
| 236 | func 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. |
| 267 | func TestPrettyError(t *testing.T) { |