Skip to content

Commit

Permalink
style: improved test and ci
Browse files Browse the repository at this point in the history
Change-Id: I5edca0090ca619c5f1b260a6fc1e744858dd3d6b
  • Loading branch information
andeya committed Dec 9, 2022
1 parent d097ddf commit d45bed8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ watch-bench:
reflex -t 50ms -s -- sh -c 'go test -benchmem -count 3 -bench ./...'

coverage:
${BIN} test -v -coverprofile=cover.out -covermode=atomic ./...
${BIN} test -v -coverprofile=cover.out -covermode=atomic .
${BIN} tool cover -html=cover.out -o cover.html

# tools
Expand Down
18 changes: 9 additions & 9 deletions result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,30 +178,30 @@ func TestResult_Err(t *testing.T) {
}
}

func TestExpectErr(t *testing.T) {
func TestResult_ExpectErr(t *testing.T) {
defer func() {
assert.Equal(t, gust.ToErrBox("Testing expect_err: 10"), recover())
}()
err := gust.Ok(10).ExpectErr("Testing expect_err")
assert.NoError(t, err)
}

func TestExpect(t *testing.T) {
func TestResult_Expect(t *testing.T) {
defer func() {
assert.Equal(t, "failed to parse number: strconv.Atoi: parsing \"4x\": invalid syntax", recover().(error).Error())
}()
gust.Ret(strconv.Atoi("4x")).
Expect("failed to parse number")
}

func TestInspectErr(t *testing.T) {
func TestIResult_nspectErr(t *testing.T) {
gust.Ret(strconv.Atoi("4x")).
InspectErr(func(err error) {
t.Logf("failed to convert: %v", err)
})
}

func TestInspect(t *testing.T) {
func TestResult_Inspect(t *testing.T) {
gust.Ret(strconv.Atoi("4")).
Inspect(func(x int) {
fmt.Println("original: ", x)
Expand Down Expand Up @@ -378,15 +378,15 @@ func TestResult_Ret(t *testing.T) {
assert.Equal(t, -1, w2.Unwrap())
}

func TestUnwrapErr_1(t *testing.T) {
func TestResult_UnwrapErr_1(t *testing.T) {
defer func() {
assert.Equal(t, gust.ToErrBox("called `Result.UnwrapErr()` on an `ok` value: 10"), recover())
}()
err := gust.Ok(10).UnwrapErr()
assert.NoError(t, err)
}

func TestUnwrapErr_2(t *testing.T) {
func TestResult_UnwrapErr_2(t *testing.T) {
err := gust.Err[int]("emergency failure").UnwrapErr()
if assert.Error(t, err) {
assert.Equal(t, "emergency failure", err.Error())
Expand All @@ -395,23 +395,23 @@ func TestUnwrapErr_2(t *testing.T) {
}
}

func TestUnwrapOrDefault(t *testing.T) {
func TestResult_UnwrapOrDefault(t *testing.T) {
assert.Equal(t, "car", gust.Ok("car").UnwrapOrDefault())
assert.Equal(t, "", gust.Err[string](nil).UnwrapOrDefault())
assert.Equal(t, time.Time{}, gust.Err[time.Time](nil).UnwrapOrDefault())
assert.Equal(t, &time.Time{}, gust.Err[*time.Time](nil).UnwrapOrDefault())
assert.Equal(t, valconv.Ref(&time.Time{}), gust.Err[**time.Time](nil).UnwrapOrDefault())
}

func TestUnwrapOrElse(t *testing.T) {
func TestResult_UnwrapOrElse(t *testing.T) {
var count = func(x error) int {
return len(x.Error())
}
assert.Equal(t, 2, gust.Ok(2).UnwrapOrElse(count))
assert.Equal(t, 3, gust.Err[int]("foo").UnwrapOrElse(count))
}

func TestUnwrap(t *testing.T) {
func TestResult_Unwrap(t *testing.T) {
defer func() {
assert.Equal(t, "strconv.Atoi: parsing \"4x\": invalid syntax", recover().(error).Error())
}()
Expand Down

0 comments on commit d45bed8

Please sign in to comment.