1package semver 2 3import ( 4 "testing" 5) 6 7type scanTest struct { 8 val interface{} 9 shouldError bool 10 expected string 11} 12 13var scanTests = []scanTest{ 14 {"1.2.3", false, "1.2.3"}, 15 {[]byte("1.2.3"), false, "1.2.3"}, 16 {7, true, ""}, 17 {7e4, true, ""}, 18 {true, true, ""}, 19} 20 21func TestScanString(t *testing.T) { 22 for _, tc := range scanTests { 23 s := &Version{} 24 err := s.Scan(tc.val) 25 if tc.shouldError { 26 if err == nil { 27 t.Fatalf("Scan did not return an error on %v (%T)", tc.val, tc.val) 28 } 29 } else { 30 if err != nil { 31 t.Fatalf("Scan returned an unexpected error: %s (%T) on %v (%T)", tc.val, tc.val, tc.val, tc.val) 32 } 33 if val, _ := s.Value(); val != tc.expected { 34 t.Errorf("Wrong Value returned, expected %q, got %q", tc.expected, val) 35 } 36 } 37 } 38} 39