mirror of
https://github.com/bestnite/sub2clash.git
synced 2025-10-26 09:11:01 +00:00
This commit is contained in:
33
test/yaml_test.go
Normal file
33
test/yaml_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user