forked from teambition/rrule-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstr_test.go
58 lines (52 loc) · 1.56 KB
/
str_test.go
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
package rrule
import (
"testing"
)
func TestStrToRRule(t *testing.T) {
str := "FREQ=WEEKLY;DTSTART=20120201T093000Z;INTERVAL=5;WKST=TU;COUNT=2;UNTIL=20130130T230000Z;BYSETPOS=2;BYMONTH=3;BYYEARDAY=95;BYWEEKNO=1;BYDAY=MO,+2FR;BYHOUR=9;BYMINUTE=30;BYSECOND=0;BYEASTER=-1"
r, _ := StrToRRule(str)
if s := r.String(); s != str {
t.Errorf("StrToRRule(%q).String() = %q, want %q", str, s, str)
}
}
func TestInvalidString(t *testing.T) {
cases := []string{
"",
"FREQ",
"FREQ=HELLO",
"BYMONTH=",
"FREQ=WEEKLY;HELLO=WORLD",
"FREQ=WEEKLY;BYMONTHDAY=I",
"FREQ=WEEKLY;BYDAY=M",
"FREQ=WEEKLY;BYDAY=MQ",
"FREQ=WEEKLY;BYDAY=+MO",
}
for _, item := range cases {
if _, e := StrToRRule(item); e == nil {
t.Errorf("StrToRRule(%q) = nil, want error", item)
}
}
}
func TestStrToRRuleSet(t *testing.T) {
str := `RRULE:FREQ=WEEKLY;DTSTART=20120201T093000Z;BYDAY=MO,TU,WE,TH,FR;COUNT=10
RDATE:20121201T093000Z
EXRULE:FREQ=WEEKLY;DTSTART=20120208T093000Z;BYDAY=MO,TU,WE,TH,FR;COUNT=3
EXDATE:20120203T093000Z`
s, err := StrToRRuleSet(str)
if err != nil {
t.Errorf("StrToRRule(%q) error: %v", str, err)
}
if len(s.All()) != 7 {
t.Errorf("len(StrToRRule(%q)) = %d, want %d", str, len(s.All()), 7)
}
}
func TestSet_String(t *testing.T) {
str := `RRULE:FREQ=WEEKLY;DTSTART=20120201T093000Z;COUNT=10;BYDAY=MO,TU,WE,TH,FR
RDATE:20121201T093000Z
EXRULE:FREQ=WEEKLY;DTSTART=20120208T093000Z;COUNT=3;BYDAY=MO,TU,WE,TH,FR
EXDATE:20120203T093000Z`
set, _ := StrToRRuleSet(str)
if s := set.String(); s != str {
t.Errorf("StrToRRuleSet(%q).String() = %q, want %q", str, s, str)
}
}