blob: bda4f79d0daa49e297d40099fdf5f274b6ada31a (
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
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
|
;;; test-card-type-twosided.el --- Tests for two-sided card type
;;; Commentary:
;; Tests for the two-sided card type in org-drill.
;;
;; Two-sided cards have two subheadings representing two "sides" of a card.
;; When presented, one of the first two subheadings is randomly chosen
;; and shown as the question, while the other serves as the answer.
;;
;; Card type: "twosided"
;; Presentation function: org-drill-present-two-sided-card
;;; Code:
(require 'ert)
(require 'assess)
(require 'org-drill)
;;; Test Data
(defconst test-card-type-twosided-basic-card
"* Two-Sided Card :drill:
:PROPERTIES:
:DRILL_CARD_TYPE: twosided
:END:
** Side 1
English: Apple
** Side 2
Spanish: Manzana
"
"Basic two-sided card for vocabulary.")
(defconst test-card-type-twosided-with-extra-sides
"* Card with Extra Sides :drill:
:PROPERTIES:
:DRILL_CARD_TYPE: twosided
:END:
** Side A
First side content.
** Side B
Second side content.
** Side C
Third side (should not be shown in two-sided mode).
** Side D
Fourth side (should not be shown in two-sided mode).
"
"Two-sided card with more than 2 subheadings.")
(defconst test-card-type-twosided-single-side
"* Card with Single Side :drill:
:PROPERTIES:
:DRILL_CARD_TYPE: twosided
:END:
** Only Side
Only one subheading present.
"
"Two-sided card with only one subheading.")
(defconst test-card-type-twosided-empty-sides
"* Card with Empty Sides :drill:
:PROPERTIES:
:DRILL_CARD_TYPE: twosided
:END:
** Side 1
** Side 2
"
"Two-sided card with empty side content.")
;;; Helper Functions
(defun test-card-type-twosided--with-card (content callback)
"Execute CALLBACK in temp buffer with drill card CONTENT."
(with-temp-buffer
(org-mode)
(insert content)
(goto-char (point-min))
(funcall callback)))
(defun test-card-type-twosided--count-subheadings ()
"Count number of level-2 subheadings under current entry."
(save-excursion
(org-back-to-heading)
(let ((count 0)
(end (save-excursion (org-end-of-subtree t t))))
(while (and (re-search-forward "^\\*\\* " end t))
(cl-incf count))
count)))
;;; Normal Cases - Card Recognition
(ert-deftest test-card-type-twosided-normal-card-type-property ()
"Test that two-sided cards have correct DRILL_CARD_TYPE property."
(test-card-type-twosided--with-card
test-card-type-twosided-basic-card
(lambda ()
(should (org-drill-entry-p))
(should (equal "twosided" (org-entry-get (point) "DRILL_CARD_TYPE"))))))
(ert-deftest test-card-type-twosided-normal-has-presentation-function ()
"Test that twosided card type has correct presentation function registered."
(let ((entry (assoc "twosided" org-drill-card-type-alist)))
(should entry)
(should (eq (cadr entry) 'org-drill-present-two-sided-card))))
(ert-deftest test-card-type-twosided-normal-drill-empty-p-flag ()
"Test that twosided card type has drill-empty-p flag set.
This allows two-sided cards to be presented even if main body is empty."
(let ((entry (assoc "twosided" org-drill-card-type-alist)))
(should entry)
;; Fourth element is drill-empty-p flag
(should (nth 3 entry))))
;;; Normal Cases - Card Structure
(ert-deftest test-card-type-twosided-normal-two-subheadings ()
"Test two-sided card with exactly two subheadings."
(test-card-type-twosided--with-card
test-card-type-twosided-basic-card
(lambda ()
(should (org-drill-entry-p))
(should (= 2 (test-card-type-twosided--count-subheadings))))))
(ert-deftest test-card-type-twosided-normal-more-than-two-subheadings ()
"Test two-sided card with more than two subheadings.
Only first two should be used for presentation."
(test-card-type-twosided--with-card
test-card-type-twosided-with-extra-sides
(lambda ()
(should (org-drill-entry-p))
(should (> (test-card-type-twosided--count-subheadings) 2)))))
;;; Boundary Cases
(ert-deftest test-card-type-twosided-boundary-single-subheading ()
"Test two-sided card with only one subheading.
Should still be a valid card, though not ideal."
(test-card-type-twosided--with-card
test-card-type-twosided-single-side
(lambda ()
(should (org-drill-entry-p))
(should (= 1 (test-card-type-twosided--count-subheadings))))))
(ert-deftest test-card-type-twosided-boundary-empty-side-content ()
"Test two-sided card where sides have no content."
(test-card-type-twosided--with-card
test-card-type-twosided-empty-sides
(lambda ()
(should (org-drill-entry-p))
(should (= 2 (test-card-type-twosided--count-subheadings))))))
(ert-deftest test-card-type-twosided-boundary-no-main-body ()
"Test two-sided card with no main body content.
This is valid because twosided has drill-empty-p flag."
(let ((content "* No Body :drill:\n:PROPERTIES:\n:DRILL_CARD_TYPE: twosided\n:END:\n\n** A\n\nContent A\n\n** B\n\nContent B\n"))
(test-card-type-twosided--with-card
content
(lambda ()
(should (org-drill-entry-p))
(should (equal "twosided" (org-entry-get (point) "DRILL_CARD_TYPE")))))))
;;; Card Type Semantics
(ert-deftest test-card-type-twosided-normal-vocabulary-use-case ()
"Test typical vocabulary card use case.
Two sides for word translation pairs."
(test-card-type-twosided--with-card
test-card-type-twosided-basic-card
(lambda ()
(should (org-drill-entry-p))
;; Verify both sides exist
(let ((sides nil))
(save-excursion
(org-back-to-heading)
(while (re-search-forward "^\\*\\* " nil t)
(let ((heading-text (buffer-substring
(point)
(line-end-position))))
(push heading-text sides))))
(should (= 2 (length sides)))
(should (member "Side 1" sides))
(should (member "Side 2" sides))))))
(ert-deftest test-card-type-twosided-normal-concept-definition-use-case ()
"Test concept/definition card use case."
(let ((content "* Concept Card :drill:\n:PROPERTIES:\n:DRILL_CARD_TYPE: twosided\n:END:\n\n** Concept\n\nPolymorphism\n\n** Definition\n\nAbility of different objects to respond to same message in different ways.\n"))
(test-card-type-twosided--with-card
content
(lambda ()
(should (org-drill-entry-p))
(should (= 2 (test-card-type-twosided--count-subheadings)))))))
(ert-deftest test-card-type-twosided-normal-different-from-simple ()
"Test that twosided is registered differently from simple."
(let ((twosided-fn (cadr (assoc "twosided" org-drill-card-type-alist)))
(simple-fn (cadr (assoc "simple" org-drill-card-type-alist))))
(should-not (eq twosided-fn simple-fn))
(should (eq twosided-fn 'org-drill-present-two-sided-card))
(should (eq simple-fn 'org-drill-present-simple-card))))
;;; Aggressive Edge Cases
(ert-deftest test-card-type-twosided-edge-unicode-in-sides ()
"Test two-sided card with Unicode in both sides.
Unicode characters should be preserved correctly."
(let ((content "* Unicode Card :drill:
:PROPERTIES:
:DRILL_CARD_TYPE: twosided
:END:
** English
Hello
** 日本語
こんにちは
"))
(test-card-type-twosided--with-card
content
(lambda ()
(should (org-drill-entry-p))
(should (= 2 (test-card-type-twosided--count-subheadings)))))))
(ert-deftest test-card-type-twosided-edge-very-long-side-content ()
"Test two-sided card with very long content in sides.
Should handle large amounts of text without issues."
(let* ((long-text (make-string 5000 ?x))
(content (format "* Long Sides :drill:
:PROPERTIES:
:DRILL_CARD_TYPE: twosided
:END:
** Side A
%s
** Side B
%s
" long-text long-text)))
(test-card-type-twosided--with-card
content
(lambda ()
(should (org-drill-entry-p))
(should (= 2 (test-card-type-twosided--count-subheadings)))))))
(ert-deftest test-card-type-twosided-edge-sides-with-lists ()
"Test two-sided card with org-mode lists in sides."
(let ((content "* Lists Card :drill:
:PROPERTIES:
:DRILL_CARD_TYPE: twosided
:END:
** Question
What are primary colors?
** Answer
- Red
- Blue
- Yellow
"))
(test-card-type-twosided--with-card
content
(lambda ()
(should (org-drill-entry-p))
(should (= 2 (test-card-type-twosided--count-subheadings)))))))
(ert-deftest test-card-type-twosided-edge-sides-with-tables ()
"Test two-sided card with org-mode tables in sides."
(let ((content "* Table Card :drill:
:PROPERTIES:
:DRILL_CARD_TYPE: twosided
:END:
** Question
Temperature conversion?
** Table
| Celsius | Fahrenheit |
|---------+------------|
| 0 | 32 |
| 100 | 212 |
"))
(test-card-type-twosided--with-card
content
(lambda ()
(should (org-drill-entry-p))
(should (= 2 (test-card-type-twosided--count-subheadings)))))))
(ert-deftest test-card-type-twosided-edge-sides-with-code-blocks ()
"Test two-sided card with source code blocks in sides."
(let ((content "* Code Card :drill:
:PROPERTIES:
:DRILL_CARD_TYPE: twosided
:END:
** Question
Python hello world?
** Code
#+BEGIN_SRC python
print(\"Hello, World!\")
#+END_SRC
"))
(test-card-type-twosided--with-card
content
(lambda ()
(should (org-drill-entry-p))
(should (= 2 (test-card-type-twosided--count-subheadings)))))))
(ert-deftest test-card-type-twosided-edge-sides-with-links ()
"Test two-sided card with org-mode links in sides."
(let ((content "* Links Card :drill:
:PROPERTIES:
:DRILL_CARD_TYPE: twosided
:END:
** Term
Emacs
** Definition
A [[https://www.gnu.org/software/emacs/][powerful text editor]].
"))
(test-card-type-twosided--with-card
content
(lambda ()
(should (org-drill-entry-p))
(should (= 2 (test-card-type-twosided--count-subheadings)))))))
(ert-deftest test-card-type-twosided-edge-sides-with-formatting ()
"Test two-sided card with org-mode text formatting in sides."
(let ((content "* Formatted Card :drill:
:PROPERTIES:
:DRILL_CARD_TYPE: twosided
:END:
** Question
What is *bold*, /italic/, =code=?
** Answer
These are *org-mode* /text/ =formatting= options.
"))
(test-card-type-twosided--with-card
content
(lambda ()
(should (org-drill-entry-p))
(should (= 2 (test-card-type-twosided--count-subheadings)))))))
(ert-deftest test-card-type-twosided-edge-sides-with-tags ()
"Test two-sided card where sides have tags.
Tags on subheadings should not interfere with card."
(let ((content "* Card with Tagged Sides :drill:
:PROPERTIES:
:DRILL_CARD_TYPE: twosided
:END:
** Question :important:
What is the answer?
** Answer :note:
42
"))
(test-card-type-twosided--with-card
content
(lambda ()
(should (org-drill-entry-p))
(should (= 2 (test-card-type-twosided--count-subheadings)))))))
(ert-deftest test-card-type-twosided-edge-nested-subheadings-in-sides ()
"Test two-sided card with nested subheadings within sides.
Nested content should be part of the side."
(let ((content "* Nested Content :drill:
:PROPERTIES:
:DRILL_CARD_TYPE: twosided
:END:
** Side A
Content A
*** Nested Under A
More details.
** Side B
Content B
"))
(test-card-type-twosided--with-card
content
(lambda ()
(should (org-drill-entry-p))
(should (= 2 (test-card-type-twosided--count-subheadings)))))))
(ert-deftest test-card-type-twosided-edge-empty-headings ()
"Test two-sided card where heading text is minimal."
(let ((content "* Minimal Headings :drill:
:PROPERTIES:
:DRILL_CARD_TYPE: twosided
:END:
** A
Full content for A.
** B
Full content for B.
"))
(test-card-type-twosided--with-card
content
(lambda ()
(should (org-drill-entry-p))
(should (= 2 (test-card-type-twosided--count-subheadings)))))))
(ert-deftest test-card-type-twosided-edge-special-characters-in-sides ()
"Test two-sided card with special characters in side content."
(let ((content "* Special Chars :drill:
:PROPERTIES:
:DRILL_CARD_TYPE: twosided
:END:
** Question
What are these: @#$%^&*()?
** Answer
Special programming characters.
"))
(test-card-type-twosided--with-card
content
(lambda ()
(should (org-drill-entry-p))
(should (= 2 (test-card-type-twosided--count-subheadings)))))))
(ert-deftest test-card-type-twosided-edge-many-extra-sides ()
"Test two-sided card with many subheadings (10+).
Only first two should be used for presentation."
(let ((content "* Many Sides :drill:
:PROPERTIES:
:DRILL_CARD_TYPE: twosided
:END:
** Side 1
Content 1
** Side 2
Content 2
** Side 3
Extra
** Side 4
Extra
** Side 5
Extra
** Side 6
Extra
** Side 7
Extra
** Side 8
Extra
** Side 9
Extra
** Side 10
Extra
"))
(test-card-type-twosided--with-card
content
(lambda ()
(should (org-drill-entry-p))
(should (>= (test-card-type-twosided--count-subheadings) 10))))))
(ert-deftest test-card-type-twosided-edge-no-subheadings ()
"Test two-sided card with no subheadings at all.
Card is invalid but should not crash."
(let ((content "* No Sides :drill:
:PROPERTIES:
:DRILL_CARD_TYPE: twosided
:END:
Just main body, no subheadings.
"))
(test-card-type-twosided--with-card
content
(lambda ()
(should (org-drill-entry-p))
(should (= 0 (test-card-type-twosided--count-subheadings)))))))
(ert-deftest test-card-type-twosided-edge-sides-with-drawers ()
"Test two-sided card with drawers in sides.
Drawers should be preserved."
(let ((content "* Drawer Card :drill:
:PROPERTIES:
:DRILL_CARD_TYPE: twosided
:END:
** Side A
:LOGBOOK:
- Note taken on [2024-01-01]
:END:
Content A
** Side B
Content B
"))
(test-card-type-twosided--with-card
content
(lambda ()
(should (org-drill-entry-p))
(should (= 2 (test-card-type-twosided--count-subheadings)))))))
(provide 'test-card-type-twosided)
;;; test-card-type-twosided.el ends here
|