Skip to content

Commit

Permalink
test: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed Mar 13, 2024
1 parent 0bde39a commit b2e2c14
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions gronx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package gronx

import (
"fmt"
"log"
"strings"
"testing"
"time"
Expand All @@ -15,13 +14,16 @@ type Case struct {
Next string `json:"next"`
}

func (test Case) run(gron Gronx) (bool, error) {
func (test Case) run(t *testing.T, gron *Gronx) (bool, error) {
if test.Ref == "" {
return gron.IsDue(test.Expr)
}

ref, err := time.Parse(FullDateFormat, test.Ref)
abort(err)
if err != nil {
t.Errorf("can't parse date: %s", test.Ref)
t.Fail()
}

return gron.IsDue(test.Expr, ref)
}
Expand Down Expand Up @@ -144,7 +146,7 @@ func TestIsDue(t *testing.T) {

for i, test := range testcases() {
t.Run(fmt.Sprintf("is due #%d=%s", i, test.Expr), func(t *testing.T) {
actual, _ := test.run(gron)
actual, _ := test.run(t, gron)

if actual != test.Expect {
t.Errorf("expected %v, got %v", test.Expect, actual)
Expand All @@ -154,7 +156,7 @@ func TestIsDue(t *testing.T) {

for i, test := range errcases() {
t.Run(fmt.Sprintf("is due err #%d=%s", i, test.Expr), func(t *testing.T) {
actual, err := test.run(gron)
actual, err := test.run(t, gron)

if actual != test.Expect {
t.Errorf("expected %v, got %v", test.Expect, actual)
Expand Down Expand Up @@ -289,13 +291,7 @@ func errcases() []Case {
{"* * * * * ZL", "", false, ""},
{"* * * * * Z#", "", false, ""},
{"* * * * * 1#Z", "", false, ""},
{"* * W * 3", "", false, ""},
{"* * W * L", "", false, ""},
{"* * 15 * 1#Z", "", false, ""},
}
}

func abort(err error) {
if err != nil {
log.Fatalf("%+v", err)
}
}

0 comments on commit b2e2c14

Please sign in to comment.