-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint.front_test.go
More file actions
62 lines (51 loc) · 1.44 KB
/
print.front_test.go
File metadata and controls
62 lines (51 loc) · 1.44 KB
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
//go:build wasm
package fmt
import (
"syscall/js"
"testing"
)
// testLastOutput stores the last output for testing
var testLastOutput string
// setupTestCapture creates a JavaScript function that captures console.log calls
func setupTestCapture() func() {
testLastOutput = ""
// Store original and create wrapper that captures + calls original
captureFunc := js.FuncOf(func(this js.Value, args []js.Value) any {
if len(args) > 0 {
testLastOutput = args[0].String()
}
return nil
})
js.Global().Set("__testConsoleLog", js.Global().Get("console").Get("log"))
js.Global().Get("console").Set("log", captureFunc)
return func() {
js.Global().Get("console").Set("log", js.Global().Get("__testConsoleLog"))
captureFunc.Release()
}
}
func TestPrintln_Frontend(t *testing.T) {
cleanup := setupTestCapture()
defer cleanup()
for _, tc := range TestPrintlnCases {
t.Run(tc.name, func(t *testing.T) {
testLastOutput = ""
Println(tc.args...)
if testLastOutput != tc.expected {
t.Errorf("Println(%v) = %q, want %q", tc.args, testLastOutput, tc.expected)
}
})
}
}
func TestPrintf_Frontend(t *testing.T) {
cleanup := setupTestCapture()
defer cleanup()
for _, tc := range TestPrintfCases {
t.Run(tc.name, func(t *testing.T) {
testLastOutput = ""
Printf(tc.format, tc.args...)
if testLastOutput != tc.expected {
t.Errorf("Printf(%q, %v) = %q, want %q", tc.format, tc.args, testLastOutput, tc.expected)
}
})
}
}