2015-01-22 14:17:02 +08:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-02-12 21:34:00 +08:00
|
|
|
"strings"
|
2015-01-22 14:17:02 +08:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestReadlines(t *testing.T) {
|
|
|
|
ret, err := ReadLines("common_test.go")
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2015-02-12 21:34:00 +08:00
|
|
|
if !strings.Contains(ret[0], "package common") {
|
2015-01-22 14:17:02 +08:00
|
|
|
t.Error("could not read correctly")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReadLinesOffsetN(t *testing.T) {
|
|
|
|
ret, err := ReadLinesOffsetN("common_test.go", 2, 1)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
fmt.Println(ret[0])
|
2015-02-12 21:34:00 +08:00
|
|
|
if !strings.Contains(ret[0], `import (`) {
|
2015-01-22 14:17:02 +08:00
|
|
|
t.Error("could not read correctly")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIntToString(t *testing.T) {
|
|
|
|
src := []int8{65, 66, 67}
|
|
|
|
dst := IntToString(src)
|
|
|
|
if dst != "ABC" {
|
|
|
|
t.Error("could not convert")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func TestByteToString(t *testing.T) {
|
|
|
|
src := []byte{65, 66, 67}
|
|
|
|
dst := ByteToString(src)
|
|
|
|
if dst != "ABC" {
|
|
|
|
t.Error("could not convert")
|
|
|
|
}
|
|
|
|
|
|
|
|
src = []byte{0, 65, 66, 67}
|
|
|
|
dst = ByteToString(src)
|
|
|
|
if dst != "ABC" {
|
|
|
|
t.Error("could not convert")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestmustParseInt32(t *testing.T) {
|
|
|
|
ret := mustParseInt32("11111")
|
|
|
|
if ret != int32(11111) {
|
|
|
|
t.Error("could not parse")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func TestmustParseUint64(t *testing.T) {
|
|
|
|
ret := mustParseUint64("11111")
|
|
|
|
if ret != uint64(11111) {
|
|
|
|
t.Error("could not parse")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func TestmustParseFloat64(t *testing.T) {
|
|
|
|
ret := mustParseFloat64("11111.11")
|
|
|
|
if ret != float64(11111.11) {
|
|
|
|
t.Error("could not parse")
|
|
|
|
}
|
|
|
|
ret = mustParseFloat64("11111")
|
|
|
|
if ret != float64(11111) {
|
|
|
|
t.Error("could not parse")
|
|
|
|
}
|
|
|
|
}
|
2015-07-21 14:25:04 +08:00
|
|
|
func TestStringsContains(t *testing.T) {
|
2015-01-22 14:17:02 +08:00
|
|
|
target, err := ReadLines("common_test.go")
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2015-07-21 14:25:04 +08:00
|
|
|
if !StringsContains(target, "func TestStringsContains(t *testing.T) {") {
|
2015-01-22 14:17:02 +08:00
|
|
|
t.Error("cloud not test correctly")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPathExists(t *testing.T) {
|
|
|
|
if !PathExists("common_test.go") {
|
|
|
|
t.Error("exists but return not exists")
|
|
|
|
}
|
|
|
|
if PathExists("should_not_exists.go") {
|
|
|
|
t.Error("not exists but return exists")
|
|
|
|
}
|
|
|
|
}
|
2016-03-13 22:42:06 +08:00
|
|
|
|
|
|
|
func TestHostEtc(t *testing.T) {
|
|
|
|
p := HostEtc("mtab")
|
|
|
|
if p != "/etc/mtab" {
|
|
|
|
t.Errorf("invalid HostEtc, %s", p)
|
|
|
|
}
|
|
|
|
}
|