package orm import "testing" func TestSanitizeFieldValueBoolFalse(t *testing.T) { // false for boolean field should stay false f := &Field{Type: TypeBoolean} got := sanitizeFieldValue(f, false) if got != false { t.Errorf("expected false, got %v", got) } } func TestSanitizeFieldValueBoolTrue(t *testing.T) { f := &Field{Type: TypeBoolean} got := sanitizeFieldValue(f, true) if got != true { t.Errorf("expected true, got %v", got) } } func TestSanitizeFieldValueCharFalse(t *testing.T) { // false for char field should become nil f := &Field{Type: TypeChar} got := sanitizeFieldValue(f, false) if got != nil { t.Errorf("expected nil, got %v", got) } } func TestSanitizeFieldValueIntFalse(t *testing.T) { f := &Field{Type: TypeInteger} got := sanitizeFieldValue(f, false) if got != nil { t.Errorf("expected nil, got %v", got) } } func TestSanitizeFieldValueFloatFalse(t *testing.T) { f := &Field{Type: TypeFloat} got := sanitizeFieldValue(f, false) if got != nil { t.Errorf("expected nil, got %v", got) } } func TestSanitizeFieldValueM2OFalse(t *testing.T) { f := &Field{Type: TypeMany2one} got := sanitizeFieldValue(f, false) if got != nil { t.Errorf("expected nil, got %v", got) } } func TestSanitizeFieldValueDateFalse(t *testing.T) { f := &Field{Type: TypeDate} got := sanitizeFieldValue(f, false) if got != nil { t.Errorf("expected nil, got %v", got) } } func TestSanitizeFieldValueFloat64ToInt(t *testing.T) { f := &Field{Type: TypeInteger} got := sanitizeFieldValue(f, float64(42)) if got != int64(42) { t.Errorf("expected int64(42), got %T %v", got, got) } } func TestSanitizeFieldValueM2OFloat(t *testing.T) { f := &Field{Type: TypeMany2one} got := sanitizeFieldValue(f, float64(5)) if got != int64(5) { t.Errorf("expected int64(5), got %T %v", got, got) } } func TestSanitizeFieldValueNil(t *testing.T) { f := &Field{Type: TypeChar} got := sanitizeFieldValue(f, nil) if got != nil { t.Errorf("expected nil, got %v", got) } } func TestSanitizeFieldValuePassthrough(t *testing.T) { f := &Field{Type: TypeChar} got := sanitizeFieldValue(f, "hello") if got != "hello" { t.Errorf("expected hello, got %v", got) } } func TestSanitizeFieldValueIntPassthrough(t *testing.T) { f := &Field{Type: TypeInteger} got := sanitizeFieldValue(f, int64(99)) if got != int64(99) { t.Errorf("expected int64(99), got %T %v", got, got) } } func TestSanitizeFieldValueFloatPassthrough(t *testing.T) { f := &Field{Type: TypeFloat} got := sanitizeFieldValue(f, float64(3.14)) if got != float64(3.14) { t.Errorf("expected 3.14, got %v", got) } }