aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/vcomponent/rrule-serialization.scm
blob: fe990e0b547eac61d4ddb1098c4a4d1a7e1cb94b (plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
(define-module (test rrule-serialization)
  :use-module (srfi srfi-64)
  :use-module (srfi srfi-88)
  :use-module ((vcomponent recurrence internal)
               :select (recur-rule->rrule-string
                        recur-rule->rrule-sxml
                        byday))
  :use-module ((vcomponent recurrence parse)
               :select (parse-recurrence-rule))
  :use-module ((ice-9 peg) :select (keyword-flatten)))

(test-equal
  "Parse of week day"
  '(#f . 3)
  ((@@ (vcomponent recurrence parse) parse-day-spec)
   "WE"))

(test-equal
  "Parse of week day with positive offset"
  '(1 . 3)
  ((@@ (vcomponent recurrence parse) parse-day-spec)
   "1WE"))

(test-equal
  "Parse of week day with positive offset (and plus)"
  '(2 . 3)
  ((@@ (vcomponent recurrence parse) parse-day-spec)
   "+2WE"))

(test-equal
  "Parse of week day with negative offset"
  '(-3 . 3)
  ((@@ (vcomponent recurrence parse) parse-day-spec)
   "-3WE"))


;; numeric prefixes in the BYDAY list is only valid when
;; FREQ={MONTHLY,YEARLY}, but that should be handled in a
;; later stage since we are just testing the parser here.
;; (p. 41)


(define field->string
  (@@ (vcomponent recurrence internal)
      field->string))

(let ((rule (parse-recurrence-rule "FREQ=WEEKLY;BYDAY=MO,TU,WE")))
  (test-equal
    "Direct return of parsed value"
    "MO,TU,WE"
    (field->string 'byday (byday rule)))
  (test-equal
    "Direct return, but as SXML"
    '((byday "MO") (byday "TU") (byday "WE"))
    (filter
      (lambda (pair) (eq? 'byday (car pair)))
      (keyword-flatten
        '(interval byday wkst freq)
        (recur-rule->rrule-sxml rule)))))

(let ((rule (parse-recurrence-rule "FREQ=WEEKLY;BYDAY=+1MO,1TU,-2FR")))
  (test-equal
    "Direct return of parsed value"
    "1MO,1TU,-2FR"
    (field->string 'byday (byday rule)))
  (test-equal
    "Direct return, but as SXML"
    '((byday "1MO") (byday "1TU") (byday "-2FR"))
    (filter
      (lambda (pair) (eq? 'byday (car pair)))
      ;; TODO why is keyword-flatten used here?
      (keyword-flatten
        '(interval byday wkst freq)
        (recur-rule->rrule-sxml rule)))))


'((vcomponent recurrence internal)
  (vcomponent recurrence parse))