File: sql_test.go

package info (click to toggle)
golang-github-blang-semver 3.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, experimental, sid
  • size: 176 kB
  • sloc: makefile: 3
file content (38 lines) | stat: -rw-r--r-- 779 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package semver

import (
	"testing"
)

type scanTest struct {
	val         interface{}
	shouldError bool
	expected    string
}

var scanTests = []scanTest{
	{"1.2.3", false, "1.2.3"},
	{[]byte("1.2.3"), false, "1.2.3"},
	{7, true, ""},
	{7e4, true, ""},
	{true, true, ""},
}

func TestScanString(t *testing.T) {
	for _, tc := range scanTests {
		s := &Version{}
		err := s.Scan(tc.val)
		if tc.shouldError {
			if err == nil {
				t.Fatalf("Scan did not return an error on %v (%T)", tc.val, tc.val)
			}
		} else {
			if err != nil {
				t.Fatalf("Scan returned an unexpected error: %s (%T) on %v (%T)", tc.val, tc.val, tc.val, tc.val)
			}
			if val, _ := s.Value(); val != tc.expected {
				t.Errorf("Wrong Value returned, expected %q, got %q", tc.expected, val)
			}
		}
	}
}