예제 #1
0
파일: number_test.go 프로젝트: vpol/govalid
func TestNumber(t *testing.T) {
	var np *int
	var nnp int = 3

	test(t, "basic number", true, v.Number(), 3)
	test(t, "non-number", false, v.Number(), "")
	test(t, "nil", false, v.Number(), nil)
	test(t, "nil int pointer", false, v.Number(), np)
	test(t, "int pointer", true, v.Number(), &nnp)

	test(t, "numis", true, v.Number(v.NumIs(3)), 3)
	test(t, "!numis", false, v.Number(v.NumIs(3)), 2)

	test(t, "minlen1", false, v.Number(v.NumMin(3)), 2)
	test(t, "minlen2", true, v.Number(v.NumMin(3)), 3)
	test(t, "minlen2", true, v.Number(v.NumMin(3)), 4)

	test(t, "maxlen1", true, v.Number(v.NumMax(3)), 2)
	test(t, "maxlen2", true, v.Number(v.NumMax(3)), 3)
	test(t, "maxlen3", false, v.Number(v.NumMax(3)), 4)

	test(t, "combination1", false, v.Number(v.NumMin(3), v.NumMax(3)), 2)
	test(t, "combination2", true, v.Number(v.NumMin(3), v.NumMax(3)), 3)
	test(t, "combination3", false, v.Number(v.NumMin(3), v.NumMax(3)), 4)
}
예제 #2
0
파일: object_test.go 프로젝트: vpol/govalid
func testObjKVs(t *testing.T) {
	counter, countingValidator := createCountingValidator()

	sch := v.Object(
		v.ObjKV(nil, v.And(v.String(v.StrIs("1")), v.Function(countingValidator))),
		v.ObjKV("1", v.And(v.String(v.StrIs("b")), v.Function(countingValidator))),
		v.ObjKV(true, v.And(v.Number(v.NumIs(3)), v.Function(countingValidator))),
	)
	m := maep{
		nil:  "1",
		"1":  "b",
		true: 3,
	}
	test(t, "mixed objkvs", true, sch, m)
	if *counter != 3 {
		t.Fatalf("value counter should be 3, got %d", *counter)
	}

	m = maep{
		nil:  "1",
		"1":  2,
		true: 3,
	}
	test(t, "!mixed objkvs", false, sch, m)

	m = maep{
		nil:  "1",
		"1":  nil,
		true: 3,
	}
	test(t, "!mixed objkvs (nil)", false, sch, m)
}