aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2021-12-20 22:09:57 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2021-12-20 22:09:57 +0100
commitd75ebbab2a414fe1a9a09d703a3bc7be782f1f1e (patch)
tree0de4f1c17afd6fbefbafc3a0a8a91bc85cb30355 /tests
parentDocument testrunner syntax. (diff)
parentDocumentation updates for util. (diff)
downloadcalp-d75ebbab2a414fe1a9a09d703a3bc7be782f1f1e.tar.gz
calp-d75ebbab2a414fe1a9a09d703a3bc7be782f1f1e.tar.xz
Merge Javascript rewrite.
Diffstat (limited to 'tests')
-rw-r--r--tests/annoying-events.scm59
-rw-r--r--tests/recurrence-simple.scm27
2 files changed, 85 insertions, 1 deletions
diff --git a/tests/annoying-events.scm b/tests/annoying-events.scm
new file mode 100644
index 00000000..ba93b9c9
--- /dev/null
+++ b/tests/annoying-events.scm
@@ -0,0 +1,59 @@
+(((srfi srfi-41 util) filter-sorted-stream)
+ ((srfi srfi-41) stream stream->list stream-filter stream-take-while)
+ ((vcomponent base) extract prop make-vcomponent)
+ ((vcomponent datetime) event-overlaps?)
+ ((datetime) date date+ date<)
+ ((calp util) set!))
+
+(define* (event key: summary dtstart dtend)
+ (define ev (make-vcomponent 'VEVENT))
+ (set! (prop ev 'SUMMARY) summary
+ (prop ev 'DTSTART) dtstart
+ (prop ev 'DTEND) dtend)
+ ev)
+
+(define start #2021-11-01)
+(define end (date+ start (date day: 8)))
+
+(define ev-set
+ (stream
+ (event ; should be part of the result
+ summary: "A"
+ dtstart: #2021-10-01
+ dtend: #2021-12-01)
+ (event ; should NOT be part of the result
+ summary: "B"
+ dtstart: #2021-10-10
+ dtend: #2021-10-11)
+ (event ; should also be part of the result
+ summary: "C"
+ dtstart: #2021-11-02
+ dtend: #2021-11-03)))
+
+;; (if (and (date< (prop ev 'DTSTART) start-date)
+;; (date<= (prop ev 'DTEND) end-date))
+;; ;; event will be picked, but next event might have
+;; (and (date< start-date (prop ev 'DTSTART))
+;; (date< end-date (prop ev 'DTEND)))
+;; ;; meaning that it wont be added, stopping filter-sorted-stream
+;; )
+
+;; The naïve way to get all events in an interval. Misses C due to B being "in the way"
+
+(test-equal "incorrect handling of non-contigious"
+ '("A" #; "C")
+ (map (extract 'SUMMARY)
+ (stream->list
+ (filter-sorted-stream
+ (lambda (ev) (event-overlaps? ev start (date+ start (date day: 8))))
+ ev-set))))
+
+;; A correct way
+
+(test-equal "correct handling of non-contigious"
+ '("A" "C")
+ (map (extract 'SUMMARY)
+ (stream->list
+ (stream-filter (lambda (ev) (event-overlaps? ev start end))
+ (stream-take-while (lambda (ev) (date< (prop ev 'DTSTART) end))
+ ev-set)))))
diff --git a/tests/recurrence-simple.scm b/tests/recurrence-simple.scm
index 166fa349..bbe6dd9d 100644
--- a/tests/recurrence-simple.scm
+++ b/tests/recurrence-simple.scm
@@ -9,7 +9,7 @@
((vcomponent base) extract prop)
((calp util exceptions) warnings-are-errors warning-handler)
- ((guile) format)
+ ((guile) format @@)
((vcomponent) parse-calendar)
((vcomponent xcal parse) sxcal->vcomponent)
@@ -242,6 +242,13 @@ END:VCALENDAR"
;;; Earlier I failed to actually parse the recurrence parts, in short, 1 ≠ "1".
+(test-assert "Test that xcal recur rules are parseable"
+ ((@@ (vcomponent xcal parse) handle-value)
+ 'recur 'props-are-unused-for-recur
+ '((freq "WEEKLY")
+ (interval "1")
+ (wkst "MO"))))
+
(define ev
(sxcal->vcomponent
'(vevent
@@ -260,3 +267,21 @@ END:VCALENDAR"
(test-assert
"Check that recurrence rule commint from xcal also works"
(generate-recurrence-set ev))
+
+;;; TODO test here, for byday parsing, and multiple byday instances in one recur element
+;;; TODO which should also test serializing and deserializing to xcal.
+;;; For example, the following rules specify every workday
+
+;; BEGIN:VCALENDAR
+;; PRODID:-//hugo//calp 0.6.1//EN
+;; VERSION:2.0
+;; CALSCALE:GREGORIAN
+;; BEGIN:VEVENT
+;; SUMMARY:Lunch
+;; DTSTART:20211129T133000
+;; DTEND:20211129T150000
+;; LAST-MODIFIED:20211204T220944Z
+;; UID:3d82c73c-6cdb-4799-beba-5f1d20d55347
+;; RRULE:FREQ=DAILY;BYDAY=MO,TU,WE,TH,FR
+;; END:VEVENT
+;; END:VCALENDAR