-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathebdb-test.el
691 lines (622 loc) · 22.1 KB
/
ebdb-test.el
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
;;; ebdb-test.el --- Tests for EBDB -*- lexical-binding: t; -*-
;; Copyright (C) 2017-2024 Free Software Foundation, Inc.
;; Author: Eric Abrahamsen <[email protected]>
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Tests for EBDB. Tests for EBDB's internationalization support are
;; in a separate file, since loading ebdb-i18n.el overloads a bunch of
;; methods, and un-overloading them is difficult.
;;; Code:
(require 'ert)
(require 'ebdb)
(require 'ebdb-com)
(require 'ebdb-snarf)
(require 'ebdb-vcard)
;; Testing macros.
(defmacro ebdb-test-with-database (db-and-filename &rest body)
"Macro providing a temporary database to work with."
(declare (indent 1) (debug ((symbolp symbolp) body)))
`(let ((,(car db-and-filename) (make-instance 'ebdb-db-file
:file ,(nth 1 db-and-filename)
:dirty t))
ebdb-db-list)
;; Save sets sync-time.
(ebdb-db-save ,(car db-and-filename) nil t)
;; Load adds to `ebdb-db-list'.
(ebdb-db-load ,(car db-and-filename))
;; `ebdb-db-load' used to add db to `ebdb-db-list', but now that
;; happens in `edbd-load'. Do it manually.
(push ,(car db-and-filename) ebdb-db-list)
(unwind-protect
(progn
,@body)
(delete-file ,(nth 1 db-and-filename)))))
(defmacro ebdb-test-with-records (&rest body)
"Don't let EBDB tests pollute `ebdb-record-tracker'."
(declare (indent 0) (debug t))
`(let ((ebdb-hashtable (make-hash-table :test 'equal))
(ebdb-org-hashtable (make-hash-table :test 'equal))
ebdb-record-tracker)
,@body))
;; Test database file name.
(defvar ebdb-test-database-1 (make-temp-name
(expand-file-name
"emacs-ebdb-test-db-1-"
temporary-file-directory)))
(defvar ebdb-test-database-2 (make-temp-name
(expand-file-name
"emacs-ebdb-test-db-2-"
temporary-file-directory)))
(ert-deftest ebdb-make-database ()
"Make a database and save it to disk."
(ebdb-test-with-database (db ebdb-test-database-1)
(should (file-exists-p ebdb-test-database-1))
(should (null (slot-value db 'dirty)))))
(ert-deftest ebdb-read-database ()
"Read a database from file."
(ebdb-test-with-database (db ebdb-test-database-1)
(let ((reloaded
(eieio-persistent-read ebdb-test-database-1 'ebdb-db t)))
(should (object-of-class-p reloaded 'ebdb-db-file)))))
(ert-deftest ebdb-database-unsynced ()
"Make sure database knows it's unsynced."
(ebdb-test-with-database (db ebdb-test-database-1)
;; Apparently the call to `ebdb-db-load' and the test are too
;; close together to register a difference in time, which I find
;; weird.
(sit-for 0.1)
(append-to-file "\n;; Junk string" nil (slot-value db 'file))
(should (ebdb-db-unsynced db))))
(ert-deftest ebdb-make-record ()
(ebdb-test-with-records
(let ((rec (make-instance ebdb-default-record-class)))
(should (object-of-class-p rec 'ebdb-record)))))
(ert-deftest ebdb-add-record ()
"Create a record, add it to DB, and make sure it has a UUID."
(ebdb-test-with-records
(ebdb-test-with-database (db ebdb-test-database-1)
(let ((rec (make-instance 'ebdb-record-person)))
(should (null (ebdb-record-uuid rec)))
(ebdb-db-add-record db rec)
(should (stringp (ebdb-record-uuid rec)))
(should (ebdb-gethash (ebdb-record-uuid rec) 'uuid))))))
(ert-deftest ebdb-load-record-multiple-databases ()
"Test loading of a record into multiple databases."
(ebdb-test-with-records
(ebdb-test-with-database (db1 ebdb-test-database-1)
(ebdb-test-with-database (db2 ebdb-test-database-2)
(let ((rec (make-instance 'ebdb-record-person)))
(ebdb-db-add-record db1 rec)
(ebdb-db-add-record db2 rec)
(should (= 1 (length ebdb-record-tracker)))
(should (equal rec (ebdb-gethash (ebdb-record-uuid rec) 'uuid))))))))
(ert-deftest ebdb-load-record-multiple-databases-error ()
"Test that record can't be edited when one of its databases is
read-only."
(ebdb-test-with-records
(ebdb-test-with-database (db1 ebdb-test-database-1)
(ebdb-test-with-database (db2 ebdb-test-database-2)
(let ((rec (make-instance 'ebdb-record-person)))
(ebdb-db-add-record db1 rec)
(ebdb-db-add-record db2 rec)
(setf (slot-value db1 'read-only) t)
(should-error
(ebdb-record-insert-field
rec (ebdb-parse 'ebdb-field-mail "[email protected]"))
:type 'ebdb-readonly-db))))))
(ert-deftest ebdb-auto-insert-timestamp-creation ()
"Test the creation of timestamp and creation-date fields.
Actually exercises the `initialize-instance' methods of records."
(ebdb-test-with-records
(ebdb-test-with-database (db ebdb-test-database-1)
(let* ((r1 (make-instance ebdb-default-record-class))
(r2 (make-instance ebdb-default-record-class
:timestamp nil
:creation-date nil))
(r2-date (slot-value (slot-value r2 'creation-date) 'timestamp)))
;; `make-instance' with no :timestamp or :creation-date values
;; should get the fields correctly.
(should (and (stringp (ebdb-string (slot-value r1 'timestamp)))
(stringp (ebdb-string (slot-value r1 'creation-date)))))
(delete-instance r1)
;; `make-instance' with tags set to nil should still get
;; correct fields (can happen in migration).
(should (and (stringp (ebdb-string (slot-value r2 'timestamp)))
(stringp (ebdb-string (slot-value r2 'creation-date)))))
;; Creating a record, saving it to the database, then
;; re-loading it shouldn't change the creation date.
(ebdb-db-add-record db r2)
(ebdb-db-save db)
(sleep-for 2)
(ebdb-db-unload db)
(setq db (eieio-persistent-read (slot-value db 'file) 'ebdb-db t))
(should (equal r2-date
(slot-value
(slot-value
(car ebdb-record-tracker)
'creation-date)
'timestamp)))))))
(ert-deftest ebdb-cant-find-related-role ()
"Find org record from a role field.
If it doesn't exist, raise `ebdb-related-unfound'."
(ebdb-test-with-records
(let ((rec (make-instance
'ebdb-record-person
:uuid (make-instance 'ebdb-field-uuid :uuid "bob")))
(role
(make-instance
'ebdb-field-role :record-uuid "bob"
:org-uuid "bogus")))
(ebdb-record-insert-field rec role)
(should-error
(ebdb-record-related rec role)
:type 'ebdb-related-unfound))))
(ert-deftest ebdb-unload-db-with-relations ()
"Cross-db relations break correctly when a db is unloaded."
(ebdb-test-with-records
(ebdb-test-with-database (db1 ebdb-test-database-1)
(ebdb-test-with-database (db2 ebdb-test-database-2)
(let ((rec1 (make-instance 'ebdb-record-person))
(rec2 (make-instance 'ebdb-record-person))
rel-f)
(ebdb-db-add-record db1 rec1)
(ebdb-db-add-record db2 rec2)
(setq rel-f (make-instance
'ebdb-field-relation :rel-uuid (ebdb-record-uuid rec2)))
(ebdb-record-insert-field rec1 rel-f)
(ebdb-db-unload db2)
(should-error
(ebdb-record-related rec1 rel-f)
:type 'ebdb-related-unfound)
(should
(string=
(ebdb-fmt-field
ebdb-default-multiline-formatter
rel-f 'oneline rec1)
"record not loaded")))))))
(ert-deftest ebdb-test-with-record-edits ()
"Test the `ebdb-with-record-edits' macro."
(ebdb-test-with-records
(ebdb-test-with-database (db1 ebdb-test-database-1)
(ebdb-test-with-database (db2 ebdb-test-database-2)
(let ((rec1 (make-instance 'ebdb-record-person))
(rec2 (make-instance 'ebdb-record-person)))
(ebdb-db-add-record db1 rec1)
(ebdb-db-add-record db2 rec1)
(ebdb-db-add-record db1 rec2)
(setf (slot-value db2 'read-only) t)
(dolist (rec (list rec1 rec2))
(ebdb-with-record-edits rec
(ebdb-record-insert-field
rec (ebdb-parse 'ebdb-field-mail "[email protected]"))))
;; Field insertion should have silently failed for rec1.
(should-not
(slot-value rec1 'mail)))))))
;; Test adding, deleting and changing fields.
(ert-deftest ebdb-add-delete-record-field ()
"Add and delete fields."
(ebdb-test-with-records
(let ((rec (make-instance 'ebdb-record-person))
(mail (ebdb-parse ebdb-default-mail-class
(phone (ebdb-parse ebdb-default-phone-class
"+1 (555) 555-5555")))
;; Pass slot explicitly.
(ebdb-record-insert-field rec mail 'mail)
;; Let the method find the slot.
(ebdb-record-insert-field rec phone)
(should (object-of-class-p
(car (ebdb-record-phone rec))
'ebdb-field-phone))
(should (object-of-class-p
(car (ebdb-record-mail rec))
'ebdb-field-mail))
(ebdb-record-delete-field rec mail)
(ebdb-record-delete-field rec phone 'phone)
(should (null (ebdb-record-mail rec)))
(should (null (ebdb-record-phone rec))))))
(ert-deftest ebdb-insert-unacceptable ()
"Make sure records reject unacceptable fields."
(ebdb-test-with-records
(let ((rec (make-instance 'ebdb-record-person))
(field (make-instance 'ebdb-field-domain :domain "gnu.org")))
(should-error (ebdb-record-field-slot-query
'ebdb-record-person (cons nil 'ebdb-field-domain))
:type 'ebdb-unacceptable-field)
(should-error (ebdb-record-insert-field rec field)
:type 'ebdb-unacceptable-field))))
(ert-deftest ebdb-change-record-field ()
"Change record's field."
(ebdb-test-with-records
(let ((rec (make-instance 'ebdb-record-person))
(mail (ebdb-parse ebdb-default-mail-class
(mail2 (ebdb-parse ebdb-default-mail-class
"[email protected]")))
(ebdb-record-insert-field rec mail)
(should (string= (ebdb-string (ebdb-record-one-mail rec))
(ebdb-record-change-field rec mail mail2)
(should (string= (ebdb-string (ebdb-record-one-mail rec))
"[email protected]")))))
;; Field instance parse tests.
;; Test `ebdb-decompose-ebdb-address'
(ert-deftest ebdb-address-decompose ()
"Test `ebdb-decompose-ebdb-address'."
(should (equal '("Charles Lamb" "[email protected]")
(ebdb-decompose-ebdb-address
"Charles Lamb <[email protected]>")))
(should (equal '("Charles Lamb" "[email protected]")
(ebdb-decompose-ebdb-address
"Charles Lamb mailto:[email protected]")))
(should (equal '("Charles Lamb" "[email protected]")
(ebdb-decompose-ebdb-address
"\"Charles Lamb\" [email protected]")))
(should (equal '("Charles Lamb" "[email protected]")
(ebdb-decompose-ebdb-address
"[email protected] (Charles Lamb)")))
(should (equal '(nil "[email protected]")
(ebdb-decompose-ebdb-address
"\"[email protected]\" [email protected]")))
(should (equal '(nil "[email protected]")
(ebdb-decompose-ebdb-address
"<[email protected]>")))
(should (equal '(nil "[email protected]")
(ebdb-decompose-ebdb-address
(should (equal '("Charles Lamb" nil)
(ebdb-decompose-ebdb-address
"Charles Lamb"))))
(ert-deftest ebdb-parse-mail ()
"Parse various strings as mail fields."
(should (equal
(slot-value
(ebdb-parse 'ebdb-field-mail "William Hazlitt <[email protected]>")
'aka)
"William Hazlitt"))
(should (equal
(slot-value
(ebdb-parse 'ebdb-field-mail "William Hazlitt <[email protected]>")
'mail)
(should-error (ebdb-parse 'ebdb-field-mail "William Hazlitt")
:type 'ebdb-unparseable))
(ert-deftest ebdb-parse-name ()
"Parse various strings as name fields."
(should (equal
(slot-value
(ebdb-parse 'ebdb-field-name-complex "Eric Abrahamsen")
'surname)
"Abrahamsen"))
(should (equal
(slot-value
(ebdb-parse 'ebdb-field-name-complex "Eric P. Abrahamsen")
'given-names)
'("Eric" "P.")))
(should (equal
(slot-value
(ebdb-parse 'ebdb-field-name-complex "Eric Abrahamsen, III")
'suffix)
"III"))
(should (equal
(slot-value
(ebdb-parse 'ebdb-field-name-complex "Albus Percival Wulfric Brian Dumbledore")
'given-names)
'("Albus" "Percival" "Wulfric" "Brian")))
(should (equal
(slot-value
(ebdb-parse 'ebdb-field-name-complex "MURAKAMI Haruki")
'surname)
"Murakami"))
(should (equal
(slot-value
(ebdb-parse 'ebdb-field-name-complex "John Reddemann")
'surname)
"Reddemann"))
(should (equal
(slot-value
(ebdb-parse 'ebdb-field-name-complex "Fintan O'Toole")
'surname)
"O'Toole"))
(should (equal
(slot-value
(ebdb-parse 'ebdb-field-name-complex "O'Toole, Fintan")
'surname)
"O'Toole"))
(should (equal
(slot-value
(ebdb-parse 'ebdb-field-name-complex "O'TOOLE Fintan")
'surname)
"O'Toole"))
(should (equal
(slot-value
(ebdb-parse 'ebdb-field-name-complex "Daniel Michael Blake Day-Lewis")
'surname)
"Day-Lewis")))
(ert-deftest ebdb-parse-phone ()
"Parse various strings as phone fields."
(let ((parsed (ebdb-parse 'ebdb-field-phone "+1 (226) 697-5852 ext. 22"))
(parsed2 (ebdb-parse 'ebdb-field-phone "+1 (226) 697 58 52X22")))
(should (eql (slot-value parsed 'country-code) 1))
(should (eql (slot-value parsed 'area-code) 226))
(should (equal (slot-value parsed 'number) "6975852"))
(should (eql (slot-value parsed 'extension) 22))
(should (equal (slot-value parsed2 'number) "6975852"))
(should (eql (slot-value parsed2 'extension) 22))))
;; Snarf testing.
(ert-deftest ebdb-snarf-mail-and-name ()
(let ((test-texts
'("Eric Abrahamsen <[email protected]>"
"Eric Abrahamsen [email protected]"
"Eric Abrahamsen ([email protected])"
"Eric Abrahamsen \n<[email protected]>"
"Eric Abrahamsen can't hold his drink\n<[email protected]> is where you can write and tell him so."))
result)
(dolist (text test-texts)
(setq result (car (ebdb-snarf-collect text)))
(pcase result
(`[nil (,name) (,mail)]
(unless (string= (ebdb-string name) "Eric Abrahamsen")
(ert-fail (list (format "Parsing \"%s\" resulted in name %s"
text (ebdb-string name)))))
(unless (string= (ebdb-string mail) "[email protected]")
(ert-fail (list (format "Parsing \"%s\" resulted in mail %s"
text (ebdb-string mail))))))
(_ (ert-fail (list (format "Parsing \"%s\" resulted in %s"
text result))))))))
;; Search testing.
(ert-deftest ebdb-message-search ()
"Test the `ebdb-message-search' function."
(ebdb-test-with-records
(ebdb-test-with-database (db ebdb-test-database-1)
(let ((rec (make-instance
'ebdb-record-person
:name (ebdb-parse 'ebdb-field-name-complex "Spongebob Squarepants")
:mail (list (ebdb-parse 'ebdb-field-mail "[email protected]")))))
(ebdb-db-add-record db rec)
;; Must init in order to get the record hashed,
;; `ebdb-message-search' relies on that.
(ebdb-init-record rec)
(should (equal (car (ebdb-message-search "Spongebob Squarepants" nil))
rec))
(should (equal (car (ebdb-message-search nil "[email protected]"))
rec))
(should (null (ebdb-message-search "Spongebob" nil)))
(should (null (ebdb-message-search nil "thepants.com")))
(ebdb-delete-record rec)))))
(ert-deftest ebdb-general-search ()
"Test some of the general search functions."
(ebdb-test-with-records
(ebdb-test-with-database (db ebdb-test-database-1)
(let ((rec (make-instance
'ebdb-record-person
:name (ebdb-parse 'ebdb-field-name-complex
"Spongebob Squarepants")
:mail (list (ebdb-parse 'ebdb-field-mail
:notes (ebdb-parse 'ebdb-field-notes
"World's greatest cartoon."))))
(ebdb-db-add-record db rec)
(ebdb-init-record rec)
;; Name is name.
(should (equal (car
(ebdb-search
(ebdb-records)
'((ebdb-field-name "Squarepants"))))
rec))
;; Mail is mail.
(should (equal (car
(ebdb-search
(ebdb-records)
'((ebdb-field-mail "thepants.com"))))
rec))
;; Mail is not notes.
(should (null (car
(ebdb-search
(ebdb-records)
'((ebdb-field-notes "thepants.com"))))))
;; Notes are notes.
(should (equal (car
(ebdb-search
(ebdb-records)
'((ebdb-field-notes "cartoon"))))
rec))
;; Notes inverted are not notes.
(should (null (car
(ebdb-search
(ebdb-records)
'((ebdb-field-notes "cartoon"))
t))))
;; Not notes inverted are.
(should (equal (car
(ebdb-search
(ebdb-records)
'((ebdb-field-notes "carton"))
t))
rec))))))
;; Test search folding and transform functions.
(ert-deftest ebdb-search-transform-and-fold ()
(ebdb-test-with-records
(let ((recs
(list (make-instance
'ebdb-record-person
:name (ebdb-parse 'ebdb-field-name-complex "Björk Jónsdóttir")))))
(ebdb-initialize recs)
(let ((ebdb-case-fold-search nil)
(ebdb-char-fold-search nil)
(ebdb-search-transform-functions nil))
(should-not (ebdb-search
recs
'((ebdb-field-name "Bjork"))))
(should-not (ebdb-search
recs
'((ebdb-field-name "björk"))))
(should (ebdb-search
recs
'((ebdb-field-name "Björk")))))
(let ((ebdb-case-fold-search t)
(ebdb-char-fold-search nil)
(ebdb-search-transform-functions nil))
(should-not (ebdb-search
recs
'((ebdb-field-name "Bjork"))))
(should (ebdb-search
recs
'((ebdb-field-name "björk"))))
(should (ebdb-search
recs
'((ebdb-field-name "Björk")))))
(let ((ebdb-case-fold-search nil)
(ebdb-char-fold-search t)
(ebdb-search-transform-functions nil))
(should (ebdb-search
recs
'((ebdb-field-name "Bjork"))))
(should-not (ebdb-search
recs
'((ebdb-field-name "björk"))))
(should (ebdb-search
recs
'((ebdb-field-name "Björk")))))
(let ((ebdb-case-fold-search t)
(ebdb-char-fold-search t)
(ebdb-search-transform-functions nil))
(should (ebdb-search
recs
'((ebdb-field-name "Bjork"))))
(should (ebdb-search
recs
'((ebdb-field-name "björk"))))
(should (ebdb-search
recs
'((ebdb-field-name "Björk"))))
(let ((ebdb-case-fold-search nil)
(ebdb-char-fold-search nil)
(ebdb-search-transform-functions
(list (lambda (str)
(concat str " Jonsdottir")))))
(should-not (ebdb-search
recs
'((ebdb-field-name "Björk")))))
(let ((ebdb-case-fold-search nil)
(ebdb-char-fold-search t)
(ebdb-search-transform-functions
(list (lambda (str)
(concat str " Jonsdottir")))))
(should (ebdb-search
recs
'((ebdb-field-name "Björk")))))))))
;; Vcard testing.
(ert-deftest ebdb-vcard-escape/unescape ()
"Test the escaping and unescaping routines."
(should (equal (ebdb-vcard-escape "Nothing.to \"escape\"!")
"Nothing.to \"escape\"!"))
(should (equal (ebdb-vcard-escape "Marry, nuncle")
"Marry\\, nuncle"))
(should (equal (ebdb-vcard-escape "Mine uncle; nay!")
"Mine uncle\\; nay!"))
;; Don't double-escape
(should (equal (ebdb-vcard-escape "Marry\\, uncle")
"Marry\\, uncle"))
;; Don't double-escape, part II
(should (equal (ebdb-vcard-escape "Marry\\n uncle!")
"Marry\\n uncle!"))
(should (equal (ebdb-vcard-escape "Mine
uncle")
"Mine \\nuncle"))
(should (equal (ebdb-vcard-unescape "Marry\\, nuncle!")
"Marry, nuncle!"))
(should (equal (ebdb-vcard-unescape "Marry \\nuncle")
"Marry
uncle"))
(should (equal (ebdb-vcard-unescape
(ebdb-vcard-escape
"Look, a bog; dogs."))
"Look, a bog; dogs.")))
(ert-deftest ebdb-vcard-fold/unfold ()
"Test line-length folding/unfolding."
(let ((short-lines "For sale:
Baby shoes,
Never used.")
(long-lines
"Turns out seventy five bytes is a lot of bytes when you just have to keep typing and typing
and typing.")
(multibyte-lines
"然后还要用中文写一行没完没了的话。
其实先要来一个短的,然后一行特别长的,那就是现在这行,
然后可以再有一个短的"))
(should (equal (ebdb-vcard-fold-lines short-lines)
"For sale:
Baby shoes,
Never used."))
(should (equal (ebdb-vcard-unfold-lines
(ebdb-vcard-fold-lines short-lines))
short-lines))
(should
(equal (ebdb-vcard-fold-lines long-lines)
"Turns out seventy five bytes is a lot of bytes when you just have to keep t
yping and typing
and typing."))
(should
(equal (ebdb-vcard-unfold-lines
(ebdb-vcard-fold-lines long-lines))
long-lines))
(should
(equal (ebdb-vcard-fold-lines multibyte-lines)
"然后还要用中文写一行没完没了的话。
其实先要来一个短的,然后一行特别长的,那就是现在这
行,
然后可以再有一个短的"))
(should
(equal (ebdb-vcard-unfold-lines
(ebdb-vcard-fold-lines multibyte-lines))
multibyte-lines))))
(ert-deftest ebdb-vcard-export-dont-explode ()
"Can we export a record to Vcard without immediate disaster?"
(ebdb-test-with-records
(let ((rec (make-instance ebdb-default-record-class
:name (ebdb-field-name-complex
:surname "Barleycorn"
:given-names '("John"))
:uuid (ebdb-field-uuid
:uuid "asdfasdfadsf")
:mail (list (ebdb-field-mail
:mail "[email protected]"))
:phone (list (ebdb-field-phone
:label "home"
:country-code 1
:area-code 555
:number "5555555"))
:notes (ebdb-field-notes
:notes "He's in the fields")))
(fmt-4
(ebdb-formatter-vcard-40
:combine nil
:collapse nil
:include '(ebdb-field-uuid
ebdb-field-name
ebdb-field-mail
ebdb-field-phone
ebdb-field-mail)))
(fmt-3
(ebdb-formatter-vcard-30
:combine nil
:collapse nil
:include '(ebdb-field-uuid
ebdb-field-name
ebdb-field-mail
ebdb-field-phone
ebdb-field-mail))))
(should (ebdb-fmt-record fmt-4 rec))
(should (ebdb-fmt-record fmt-3 rec)))))
(provide 'ebdb-test)
;;; ebdb-test.el ends here