sql_test.go 779 B

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