common_test.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package common
  2. import (
  3. "github.com/smartystreets/goconvey/convey"
  4. "testing"
  5. "time"
  6. )
  7. func TestFormatTime_Scan(t *testing.T) {
  8. convey.Convey("FormatTime_Scan", t, func(ctx convey.C) {
  9. a := FormatTime("2018-01-01 01:00:00")
  10. b := time.Time{}
  11. err := a.Scan(b)
  12. ctx.Convey("FormatTime_Scan", func(ctx convey.C) {
  13. convey.So(err, convey.ShouldBeNil)
  14. })
  15. })
  16. }
  17. func TestWaitTime(t *testing.T) {
  18. convey.Convey("WaitTime", t, func(ctx convey.C) {
  19. b := time.Time{}
  20. WaitTime(b)
  21. })
  22. }
  23. func TestParseWaitTime(t *testing.T) {
  24. convey.Convey("ParseWaitTime", t, func(ctx convey.C) {
  25. b := time.Time{}.Unix()
  26. ParseWaitTime(b)
  27. })
  28. }
  29. var s = IntTime(time.Now().Unix())
  30. func TestIntTime_Scan(t *testing.T) {
  31. convey.Convey("IntTime_Scan", t, func(ctx convey.C) {
  32. b := time.Time{}
  33. err := s.Scan(&b)
  34. ctx.Convey("IntTime_Scan", func(ctx convey.C) {
  35. convey.So(err, convey.ShouldBeNil)
  36. })
  37. })
  38. }
  39. func TestIntTime_Value(t *testing.T) {
  40. convey.Convey("IntTime_Value", t, func(ctx convey.C) {
  41. s.Value()
  42. })
  43. }
  44. func TestIntTime_UnmarshalJSON(t *testing.T) {
  45. convey.Convey("IntTime_UnmarshalJSON", t, func(ctx convey.C) {
  46. err := s.UnmarshalJSON(nil)
  47. ctx.Convey("IntTime_UnmarshalJSON", func(ctx convey.C) {
  48. convey.So(err, convey.ShouldBeNil)
  49. })
  50. })
  51. }
  52. func TestFilterName(t *testing.T) {
  53. convey.Convey("FilterName", t, func(ctx convey.C) {
  54. a := FilterName("hahah一个")
  55. convey.So(a, convey.ShouldEqual, "hahah")
  56. })
  57. }
  58. func TestFilterChname(t *testing.T) {
  59. convey.Convey("FilterChname", t, func(ctx convey.C) {
  60. a := FilterChname("hahah一个")
  61. convey.So(a, convey.ShouldEqual, "一个")
  62. })
  63. }
  64. func TestFilterBusinessName(t *testing.T) {
  65. convey.Convey("FilterBusinessName", t, func(ctx convey.C) {
  66. a := FilterBusinessName("hahah一个")
  67. convey.So(a, convey.ShouldEqual, "hahah一个")
  68. })
  69. }
  70. func TestUnique(t *testing.T) {
  71. convey.Convey("Unique", t, func(ctx convey.C) {
  72. b := []int64{1, -1, 0, 1, 1}
  73. a := Unique(b, true)
  74. convey.So(len(a), convey.ShouldEqual, 1)
  75. convey.So(a[0], convey.ShouldEqual, 1)
  76. })
  77. }
  78. func TestCopyMap(t *testing.T) {
  79. convey.Convey("CopyMap", t, func(ctx convey.C) {
  80. b := map[int64][]int64{}
  81. a := CopyMap(map[int64][]int64{1: []int64{1}}, b, true)
  82. convey.So(len(a), convey.ShouldEqual, 1)
  83. })
  84. }