refactored data-types to reduce plugin sizes

This commit is contained in:
2026-06-08 07:02:56 +02:00
parent fec7cc546c
commit b6da9bcad4
90 changed files with 1039 additions and 803 deletions
+23 -18
View File
@@ -10,6 +10,11 @@ import (
"testing"
"git.portale-stac.it/go-pkg/expr/kern"
"git.portale-stac.it/go-pkg/expr/types"
"git.portale-stac.it/go-pkg/expr/types/array"
"git.portale-stac.it/go-pkg/expr/types/boolean"
"git.portale-stac.it/go-pkg/expr/types/float"
"git.portale-stac.it/go-pkg/expr/types/str"
"git.portale-stac.it/go-pkg/expr/util"
)
@@ -19,7 +24,7 @@ func TestIsString(t *testing.T) {
failed := 0
count++
if !kern.IsBool(true) {
if !boolean.IsBool(true) {
t.Errorf("%d: IsBool(true) -> result = false, want true", count)
failed++
} else {
@@ -27,7 +32,7 @@ func TestIsString(t *testing.T) {
}
count++
if !kern.IsString("abc") {
if !str.IsString("abc") {
t.Errorf("%d: IsString(\"abc\") -> result = false, want true", count)
failed++
} else {
@@ -35,7 +40,7 @@ func TestIsString(t *testing.T) {
}
count++
if !kern.IsInteger(int64(123)) {
if !types.IsInteger(int64(123)) {
t.Errorf("%d: IsInteger(123) -> result = false, want true", count)
failed++
} else {
@@ -43,7 +48,7 @@ func TestIsString(t *testing.T) {
}
count++
if !kern.IsFloat(1.23) {
if !float.IsFloat(1.23) {
t.Errorf("%d: IsFloat(1.23) -> result = false, want true", count)
failed++
} else {
@@ -51,7 +56,7 @@ func TestIsString(t *testing.T) {
}
count++
if !kern.IsFloat(kern.NumAsFloat(123)) {
if !float.IsFloat(types.NumAsFloat(123)) {
t.Errorf("%d: IsFloat(numAsFloat(123)) -> result = false, want true", count)
failed++
} else {
@@ -60,14 +65,14 @@ func TestIsString(t *testing.T) {
count++
if kern.IsIterator("fake") {
t.Errorf(`%d: isIterator("fake") -> result = true, want false`, count)
t.Errorf(`%d: IsIterator("fake") -> result = true, want false`, count)
failed++
} else {
succeeded++
}
count++
b, ok := kern.ToBool(true)
b, ok := boolean.ToBool(true)
if !(ok && b) {
t.Errorf("%d: toBool(true) b=%v, ok=%v -> result = false, want true", count, b, ok)
failed++
@@ -76,7 +81,7 @@ func TestIsString(t *testing.T) {
}
count++
b, ok = kern.ToBool("abc")
b, ok = boolean.ToBool("abc")
if !(ok && b) {
t.Errorf("%d: toBool(\"abc\") b=%v, ok=%v -> result = false, want true", count, b, ok)
failed++
@@ -85,7 +90,7 @@ func TestIsString(t *testing.T) {
}
count++
b, ok = kern.ToBool([]int{})
b, ok = boolean.ToBool([]int{})
if ok {
t.Errorf("%d: toBool([]) b=%v, ok=%v -> result = true, want false", count, b, ok)
failed++
@@ -101,7 +106,7 @@ func TestToIntOk(t *testing.T) {
wantValue := int(64)
wantErr := error(nil)
gotValue, gotErr := kern.ToGoInt(source, "test")
gotValue, gotErr := types.ToGoInt(source, "test")
if gotErr != nil || gotValue != wantValue {
t.Errorf("toInt(%v, \"test\") gotValue=%v, gotErr=%v -> wantValue=%v, wantErr=%v",
@@ -114,7 +119,7 @@ func TestToIntErr(t *testing.T) {
wantValue := 0
wantErr := errors.New(`test expected integer, got uint64 (64)`)
gotValue, gotErr := kern.ToGoInt(source, "test")
gotValue, gotErr := types.ToGoInt(source, "test")
if gotErr.Error() != wantErr.Error() || gotValue != wantValue {
t.Errorf("toInt(%v, \"test\") gotValue=%v, gotErr=%v -> wantValue=%v, wantErr=%v",
@@ -127,7 +132,7 @@ func TestToInt64Ok(t *testing.T) {
wantValue := int64(64)
wantErr := error(nil)
gotValue, gotErr := kern.ToGoInt64(source, "test")
gotValue, gotErr := types.ToGoInt64(source, "test")
if gotErr != nil || gotValue != wantValue {
t.Errorf("toInt64(%v, \"test\") gotValue=%v, gotErr=%v -> wantValue=%v, wantErr=%v",
@@ -140,7 +145,7 @@ func TestToInt64Err(t *testing.T) {
wantValue := int64(0)
wantErr := errors.New(`test expected integer, got uint64 (64)`)
gotValue, gotErr := kern.ToGoInt64(source, "test")
gotValue, gotErr := types.ToGoInt64(source, "test")
if gotErr.Error() != wantErr.Error() || gotValue != wantValue {
t.Errorf("toInt64(%v, \"test\") gotValue=%v, gotErr=%v -> wantValue=%v, wantErr=%v",
@@ -173,7 +178,7 @@ func TestAnyInteger(t *testing.T) {
failed := 0
for i, input := range inputs {
gotValue, gotOk := kern.AnyInteger(input.source)
gotValue, gotOk := types.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)
@@ -199,7 +204,7 @@ func TestToStringOk(t *testing.T) {
wantValue := "ciao"
wantErr := error(nil)
gotValue, gotErr := kern.ToGoString(source, "test")
gotValue, gotErr := str.ToGoString(source, "test")
if gotErr != nil {
t.Error(gotErr)
@@ -210,11 +215,11 @@ func TestToStringOk(t *testing.T) {
}
func TestToStringErr(t *testing.T) {
source := kern.NewListA()
source := array.NewListA()
wantValue := ""
wantErr := errors.New(`test expected string, got list ([])`)
wantErr := errors.New(`test expected string, got array ([])`)
gotValue, gotErr := kern.ToGoString(source, "test")
gotValue, gotErr := str.ToGoString(source, "test")
if gotErr != nil && gotErr.Error() != wantErr.Error() {
t.Errorf(`ToGoString(%v, "test") gotValue=%q, gotErr=%v -> wantValue=%q, wantErr=%v`,