-
Notifications
You must be signed in to change notification settings - Fork 0
/
ptr_test.go
106 lines (86 loc) · 2.27 KB
/
ptr_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package ptr
// Copyright 2023 Igor Shishkin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import (
"testing"
"time"
"github.com/stretchr/testify/suite"
)
func (s *ptrTestSuite) TestBool() {
b := Bool(true)
s.Require().Equal(true, *b)
}
func (s *ptrTestSuite) TestDuration() {
d := Duration(1 * time.Minute)
s.Require().Equal(1*time.Minute, *d)
}
func (s *ptrTestSuite) TestFloat32() {
f := Float32(123)
s.Require().Equal(float32(123), *f)
}
func (s *ptrTestSuite) TestFloat64() {
f := Float64(123)
s.Require().Equal(float64(123), *f)
}
func (s *ptrTestSuite) TestInt() {
i := Int(123)
s.Require().Equal(int(123), *i)
}
func (s *ptrTestSuite) TestInt64() {
i := Int64(123)
s.Require().Equal(int64(123), *i)
}
func (s *ptrTestSuite) TestString() {
st := String("test")
s.Require().Equal("test", *st)
}
func (s *ptrTestSuite) TestTime() {
now := time.Now()
t := Time(now)
s.Require().Equal(now, *t)
}
func (s *ptrTestSuite) TestUint8() {
u := Uint8(123)
s.Require().Equal(uint8(123), *u)
}
func (s *ptrTestSuite) TestUint16() {
u := Uint16(123)
s.Require().Equal(uint16(123), *u)
}
func (s *ptrTestSuite) TestUint32() {
u := Uint32(123)
s.Require().Equal(uint32(123), *u)
}
func (s *ptrTestSuite) TestUint64() {
u := Uint64(123)
s.Require().Equal(uint64(123), *u)
}
func (s *ptrTestSuite) TestPtr() {
vi := Ptr(123)
s.Require().Equal(int(123), *vi)
vf := Ptr(123.321)
s.Require().Equal(float64(123.321), *vf)
vs := Ptr("test string")
s.Require().Equal("test string", *vs)
}
// ========================================================================
// Test suite setup
// ========================================================================
type ptrTestSuite struct {
suite.Suite
}
func TestPtrTestSuite(t *testing.T) {
suite.Run(t, &ptrTestSuite{})
}