コード例 #1
0
ファイル: json_array_test.go プロジェクト: piotrkowalczuk/pqt
func TestJSONArrayFloat64_Scan_nil(t *testing.T) {
	var got pqt.JSONArrayFloat64

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

	}
}
コード例 #2
0
ファイル: json_array_test.go プロジェクト: piotrkowalczuk/pqt
func TestJSONArrayFloat64_Scan(t *testing.T) {
	success := map[string]pqt.JSONArrayFloat64{
		"[1.1,2.2,3.5,4.65]": {0: 1.1, 1: 2.2, 2: 3.5, 3: 4.65},
		"[]":                 {},
	}

SuccessLoop:
	for src, expected := range success {
		var got pqt.JSONArrayFloat64

		err := got.Scan(src)
		if err != nil {
			t.Errorf("unexpected error: %s", err.Error())
			continue SuccessLoop
		}

		if !reflect.DeepEqual(expected, got) {
			t.Errorf("wrong output, expected %v but got %v", expected, got)
		}
	}

	fail := map[string]interface{}{
		`pqt: expected to get source argument in format "[1.3,2.4,...,N.M]", but got string1 at index 0`: "[string1,string2]",
		`pqt: expected to get source argument in format "[1.3,2.4,...,N.M]", but got ]`:                  "]",
		`pqt: expected to get source argument in format "[1.3,2.4,...,N.M]", but got [`:                  "[",
		`pqt: expected to get source argument in format "[1.3,2.4,...,N.M]", but got 12412s at index 0`:  "[12412s]",
		`pqt: expected to get source argument in format "[1.3,2.4,...,N.M]", but got {1.1,2.2,3.5}`:      "{1.1,2.2,3.5}",
		`pqt: expected to get source argument in format "[1.3,2.4,...,N.M]", but got (1.1,2.2,3.5)`:      "(1.1,2.2,3.5)",
	}

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

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