Files
sub2clash/test/yaml_test.go
2025-10-17 18:13:49 +11:00

34 lines
637 B
Go

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)
}
}