This commit is contained in:
2025-10-17 18:13:49 +11:00
parent be656cca57
commit 1e8a79c2d2
21 changed files with 186 additions and 132 deletions

33
test/yaml_test.go Normal file
View File

@@ -0,0 +1,33 @@
package test
import (
"testing"
"github.com/bestnite/sub2clash/model/proxy"
"gopkg.in/yaml.v3"
)
type testStruct struct {
A proxy.IntOrString `yaml:"a"`
}
func TestUnmarshal(t *testing.T) {
yamlData1 := `a: 123`
res := testStruct{}
err := yaml.Unmarshal([]byte(yamlData1), &res)
if err != nil {
t.Errorf("failed to unmarshal yaml: %v", err)
}
if res.A != 123 {
t.Errorf("expected 123, but got %v", res.A)
}
yamlData2 := `a: "123"`
err = yaml.Unmarshal([]byte(yamlData2), &res)
if err != nil {
t.Errorf("failed to unmarshal yaml: %v", err)
}
if res.A != 123 {
t.Errorf("expected 123, but got %v", res.A)
}
}