FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
date/sql_test.go at v2 · rickb777/date · GitHub
rickb777
date
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
date
/
sql_test.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
87 lines (77 loc) · 1.97 KB
Breadcrumbs
date
/
sql_test.go
Copy path
File metadata and controls
87 lines (77 loc) · 1.97 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
// Copyright 2015 Rick Beton. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
date
import
(
"database/sql/driver"
"testing"
)
func
TestDate_Scan
(
t
*
testing.
T
) {
cases
:=
[]
struct
{
v
interface
{}
expected
Date
}{
{
v
:
int64
(
0
),
expected
:
0
},
{
v
:
int64
(
1
),
expected
:
1
},
{
v
:
int64
(
1000
),
expected
:
1000
},
{
v
:
int64
(
10000
),
expected
:
10000
},
//{v: "00000101", expected: 0},
//{v: "00000102", expected: 1},
{
v
:
"0001-01-01"
,
expected
:
0
},
{
v
:
"19700101"
,
expected
:
ZeroOffset
},
{
v
:
"1970-01-01"
,
expected
:
ZeroOffset
},
{
v
:
"1971-01-01"
,
expected
:
365
+
ZeroOffset
},
{
v
:
"2018-12-31"
,
expected
:
17896
+
ZeroOffset
},
{
v
:
"31/12/2018"
,
expected
:
17896
+
ZeroOffset
},
{
v
: []
byte
(
"19700101"
),
expected
:
ZeroOffset
},
{
v
:
Date
(
10000
).
Midnight
(),
expected
:
10000
},
}
for
i
,
c
:=
range
cases
{
r
:=
new
(
Date
)
e
:=
r
.
Scan
(
c
.
v
)
if
e
!=
nil
{
t
.
Errorf
(
"%d: Got %v for %d"
,
i
,
e
,
c
.
expected
)
}
if
*
r
!=
c
.
expected
{
t
.
Errorf
(
"%d: Got %v, want %d"
,
i
,
*
r
,
c
.
expected
)
}
var
d
driver.
Valuer
=
*
r
q
,
e
:=
d
.
Value
()
if
e
!=
nil
{
t
.
Errorf
(
"%d: Got %v for %d"
,
i
,
e
,
c
.
expected
)
}
if
q
.(
string
)
!=
c
.
expected
.
String
() {
t
.
Errorf
(
"%d: Got %v, want %d"
,
i
,
q
,
c
.
expected
)
}
q
,
e
=
ValueAsInt
(
*
r
)
if
e
!=
nil
{
t
.
Errorf
(
"%d: Got %v for %d"
,
i
,
e
,
c
.
expected
)
}
if
q
.(
int64
)
!=
int64
(
c
.
expected
) {
t
.
Errorf
(
"%d: Got %v, want %d"
,
i
,
q
,
c
.
expected
)
}
}
}
func
TestDate_Scan_with_junk
(
t
*
testing.
T
) {
cases
:=
[]
struct
{
v
interface
{}
expected
string
}{
{
true
,
"bool true is not a meaningful date"
},
{
true
,
"bool true is not a meaningful date"
},
}
for
i
,
c
:=
range
cases
{
r
:=
new
(
Date
)
e
:=
r
.
Scan
(
c
.
v
)
if
e
.
Error
()
!=
c
.
expected
{
t
.
Errorf
(
"%d: Got %q, want %q"
,
i
,
e
.
Error
(),
c
.
expected
)
}
}
}
func
TestDate_Scan_with_nil
(
t
*
testing.
T
) {
var
r
*
Date
e
:=
r
.
Scan
(
nil
)
if
e
!=
nil
{
t
.
Errorf
(
"Got %v"
,
e
)
}
}
Back
|
FazBrowse Home
|
New Git URL