Пример #1
0
func TestGOPATH(t *testing.T) {

	pack := assert.Pack

	assert.HasError(t, pack(getGOPATH("")))
	assert.HasError(t, pack(getGOPATH("/")))
	assert.HasError(t, pack(getGOPATH("c:/home/lmw")))

	assert.Equal(t, pack(getGOPATH("/home/lmw/src/test/wibble")), pack("/home/lmw", nil))
	assert.Equal(t, pack(getGOPATH("/home/lmw/src/src")), pack("/home/lmw/src", nil))

	assert.Equal(t, pack(getGOPATH("c:/home/lmw/src/test/wibble")), pack("c:/home/lmw", nil))
}
Пример #2
0
func TestPkgHash(t *testing.T) {
	h1 := generatePackageHash("github.com/user/name")
	h2 := generatePackageHash("github.com/user/name")
	h3 := generatePackageHash("github.com/user/namex")

	assert.Equal(t, h1, h2)
	assert.NotEqual(t, h2, h3)
}
Пример #3
0
func TestThrow(t *testing.T) {
	extype, finallyCalled := testEx1(func() { Throw(5) })
	assert.Equal(t, extype, reflect.TypeOf(5))
	assert.True(t, finallyCalled)

	extype, finallyCalled = testEx1(func() { Throw("bang") })
	assert.Equal(t, extype, reflect.TypeOf("bang"))
	assert.True(t, finallyCalled)

	extype, finallyCalled = testEx1(func() { Throw(errors.New("bang")) })
	assert.Equal(t, extype, errorType)
	assert.True(t, finallyCalled)

	extype, finallyCalled = testEx1(func() {})
	assert.Nil(t, extype)
	assert.True(t, finallyCalled)

	assert.MustPanic(t, func(t *testing.T) {
		testEx1(func() {
			Throw(empty{})
		})
	})

	assert.MustPanic(t, func(t *testing.T) {
		Try(func() {
		}).Catch(func(e int) {
		}).Finally(func() {
			Throw("asdf")
		})
	})

	Try(func() {
		Throw(5)
	}).Catch(func(e int, e2 int) {
		assert.True(t, false) // should not get here
	}).Catch(func(e int) {
	}).Finally(func() {
	})
}
Пример #4
0
func TestMinMax(t *testing.T) {
	assert.Equal(t, min(1, 2), 1)
	assert.Equal(t, min(2, 1), 1)
	assert.Equal(t, min(1, 1), 1)
	assert.Equal(t, max(1, 2), 2)
	assert.Equal(t, max(2, 1), 2)
	assert.Equal(t, max(2, 2), 2)
}
Пример #5
0
func TestCoord(t *testing.T) {
	c := Vec{10, 20}
	c.Add(Vec{1, 1})
	assert.Equal(t, c, Vec{11, 21})
}