예제 #1
0
/////////////////////////////// Slice
func TestSlice(t *testing.T) {
	fn := func(val interface{}, result []interface{}) {
		ret, err := Slice(val)
		assert.Nil(t, err)
		assert.Equal(t, ret, result)
	}

	fn("123", []interface{}{int32(49), int32(50), int32(51)})
	fn([]int{1, 2, 3}, []interface{}{int(1), int(2), int(3)})
	fn([]string{"1", "ss"}, []interface{}{"1", "ss"})
}
예제 #2
0
func TestMap(t *testing.T) {
	fn := func(val interface{}, result map[string]interface{}) {
		ret, err := Map(val)
		assert.Nil(t, err)
		assert.Equal(t, ret, result)
	}

	fn(map[string]interface{}{"1": 1, "2": 3}, map[string]interface{}{"1": 1, "2": 3})
	obj := &test1{5, "admin", "abc"}
	fn(obj, map[string]interface{}{"Id": 5, "Name": "admin"})

}
예제 #3
0
//////////////////////////////// Bytes
func TestBytes(t *testing.T) {
	fn := func(val interface{}, result []byte) {
		ret, err := Bytes(val)
		assert.Nil(t, err)
		assert.Equal(t, ret, result)
	}

	fn(11, []byte{49, 49})
	fn("1.11", []byte{49, 46, 49, 49})
	fn(-1.11, []byte{45, 49, 46, 49, 49, 48, 48, 48})
	fn(0, []byte{48})
}
예제 #4
0
func TestSessionID(t *testing.T) {
	m := make(map[string]interface{}, 0)

	// 随机产生几个字符串,看是否有可能重复
	for i := 0; i < 10000; i++ {
		sid, err := sessionID()
		assert.Nil(t, err)
		//assert.Equal(t, len(sid), sessionIDLen)

		_, found := m[sid]
		assert.False(t, found)

		m[sid] = nil
	}
}
예제 #5
0
////////////////////////////////// String
func TestString(t *testing.T) {
	fn := func(val interface{}, result string) {
		ret, err := String(val)
		assert.Nil(t, err)
		assert.Equal(t, ret, result)
	}

	fn(5, "5")
	fn(int32(5), "5")
	fn(uint(0), "0")
	fn(1.32, "1.32")
	fn("0.00", "0.00")
	fn(-1.1, "-1.1")
	fn(1.0, "1")
}
예제 #6
0
////////////////////////////////// Uint64
func TestFloat32(t *testing.T) {
	fn := func(val interface{}, result float32) {
		ret, err := Float32(val)
		assert.Nil(t, err)
		assert.Equal(t, ret, result)
	}

	fn(5, 5)
	fn(int32(5), 5)
	fn(uint(0), 0)
	fn(1.32, 1.32)
	fn("0.00", 0)
	fn("1.1", 1.1)
	fn("123", 123)
}
예제 #7
0
////////////////////////////////// Uint64
func TestUint64(t *testing.T) {
	fn := func(val interface{}, result uint64) {
		ret, err := Uint64(val)
		assert.Nil(t, err)
		assert.Equal(t, ret, result)
	}

	fn(5, 5)
	fn(int32(5), 5)
	fn(uint(0), 0)
	fn(1.32, 1)
	fn(0.00, 0)
	fn("1.1", 1)
	fn("123", 123)
}
예제 #8
0
////////////////////////////////// Int64
func TestInt64(t *testing.T) {
	fn := func(val interface{}, result int64) {
		ret, err := Int64(val)
		assert.Nil(t, err)
		assert.Equal(t, ret, result)
	}

	fn(5, 5)
	fn(int(-11), -11)
	fn(int32(5), 5)
	fn(uint(3), 3)
	fn(uint64(0), 0)
	fn(1.32, 1)
	fn(0.00, 0)
	fn(-1.3, -1)
	fn("-1.1", -1)
	fn("123", 123)
}
예제 #9
0
/////////////////////////// Bool
func TestBool(t *testing.T) {
	fn := func(val interface{}, result bool) {
		ret, err := Bool(val)
		assert.Equal(t, ret, result)
		assert.Nil(t, err)
	}

	fn(5, true)
	fn(int64(-11), true)
	fn(int32(5), true)
	fn(uint(3), true)
	fn(uint64(0), false)
	fn(1.32, true)
	fn(0.00, false)
	fn("off", false)
	fn("true", true)
	fn(-1.3, true)
}