mirror of
				https://github.com/bestnite/sub2clash.git
				synced 2025-11-04 04:40:36 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			34 lines
		
	
	
		
			637 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			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)
 | 
						|
	}
 | 
						|
}
 |