-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: rework and add tests for all rrule parts
- Loading branch information
1 parent
b99b3cb
commit 0a7b75c
Showing
27 changed files
with
902 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package recurrence_rule | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestNewByDayPart(t *testing.T) { | ||
week1, _ := NewWeekDayWithOrdinal(1, Tuesday) | ||
week2, _ := NewWeekDayWithOrdinal(20, Tuesday) | ||
type args struct { | ||
days []weekDayWithOrdinal | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
}{ | ||
{ | ||
"Create BYDAY Recurrence rule component #1", | ||
args{days: []weekDayWithOrdinal{*week1}}, | ||
"1TU", | ||
}, | ||
{ | ||
"Create BYDAY Recurrence rule component #2", | ||
args{days: []weekDayWithOrdinal{*week2}}, | ||
"20TU", | ||
}, | ||
{ | ||
"Create BYDAY Recurrence rule component #3", | ||
args{days: []weekDayWithOrdinal{*week1, *week2}}, | ||
"1TU,20TU", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := NewByDayPart(tt.args.days); !reflect.DeepEqual(got.GetPartValue(), tt.want) { | ||
t.Errorf("got.GetPartValue() = %s, want %s", got.GetPartValue(), tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestNewWeekDayWithOrdinal(t *testing.T) { | ||
type args struct { | ||
ordinal int32 | ||
weekDay WeekDay | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
wantErr bool | ||
}{ | ||
{"Create WeekDay (no error)", args{ordinal: 1, weekDay: Tuesday}, "1TU", false}, | ||
{"Create WeekDay (with error)", args{ordinal: 100, weekDay: Tuesday}, "", true}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := NewWeekDayWithOrdinal(tt.args.ordinal, tt.args.weekDay) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("NewWeekDayWithOrdinal() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got.ToString(), tt.want) { | ||
t.Errorf("got.ToString() = %s, want %s", got.ToString(), tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package recurrence_rule | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestNewByHourPart(t *testing.T) { | ||
type args struct { | ||
hours []int32 | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
wantErr bool | ||
}{ | ||
{"Create BYHOUR Recurrence rule component #1", args{hours: []int32{10}}, "10", false}, | ||
{ | ||
"Create BYHOUR Recurrence rule component #2", | ||
args{hours: []int32{10, 22}}, | ||
"10,22", | ||
false, | ||
}, | ||
{"Create BYHOUR Recurrence rule component #3", args{hours: []int32{10, 22, 33}}, "0", true}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := NewByHourPart(tt.args.hours) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("NewByHourPart() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got.GetPartValue(), tt.want) { | ||
t.Errorf("got.ToString() = %s, want %s", got.GetPartValue(), tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.