2021-02-18 14:32:31 +08:00
|
|
|
package carbon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCarbon_IsZero(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-10 15:50:17 +08:00
|
|
|
{"", true},
|
|
|
|
{"0", true},
|
2021-07-08 09:46:48 +08:00
|
|
|
{"0000-00-00", true},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"00:00:00", true},
|
|
|
|
{"0000-00-00 00:00:00", true},
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-08-05", false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).IsZero()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is zero, expected true, but got false\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is zero, expected false, but got true\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsNow(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-02-23 09:32:55 +08:00
|
|
|
input Carbon // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-10 15:50:17 +08:00
|
|
|
{Parse(""), false},
|
|
|
|
{Parse("0"), false},
|
|
|
|
{Parse("0000-00-00"), false},
|
|
|
|
{Parse("00:00:00"), false},
|
2021-02-23 09:32:55 +08:00
|
|
|
{Parse("0000-00-00 00:00:00"), false},
|
|
|
|
{Tomorrow(), false},
|
|
|
|
{Now(), true},
|
|
|
|
{Yesterday(), false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-02-23 09:32:55 +08:00
|
|
|
output := v.input.IsNow()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
|
|
|
t.Errorf("Input %s is now, expected true, but got false\n", v.input.ToDateString())
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
|
|
|
t.Errorf("Input %s is now, expected false, but got true\n", v.input.ToDateString())
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsFuture(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-02-23 09:32:55 +08:00
|
|
|
input Carbon // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-10 15:50:17 +08:00
|
|
|
{Parse(""), false},
|
|
|
|
{Parse("0"), false},
|
|
|
|
{Parse("0000-00-00"), false},
|
|
|
|
{Parse("00:00:00"), false},
|
2021-02-23 09:32:55 +08:00
|
|
|
{Parse("0000-00-00 00:00:00"), false},
|
|
|
|
{Tomorrow(), true},
|
|
|
|
{Now(), false},
|
|
|
|
{Yesterday(), false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-02-23 09:32:55 +08:00
|
|
|
output := v.input.IsFuture()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
|
|
|
t.Errorf("Input %s is future, expected true, but got false\n", v.input.ToDateString())
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
|
|
|
t.Errorf("Input %s is future, expected false, but got true\n", v.input.ToDateString())
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsPast(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-02-23 09:32:55 +08:00
|
|
|
input Carbon // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-09 15:11:48 +08:00
|
|
|
{Parse(""), false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{Parse("0"), false},
|
2021-07-09 15:11:48 +08:00
|
|
|
{Parse("0000-00-00"), false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{Parse("00:00:00"), false},
|
|
|
|
{Parse("0000-00-00 00:00:00"), false},
|
2021-02-23 09:32:55 +08:00
|
|
|
{Tomorrow(), false},
|
|
|
|
{Now(), false},
|
|
|
|
{Yesterday(), true},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-02-23 09:32:55 +08:00
|
|
|
output := v.input.IsPast()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
|
|
|
t.Errorf("Input %s is past, expected true, but got false\n", v.input.ToDateString())
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
|
|
|
t.Errorf("Input %s is past, expected false, but got true\n", v.input.ToDateString())
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsLeapYear(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-09 15:11:48 +08:00
|
|
|
{"", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"0", false},
|
2021-07-09 15:11:48 +08:00
|
|
|
{"0000-00-00", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"00:00:00", false},
|
|
|
|
{"0000-00-00 00:00:00", false},
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2016-01-01", true},
|
|
|
|
{"2017-01-01", false},
|
|
|
|
{"2018-01-01", false},
|
|
|
|
{"2019-01-01", false},
|
|
|
|
{"2020-01-01", true},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).IsLeapYear()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is leap year, expected true, but got false\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is leap year, expected false, but got true\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsLongYear(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-09 15:11:48 +08:00
|
|
|
{"", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"0", false},
|
2021-07-09 15:11:48 +08:00
|
|
|
{"0000-00-00", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"00:00:00", false},
|
|
|
|
{"0000-00-00 00:00:00", false},
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2015-01-01", true},
|
|
|
|
{"2016-01-01", false},
|
|
|
|
{"2017-01-01", false},
|
|
|
|
{"2018-01-01", false},
|
|
|
|
{"2019-01-01", false},
|
|
|
|
{"2020-01-01", true},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).IsLongYear()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is long year, expected true, but got false\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is long year, expected false, but got true\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsJanuary(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-09 15:11:48 +08:00
|
|
|
{"", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"0", false},
|
2021-07-09 15:11:48 +08:00
|
|
|
{"0000-00-00", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"00:00:00", false},
|
|
|
|
{"0000-00-00 00:00:00", false},
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-01-01", true},
|
|
|
|
{"2020-02-01", false},
|
|
|
|
{"2020-03-01", false},
|
|
|
|
{"2020-04-01", false},
|
|
|
|
{"2020-05-01", false},
|
|
|
|
{"2020-06-01", false},
|
|
|
|
{"2020-07-01", false},
|
|
|
|
{"2020-08-01", false},
|
|
|
|
{"2020-09-01", false},
|
|
|
|
{"2020-10-01", false},
|
|
|
|
{"2020-11-01", false},
|
|
|
|
{"2020-12-01", false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).IsJanuary()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is January, expected true, but got false\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is January, expected false, but got true\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsFebruary(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-09 15:11:48 +08:00
|
|
|
{"", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"0", false},
|
2021-07-09 15:11:48 +08:00
|
|
|
{"0000-00-00", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"00:00:00", false},
|
|
|
|
{"0000-00-00 00:00:00", false},
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-01-01", false},
|
|
|
|
{"2020-02-01", true},
|
|
|
|
{"2020-03-01", false},
|
|
|
|
{"2020-04-01", false},
|
|
|
|
{"2020-05-01", false},
|
|
|
|
{"2020-06-01", false},
|
|
|
|
{"2020-07-01", false},
|
|
|
|
{"2020-08-01", false},
|
|
|
|
{"2020-09-01", false},
|
|
|
|
{"2020-10-01", false},
|
|
|
|
{"2020-11-01", false},
|
|
|
|
{"2020-12-01", false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).IsFebruary()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is February, expected true, but got false\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is February, expected false, but got true\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsMarch(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-09 15:11:48 +08:00
|
|
|
{"", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"0", false},
|
2021-07-09 15:11:48 +08:00
|
|
|
{"0000-00-00", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"00:00:00", false},
|
|
|
|
{"0000-00-00 00:00:00", false},
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-01-01", false},
|
|
|
|
{"2020-02-01", false},
|
|
|
|
{"2020-03-01", true},
|
|
|
|
{"2020-04-01", false},
|
|
|
|
{"2020-05-01", false},
|
|
|
|
{"2020-06-01", false},
|
|
|
|
{"2020-07-01", false},
|
|
|
|
{"2020-08-01", false},
|
|
|
|
{"2020-09-01", false},
|
|
|
|
{"2020-10-01", false},
|
|
|
|
{"2020-11-01", false},
|
|
|
|
{"2020-12-01", false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).IsMarch()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is March, expected true, but got false\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is March, expected false, but got true\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsApril(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-09 15:11:48 +08:00
|
|
|
{"", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"0", false},
|
2021-07-09 15:11:48 +08:00
|
|
|
{"0000-00-00", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"00:00:00", false},
|
|
|
|
{"0000-00-00 00:00:00", false},
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-01-01", false},
|
|
|
|
{"2020-02-01", false},
|
|
|
|
{"2020-03-01", false},
|
|
|
|
{"2020-04-01", true},
|
|
|
|
{"2020-05-01", false},
|
|
|
|
{"2020-06-01", false},
|
|
|
|
{"2020-07-01", false},
|
|
|
|
{"2020-08-01", false},
|
|
|
|
{"2020-09-01", false},
|
|
|
|
{"2020-10-01", false},
|
|
|
|
{"2020-11-01", false},
|
|
|
|
{"2020-12-01", false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).IsApril()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is April, expected true, but got false\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is April, expected false, but got true\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsMay(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-09 15:11:48 +08:00
|
|
|
{"", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"0", false},
|
2021-07-09 15:11:48 +08:00
|
|
|
{"0000-00-00", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"00:00:00", false},
|
|
|
|
{"0000-00-00 00:00:00", false},
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-01-01", false},
|
|
|
|
{"2020-02-01", false},
|
|
|
|
{"2020-03-01", false},
|
|
|
|
{"2020-04-01", false},
|
|
|
|
{"2020-05-01", true},
|
|
|
|
{"2020-06-01", false},
|
|
|
|
{"2020-07-01", false},
|
|
|
|
{"2020-08-01", false},
|
|
|
|
{"2020-09-01", false},
|
|
|
|
{"2020-10-01", false},
|
|
|
|
{"2020-11-01", false},
|
|
|
|
{"2020-12-01", false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).IsMay()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is May, expected true, but got false\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is May, expected false, but got true\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsJune(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-09 15:11:48 +08:00
|
|
|
{"", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"0", false},
|
2021-07-09 15:11:48 +08:00
|
|
|
{"0000-00-00", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"00:00:00", false},
|
|
|
|
{"0000-00-00 00:00:00", false},
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-01-01", false},
|
|
|
|
{"2020-02-01", false},
|
|
|
|
{"2020-03-01", false},
|
|
|
|
{"2020-04-01", false},
|
|
|
|
{"2020-05-01", false},
|
|
|
|
{"2020-06-01", true},
|
|
|
|
{"2020-07-01", false},
|
|
|
|
{"2020-08-01", false},
|
|
|
|
{"2020-09-01", false},
|
|
|
|
{"2020-10-01", false},
|
|
|
|
{"2020-11-01", false},
|
|
|
|
{"2020-12-01", false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).IsJune()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is June, expected true, but got false\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is June, expected false, but got true\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsJuly(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-09 15:11:48 +08:00
|
|
|
{"", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"0", false},
|
2021-07-09 15:11:48 +08:00
|
|
|
{"0000-00-00", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"00:00:00", false},
|
|
|
|
{"0000-00-00 00:00:00", false},
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-01-01", false},
|
|
|
|
{"2020-02-01", false},
|
|
|
|
{"2020-03-01", false},
|
|
|
|
{"2020-04-01", false},
|
|
|
|
{"2020-05-01", false},
|
|
|
|
{"2020-06-01", false},
|
|
|
|
{"2020-07-01", true},
|
|
|
|
{"2020-08-01", false},
|
|
|
|
{"2020-09-01", false},
|
|
|
|
{"2020-10-01", false},
|
|
|
|
{"2020-11-01", false},
|
|
|
|
{"2020-12-01", false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).IsJuly()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is July, expected true, but got false\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is July, expected false, but got true\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsAugust(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-09 15:11:48 +08:00
|
|
|
{"", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"0", false},
|
2021-07-09 15:11:48 +08:00
|
|
|
{"0000-00-00", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"00:00:00", false},
|
|
|
|
{"0000-00-00 00:00:00", false},
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-01-01", false},
|
|
|
|
{"2020-02-01", false},
|
|
|
|
{"2020-03-01", false},
|
|
|
|
{"2020-04-01", false},
|
|
|
|
{"2020-05-01", false},
|
|
|
|
{"2020-06-01", false},
|
|
|
|
{"2020-07-01", false},
|
|
|
|
{"2020-08-01", true},
|
|
|
|
{"2020-09-01", false},
|
|
|
|
{"2020-10-01", false},
|
|
|
|
{"2020-11-01", false},
|
|
|
|
{"2020-12-01", false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).IsAugust()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is August, expected true, but got false\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is August, expected false, but got true\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsSeptember(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-09 15:11:48 +08:00
|
|
|
{"", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"0", false},
|
2021-07-09 15:11:48 +08:00
|
|
|
{"0000-00-00", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"00:00:00", false},
|
|
|
|
{"0000-00-00 00:00:00", false},
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-01-01", false},
|
|
|
|
{"2020-02-01", false},
|
|
|
|
{"2020-03-01", false},
|
|
|
|
{"2020-04-01", false},
|
|
|
|
{"2020-05-01", false},
|
|
|
|
{"2020-06-01", false},
|
|
|
|
{"2020-07-01", false},
|
|
|
|
{"2020-08-01", false},
|
|
|
|
{"2020-09-01", true},
|
|
|
|
{"2020-10-01", false},
|
|
|
|
{"2020-11-01", false},
|
|
|
|
{"2020-12-01", false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).IsSeptember()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is september, expected true, but got false\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is september, expected false, but got true\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsOctober(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-09 15:11:48 +08:00
|
|
|
{"", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"0", false},
|
2021-07-09 15:11:48 +08:00
|
|
|
{"0000-00-00", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"00:00:00", false},
|
|
|
|
{"0000-00-00 00:00:00", false},
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-01-01", false},
|
|
|
|
{"2020-02-01", false},
|
|
|
|
{"2020-03-01", false},
|
|
|
|
{"2020-04-01", false},
|
|
|
|
{"2020-05-01", false},
|
|
|
|
{"2020-06-01", false},
|
|
|
|
{"2020-07-01", false},
|
|
|
|
{"2020-08-01", false},
|
|
|
|
{"2020-09-01", false},
|
|
|
|
{"2020-10-01", true},
|
|
|
|
{"2020-11-01", false},
|
|
|
|
{"2020-12-01", false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).IsOctober()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is October, expected true, but got false\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is October, expected false, but got true\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsNovember(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-09 15:11:48 +08:00
|
|
|
{"", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"0", false},
|
2021-07-09 15:11:48 +08:00
|
|
|
{"0000-00-00", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"00:00:00", false},
|
|
|
|
{"0000-00-00 00:00:00", false},
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-01-01", false},
|
|
|
|
{"2020-02-01", false},
|
|
|
|
{"2020-03-01", false},
|
|
|
|
{"2020-04-01", false},
|
|
|
|
{"2020-05-01", false},
|
|
|
|
{"2020-06-01", false},
|
|
|
|
{"2020-07-01", false},
|
|
|
|
{"2020-08-01", false},
|
|
|
|
{"2020-09-01", false},
|
|
|
|
{"2020-10-01", false},
|
|
|
|
{"2020-11-01", true},
|
|
|
|
{"2020-12-01", false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).IsNovember()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is November, expected true, but got false\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is November, expected false, but got true\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsDecember(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-09 15:11:48 +08:00
|
|
|
{"", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"0", false},
|
2021-07-09 15:11:48 +08:00
|
|
|
{"0000-00-00", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"00:00:00", false},
|
|
|
|
{"0000-00-00 00:00:00", false},
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-01-01", false},
|
|
|
|
{"2020-02-01", false},
|
|
|
|
{"2020-03-01", false},
|
|
|
|
{"2020-04-01", false},
|
|
|
|
{"2020-05-01", false},
|
|
|
|
{"2020-06-01", false},
|
|
|
|
{"2020-07-01", false},
|
|
|
|
{"2020-08-01", false},
|
|
|
|
{"2020-09-01", false},
|
|
|
|
{"2020-10-01", false},
|
|
|
|
{"2020-11-01", false},
|
|
|
|
{"2020-12-01", true},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).IsDecember()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is December, expected true, but got false\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is December, expected false, but got true\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsMonday(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-09 15:11:48 +08:00
|
|
|
{"", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"0", false},
|
2021-07-09 15:11:48 +08:00
|
|
|
{"0000-00-00", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"00:00:00", false},
|
|
|
|
{"0000-00-00 00:00:00", false},
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-10-05", true},
|
|
|
|
{"2020-10-06", false},
|
|
|
|
{"2020-10-07", false},
|
|
|
|
{"2020-10-08", false},
|
|
|
|
{"2020-10-09", false},
|
|
|
|
{"2020-10-10", false},
|
|
|
|
{"2020-10-11", false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).IsMonday()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is Monday, expected true, but got false\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is Monday, expected false, but got true\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsTuesday(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-09 15:11:48 +08:00
|
|
|
{"", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"0", false},
|
2021-07-09 15:11:48 +08:00
|
|
|
{"0000-00-00", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"00:00:00", false},
|
|
|
|
{"0000-00-00 00:00:00", false},
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-10-05", false},
|
|
|
|
{"2020-10-06", true},
|
|
|
|
{"2020-10-07", false},
|
|
|
|
{"2020-10-08", false},
|
|
|
|
{"2020-10-09", false},
|
|
|
|
{"2020-10-10", false},
|
|
|
|
{"2020-10-11", false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).IsTuesday()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is Tuesday, expected true, but got false\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is Tuesday, expected false, but got true\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsWednesday(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-09 15:11:48 +08:00
|
|
|
{"", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"0", false},
|
2021-07-09 15:11:48 +08:00
|
|
|
{"0000-00-00", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"00:00:00", false},
|
|
|
|
{"0000-00-00 00:00:00", false},
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-10-05", false},
|
|
|
|
{"2020-10-06", false},
|
|
|
|
{"2020-10-07", true},
|
|
|
|
{"2020-10-08", false},
|
|
|
|
{"2020-10-09", false},
|
|
|
|
{"2020-10-10", false},
|
|
|
|
{"2020-10-11", false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).IsWednesday()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is Wednesday, expected true, but got false\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is Wednesday, expected false, but got true\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsThursday(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-09 15:11:48 +08:00
|
|
|
{"", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"0", false},
|
2021-07-09 15:11:48 +08:00
|
|
|
{"0000-00-00", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"00:00:00", false},
|
|
|
|
{"0000-00-00 00:00:00", false},
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-10-05", false},
|
|
|
|
{"2020-10-06", false},
|
|
|
|
{"2020-10-07", false},
|
|
|
|
{"2020-10-08", true},
|
|
|
|
{"2020-10-09", false},
|
|
|
|
{"2020-10-10", false},
|
|
|
|
{"2020-10-11", false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).IsThursday()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is Thursday, expected true, but got false\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is Thursday, expected false, but got true\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsFriday(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-09 15:11:48 +08:00
|
|
|
{"", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"0", false},
|
2021-07-09 15:11:48 +08:00
|
|
|
{"0000-00-00", false},
|
2021-07-10 15:50:17 +08:00
|
|
|
{"00:00:00", false},
|
|
|
|
{"0000-00-00 00:00:00", false},
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-10-05", false},
|
|
|
|
{"2020-10-06", false},
|
|
|
|
{"2020-10-07", false},
|
|
|
|
{"2020-10-08", false},
|
|
|
|
{"2020-10-09", true},
|
|
|
|
{"2020-10-10", false},
|
|
|
|
{"2020-10-11", false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).IsFriday()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is Friday, expected true, but got false\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is Friday, expected false, but got true\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsSaturday(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-09 15:11:48 +08:00
|
|
|
{"", false},
|
|
|
|
{"0000-00-00", false},
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-10-05", false},
|
|
|
|
{"2020-10-06", false},
|
|
|
|
{"2020-10-07", false},
|
|
|
|
{"2020-10-08", false},
|
|
|
|
{"2020-10-09", false},
|
|
|
|
{"2020-10-10", true},
|
|
|
|
{"2020-10-11", false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).IsSaturday()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is Saturday, expected true, but got false\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is Saturday, expected false, but got true\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsSunday(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-09 15:11:48 +08:00
|
|
|
{"", false},
|
|
|
|
{"0000-00-00", false},
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-10-05", false},
|
|
|
|
{"2020-10-06", false},
|
|
|
|
{"2020-10-07", false},
|
|
|
|
{"2020-10-08", false},
|
|
|
|
{"2020-10-09", false},
|
|
|
|
{"2020-10-10", false},
|
|
|
|
{"2020-10-11", true},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).IsSunday()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is Sunday, expected true, but got false\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is Sunday, expected false, but got true\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsWeekday(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-09 15:11:48 +08:00
|
|
|
{"", false},
|
|
|
|
{"0000-00-00", false},
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-10-05", true},
|
|
|
|
{"2020-10-06", true},
|
|
|
|
{"2020-10-07", true},
|
|
|
|
{"2020-10-08", true},
|
|
|
|
{"2020-10-09", true},
|
|
|
|
{"2020-10-10", false},
|
|
|
|
{"2020-10-11", false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).IsWeekday()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is weekday, expected true, but got false\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is weekday, expected false, but got true\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsWeekend(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-09 15:11:48 +08:00
|
|
|
{"", false},
|
|
|
|
{"0000-00-00", false},
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-10-05", false},
|
|
|
|
{"2020-10-06", false},
|
|
|
|
{"2020-10-07", false},
|
|
|
|
{"2020-10-08", false},
|
|
|
|
{"2020-10-09", false},
|
|
|
|
{"2020-10-10", true},
|
|
|
|
{"2020-10-11", true},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).IsWeekend()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is weekend, expected true, but got false\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s is weekend, expected false, but got true\n", v.input)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsYesterday(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-02-23 09:32:55 +08:00
|
|
|
input Carbon // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-02-23 09:32:55 +08:00
|
|
|
{Now(), false},
|
|
|
|
{Yesterday(), true},
|
|
|
|
{Tomorrow(), false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-02-23 09:32:55 +08:00
|
|
|
output := v.input.IsYesterday()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
|
|
|
t.Errorf("Input %s is yesterday, expected true, but got false\n", v.input.ToDateString())
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
|
|
|
t.Errorf("Input %s is yesterday, expected false, but got true\n", v.input.ToDateString())
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsToday(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-02-23 09:32:55 +08:00
|
|
|
input Carbon // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-02-23 09:32:55 +08:00
|
|
|
{Now(), true},
|
|
|
|
{Yesterday(), false},
|
|
|
|
{Tomorrow(), false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-02-23 09:32:55 +08:00
|
|
|
output := v.input.IsToday()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
|
|
|
t.Errorf("Input %s is today, expected true, but got false\n", v.input.ToDateString())
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
|
|
|
t.Errorf("Input %s is today, expected false, but got true\n", v.input.ToDateString())
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsTomorrow(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-02-23 09:32:55 +08:00
|
|
|
input Carbon // 输入值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-02-23 09:32:55 +08:00
|
|
|
{Now(), false},
|
|
|
|
{Yesterday(), false},
|
|
|
|
{Tomorrow(), true},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-02-23 09:32:55 +08:00
|
|
|
output := v.input.IsTomorrow()
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
|
|
|
t.Errorf("Input %s is tomorrow, expected true, but got false\n", v.input.ToDateString())
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
|
|
|
t.Errorf("Input %s is tomorrow, expected false, but got true\n", v.input.ToDateString())
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_Compare(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
2021-02-23 09:32:55 +08:00
|
|
|
param1 string // 输入参数1
|
2021-07-08 09:46:48 +08:00
|
|
|
param2 string // 输入参数2
|
2021-02-23 09:32:55 +08:00
|
|
|
output bool // 期望输出值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-08-05", ">", "2020-08-04", true},
|
|
|
|
{"2020-08-05", "<", "2020-08-04", false},
|
|
|
|
{"2020-08-05", "<", "2020-08-06", true},
|
|
|
|
{"2020-08-05", ">", "2020-08-06", false},
|
|
|
|
{"2020-08-05", "=", "2020-08-05", true},
|
|
|
|
{"2020-08-05", ">=", "2020-08-05", true},
|
|
|
|
{"2020-08-05", "<=", "2020-08-05", true},
|
|
|
|
{"2020-08-05", "!=", "2020-08-05", false},
|
|
|
|
{"2020-08-05", "<>", "2020-08-05", false},
|
|
|
|
{"2020-08-05", "!=", "2020-08-04", true},
|
|
|
|
{"2020-08-05", "<>", "2020-08-04", true},
|
|
|
|
{"2020-08-05", "+", "2020-08-04", false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).Compare(v.param1, Parse(v.param2))
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %v %s %v, expected true, but got false\n", v.input, v.param1, v.param2)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %v %s %v, expected false, but got true\n", v.input, v.param1, v.param2)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_Gt(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
|
|
|
param string // 参数值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-08-05", "2020-08-05", false},
|
|
|
|
{"2020-08-05", "2020-08-04", true},
|
|
|
|
{"2020-08-05", "2020-08-06", false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).Gt(Parse(v.param))
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s > %s, expected true, but got false\n", v.input, v.param)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s > %s, expected false, but got true\n", v.input, v.param)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_Lt(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
|
|
|
param string // 参数值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-08-05", "2020-08-05", false},
|
|
|
|
{"2020-08-05", "2020-08-04", false},
|
|
|
|
{"2020-08-05", "2020-08-06", true},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).Lt(Parse(v.param))
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s < %s, expected true, but got false\n", v.input, v.param)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s < %s, expected false, but got true\n", v.input, v.param)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_Eq(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
|
|
|
param string // 参数值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-08-05", "2020-08-05", true},
|
|
|
|
{"2020-08-05", "2020-08-04", false},
|
|
|
|
{"2020-08-05", "2020-08-06", false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).Eq(Parse(v.param))
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s == %s, expected true, but got false\n", v.input, v.param)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s == %s, expected false, but got true\n", v.input, v.param)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_Ne(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
|
|
|
param string // 参数值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-08-05", "2020-08-05", false},
|
|
|
|
{"2020-08-05", "2020-08-04", true},
|
|
|
|
{"2020-08-05", "2020-08-06", true},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).Ne(Parse(v.param))
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s != %s, expected true, but got false\n", v.input, v.param)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s != %s, expected false, but got true\n", v.input, v.param)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_Gte(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
|
|
|
param string // 参数值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-08-05", "2020-08-05", true},
|
|
|
|
{"2020-08-05", "2020-08-04", true},
|
|
|
|
{"2020-08-05", "2020-08-06", false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).Gte(Parse(v.param))
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s >= %s, expected true, but got false\n", v.input, v.param)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s >= %s, expected false, but got true\n", v.input, v.param)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_Lte(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
|
|
|
param string // 参数值
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-08-05", "2020-08-05", true},
|
|
|
|
{"2020-08-05", "2020-08-04", false},
|
|
|
|
{"2020-08-05", "2020-08-06", true},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).Lte(Parse(v.param))
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s <= %s, expected true, but got false\n", v.input, v.param)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s <= %s, expected false, but got true\n", v.input, v.param)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_Between(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
|
|
|
param1 string // 输入参数1
|
|
|
|
param2 string // 输入参数2
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-08-05 13:14:15", "2020-08-05 13:14:15", "2020-08-05 13:14:15", false},
|
|
|
|
{"2020-08-05 13:14:15", "2020-08-05 13:14:15", "2020-08-06 13:14:15", false},
|
|
|
|
{"2020-08-05 13:14:15", "2020-08-04 13:14:15", "2020-08-05 13:14:15", false},
|
|
|
|
{"2020-08-05 13:14:15", "2020-08-04 13:14:15", "2020-08-06 13:14:15", true},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).Between(Parse(v.param1), Parse(v.param2))
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s < %s < %s, expected true, but got false\n", v.param1, v.input, v.param2)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s < %s < %s, expected false, but got true\n", v.param1, v.input, v.param2)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_BetweenIncludedStartTime(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
|
|
|
param1 string // 输入参数1
|
|
|
|
param2 string // 输入参数2
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-08-05 13:14:15", "2020-08-05 13:14:15", "2020-08-05 13:14:15", false},
|
|
|
|
{"2020-08-05 13:14:15", "2020-08-05 13:14:15", "2020-08-06 13:14:15", true},
|
|
|
|
{"2020-08-05 13:14:15", "2020-08-04 13:14:15", "2020-08-05 13:14:15", false},
|
|
|
|
{"2020-08-05 13:14:15", "2020-08-04 13:14:15", "2020-08-06 13:14:15", true},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).BetweenIncludedStartTime(Parse(v.param1), Parse(v.param2))
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s <= %s < %s, expected true, but got false\n", v.param1, v.input, v.param2)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s <= %s < %s, expected false, but got true\n", v.param1, v.input, v.param2)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_BetweenIncludedEndTime(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
|
|
|
param1 string // 输入参数1
|
|
|
|
param2 string // 输入参数2
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-08-05 13:14:15", "2020-08-05 13:14:15", "2020-08-05 13:14:15", false},
|
|
|
|
{"2020-08-05 13:14:15", "2020-08-05 13:14:15", "2020-08-06 13:14:15", false},
|
|
|
|
{"2020-08-05 13:14:15", "2020-08-04 13:14:15", "2020-08-05 13:14:15", true},
|
|
|
|
{"2020-08-05 13:14:15", "2020-08-04 13:14:15", "2020-08-06 13:14:15", true},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).BetweenIncludedEndTime(Parse(v.param1), Parse(v.param2))
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s < %s <= %s, expected true, but got false\n", v.param1, v.input, v.param2)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s < %s <= %s, expected false, but got true\n", v.param1, v.input, v.param2)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_BetweenIncludedBoth(t *testing.T) {
|
|
|
|
Tests := []struct {
|
2021-07-08 09:46:48 +08:00
|
|
|
input string // 输入值
|
|
|
|
param1 string // 输入参数1
|
|
|
|
param2 string // 输入参数2
|
2021-02-18 14:32:31 +08:00
|
|
|
output bool // 期望输出值
|
|
|
|
}{
|
2021-07-08 09:46:48 +08:00
|
|
|
{"2020-08-05 13:14:15", "2020-08-05 13:14:15", "2020-08-05 13:14:15", true},
|
|
|
|
{"2020-08-05 13:14:15", "2020-08-05 13:14:15", "2020-08-06 13:14:15", true},
|
|
|
|
{"2020-08-05 13:14:15", "2020-08-04 13:14:15", "2020-08-05 13:14:15", true},
|
|
|
|
{"2020-08-05 13:14:15", "2020-08-04 13:14:15", "2020-08-06 13:14:15", true},
|
|
|
|
{"2020-08-05 13:14:15", "2020-08-06 13:14:15", "2020-08-06 13:14:15", false},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range Tests {
|
2021-07-08 09:46:48 +08:00
|
|
|
output := Parse(v.input).BetweenIncludedBoth(Parse(v.param1), Parse(v.param2))
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
if output == true {
|
|
|
|
if v.output == false {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s <= %s <= %s, expected true, but got false\n", v.param1, v.input, v.param2)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
} else {
|
|
|
|
if v.output == true {
|
2021-07-08 09:46:48 +08:00
|
|
|
t.Errorf("Input %s <= %s <= %s, expected false, but got true\n", v.param1, v.input, v.param2)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|