Example #1
0
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)
}
Example #2
0
func TestAnd(t *testing.T) {
	test(t, "combination1", true, v.And(), nil)

	test(t, "combination2", false, v.And(v.String(v.StrMin(3)), v.String(v.StrMax(3))), "aa")
	test(t, "combination3", true, v.And(v.String(v.StrMin(3)), v.String(v.StrMax(3))), "aaa")
	test(t, "combination4", false, v.And(v.String(v.StrMin(3)), v.String(v.StrMax(3))), "aaaa")

	test(t, "combination5", false, v.And(v.String(v.StrMin(3)), v.String(v.StrMax(4))), "bb")
	test(t, "combination6", true, v.And(v.String(v.StrMin(3)), v.String(v.StrMax(4))), "bbb")
	test(t, "combination7", true, v.And(v.String(v.StrMin(3)), v.String(v.StrMax(4))), "bbbb")
	test(t, "combination8", false, v.And(v.String(v.StrMin(3)), v.String(v.StrMax(4))), "bbbbb")
}