update jstring test
This commit is contained in:
@@ -12,6 +12,7 @@ func Equal(t *testing.T, expected any, actual any, msgAndArgs ...any) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
t.Errorf("not equal expect:%v actual:%v", expected, actual)
|
||||
t.Error(msgAndArgs...)
|
||||
|
||||
return false
|
||||
|
||||
@@ -37,7 +37,7 @@ func ErrorIs(t *testing.T, err, ex error, msgAndArgs ...any) {
|
||||
func ErrorIsf(t *testing.T, err, ex error, msg string, args ...any) {
|
||||
t.Helper()
|
||||
|
||||
if !errors.Is(ex, err) {
|
||||
if !errors.Is(err, ex) {
|
||||
t.Errorf(msg, args...)
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package value_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -10,7 +11,7 @@ import (
|
||||
"gitoa.ru/go-4devs/config/value"
|
||||
)
|
||||
|
||||
func TestStringDuration(t *testing.T) {
|
||||
func TestJStringDuration(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := map[string]struct {
|
||||
@@ -31,7 +32,47 @@ func TestStringDuration(t *testing.T) {
|
||||
for name, data := range tests {
|
||||
require.Equal(t, data.exp, data.raw.Duration(), name)
|
||||
d, err := data.raw.ParseDuration()
|
||||
require.Truef(t, errors.Is(err, data.err), "%[1]s: expect:%#[2]v, got:%#[3]v", name, data.err, err)
|
||||
require.ErrorIsf(t, err, data.err, "%[1]s: expect:%#[2]v, got:%#[3]v", name, data.err, err)
|
||||
require.Equal(t, data.exp, d, name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestJStringInt(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := map[string]struct {
|
||||
raw value.JString
|
||||
exp int
|
||||
err error
|
||||
}{
|
||||
"empty": {
|
||||
raw: value.JString(strconv.Itoa(0)),
|
||||
exp: 0,
|
||||
},
|
||||
"42": {
|
||||
raw: value.JString("42"),
|
||||
exp: 42,
|
||||
},
|
||||
"err": {
|
||||
raw: value.JString("err"),
|
||||
exp: 0,
|
||||
err: config.ErrInvalidValue,
|
||||
},
|
||||
"float": {
|
||||
raw: value.JString("0.23"),
|
||||
exp: 0,
|
||||
err: config.ErrInvalidValue,
|
||||
},
|
||||
"maxInt": {
|
||||
raw: value.JString(strconv.Itoa(math.MaxInt)),
|
||||
exp: math.MaxInt,
|
||||
},
|
||||
}
|
||||
|
||||
for name, data := range tests {
|
||||
require.Equal(t, data.exp, data.raw.Int(), name)
|
||||
res, err := data.raw.ParseInt()
|
||||
require.ErrorIs(t, err, data.err)
|
||||
require.Equal(t, data.exp, res, name)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user