diff options
author | EuAndreh <eu@euandre.org> | 2024-10-19 18:11:33 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-10-20 03:27:09 -0300 |
commit | 149d33fa6adb9be835d1c1404346d82124dda454 (patch) | |
tree | d9c12a2d10ef32098cfb4485801446501797d0c4 /tests/functional/string-round-trip | |
parent | src/guuid.go: Remove NewBytes() (diff) | |
download | uuid-149d33fa6adb9be835d1c1404346d82124dda454.tar.gz uuid-149d33fa6adb9be835d1c1404346d82124dda454.tar.xz |
Setup conventional functional tests, fuzz targets and benchmarks
Diffstat (limited to 'tests/functional/string-round-trip')
-rw-r--r-- | tests/functional/string-round-trip/guuid.go | 62 | ||||
l--------- | tests/functional/string-round-trip/main.go | 1 |
2 files changed, 63 insertions, 0 deletions
diff --git a/tests/functional/string-round-trip/guuid.go b/tests/functional/string-round-trip/guuid.go new file mode 100644 index 0000000..764576e --- /dev/null +++ b/tests/functional/string-round-trip/guuid.go @@ -0,0 +1,62 @@ +package guuid + +import ( + "fmt" + "os" + "reflect" +) + + + +func showColour() bool { + return os.Getenv("NO_COLOUR") == "" +} + +func testing(message string, body func()) { + if showColour() { + fmt.Fprintf( + os.Stderr, + "\033[0;33mtesting\033[0m: %s... ", + message, + ) + body() + fmt.Fprintf(os.Stderr, "\033[0;32mOK\033[0m.\n") + } else { + fmt.Fprintf(os.Stderr, "testing: %s... ", message) + body() + fmt.Fprintf(os.Stderr, "OK.\n") + } +} + +func assertEq(given any, expected any) { + if !reflect.DeepEqual(given, expected) { + if showColour() { + fmt.Fprintf(os.Stderr, "\033[0;31mERR\033[0m.\n") + } else { + fmt.Fprintf(os.Stderr, "ERR.\n") + } + fmt.Fprintf(os.Stderr, "given != expected\n") + fmt.Fprintf(os.Stderr, "given: %#v\n", given) + fmt.Fprintf(os.Stderr, "expected: %#v\n", expected) + os.Exit(1) + } +} + + + +func MainTest() { + testing("string is the same after round-trip", func() { + str1 := New().String() + id, err := FromString(str1) + assertEq(err, nil) + str2 := id.String() + assertEq(str1, str2) + }) + + testing("UUID is the same after round-trip", func() { + id1 := New() + id2, err := FromString(id1.String()) + assertEq(err, nil) + assertEq(id1, id2) + }) +} diff --git a/tests/functional/string-round-trip/main.go b/tests/functional/string-round-trip/main.go new file mode 120000 index 0000000..f67563d --- /dev/null +++ b/tests/functional/string-round-trip/main.go @@ -0,0 +1 @@ +../../main.go
\ No newline at end of file |