Skip to content

Commit

Permalink
add ToInt and ToInt32
Browse files Browse the repository at this point in the history
  • Loading branch information
wenzuochao committed Jan 18, 2021
1 parent 5da4c33 commit b6aa048
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tea/tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -1099,3 +1099,11 @@ func Prettify(i interface{}) string {
resp, _ := json.MarshalIndent(i, "", " ")
return string(resp)
}

func ToInt(a *int32) *int {
return Int(int(Int32Value(a)))
}

func ToInt32(a *int) *int32 {
return Int32(int32(IntValue(a)))
}
8 changes: 8 additions & 0 deletions tea/tea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,3 +785,11 @@ func Test_Prettify(t *testing.T) {
str = Prettify(nil)
utils.AssertEqual(t, str, "null")
}

func Test_TransInt32AndInt(t *testing.T) {
a := ToInt(Int32(10))
utils.AssertEqual(t, IntValue(a), 10)

b := ToInt32(a)
utils.AssertEqual(t, Int32Value(b), int32(10))
}

0 comments on commit b6aa048

Please sign in to comment.