aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2021-08-21 11:57:26 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2021-08-21 11:57:26 +0200
commitc28ee92cc49444a04ce44440b1e0c4bc1ac87126 (patch)
treed8f51c23326632865fd90485190f53c358d4708b
parentMake zero-length events be part of day flow. (diff)
downloadcalp-c28ee92cc49444a04ce44440b1e0c4bc1ac87126.tar.gz
calp-c28ee92cc49444a04ce44440b1e0c4bc1ac87126.tar.xz
Repair BYDAY output for ical serialization.
I have no idea why the byday case was commented out while implementing xcal output. Either way it's now fixed, and should hopefully stay fixed with some tests.
Diffstat (limited to '')
-rw-r--r--module/vcomponent/recurrence/internal.scm4
-rw-r--r--tests/rrule-serialization.scm76
2 files changed, 78 insertions, 2 deletions
diff --git a/module/vcomponent/recurrence/internal.scm b/module/vcomponent/recurrence/internal.scm
index 1b9dd405..a57dfd65 100644
--- a/module/vcomponent/recurrence/internal.scm
+++ b/module/vcomponent/recurrence/internal.scm
@@ -92,8 +92,8 @@
(string-upcase
(week-day-name value 2
locale: (make-locale (list LC_TIME) "C")))]
- ;; [(byday)
- ;; (string-join (map byday->string value) ",")]
+ [(byday)
+ (string-join (map byday->string value) ",")]
[(freq count interval)
(format #f "~a" value)]
[(until)
diff --git a/tests/rrule-serialization.scm b/tests/rrule-serialization.scm
new file mode 100644
index 00000000..53365661
--- /dev/null
+++ b/tests/rrule-serialization.scm
@@ -0,0 +1,76 @@
+(
+ ;; Yes, this is ugly. But how else would I test a private procedure?
+ ((guile) @@)
+
+ ((vcomponent recurrence internal)
+ recur-rule->rrule-string
+ recur-rule->rrule-sxml
+ byday
+ )
+
+ ((vcomponent recurrence parse) parse-recurrence-rule)
+
+ ((ice-9 peg)
+ 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 "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)
+ (recur-rule->rrule-sxml rule)))))
+
+(let ((rule (parse-recurrence-rule "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)))
+ (keyword-flatten '(interval byday wkst)
+ (recur-rule->rrule-sxml rule)))))