blob: 23df2b7fa4b16684b361fdc06e6da6bc67392e93 (
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
(define-module (test create)
:use-module ((srfi srfi-1) :select (every))
:use-module (srfi srfi-64)
:use-module (srfi srfi-64 test-error)
:use-module (srfi srfi-88)
:use-module ((hnh util) :select (-> sort*))
:use-module ((hnh util table) :select (alist->table))
:use-module ((vcomponent base) :select (vcomponent?))
:use-module (vcomponent)
:use-module ((vcomponent create)
:select (create-vcomponent
with-parameters
as-list
vcalendar
vevent
vtimezone
standard
daylight))
:use-module ((vcomponent)
:select (children
properties
type
prop prop*
extract
param
vline?)))
;; vevent, vcalendar, vtimezone, standard, and daylight all trivial
;; and therefore not tested
(test-group "Empty component"
(let ((ev (create-vcomponent 'TEST)))
(test-equal 'TEST (type ev))
(test-equal '() (children ev))
(test-equal '() (properties ev))))
(test-group "Component with properties, but no children"
(let ((ev (create-vcomponent 'TEST
prop: "value")))
(test-equal '(PROP) (map car (properties ev)))
(test-equal "value" (prop ev 'PROP))))
(test-group "Component with children, but no properties"
(let* ((child (create-vcomponent 'CHILD))
(ev (create-vcomponent 'TEST
(list child))))
(test-equal '() (properties ev))
(test-equal 1 (length (children ev)))
; (test-eq child (car (children ev)))
))
(test-group "Component with both children and properties"
(let* ((child (create-vcomponent 'CHILD))
(ev (create-vcomponent 'TEST
prop: "VALUE"
(list child))))
(test-equal '(PROP) (map car (properties ev)))
(test-equal "VALUE" (prop ev 'PROP))
(test-equal 1 (length (children ev)))
; (test-eq child (car (children ev)))
))
(test-group "Component with multiple children"
(let ((cal
(vcalendar
calscale: "GREGORIAN"
(list
(vevent summary: "Child 1")
(vevent summary: "Child 2")))))
(test-equal 2 (length (children cal)))
(test-equal "GREGORIAN" (-> cal (prop 'CALSCALE)))
(let ((ch (sort* (children cal)
string<? (extract 'SUMMARY))))
(test-equal "Child 1" (-> ch (list-ref 0) (prop 'SUMMARY)))
(test-equal "Child 2" (-> ch (list-ref 1) (prop 'SUMMARY))))))
(test-group "Component with no children, where last elements value is a list"
(let ((ev (create-vcomponent 'TEST prop: (list 1 2 3))))
(test-equal '() (children ev))
(test-equal '(PROP) (map car (properties ev)))
(test-equal '(1 2 3) (prop ev 'PROP))))
(test-group "With parameters"
(let ((ev (create-vcomponent 'TEST
prop: (with-parameters param: 1 2))))
(test-equal 2 (prop ev 'PROP))
(test-equal '(1) (param (prop* ev 'PROP) 'PARAM))))
(test-group "As list"
(let ((ev (create-vcomponent 'TEST
prop: (as-list (list 1 2 3)))))
(test-equal '(1 2 3) (prop ev 'PROP))
(test-equal 3 (length (prop* ev 'PROP)))
(test-assert (every vline? (prop* ev 'PROP)))))
(test-group "List and parameters"
(let ((ev
(vevent
prop: (as-list
(list
"One"
(with-parameters lang: "sv" "Två")
(with-parameters numeric: "3" "Three"))))))
(test-equal 3 (length (prop* ev 'PROP)))
(test-equal '("One" "Två" "Three") (prop ev 'PROP))
(test-assert (every vline? (prop* ev 'PROP)))
(test-equal (list (vline key: 'PROP
vline-value: "One")
(vline key: 'PROP
vline-value: "Två"
vline-parameters:
(alist->table '((LANG . "sv"))))
(vline key: 'PROP
vline-value: "Three"
vline-parameters:
(alist->table '((NUMERIC . "3")))))
(prop* ev 'PROP))))
(test-error "Fail on nested with-parameters"
'wrong-type-arg
(vevent prop: (with-parameters a: "1"
(with-parameters b: "2"
"3"))))
(test-group "An empty as-list is effectively the same as not having the property"
(let ((ev (vevent prop: (as-list '()))))
(test-equal '() (properties ev))))
(test-error "Fail on nested as-list"
'wrong-type-arg
(vevent prop: (as-list (list (as-list '())))))
(test-error "Fail on as-list inside with-parameters"
'wrong-type-arg
(vevent prop: (with-parameters a: "1"
(as-list '()))))
(test-assert (vcomponent? (vcalendar)))
(test-eq 'VCALENDAR (type (vcalendar)))
(test-assert (vcomponent? (vevent)))
(test-eq 'VEVENT (type (vevent)))
(test-assert (vcomponent? (vtimezone)))
(test-eq 'VTIMEZONE (type (vtimezone)))
(test-assert (vcomponent? (standard)))
(test-eq 'STANDARD (type (standard)))
(test-assert (vcomponent? (daylight)))
(test-eq 'DAYLIGHT (type (daylight)))
'((vcomponent create))
|