Skip to content

Commit

Permalink
write unit test for field format method
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsoftware committed Jul 1, 2024
1 parent 9b6157e commit 3b41439
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package errors_test

import (
"fmt"
"testing"

"github.com/mrsoftware/errors"
Expand Down Expand Up @@ -42,3 +43,37 @@ func TestFindFieldInChain(t *testing.T) {
assert.Equal(t, field2, errors.FindFieldInChain("field2", err4))
assert.Equal(t, field1, errors.FindFieldInChain("field1", err1))
}

func TestField_Format(t *testing.T) {
t.Parallel()

t.Run("format q", func(t *testing.T) {
field := errors.String("username", "mrsoftware")

assert.Equal(t, "\"mrsoftware\"", fmt.Sprintf("%q", field))
})

t.Run("format s", func(t *testing.T) {
field := errors.String("username", "mrsoftware")

assert.Equal(t, "[username: mrsoftware]", fmt.Sprintf("%s", field))
})

t.Run("format v", func(t *testing.T) {
field := errors.String("username", "mrsoftware")

assert.Equal(t, "{Key: username, Value: mrsoftware}", fmt.Sprintf("%v", field))
})

t.Run("format +v", func(t *testing.T) {
field := errors.String("username", "mrsoftware")

assert.Equal(t, "{Key: username, Type: String, Value: mrsoftware}", fmt.Sprintf("%+v", field))
})

t.Run("format #v", func(t *testing.T) {
field := errors.String("username", "mrsoftware")

assert.Equal(t, "{username: \"mrsoftware\"}", fmt.Sprintf("%#v", field))
})
}

0 comments on commit 3b41439

Please sign in to comment.