-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtinystring_test.go
More file actions
72 lines (60 loc) · 1.94 KB
/
tinystring_test.go
File metadata and controls
72 lines (60 loc) · 1.94 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
63
64
65
66
67
68
69
70
71
72
package client
import (
"fmt"
"strings"
"testing"
)
func TestTinyStringMessages(t *testing.T) {
t.Run("Test error messages with TinyString", func(t *testing.T) {
config := NewConfig()
config.SourceDir = func() string { return "test" }
config.OutputDir = func() string { return "public" }
tw := New(config)
tw.SetAppRootDir(t.TempDir())
// Test validation error
if err := tw.validateMode("invalid"); err == nil {
t.Fatal("Expected validation error for invalid mode")
}
// Puedes ajustar aquí la validación según el formato real del error si lo deseas
})
t.Run("Test Change method with TinyString messages", func(t *testing.T) {
config := NewConfig()
config.SourceDir = func() string { return "test" }
config.OutputDir = func() string { return "public" }
tw := New(config)
tw.SetAppRootDir(t.TempDir())
var got string
tw.SetLog(func(message ...any) {
if len(message) > 0 {
got = fmt.Sprint(message[0])
}
})
// Test valid mode change
tw.Change("L")
// Allow warning if no main.wasm.go exists in test env
if got == "" {
t.Fatalf("Expected non-empty success or warning message, got: '%s'", got)
}
// Test invalid mode (non-existent mode)
var errMsg string
tw.SetLog(func(message ...any) {
if len(message) > 0 {
errMsg = fmt.Sprint(message[0])
}
})
tw.Change("invalid")
// Ensure that the current value did not change and that validateMode reports an error.
if tw.Value() != "L" {
t.Errorf("Expected compiler mode to remain 'L' after invalid change, got: %s", tw.Value())
}
if err := tw.validateMode("invalid"); err == nil {
t.Fatal("Expected validateMode to return an error for invalid mode")
}
if errMsg != "" {
// If a progress message exists, prefer a non-fatal assertion that it mentions invalidity.
if !strings.Contains(strings.ToLower(errMsg), "invalid") {
t.Logf("Progress message for invalid mode did not contain 'invalid': %s", errMsg)
}
}
})
}