示例#1
0
func TestJSONArrayString_Scan_nil(t *testing.T) {
	var got, expected pqt.JSONArrayString
	err := got.Scan(nil)

	if err != nil {
		t.Fatalf("unexpected error: %s", err.Error())
	}
	if !reflect.DeepEqual(expected, got) {
		t.Errorf("unexpected output, expected: %T\n	%s\n	but got: %T\n	%s,", expected, expected, got, got)

	}
}
示例#2
0
func TestJSONArrayString_Scan(t *testing.T) {
	success := map[string]pqt.JSONArrayString{
		"[1,2,3,4]": {0: "1", 1: "2", 2: "3", 3: "4"},
	}

SuccessLoop:
	for src, expected := range success {
		var got pqt.JSONArrayString
		if err := got.Scan(src); err != nil {
			t.Errorf("unexpected error: %s", err.Error())
			continue SuccessLoop
		}
		if !reflect.DeepEqual(expected, got) {
			t.Errorf("unexpected output, expected: %T\n	%s\n	but got: %T\n	%s,", expected, expected, got, got)

		}
	}

	fail := map[string]interface{}{
		`pqt: expected slice of bytes or string as a source argument in Scan, not int64`:                        int64(1),
		`pqt: expected slice of bytes or string as a source argument in Scan, not bool`:                         false,
		`pqt: expected slice of bytes or string as a source argument in Scan, not float64`:                      float64(12.2),
		`pqt: expected slice of bytes or string as a source argument in Scan, not time.Time`:                    time.Now(),
		`pqt: expected to get source argument in format "[text1,text2,...,textN]", but got [`:                   "[",
		`pqt: expected to get source argument in format "[text1,text2,...,textN]", but got ]`:                   "]",
		`pqt: expected to get source argument in format "[text1,text2,...,textN]", but got {text1,text2,text3}`: "{text1,text2,text3}",
		`pqt: expected to get source argument in format "[text1,text2,...,textN]", but got (text1,text2,text3)`: "(text1,text2,text3)",
	}

FailLoop:
	for expected, src := range fail {
		var got pqt.JSONArrayString

		err := got.Scan(src)
		if err == nil {
			t.Errorf("expected error: %s", expected)
			continue FailLoop
		}
		if expected != err.Error() {
			t.Errorf("undexpected error, got:\n	%s\nbut expected:\n	%s", err.Error(), expected)
		}
	}
}