Files
masonry/lang/test_field_comparisons.go

70 lines
1.6 KiB
Go

package lang
// Field and validation comparison functions for parser tests
func fieldEqual(got, want Field) bool {
if got.Name != want.Name || got.Type != want.Type {
return false
}
if got.Required != want.Required || got.Unique != want.Unique || got.Index != want.Index {
return false
}
if !stringPtrEqual(got.Default, want.Default) {
return false
}
if len(got.Validations) != len(want.Validations) {
return false
}
for i, validation := range got.Validations {
if !validationEqual(validation, want.Validations[i]) {
return false
}
}
if (got.Relationship == nil) != (want.Relationship == nil) {
return false
}
if got.Relationship != nil && want.Relationship != nil {
if !relationshipEqual(*got.Relationship, *want.Relationship) {
return false
}
}
return true
}
func validationEqual(got, want Validation) bool {
return got.Type == want.Type && stringPtrEqual(got.Value, want.Value)
}
func relationshipEqual(got, want Relationship) bool {
return got.Type == want.Type &&
got.Cardinality == want.Cardinality &&
stringPtrEqual(got.ForeignKey, want.ForeignKey) &&
stringPtrEqual(got.Through, want.Through)
}
func fieldRelationEqual(got, want *FieldRelation) bool {
if (got == nil) != (want == nil) {
return false
}
if got != nil && want != nil {
return got.Type == want.Type
}
return true
}
func componentValidationEqual(got, want *ComponentValidation) bool {
if (got == nil) != (want == nil) {
return false
}
if got != nil && want != nil {
return got.Type == want.Type && stringPtrEqual(got.Value, want.Value)
}
return true
}