moved a subset of source file to the kern package
This commit is contained in:
+21
-19
@@ -8,6 +8,8 @@ import (
|
||||
"errors"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"git.portale-stac.it/go-pkg/expr/kern"
|
||||
)
|
||||
|
||||
func TestIsString(t *testing.T) {
|
||||
@@ -16,7 +18,7 @@ func TestIsString(t *testing.T) {
|
||||
failed := 0
|
||||
|
||||
count++
|
||||
if !IsBool(true) {
|
||||
if !kern.IsBool(true) {
|
||||
t.Errorf("%d: IsBool(true) -> result = false, want true", count)
|
||||
failed++
|
||||
} else {
|
||||
@@ -24,7 +26,7 @@ func TestIsString(t *testing.T) {
|
||||
}
|
||||
|
||||
count++
|
||||
if !IsString("abc") {
|
||||
if !kern.IsString("abc") {
|
||||
t.Errorf("%d: IsString(\"abc\") -> result = false, want true", count)
|
||||
failed++
|
||||
} else {
|
||||
@@ -32,7 +34,7 @@ func TestIsString(t *testing.T) {
|
||||
}
|
||||
|
||||
count++
|
||||
if !IsInteger(int64(123)) {
|
||||
if !kern.IsInteger(int64(123)) {
|
||||
t.Errorf("%d: IsInteger(123) -> result = false, want true", count)
|
||||
failed++
|
||||
} else {
|
||||
@@ -40,7 +42,7 @@ func TestIsString(t *testing.T) {
|
||||
}
|
||||
|
||||
count++
|
||||
if !IsFloat(1.23) {
|
||||
if !kern.IsFloat(1.23) {
|
||||
t.Errorf("%d: IsFloat(1.23) -> result = false, want true", count)
|
||||
failed++
|
||||
} else {
|
||||
@@ -48,7 +50,7 @@ func TestIsString(t *testing.T) {
|
||||
}
|
||||
|
||||
count++
|
||||
if !IsFloat(numAsFloat(123)) {
|
||||
if !kern.IsFloat(kern.NumAsFloat(123)) {
|
||||
t.Errorf("%d: IsFloat(numAsFloat(123)) -> result = false, want true", count)
|
||||
failed++
|
||||
} else {
|
||||
@@ -56,7 +58,7 @@ func TestIsString(t *testing.T) {
|
||||
}
|
||||
|
||||
count++
|
||||
if isIterator("fake") {
|
||||
if kern.IsIterator("fake") {
|
||||
t.Errorf(`%d: isIterator("fake") -> result = true, want false`, count)
|
||||
failed++
|
||||
} else {
|
||||
@@ -64,7 +66,7 @@ func TestIsString(t *testing.T) {
|
||||
}
|
||||
|
||||
count++
|
||||
b, ok := ToBool(true)
|
||||
b, ok := kern.ToBool(true)
|
||||
if !(ok && b) {
|
||||
t.Errorf("%d: toBool(true) b=%v, ok=%v -> result = false, want true", count, b, ok)
|
||||
failed++
|
||||
@@ -73,7 +75,7 @@ func TestIsString(t *testing.T) {
|
||||
}
|
||||
|
||||
count++
|
||||
b, ok = ToBool("abc")
|
||||
b, ok = kern.ToBool("abc")
|
||||
if !(ok && b) {
|
||||
t.Errorf("%d: toBool(\"abc\") b=%v, ok=%v -> result = false, want true", count, b, ok)
|
||||
failed++
|
||||
@@ -82,7 +84,7 @@ func TestIsString(t *testing.T) {
|
||||
}
|
||||
|
||||
count++
|
||||
b, ok = ToBool([]int{})
|
||||
b, ok = kern.ToBool([]int{})
|
||||
if ok {
|
||||
t.Errorf("%d: toBool([]) b=%v, ok=%v -> result = true, want false", count, b, ok)
|
||||
failed++
|
||||
@@ -98,7 +100,7 @@ func TestToIntOk(t *testing.T) {
|
||||
wantValue := int(64)
|
||||
wantErr := error(nil)
|
||||
|
||||
gotValue, gotErr := ToGoInt(source, "test")
|
||||
gotValue, gotErr := kern.ToGoInt(source, "test")
|
||||
|
||||
if gotErr != nil || gotValue != wantValue {
|
||||
t.Errorf("toInt(%v, \"test\") gotValue=%v, gotErr=%v -> wantValue=%v, wantErr=%v",
|
||||
@@ -111,7 +113,7 @@ func TestToIntErr(t *testing.T) {
|
||||
wantValue := 0
|
||||
wantErr := errors.New(`test expected integer, got uint64 (64)`)
|
||||
|
||||
gotValue, gotErr := ToGoInt(source, "test")
|
||||
gotValue, gotErr := kern.ToGoInt(source, "test")
|
||||
|
||||
if gotErr.Error() != wantErr.Error() || gotValue != wantValue {
|
||||
t.Errorf("toInt(%v, \"test\") gotValue=%v, gotErr=%v -> wantValue=%v, wantErr=%v",
|
||||
@@ -144,7 +146,7 @@ func TestAnyInteger(t *testing.T) {
|
||||
failed := 0
|
||||
|
||||
for i, input := range inputs {
|
||||
gotValue, gotOk := anyInteger(input.source)
|
||||
gotValue, gotOk := kern.AnyInteger(input.source)
|
||||
if gotOk != input.wantOk || gotValue != input.wantValue {
|
||||
t.Errorf("%d: anyInteger(%v) -> gotOk = %t, wantOk = %t; gotValue = %v, wantValue = %v",
|
||||
i+1, input.source, gotOk, input.wantOk, gotValue, input.wantValue)
|
||||
@@ -159,7 +161,7 @@ func TestAnyInteger(t *testing.T) {
|
||||
func TestCopyMap(t *testing.T) {
|
||||
source := map[string]int{"one": 1, "two": 2, "three": 3}
|
||||
dest := make(map[string]int)
|
||||
result := CopyMap(dest, source)
|
||||
result := kern.CopyMap(dest, source)
|
||||
if !reflect.DeepEqual(result, source) {
|
||||
t.Errorf("utils.CopyMap() failed")
|
||||
}
|
||||
@@ -170,7 +172,7 @@ func TestToStringOk(t *testing.T) {
|
||||
wantValue := "ciao"
|
||||
wantErr := error(nil)
|
||||
|
||||
gotValue, gotErr := ToGoString(source, "test")
|
||||
gotValue, gotErr := kern.ToGoString(source, "test")
|
||||
|
||||
if gotErr != nil {
|
||||
t.Error(gotErr)
|
||||
@@ -181,11 +183,11 @@ func TestToStringOk(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestToStringErr(t *testing.T) {
|
||||
source := newListA()
|
||||
source := kern.NewListA()
|
||||
wantValue := ""
|
||||
wantErr := errors.New(`test expected string, got list ([])`)
|
||||
|
||||
gotValue, gotErr := ToGoString(source, "test")
|
||||
gotValue, gotErr := kern.ToGoString(source, "test")
|
||||
|
||||
if gotErr != nil && gotErr.Error() != wantErr.Error() {
|
||||
t.Errorf(`ToGoString(%v, "test") gotValue=%q, gotErr=%v -> wantValue=%q, wantErr=%v`,
|
||||
@@ -197,15 +199,15 @@ func TestToStringErr(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIsFunctorSucc(t *testing.T) {
|
||||
f := NewGolangFunctor(isNilFunc)
|
||||
if !isFunctor(f) {
|
||||
f := kern.NewGolangFunctor(isNilFunc)
|
||||
if !kern.IsFunctor(f) {
|
||||
t.Errorf("isNilFunc() evalued as not a functor")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsFunctorFail(t *testing.T) {
|
||||
f := int64(1)
|
||||
if isFunctor(f) {
|
||||
if kern.IsFunctor(f) {
|
||||
t.Errorf("int evalued as a functor")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user