Skip to content

Commit

Permalink
engine: util: Add more cmp utility functions
Browse files Browse the repository at this point in the history
  • Loading branch information
purpleidea committed Nov 7, 2024
1 parent 098ab20 commit 83fd8b7
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions engine/util/cmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ import (
"fmt"
)

// StrPtrCmp compares two pointers to strings. If they aren't both nil or aren't
// both of the same value, then this errors.
func StrPtrCmp(x, y *string) error {
if (x == nil) != (y == nil) { // xor
return fmt.Errorf("the Content differs")
}
if x != nil && y != nil {
if *x != *y { // compare the strings
return fmt.Errorf("the contents of ptr differ")
}
}
return nil
}

// StrListCmp compares two lists of strings. If they are not the same length or
// do not contain identical strings in the same order, then this errors.
func StrListCmp(x, y []string) error {
Expand Down

0 comments on commit 83fd8b7

Please sign in to comment.