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
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
| | ;;; test-ox.el --- Tests for ox.el
;; Copyright (C) 2012, 2013 Nicolas Goaziou
;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
;; This file is not part of GNU Emacs.
;; 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/>.
;;; Code:
(unless (featurep 'ox)
(signal 'missing-test-dependency "org-export"))
(defmacro org-test-with-backend (backend &rest body)
"Execute body with an export back-end defined.
BACKEND is the name of the back-end. BODY is the body to
execute. The defined back-end simply returns parsed data as Org
syntax."
(declare (debug (form body)) (indent 1))
`(let ((org-export-registered-backends
',(list
(list backend
:translate-alist
(let (transcode-table)
(dolist (type (append org-element-all-elements
org-element-all-objects)
transcode-table)
(push
(cons type
(lambda (obj contents info)
(funcall
(intern (format "org-element-%s-interpreter"
type))
obj contents)))
transcode-table)))))))
(progn ,@body)))
(defmacro org-test-with-parsed-data (data &rest body)
"Execute body with parsed data available.
DATA is a string containing the data to be parsed. BODY is the
body to execute. Parse tree is available under the `tree'
variable, and communication channel under `info'.
This function calls `org-export-collect-tree-properties'. As
such, `:ignore-list' (for `org-element-map') and
`:parse-tree' (for `org-export-get-genealogy') properties are
already filled in `info'."
(declare (debug (form body)) (indent 1))
`(org-test-with-temp-text ,data
(let* ((tree (org-element-parse-buffer))
(info (org-export-collect-tree-properties
tree (org-export-get-environment))))
,@body)))
\f
;;; Internal Tests
(ert-deftest test-org-export/bind-keyword ()
"Test reading #+BIND: keywords."
;; Test with `org-export-allow-bind-keywords' set to t.
(should
(org-test-with-temp-text "#+BIND: test-ox-var value"
(let ((org-export-allow-bind-keywords t))
(org-export-get-environment)
(eq test-ox-var 'value))))
;; Test with `org-export-allow-bind-keywords' set to nil.
(should-not
(org-test-with-temp-text "#+BIND: test-ox-var value"
(let ((org-export-allow-bind-keywords nil))
(org-export-get-environment)
(boundp 'test-ox-var))))
;; BIND keywords are case-insensitive.
(should
(org-test-with-temp-text "#+bind: test-ox-var value"
(let ((org-export-allow-bind-keywords t))
(org-export-get-environment)
(eq test-ox-var 'value))))
;; Preserve order of BIND keywords.
(should
(org-test-with-temp-text "#+BIND: test-ox-var 1\n#+BIND: test-ox-var 2"
(let ((org-export-allow-bind-keywords t))
(org-export-get-environment)
(eq test-ox-var 2))))
;; Read BIND keywords in setup files.
(should
(org-test-with-temp-text
(format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
(let ((org-export-allow-bind-keywords t))
(org-export-get-environment)
(eq variable 'value))))
;; Verify that bound variables are seen during export.
(should
(equal "Yes\n"
(org-test-with-temp-text "#+BIND: test-ox-var value"
(let ((org-export-allow-bind-keywords t)
org-export-registered-backends)
(org-export-define-backend 'check
'((section . (lambda (s c i)
(if (eq test-ox-var 'value) "Yes" "No")))))
(org-export-as 'check))))))
(ert-deftest test-org-export/parse-option-keyword ()
"Test reading all standard #+OPTIONS: items."
(should
(equal
(org-export--parse-option-keyword
"H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
*:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil
stat:t")
'(:headline-levels
1 :preserve-breaks t :section-numbers t :time-stamp-file t
:with-archived-trees t :with-author t :with-creator t :with-drawers t
:with-email t :with-emphasize t :with-entities t :with-fixed-width t
:with-footnotes t :with-inlinetasks nil :with-priority t
:with-special-strings t :with-statistics-cookies t :with-sub-superscript t
:with-toc t :with-tables t :with-tags t :with-tasks t :with-timestamps t
:with-todo-keywords t)))
;; Test some special values.
(should
(equal
(org-export--parse-option-keyword
"arch:headline creator:comment d:(\"TEST\")
^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
'( :section-numbers
2
:with-archived-trees headline :with-creator comment
:with-drawers ("TEST") :with-sub-superscript {} :with-toc 1
:with-tags not-in-toc :with-tasks todo :with-timestamps active))))
(ert-deftest test-org-export/get-inbuffer-options ()
"Test reading all standard export keywords."
;; Properties should follow buffer order.
(should
(equal
(org-test-with-temp-text "#+LANGUAGE: fr\n#+CREATOR: Me\n#+EMAIL: email"
(org-export--get-inbuffer-options))
'(:language "fr" :creator "Me" :email "email")))
;; Parse document keywords.
(should
(equal
(org-test-with-temp-text "#+AUTHOR: Me"
(org-export--get-inbuffer-options))
'(:author ("Me"))))
;; Test `space' behaviour.
(should
(equal
(org-test-with-temp-text "#+TITLE: Some title\n#+TITLE: with spaces"
(org-export--get-inbuffer-options))
'(:title ("Some title with spaces"))))
;; Test `newline' behaviour.
(should
(equal
(org-test-with-temp-text "#+DESCRIPTION: With\n#+DESCRIPTION: two lines"
(org-export--get-inbuffer-options))
'(:description "With\ntwo lines")))
;; Test `split' behaviour.
(should
(equal
(org-test-with-temp-text "#+SELECT_TAGS: a\n#+SELECT_TAGS: b"
(org-export--get-inbuffer-options))
'(:select-tags ("a" "b"))))
;; Options set through SETUPFILE.
(should
(equal
(org-test-with-temp-text
(format "#+DESCRIPTION: l1
#+LANGUAGE: es
#+SELECT_TAGS: a
#+TITLE: a
#+SETUPFILE: \"%s/examples/setupfile.org\"
#+DESCRIPTION: l3
#+LANGUAGE: fr
#+SELECT_TAGS: c
#+TITLE: c"
org-test-dir)
(org-export--get-inbuffer-options))
'(:description "l1\nl2\nl3":language "fr" :select-tags ("a" "b" "c")
:title ("a b c")))))
(ert-deftest test-org-export/get-subtree-options ()
"Test setting options from headline's properties."
;; EXPORT_TITLE.
(org-test-with-temp-text "#+TITLE: Title
* Headline
:PROPERTIES:
:EXPORT_TITLE: Subtree Title
:END:
Paragraph"
(forward-line)
(should (equal (plist-get (org-export-get-environment nil t) :title)
'("Subtree Title"))))
:title
'("subtree-title")
;; EXPORT_OPTIONS.
(org-test-with-temp-text "#+OPTIONS: H:1
* Headline
:PROPERTIES:
:EXPORT_OPTIONS: H:2
:END:
Paragraph"
(forward-line)
(should
(= 2 (plist-get (org-export-get-environment nil t) :headline-levels))))
;; EXPORT_DATE.
(org-test-with-temp-text "#+DATE: today
* Headline
:PROPERTIES:
:EXPORT_DATE: 29-03-2012
:END:
Paragraph"
(forward-line)
(should (equal (plist-get (org-export-get-environment nil t) :date)
'("29-03-2012"))))
;; Properties with `split' behaviour are stored as a list of
;; strings.
(should
(equal '("a" "b")
(org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
* Headline
:PROPERTIES:
:EXPORT_EXCLUDE_TAGS: a b
:END:
Paragraph"
(progn
(forward-line)
(plist-get (org-export-get-environment nil t) :exclude-tags)))))
;; Handle :PROPERTY+: syntax.
(should
(equal '("a" "b")
(org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
* Headline
:PROPERTIES:
:EXPORT_EXCLUDE_TAGS: a
:EXPORT_EXCLUDE_TAGS+: b
:END:
Paragraph"
(progn
(forward-line)
(plist-get (org-export-get-environment nil t) :exclude-tags)))))
;; Export properties are case-insensitive.
(org-test-with-temp-text "* Headline
:PROPERTIES:
:EXPORT_Date: 29-03-2012
:END:
Paragraph"
(should (equal (plist-get (org-export-get-environment nil t) :date)
'("29-03-2012"))))
;; Still grab correct options when section above is empty.
(should
(equal '("H1")
(org-test-with-temp-text "* H1\n** H11\n** H12"
(progn (forward-line 2)
(plist-get (org-export-get-environment nil t) :title))))))
(ert-deftest test-org-export/handle-options ()
"Test if export options have an impact on output."
;; Test exclude tags for headlines and inlinetasks.
(should
(equal ""
(org-test-with-temp-text "* Head1 :noexp:"
(org-test-with-backend test
(org-export-as 'test nil nil nil '(:exclude-tags ("noexp")))))))
;; Test include tags for headlines and inlinetasks.
(should
(equal "* H2\n** Sub :exp:\n*** Sub Sub\n"
(org-test-with-temp-text "* H1\n* H2\n** Sub :exp:\n*** Sub Sub\n* H3"
(let ((org-tags-column 0))
(org-test-with-backend test
(org-export-as 'test nil nil nil '(:select-tags ("exp"))))))))
;; Test mixing include tags and exclude tags.
(org-test-with-temp-text "
* Head1 :export:
** Sub-Head1 :noexport:
** Sub-Head2
* Head2 :noexport:
** Sub-Head1 :export:"
(org-test-with-backend test
(should
(string-match
"\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
(org-export-as
'test nil nil nil
'(:select-tags ("export") :exclude-tags ("noexport")))))))
;; Ignore tasks.
(should
(equal ""
(let ((org-todo-keywords '((sequence "TODO" "DONE"))))
(org-test-with-temp-text "* TODO Head1"
(org-test-with-backend test
(org-export-as 'test nil nil nil '(:with-tasks nil)))))))
(should
(equal "* TODO Head1\n"
(let ((org-todo-keywords '((sequence "TODO" "DONE"))))
(org-test-with-temp-text "* TODO Head1"
(org-test-with-backend test
(org-export-as 'test nil nil nil '(:with-tasks t)))))))
;; Archived tree.
(org-test-with-temp-text "* Head1 :archive:"
(let ((org-archive-tag "archive"))
(org-test-with-backend test
(should
(equal (org-export-as 'test nil nil nil '(:with-archived-trees nil))
"")))))
(org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
(let ((org-archive-tag "archive"))
(org-test-with-backend test
(should
(string-match
"\\* Head1[ \t]+:archive:"
(org-export-as 'test nil nil nil
'(:with-archived-trees headline)))))))
(org-test-with-temp-text "* Head1 :archive:"
(let ((org-archive-tag "archive"))
(org-test-with-backend test
(should
(string-match
"\\`\\* Head1[ \t]+:archive:\n\\'"
(org-export-as 'test nil nil nil '(:with-archived-trees t)))))))
;; Clocks.
(let ((org-clock-string "CLOCK:"))
(org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
(org-test-with-backend test
(should
(equal (org-export-as 'test nil nil nil '(:with-clocks t))
"CLOCK: [2012-04-29 sun. 10:45]\n"))
(should
(equal (org-export-as 'test nil nil nil '(:with-clocks nil)) "")))))
;; Drawers.
(let ((org-drawers '("TEST")))
(org-test-with-temp-text ":TEST:\ncontents\n:END:"
(org-test-with-backend test
(should (equal (org-export-as 'test nil nil nil '(:with-drawers nil))
""))
(should (equal (org-export-as 'test nil nil nil '(:with-drawers t))
":TEST:\ncontents\n:END:\n")))))
(let ((org-drawers '("FOO" "BAR")))
(org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
(org-test-with-backend test
(should
(equal (org-export-as 'test nil nil nil '(:with-drawers ("FOO")))
":FOO:\nkeep\n:END:\n")))))
(let ((org-drawers '("FOO" "BAR")))
(org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
(org-test-with-backend test
(should
(equal (org-export-as 'test nil nil nil '(:with-drawers (not "BAR")))
":FOO:\nkeep\n:END:\n")))))
;; Inlinetasks.
(when (featurep 'org-inlinetask)
(should
(equal
(let ((org-inlinetask-min-level 15))
(org-test-with-temp-text "*************** Task"
(org-test-with-backend test
(org-export-as 'test nil nil nil '(:with-inlinetasks nil)))))
""))
(should
(equal
(let ((org-inlinetask-min-level 15))
(org-test-with-temp-text
"*************** Task\nContents\n*************** END"
(org-test-with-backend test
(org-export-as 'test nil nil nil '(:with-inlinetasks nil)))))
"")))
;; Plannings.
(let ((org-closed-string "CLOSED:"))
(org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
(org-test-with-backend test
(should
(equal (org-export-as 'test nil nil nil '(:with-plannings t))
"CLOSED: [2012-04-29 sun. 10:45]\n"))
(should
(equal (org-export-as 'test nil nil nil '(:with-plannings nil))
"")))))
;; Statistics cookies.
(should
(equal ""
(org-test-with-temp-text "[0/0]"
(org-test-with-backend test
(org-export-as
'test nil nil nil '(:with-statistics-cookies nil))))))
;; Timestamps.
(org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
(org-test-with-backend test
(should
(equal (org-export-as 'test nil nil nil '(:with-timestamps t))
"[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n"))
(should
(equal (org-export-as 'test nil nil nil '(:with-timestamps nil)) ""))
(should
(equal (org-export-as 'test nil nil nil '(:with-timestamps active))
"<2012-04-29 sun. 10:45>\n"))
(should
(equal (org-export-as 'test nil nil nil '(:with-timestamps inactive))
"[2012-04-29 sun. 10:45]\n")))))
(ert-deftest test-org-export/comment-tree ()
"Test if export process ignores commented trees."
(let ((org-comment-string "COMMENT"))
(org-test-with-temp-text "* COMMENT Head1"
(org-test-with-backend test
(should (equal (org-export-as 'test) ""))))))
(ert-deftest test-org-export/export-scope ()
"Test all export scopes."
(org-test-with-temp-text "
* Head1
** Head2
text
*** Head3"
(org-test-with-backend test
;; Subtree.
(forward-line 3)
(should (equal (org-export-as 'test 'subtree) "text\n*** Head3\n"))
;; Visible.
(goto-char (point-min))
(forward-line)
(org-cycle)
(should (equal (org-export-as 'test nil 'visible) "* Head1\n"))
;; Region.
(goto-char (point-min))
(forward-line 3)
(transient-mark-mode 1)
(push-mark (point) t t)
(goto-char (point-at-eol))
(should (equal (org-export-as 'test) "text\n"))))
;; Subtree with a code block calling another block outside.
(should
(equal ": 3\n"
(org-test-with-temp-text "
* Head1
#+BEGIN_SRC emacs-lisp :noweb yes :exports results
<<test>>
#+END_SRC
* Head2
#+NAME: test
#+BEGIN_SRC emacs-lisp
\(+ 1 2)
#+END_SRC"
(org-test-with-backend test
(forward-line 1)
(org-export-as 'test 'subtree)))))
;; Body only.
(org-test-with-temp-text "Text"
(org-test-with-backend test
(plist-put
(cdr (assq 'test org-export-registered-backends))
:translate-alist
(cons (cons 'template (lambda (body info) (format "BEGIN\n%sEND" body)))
(org-export-backend-translate-table 'test)))
(should (equal (org-export-as 'test nil nil 'body-only) "Text\n"))
(should (equal (org-export-as 'test) "BEGIN\nText\nEND")))))
(ert-deftest test-org-export/output-file-name ()
"Test `org-export-output-file-name' specifications."
;; Export from a file: name is built from original file name.
(should
(org-test-with-temp-text-in-file "Test"
(equal (concat (file-name-as-directory ".")
(file-name-nondirectory
(file-name-sans-extension (buffer-file-name))))
(file-name-sans-extension (org-export-output-file-name ".ext")))))
;; When exporting to subtree, check EXPORT_FILE_NAME property first.
(should
(org-test-with-temp-text-in-file
"* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
(equal (org-export-output-file-name ".ext" t) "./test.ext")))
;; From a buffer not associated to a file, too.
(should
(org-test-with-temp-text
"* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
(equal (org-export-output-file-name ".ext" t) "./test.ext")))
;; When provided name is absolute, preserve it.
(should
(org-test-with-temp-text
(format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
(expand-file-name "test"))
(file-name-absolute-p (org-export-output-file-name ".ext" t))))
;; When PUB-DIR argument is provided, use it.
(should
(org-test-with-temp-text-in-file "Test"
(equal (file-name-directory
(org-export-output-file-name ".ext" nil "dir/"))
"dir/")))
;; When returned name would overwrite original file, add EXTENSION
;; another time.
(should
(org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
(equal (org-export-output-file-name ".org") "./normal.org.org"))))
(ert-deftest test-org-export/expand-include ()
"Test file inclusion in an Org buffer."
;; Error when file isn't specified.
(should-error
(org-test-with-temp-text "#+INCLUDE: dummy.org"
(org-export-expand-include-keyword)))
;; Full insertion with recursive inclusion.
(org-test-with-temp-text
(format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir)
(org-export-expand-include-keyword)
(should (equal (buffer-string)
"Small Org file with an include keyword.
#+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
Success!
* Heading
body\n")))
;; Localized insertion.
(org-test-with-temp-text
(format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
org-test-dir)
(org-export-expand-include-keyword)
(should (equal (buffer-string)
"Small Org file with an include keyword.\n")))
;; Insertion with constraints on headlines level.
(should
(equal
"* Top heading\n** Heading\nbody\n"
(org-test-with-temp-text
(format
"* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
org-test-dir)
(org-export-expand-include-keyword)
(buffer-string))))
(should
(equal
"* Top heading\n* Heading\nbody\n"
(org-test-with-temp-text
(format
"* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\" :minlevel 1"
org-test-dir)
(org-export-expand-include-keyword)
(buffer-string))))
;; Inclusion within an example block.
(org-test-with-temp-text
(format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
org-test-dir)
(org-export-expand-include-keyword)
(should
(equal
(buffer-string)
"#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
;; Inclusion within a src-block.
(org-test-with-temp-text
(format
"#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
org-test-dir)
(org-export-expand-include-keyword)
(should (equal (buffer-string)
"#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
(ert-deftest test-org-export/expand-macro ()
"Test macro expansion in an Org buffer."
;; Standard macro expansion.
(should
(equal "#+MACRO: macro1 value\nvalue\n"
(org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
(org-test-with-backend test (org-export-as 'test)))))
;; Expand specific macros.
(should
(equal "me 2012-03-29 me@here Title\n"
(org-test-with-temp-text
"
#+TITLE: Title
#+DATE: 2012-03-29
#+AUTHOR: me
#+EMAIL: me@here
{{{author}}} {{{date}}} {{{email}}} {{{title}}}"
(let ((output (org-test-with-backend test (org-export-as 'test))))
(substring output (string-match ".*\n\\'" output))))))
;; Expand specific macros when property contained a regular macro
;; already.
(should
(equal "value\n"
(org-test-with-temp-text "
#+MACRO: macro1 value
#+TITLE: {{{macro1}}}
{{{title}}}"
(let ((output (org-test-with-backend test (org-export-as 'test))))
(substring output (string-match ".*\n\\'" output))))))
;; Expand macros with templates in included files.
(should
(equal "success\n"
(org-test-with-temp-text
(format "#+INCLUDE: \"%s/examples/macro-templates.org\"
{{{included-macro}}}" org-test-dir)
(let ((output (org-test-with-backend test (org-export-as 'test))))
(substring output (string-match ".*\n\\'" output)))))))
(ert-deftest test-org-export/user-ignore-list ()
"Test if `:ignore-list' accepts user input."
(org-test-with-backend test
(flet ((skip-note-head
(data backend info)
;; Ignore headlines with the word "note" in their title.
(org-element-map data 'headline
(lambda (headline)
(when (string-match "\\<note\\>"
(org-element-property :raw-value headline))
(org-export-ignore-element headline info)))
info)
data))
;; Install function in parse tree filters.
(let ((org-export-filter-parse-tree-functions '(skip-note-head)))
(org-test-with-temp-text "* Head1\n* Head2 (note)\n"
(should (equal (org-export-as 'test) "* Head1\n")))))))
(ert-deftest test-org-export/before-processing-hook ()
"Test `org-export-before-processing-hook'."
(should
(equal
"#+MACRO: mac val\nTest\n"
(org-test-with-backend test
(org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
(let ((org-export-before-processing-hook
'((lambda (backend)
(while (re-search-forward "{{{" nil t)
(let ((object (org-element-context)))
(when (eq (org-element-type object) 'macro)
(delete-region
(org-element-property :begin object)
(org-element-property :end object)))))))))
(org-export-as 'test)))))))
(ert-deftest test-org-export/before-parsing-hook ()
"Test `org-export-before-parsing-hook'."
(should
(equal "Body 1\nBody 2\n"
(org-test-with-backend test
(org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
(let ((org-export-before-parsing-hook
'((lambda (backend)
(goto-char (point-min))
(while (re-search-forward org-outline-regexp-bol nil t)
(delete-region
(point-at-bol) (progn (forward-line) (point))))))))
(org-export-as 'test)))))))
\f
;;; Affiliated Keywords
(ert-deftest test-org-export/read-attribute ()
"Test `org-export-read-attribute' specifications."
;; Standard test.
(should
(equal
(org-export-read-attribute
:attr_html
(org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
(org-element-at-point)))
'(:a "1" :b "2")))
;; Return nil on empty attribute.
(should-not
(org-export-read-attribute
:attr_html
(org-test-with-temp-text "Paragraph" (org-element-at-point))))
;; Return nil on "nil" string.
(should
(equal '(:a nil :b nil)
(org-export-read-attribute
:attr_html
(org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
(org-element-at-point)))))
;; Return nil on empty string.
(should
(equal '(:a nil :b nil)
(org-export-read-attribute
:attr_html
(org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
(org-element-at-point)))))
;; Ignore text before first property.
(should-not
(member "ignore"
(org-export-read-attribute
:attr_html
(org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
(org-element-at-point))))))
(ert-deftest test-org-export/get-caption ()
"Test `org-export-get-caption' specifications."
;; Without optional argument, return long caption
(should
(equal
'("l")
(org-test-with-temp-text "#+CAPTION[s]: l\nPara"
(org-export-get-caption (org-element-at-point)))))
;; With optional argument, return short caption.
(should
(equal
'("s")
(org-test-with-temp-text "#+CAPTION[s]: l\nPara"
(org-export-get-caption (org-element-at-point) t))))
;; Multiple lines are separated by white spaces.
(should
(equal
'("a" " " "b")
(org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
(org-export-get-caption (org-element-at-point))))))
\f
;;; Back-End Tools
(ert-deftest test-org-export/define-backend ()
"Test back-end definition and accessors."
;; Translate table.
(should
(equal '((headline . my-headline-test))
(let (org-export-registered-backends)
(org-export-define-backend 'test '((headline . my-headline-test)))
(org-export-backend-translate-table 'test))))
;; Filters.
(should
(equal '((:filter-headline . my-filter))
(let (org-export-registered-backends)
(org-export-define-backend 'test
'((headline . my-headline-test))
:filters-alist '((:filter-headline . my-filter)))
(org-export-backend-filters 'test))))
;; Options.
(should
(equal '((:prop value))
(let (org-export-registered-backends)
(org-export-define-backend 'test
'((headline . my-headline-test))
:options-alist '((:prop value)))
(org-export-backend-options 'test))))
;; Menu.
(should
(equal '(?k "Test Export" test)
(let (org-export-registered-backends)
(org-export-define-backend 'test
'((headline . my-headline-test))
:menu-entry '(?k "Test Export" test))
(org-export-backend-menu 'test))))
;; Export Blocks.
(should
(equal '(("TEST" . org-element-export-block-parser))
(let (org-export-registered-backends org-element-block-name-alist)
(org-export-define-backend 'test
'((headline . my-headline-test))
:export-block '("test"))
org-element-block-name-alist))))
(ert-deftest test-org-export/define-derived-backend ()
"Test `org-export-define-derived-backend' specifications."
;; Error when parent back-end is not defined.
(should-error
(let (org-export-registered-backends)
(org-export-define-derived-backend 'test 'parent)))
;; Append translation table to parent's.
(should
(equal '((:headline . test) (:headline . parent))
(let (org-export-registered-backends)
(org-export-define-backend 'parent '((:headline . parent)))
(org-export-define-derived-backend 'test 'parent
:translate-alist '((:headline . test)))
(org-export-backend-translate-table 'test))))
;; Options defined in the new back have priority over those defined
;; in parent.
(should
(eq 'test
(let (org-export-registered-backends)
(org-export-define-backend 'parent
'((:headline . parent))
:options-alist '((:a nil nil 'parent)))
(org-export-define-derived-backend 'test 'parent
:options-alist '((:a nil nil 'test)))
(plist-get (org-export--get-global-options 'test) :a)))))
(ert-deftest test-org-export/derived-backend-p ()
"Test `org-export-derived-backend-p' specifications."
;; Non-nil with direct match.
(should
(let (org-export-registered-backends)
(org-export-define-backend 'test '((headline . test)))
(org-export-derived-backend-p 'test 'test)))
(should
(let (org-export-registered-backends)
(org-export-define-backend 'test '((headline . test)))
(org-export-define-derived-backend 'test2 'test)
(org-export-derived-backend-p 'test2 'test2)))
;; Non-nil with a direct parent.
(should
(let (org-export-registered-backends)
(org-export-define-backend 'test '((headline . test)))
(org-export-define-derived-backend 'test2 'test)
(org-export-derived-backend-p 'test2 'test)))
;; Non-nil with an indirect parent.
(should
(let (org-export-registered-backends)
(org-export-define-backend 'test '((headline . test)))
(org-export-define-derived-backend 'test2 'test)
(org-export-define-derived-backend 'test3 'test2)
(org-export-derived-backend-p 'test3 'test)))
;; Nil otherwise.
(should-not
(let (org-export-registered-backends)
(org-export-define-backend 'test '((headline . test)))
(org-export-define-backend 'test2 '((headline . test2)))
(org-export-derived-backend-p 'test2 'test)))
(should-not
(let (org-export-registered-backends)
(org-export-define-backend 'test '((headline . test)))
(org-export-define-backend 'test2 '((headline . test2)))
(org-export-define-derived-backend 'test3 'test2)
(org-export-derived-backend-p 'test3 'test))))
(ert-deftest test-org-export/with-backend ()
"Test `org-export-with-backend' definition."
;; Error when calling an undefined back-end
(should-error
(let (org-export-registered-backends)
(org-export-with-backend 'test "Test")))
;; Error when called back-end doesn't have an appropriate
;; transcoder.
(should-error
(let (org-export-registered-backends)
(org-export-define-backend 'test ((headline . ignore)))
(org-export-with-backend 'test "Test")))
;; Otherwise, export using correct transcoder
(should
(equal "Success"
(let (org-export-registered-backends)
(org-export-define-backend 'test
'((plain-text . (lambda (text contents info) "Failure"))))
(org-export-define-backend 'test2
'((plain-text . (lambda (text contents info) "Success"))))
(org-export-with-backend 'test2 "Test")))))
(ert-deftest test-org-export/data-with-translations ()
"Test `org-export-data-with-translations' specifications."
(should
(equal
"Success!"
(org-export-data-with-translations
'(bold nil "Test")
'((plain-text . (lambda (text info) "Success"))
(bold . (lambda (bold contents info) (concat contents "!"))))
'(:with-emphasize t)))))
(ert-deftest test-org-export/data-with-backend ()
"Test `org-export-data-with-backend' specifications."
;; Error when calling an undefined back-end.
(should-error
(let (org-export-registered-backends)
(org-export-data-with-backend 'test "Test" nil)))
;; Otherwise, export data recursively, using correct back-end.
(should
(equal
"Success!"
(let (org-export-registered-backends)
(org-export-define-backend 'test
'((plain-text . (lambda (text info) "Success"))
(bold . (lambda (bold contents info) (concat contents "!")))))
(org-export-data-with-backend
'(bold nil "Test") 'test '(:with-emphasize t))))))
\f
;;; Export Snippets
(ert-deftest test-org-export/export-snippet ()
"Test export snippets transcoding."
(org-test-with-temp-text "@@test:A@@@@t:B@@"
(org-test-with-backend test
(plist-put
(cdr (assq 'test org-export-registered-backends))
:translate-alist
(cons (cons 'export-snippet
(lambda (snippet contents info)
(when (eq (org-export-snippet-backend snippet) 'test)
(org-element-property :value snippet))))
(org-export-backend-translate-table 'test)))
(let ((org-export-snippet-translation-alist nil))
(should (equal (org-export-as 'test) "A\n")))
(let ((org-export-snippet-translation-alist '(("t" . "test"))))
(should (equal (org-export-as 'test) "AB\n")))))
;; Ignored export snippets do not remove any blank.
(should
(equal "begin end\n"
(org-test-with-parsed-data "begin @@test:A@@ end"
(org-export-data-with-translations
tree
'((paragraph . (lambda (paragraph contents info) contents))
(section . (lambda (section contents info) contents)))
info)))))
\f
;;; Footnotes
(ert-deftest test-org-export/footnotes ()
"Test footnotes specifications."
(let ((org-footnote-section nil)
(org-export-with-footnotes t))
;; 1. Read every type of footnote.
(should
(equal
'((1 . "A\n") (2 . "B") (3 . "C") (4 . "D"))
(org-test-with-parsed-data
"Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
(org-element-map tree 'footnote-reference
(lambda (ref)
(let ((def (org-export-get-footnote-definition ref info)))
(cons (org-export-get-footnote-number ref info)
(if (eq (org-element-property :type ref) 'inline) (car def)
(car (org-element-contents
(car (org-element-contents def))))))))
info))))
;; 2. Test nested footnotes order.
(org-test-with-parsed-data
"Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
(should
(equal
'((1 . "fn:1") (2 . "fn:2") (3 . "fn:3") (4))
(org-element-map tree 'footnote-reference
(lambda (ref)
(when (org-export-footnote-first-reference-p ref info)
(cons (org-export-get-footnote-number ref info)
(org-element-property :label ref))))
info))))
;; 3. Test nested footnote in invisible definitions.
(org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
;; Hide definitions.
(narrow-to-region (point) (point-at-eol))
(let* ((tree (org-element-parse-buffer))
(info (org-combine-plists
`(:parse-tree ,tree)
(org-export-collect-tree-properties
tree (org-export-get-environment)))))
;; Both footnotes should be seen.
(should
(= (length (org-export-collect-footnote-definitions tree info)) 2))))
;; 4. Test footnotes definitions collection.
(org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
\[fn:2] B [fn:3] [fn::D].
\[fn:3] C."
(should (= (length (org-export-collect-footnote-definitions tree info))
4)))
;; 5. Test export of footnotes defined outside parsing scope.
(org-test-with-temp-text "[fn:1] Out of scope
* Title
Paragraph[fn:1]"
(org-test-with-backend test
(plist-put
(cdr (assq 'test org-export-registered-backends))
:translate-alist
(cons (cons 'footnote-reference
(lambda (fn contents info)
(org-element-interpret-data
(org-export-get-footnote-definition fn info))))
(org-export-backend-translate-table 'test)))
(forward-line)
(should (equal "ParagraphOut of scope\n"
(org-export-as 'test 'subtree)))))
;; 6. Footnotes without a definition should be provided a fallback
;; definition.
(should
(org-test-with-parsed-data "[fn:1]"
(org-export-get-footnote-definition
(org-element-map tree 'footnote-reference 'identity info t) info)))
;; 7. Footnote section should be ignored in TOC and in headlines
;; numbering.
(should
(= 1 (let ((org-footnote-section "Footnotes"))
(length (org-test-with-parsed-data "* H1\n* Footnotes\n"
(org-export-collect-headlines info))))))
(should
(equal '(2)
(let ((org-footnote-section "Footnotes"))
(org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
(org-element-map tree 'headline
(lambda (hl)
(when (equal (org-element-property :raw-value hl) "H2")
(org-export-get-headline-number hl info)))
info t)))))))
\f
;;; Headlines and Inlinetasks
(ert-deftest test-org-export/get-relative-level ()
"Test `org-export-get-relative-level' specifications."
;; Standard test.
(should
(equal '(1 2)
(let ((org-odd-levels-only nil))
(org-test-with-parsed-data "* Headline 1\n** Headline 2"
(org-element-map tree 'headline
(lambda (h) (org-export-get-relative-level h info))
info)))))
;; Missing levels
(should
(equal '(1 3)
(let ((org-odd-levels-only nil))
(org-test-with-parsed-data "** Headline 1\n**** Headline 2"
(org-element-map tree 'headline
(lambda (h) (org-export-get-relative-level h info))
info))))))
(ert-deftest test-org-export/low-level-p ()
"Test `org-export-low-level-p' specifications."
(should
(equal
'(no yes)
(let ((org-odd-levels-only nil))
(org-test-with-parsed-data "* Headline 1\n** Headline 2"
(org-element-map tree 'headline
(lambda (h) (if (org-export-low-level-p h info) 'yes 'no))
(plist-put info :headline-levels 1)))))))
(ert-deftest test-org-export/get-headline-number ()
"Test `org-export-get-headline-number' specifications."
;; Standard test.
(should
(equal
'((1) (1 1))
(let ((org-odd-levels-only nil))
(org-test-with-parsed-data "* Headline 1\n** Headline 2"
(org-element-map tree 'headline
(lambda (h) (org-export-get-headline-number h info))
info)))))
;; Missing levels are replaced with 0.
(should
(equal
'((1) (1 0 1))
(let ((org-odd-levels-only nil))
(org-test-with-parsed-data "* Headline 1\n*** Headline 2"
(org-element-map tree 'headline
(lambda (h) (org-export-get-headline-number h info))
info))))))
(ert-deftest test-org-export/numbered-headline-p ()
"Test `org-export-numbered-headline-p' specifications."
;; If `:section-numbers' is nil, never number headlines.
(should-not
(org-test-with-parsed-data "* Headline"
(org-element-map tree 'headline
(lambda (h) (org-export-numbered-headline-p h info))
(plist-put info :section-numbers nil))))
;; If `:section-numbers' is a number, only number headlines with
;; a level greater that it.
(should
(equal
'(yes no)
(org-test-with-parsed-data "* Headline 1\n** Headline 2"
(org-element-map tree 'headline
(lambda (h) (if (org-export-numbered-headline-p h info) 'yes 'no))
(plist-put info :section-numbers 1)))))
;; Otherwise, headlines are always numbered.
(should
(org-test-with-parsed-data "* Headline"
(org-element-map tree 'headline
(lambda (h) (org-export-numbered-headline-p h info))
(plist-put info :section-numbers t)))))
(ert-deftest test-org-export/number-to-roman ()
"Test `org-export-number-to-roman' specifications."
;; If number is negative, return it as a string.
(should (equal (org-export-number-to-roman -1) "-1"))
;; Otherwise, return it as a roman number.
(should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
(ert-deftest test-org-export/get-optional-title ()
"Test `org-export-get-alt-title' specifications."
;; If ALT_TITLE property is defined, use it.
(should
(equal '("opt")
(org-test-with-parsed-data
"* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
(org-export-get-alt-title
(org-element-map tree 'headline 'identity info t)
info))))
;; Otherwise, fall-back to regular title.
(should
(equal '("Headline")
(org-test-with-parsed-data "* Headline"
(org-export-get-alt-title
(org-element-map tree 'headline 'identity info t)
info)))))
(ert-deftest test-org-export/get-tags ()
"Test `org-export-get-tags' specifications."
(let ((org-export-exclude-tags '("noexport"))
(org-export-select-tags '("export")))
;; Standard test: tags which are not a select tag, an exclude tag,
;; or specified as optional argument shouldn't be ignored.
(should
(org-test-with-parsed-data "* Headline :tag:"
(org-export-get-tags (org-element-map tree 'headline 'identity info t)
info)))
;; Exclude tags are removed.
(should-not
(org-test-with-parsed-data "* Headline :noexport:"
(org-export-get-tags (org-element-map tree 'headline 'identity info t)
info)))
;; Select tags are removed.
(should-not
(org-test-with-parsed-data "* Headline :export:"
(org-export-get-tags (org-element-map tree 'headline 'identity info t)
info)))
(should
(equal
'("tag")
(org-test-with-parsed-data "* Headline :tag:export:"
(org-export-get-tags (org-element-map tree 'headline 'identity info t)
info))))
;; Tags provided in the optional argument are also ignored.
(should-not
(org-test-with-parsed-data "* Headline :ignore:"
(org-export-get-tags (org-element-map tree 'headline 'identity info t)
info '("ignore"))))
;; Allow tag inheritance.
(should
(equal
'(("tag") ("tag"))
(org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
(org-element-map tree 'headline
(lambda (hl) (org-export-get-tags hl info nil t)) info))))
;; Tag inheritance checks FILETAGS keywords.
(should
(equal
'(("a" "b" "tag"))
(org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
(org-element-map tree 'headline
(lambda (hl) (org-export-get-tags hl info nil t)) info))))))
(ert-deftest test-org-export/get-node-property ()
"Test`org-export-get-node-property' specifications."
;; Standard test.
(should
(equal "value"
(org-test-with-parsed-data "* Headline
:PROPERTIES:
:prop: value
:END:"
(org-export-get-node-property
:PROP (org-element-map tree 'headline 'identity nil t)))))
;; Test inheritance.
(should
(equal "value"
(org-test-with-parsed-data "* Parent
:PROPERTIES:
:prop: value
:END:
** Headline
Paragraph"
(org-export-get-node-property
:PROP (org-element-map tree 'paragraph 'identity nil t) t))))
;; Cannot return a value before the first headline.
(should-not
(org-test-with-parsed-data "Paragraph
* Headline
:PROPERTIES:
:prop: value
:END:"
(org-export-get-node-property
:PROP (org-element-map tree 'paragraph 'identity nil t)))))
(ert-deftest test-org-export/get-category ()
"Test `org-export-get-category' specifications."
;; Standard test.
(should
(equal "value"
(org-test-with-parsed-data "* Headline
:PROPERTIES:
:CATEGORY: value
:END:"
(org-export-get-category
(org-element-map tree 'headline 'identity nil t) info))))
;; Test inheritance from a parent headline.
(should
(equal '("value" "value")
(org-test-with-parsed-data "* Headline1
:PROPERTIES:
:CATEGORY: value
:END:
** Headline2"
(org-element-map tree 'headline
(lambda (hl) (org-export-get-category hl info)) info))))
;; Test inheritance from #+CATEGORY keyword
(should
(equal "value"
(org-test-with-parsed-data "#+CATEGORY: value
* Headline"
(org-export-get-category
(org-element-map tree 'headline 'identity nil t) info))))
;; Test inheritance from file name.
(should
(equal "test"
(org-test-with-parsed-data "* Headline"
(let ((info (plist-put info :input-file "~/test.org")))
(org-export-get-category
(org-element-map tree 'headline 'identity nil t) info)))))
;; Fall-back value.
(should
(equal "???"
(org-test-with-parsed-data "* Headline"
(org-export-get-category
(org-element-map tree 'headline 'identity nil t) info)))))
(ert-deftest test-org-export/first-sibling-p ()
"Test `org-export-first-sibling-p' specifications."
;; Standard test.
(should
(equal
'(yes yes no)
(org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
(org-element-map tree 'headline
(lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
info))))
;; Ignore headlines not exported.
(should
(equal
'(yes)
(let ((org-export-exclude-tags '("ignore")))
(org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
(org-element-map tree 'headline
(lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
info))))))
(ert-deftest test-org-export/last-sibling-p ()
"Test `org-export-last-sibling-p' specifications."
;; Standard test.
(should
(equal
'(yes no yes)
(org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
(org-element-map tree 'headline
(lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
info))))
;; Ignore headlines not exported.
(should
(equal
'(yes)
(let ((org-export-exclude-tags '("ignore")))
(org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
(org-element-map tree 'headline
(lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
info))))))
(ert-deftest test-org-export/handle-inlinetasks ()
"Test inlinetask export."
;; Inlinetask with an exclude tag.
(when (featurep 'org-inlinetask)
(should
(equal
""
(let ((org-inlinetask-min-level 3))
(org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
(org-test-with-backend test
(org-export-as 'test nil nil nil '(:exclude-tags ("noexp"))))))))
;; Inlinetask with an include tag.
(should
(equal
"* H2\n*** Inline :exp:\n"
(let ((org-inlinetask-min-level 3)
(org-tags-column 0))
(org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
(org-test-with-backend test
(org-export-as 'test nil nil nil '(:select-tags ("exp"))))))))
;; Ignore inlinetask with a TODO keyword and tasks excluded.
(should
(equal ""
(let ((org-todo-keywords '((sequence "TODO" "DONE")))
(org-inlinetask-min-level 3))
(org-test-with-temp-text "*** TODO Inline"
(org-test-with-backend test
(org-export-as 'test nil nil nil '(:with-tasks nil)))))))))
\f
;;; Keywords
(ert-deftest test-org-export/get-date ()
"Test `org-export-get-date' specifications."
;; Return a properly formatted string when
;; `org-export-date-timestamp-format' is non-nil and DATE keyword
;; consists in a single timestamp.
(should
(equal "29 03 2012"
(let ((org-export-date-timestamp-format "%d %m %Y"))
(org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
(org-export-get-date info)))))
;; Return a secondary string otherwise.
(should-not
(stringp
(let ((org-export-date-timestamp-format nil))
(org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
(org-export-get-date info)))))
(should
(equal '("Date")
(org-test-with-parsed-data "#+DATE: Date"
(org-export-get-date info))))
;; Optional argument has precedence over
;; `org-export-date-timestamp-format'.
(should
(equal "29 03"
(let ((org-export-date-timestamp-format "%d %m %Y"))
(org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
(org-export-get-date info "%d %m"))))))
\f
;;; Links
(ert-deftest test-org-export/get-coderef-format ()
"Test `org-export-get-coderef-format' specifications."
;; A link without description returns "%s"
(should (equal (org-export-get-coderef-format "(ref:line)" nil)
"%s"))
;; Return "%s" when path is matched within description.
(should (equal (org-export-get-coderef-format "path" "desc (path)")
"desc %s"))
;; Otherwise return description.
(should (equal (org-export-get-coderef-format "path" "desc")
"desc")))
(ert-deftest test-org-export/inline-image-p ()
"Test `org-export-inline-image-p' specifications."
(should
(org-export-inline-image-p
(org-test-with-temp-text "[[#id]]"
(org-element-map (org-element-parse-buffer) 'link 'identity nil t))
'(("custom-id" . "id")))))
(ert-deftest test-org-export/fuzzy-link ()
"Test fuzzy links specifications."
;; Link to an headline should return headline's number.
(org-test-with-parsed-data
"Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
(should
;; Note: Headline's number is in fact a list of numbers.
(equal '(2)
(org-element-map tree 'link
(lambda (link)
(org-export-get-ordinal
(org-export-resolve-fuzzy-link link info) info)) info t))))
;; Link to a target in an item should return item's number.
(org-test-with-parsed-data
"- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
(should
;; Note: Item's number is in fact a list of numbers.
(equal '(1 2)
(org-element-map tree 'link
(lambda (link)
(org-export-get-ordinal
(org-export-resolve-fuzzy-link link info) info)) info t))))
;; Link to a target in a footnote should return footnote's number.
(org-test-with-parsed-data "
Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
(should
(equal '(2 3)
(org-element-map tree 'link
(lambda (link)
(org-export-get-ordinal
(org-export-resolve-fuzzy-link link info) info)) info))))
;; Link to a named element should return sequence number of that
;; element.
(org-test-with-parsed-data
"#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
(should
(= 2
(org-element-map tree 'link
(lambda (link)
(org-export-get-ordinal
(org-export-resolve-fuzzy-link link info) info)) info t))))
;; Link to a target not within an item, a table, a footnote
;; reference or definition should return section number.
(org-test-with-parsed-data
"* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
(should
(equal '(2)
(org-element-map tree 'link
(lambda (link)
(org-export-get-ordinal
(org-export-resolve-fuzzy-link link info) info)) info t))))
;; Space are not significant when matching a fuzzy link.
(should
(org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
(org-element-map tree 'link
(lambda (link) (org-export-resolve-fuzzy-link link info))
info t)))
;; Statistics cookies are ignored for headline match.
(should
(org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
(org-element-map tree 'link
(lambda (link) (org-export-resolve-fuzzy-link link info))
info t)))
(should
(org-test-with-parsed-data "* Head [100%]\n[[Head]]"
(org-element-map tree 'link
(lambda (link) (org-export-resolve-fuzzy-link link info))
info t))))
(ert-deftest test-org-export/resolve-coderef ()
"Test `org-export-resolve-coderef' specifications."
(let ((org-coderef-label-format "(ref:%s)"))
;; 1. A link to a "-n -k -r" block returns line number.
(org-test-with-parsed-data
"#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
(should (= (org-export-resolve-coderef "coderef" info) 1)))
(org-test-with-parsed-data
"#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
(should (= (org-export-resolve-coderef "coderef" info) 1)))
;; 2. A link to a "-n -r" block returns line number.
(org-test-with-parsed-data
"#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
(should (= (org-export-resolve-coderef "coderef" info) 1)))
(org-test-with-parsed-data
"#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
(should (= (org-export-resolve-coderef "coderef" info) 1)))
;; 3. A link to a "-n" block returns coderef.
(org-test-with-parsed-data
"#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
(should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
(org-test-with-parsed-data
"#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
(should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
;; 4. A link to a "-r" block returns line number.
(org-test-with-parsed-data
"#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
(should (= (org-export-resolve-coderef "coderef" info) 1)))
(org-test-with-parsed-data
"#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
(should (= (org-export-resolve-coderef "coderef" info) 1)))
;; 5. A link to a block without a switch returns coderef.
(org-test-with-parsed-data
"#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
(should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
(org-test-with-parsed-data
"#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
(should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
;; 6. Correctly handle continued line numbers. A "+n" switch
;; should resume numbering from previous block with numbered
;; lines, ignoring blocks not numbering lines in the process.
;; A "-n" switch resets count.
(org-test-with-parsed-data "
#+BEGIN_EXAMPLE -n
Text.
#+END_EXAMPLE
#+BEGIN_SRC emacs-lisp
\(- 1 1)
#+END_SRC
#+BEGIN_SRC emacs-lisp +n -r
\(+ 1 1) (ref:addition)
#+END_SRC
#+BEGIN_EXAMPLE -n -r
Another text. (ref:text)
#+END_EXAMPLE"
(should (= (org-export-resolve-coderef "addition" info) 2))
(should (= (org-export-resolve-coderef "text" info) 1)))
;; 7. Recognize coderef with user-specified syntax.
(org-test-with-parsed-data
"#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
(should (equal (org-export-resolve-coderef "text" info) "text")))))
(ert-deftest test-org-export/resolve-fuzzy-link ()
"Test `org-export-resolve-fuzzy-link' specifications."
;; Match target objects.
(should
(org-test-with-parsed-data "<<target>> [[target]]"
(org-export-resolve-fuzzy-link
(org-element-map tree 'link 'identity info t) info)))
;; Match named elements.
(should
(org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
(org-export-resolve-fuzzy-link
(org-element-map tree 'link 'identity info t) info)))
;; Match exact headline's name.
(should
(org-test-with-parsed-data "* My headline\n[[My headline]]"
(org-export-resolve-fuzzy-link
(org-element-map tree 'link 'identity info t) info)))
;; Targets objects have priority over named elements and headline
;; titles.
(should
(eq 'target
(org-test-with-parsed-data
"* target\n#+NAME: target\n<<target>>\n\n[[target]]"
(org-element-type
(org-export-resolve-fuzzy-link
(org-element-map tree 'link 'identity info t) info)))))
;; Named elements have priority over headline titles.
(should
(eq 'paragraph
(org-test-with-parsed-data
"* target\n#+NAME: target\nParagraph\n\n[[target]]"
(org-element-type
(org-export-resolve-fuzzy-link
(org-element-map tree 'link 'identity info t) info)))))
;; If link's path starts with a "*", only match headline titles,
;; though.
(should
(eq 'headline
(org-test-with-parsed-data
"* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
(org-element-type
(org-export-resolve-fuzzy-link
(org-element-map tree 'link 'identity info t) info)))))
;; Return nil if no match.
(should-not
(org-test-with-parsed-data "[[target]]"
(org-export-resolve-fuzzy-link
(org-element-map tree 'link 'identity info t) info))))
(ert-deftest test-org-export/resolve-id-link ()
"Test `org-export-resolve-id-link' specifications."
;; 1. Regular test for custom-id link.
(org-test-with-parsed-data "* Headline1
:PROPERTIES:
:CUSTOM_ID: test
:END:
* Headline 2
\[[#test]]"
(should
(org-export-resolve-id-link
(org-element-map tree 'link 'identity info t) info)))
;; 2. Failing test for custom-id link.
(org-test-with-parsed-data "* Headline1
:PROPERTIES:
:CUSTOM_ID: test
:END:
* Headline 2
\[[#no-match]]"
(should-not
(org-export-resolve-id-link
(org-element-map tree 'link 'identity info t) info)))
;; 3. Test for internal id target.
(org-test-with-parsed-data "* Headline1
:PROPERTIES:
:ID: aaaa
:END:
* Headline 2
\[[id:aaaa]]"
(should
(org-export-resolve-id-link
(org-element-map tree 'link 'identity info t) info)))
;; 4. Test for external id target.
(org-test-with-parsed-data "[[id:aaaa]]"
(should
(org-export-resolve-id-link
(org-element-map tree 'link 'identity info t)
(org-combine-plists info '(:id-alist (("aaaa" . "external-file"))))))))
(ert-deftest test-org-export/resolve-radio-link ()
"Test `org-export-resolve-radio-link' specifications."
;; Standard test.
(should
(org-test-with-temp-text "<<<radio>>> radio"
(org-update-radio-target-regexp)
(let* ((tree (org-element-parse-buffer))
(info `(:parse-tree ,tree)))
(org-export-resolve-radio-link
(org-element-map tree 'link 'identity info t)
info))))
;; Radio targets are case-insensitive.
(should
(org-test-with-temp-text "<<<RADIO>>> radio"
(org-update-radio-target-regexp)
(let* ((tree (org-element-parse-buffer))
(info `(:parse-tree ,tree)))
(org-export-resolve-radio-link
(org-element-map tree 'link 'identity info t)
info))))
;; Radio target with objects.
(should
(org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
(org-update-radio-target-regexp)
(let* ((tree (org-element-parse-buffer))
(info `(:parse-tree ,tree)))
(org-export-resolve-radio-link
(org-element-map tree 'link 'identity info t)
info)))))
\f
;;; Src-block and example-block
(ert-deftest test-org-export/unravel-code ()
"Test `org-export-unravel-code' function."
(let ((org-coderef-label-format "(ref:%s)"))
;; 1. Code without reference.
(org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
(should (equal (org-export-unravel-code (org-element-at-point))
'("(+ 1 1)\n"))))
;; 2. Code with reference.
(org-test-with-temp-text
"#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
(should (equal (org-export-unravel-code (org-element-at-point))
'("(+ 1 1)\n" (1 . "test")))))
;; 3. Code with user-defined reference.
(org-test-with-temp-text
"#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
(should (equal (org-export-unravel-code (org-element-at-point))
'("(+ 1 1)\n" (1 . "test")))))
;; 4. Code references keys are relative to the current block.
(org-test-with-temp-text "
#+BEGIN_EXAMPLE -n
\(+ 1 1)
#+END_EXAMPLE
#+BEGIN_EXAMPLE +n
\(+ 2 2)
\(+ 3 3) (ref:one)
#+END_EXAMPLE"
(goto-line 5)
(should (equal (org-export-unravel-code (org-element-at-point))
'("(+ 2 2)\n(+ 3 3)\n" (2 . "one")))))))
(ert-deftest test-org-export/format-code-default ()
"Test `org-export-format-code-default' specifications."
;; Return the empty string when code is empty.
(should
(equal ""
(org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
(org-export-format-code-default
(org-element-map tree 'src-block 'identity info t) info))))
;; Number lines, two whitespace characters before the actual loc.
(should
(equal "1 a\n2 b\n"
(org-test-with-parsed-data
"#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
(org-export-format-code-default
(org-element-map tree 'src-block 'identity info t) info))))
;; Put references 6 whitespace characters after the widest line,
;; wrapped within parenthesis.
(should
(equal "123 (a)\n1 (b)\n"
(let ((org-coderef-label-format "(ref:%s)"))
(org-test-with-parsed-data
"#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
(org-export-format-code-default
(org-element-map tree 'src-block 'identity info t) info))))))
\f
;;; Smart Quotes
(ert-deftest test-org-export/activate-smart-quotes ()
"Test `org-export-activate-smart-quotes' specifications."
;; Opening double quotes: standard test.
(should
(equal
'("some “paragraph")
(let ((org-export-default-language "en"))
(org-test-with-parsed-data "some \"paragraph"
(org-element-map tree 'plain-text
(lambda (s) (org-export-activate-smart-quotes s :html info))
info)))))
;; Opening quotes: at the beginning of a paragraph.
(should
(equal
'("“begin")
(let ((org-export-default-language "en"))
(org-test-with-parsed-data "\"begin"
(org-element-map tree 'plain-text
(lambda (s) (org-export-activate-smart-quotes s :html info))
info)))))
;; Opening quotes: after an object.
(should
(equal
'("“begin")
(let ((org-export-default-language "en"))
(org-test-with-parsed-data "=verb= \"begin"
(org-element-map tree 'plain-text
(lambda (s) (org-export-activate-smart-quotes s :html info))
info)))))
;; Closing quotes: standard test.
(should
(equal
'("some” paragraph")
(let ((org-export-default-language "en"))
(org-test-with-parsed-data "some\" paragraph"
(org-element-map tree 'plain-text
(lambda (s) (org-export-activate-smart-quotes s :html info))
info)))))
;; Closing quotes: at the end of a paragraph.
(should
(equal
'("end”")
(let ((org-export-default-language "en"))
(org-test-with-parsed-data "end\""
(org-element-map tree 'plain-text
(lambda (s) (org-export-activate-smart-quotes s :html info))
info)))))
;; Apostrophe: standard test.
(should
(equal
'("It shouldn’t fail")
(let ((org-export-default-language "en"))
(org-test-with-parsed-data "It shouldn't fail"
(org-element-map tree 'plain-text
(lambda (s) (org-export-activate-smart-quotes s :html info))
info)))))
;; Apostrophe: before an object.
(should
(equal
'("a’")
(let ((org-export-default-language "en"))
(org-test-with-parsed-data "a'=b="
(org-element-map tree 'plain-text
(lambda (s) (org-export-activate-smart-quotes s :html info))
info)))))
;; Apostrophe: after an object.
(should
(equal
'("’s")
(let ((org-export-default-language "en"))
(org-test-with-parsed-data "=code='s"
(org-element-map tree 'plain-text
(lambda (s) (org-export-activate-smart-quotes s :html info))
info)))))
;; Special case: isolated quotes.
(should
(equal '("“" "”")
(let ((org-export-default-language "en"))
(org-test-with-parsed-data "\"$x$\""
(org-element-map tree 'plain-text
(lambda (s) (org-export-activate-smart-quotes s :html info))
info)))))
;; Smart quotes in secondary strings.
(should
(equal '("“" "”")
(let ((org-export-default-language "en"))
(org-test-with-parsed-data "* \"$x$\""
(org-element-map tree 'plain-text
(lambda (s) (org-export-activate-smart-quotes s :html info))
info)))))
;; Smart quotes in document keywords.
(should
(equal '("“" "”")
(let ((org-export-default-language "en"))
(org-test-with-parsed-data "#+TITLE: \"$x$\""
(org-element-map (plist-get info :title) 'plain-text
(lambda (s) (org-export-activate-smart-quotes s :html info))
info)))))
;; Smart quotes in parsed affiliated keywords.
(should
(equal '("“" "”" "Paragraph")
(let ((org-export-default-language "en"))
(org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
(org-element-map tree 'plain-text
(lambda (s) (org-export-activate-smart-quotes s :html info))
info nil nil t))))))
\f
;;; Tables
(ert-deftest test-org-export/special-column ()
"Test if the table's special column is properly recognized."
;; 1. First column is special if it contains only a special marking
;; characters or empty cells.
(org-test-with-temp-text "
| ! | 1 |
| | 2 |"
(should
(org-export-table-has-special-column-p
(org-element-map
(org-element-parse-buffer) 'table 'identity nil 'first-match))))
;; 2. If the column contains anything else, it isn't special.
(org-test-with-temp-text "
| ! | 1 |
| b | 2 |"
(should-not
(org-export-table-has-special-column-p
(org-element-map
(org-element-parse-buffer) 'table 'identity nil 'first-match))))
;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
;; and "!".
(org-test-with-temp-text "
| # | 1 |
| ^ | 2 |
| * | 3 |
| _ | 4 |
| / | 5 |
| $ | 6 |
| ! | 7 |"
(should
(org-export-table-has-special-column-p
(org-element-map
(org-element-parse-buffer) 'table 'identity nil 'first-match))))
;; 4. A first column with only empty cells isn't considered as
;; special.
(org-test-with-temp-text "
| | 1 |
| | 2 |"
(should-not
(org-export-table-has-special-column-p
(org-element-map
(org-element-parse-buffer) 'table 'identity nil 'first-match)))))
(ert-deftest test-org-export/table-row-is-special-p ()
"Test `org-export-table-row-is-special-p' specifications."
;; 1. A row is special if it has a special marking character in the
;; special column.
(org-test-with-parsed-data "| ! | 1 |"
(should
(org-export-table-row-is-special-p
(org-element-map tree 'table-row 'identity nil 'first-match) info)))
;; 2. A row is special when its first field is "/"
(org-test-with-parsed-data "
| / | 1 |
| a | b |"
(should
(org-export-table-row-is-special-p
(org-element-map tree 'table-row 'identity nil 'first-match) info)))
;; 3. A row only containing alignment cookies is also considered as
;; special.
(org-test-with-parsed-data "| <5> | | <l> | <l22> |"
(should
(org-export-table-row-is-special-p
(org-element-map tree 'table-row 'identity nil 'first-match) info)))
;; 4. Everything else isn't considered as special.
(org-test-with-parsed-data "| \alpha | | c |"
(should-not
(org-export-table-row-is-special-p
(org-element-map tree 'table-row 'identity nil 'first-match) info)))
;; 5. Table's rules are never considered as special rows.
(org-test-with-parsed-data "|---+---|"
(should-not
(org-export-table-row-is-special-p
(org-element-map tree 'table-row 'identity nil 'first-match) info))))
(ert-deftest test-org-export/has-header-p ()
"Test `org-export-table-has-header-p' specifications."
;; 1. With an header.
(org-test-with-parsed-data "
| a | b |
|---+---|
| c | d |"
(should
(org-export-table-has-header-p
(org-element-map tree 'table 'identity info 'first-match)
info)))
;; 2. Without an header.
(org-test-with-parsed-data "
| a | b |
| c | d |"
(should-not
(org-export-table-has-header-p
(org-element-map tree 'table 'identity info 'first-match)
info)))
;; 3. Don't get fooled with starting and ending rules.
(org-test-with-parsed-data "
|---+---|
| a | b |
| c | d |
|---+---|"
(should-not
(org-export-table-has-header-p
(org-element-map tree 'table 'identity info 'first-match)
info))))
(ert-deftest test-org-export/table-row-group ()
"Test `org-export-table-row-group' specifications."
;; 1. A rule creates a new group.
(org-test-with-parsed-data "
| a | b |
|---+---|
| 1 | 2 |"
(should
(equal
'(1 nil 2)
(mapcar (lambda (row) (org-export-table-row-group row info))
(org-element-map tree 'table-row 'identity)))))
;; 2. Special rows are ignored in count.
(org-test-with-parsed-data "
| / | < | > |
|---|---+---|
| | 1 | 2 |"
(should
(equal
'(nil nil 1)
(mapcar (lambda (row) (org-export-table-row-group row info))
(org-element-map tree 'table-row 'identity)))))
;; 3. Double rules also are ignored in count.
(org-test-with-parsed-data "
| a | b |
|---+---|
|---+---|
| 1 | 2 |"
(should
(equal
'(1 nil nil 2)
(mapcar (lambda (row) (org-export-table-row-group row info))
(org-element-map tree 'table-row 'identity))))))
(ert-deftest test-org-export/table-row-number ()
"Test `org-export-table-row-number' specifications."
;; Standard test. Number is 0-indexed.
(should
(equal '(0 1)
(org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
(org-element-map tree 'table-row
(lambda (row) (org-export-table-row-number row info)) info))))
;; Number ignores separators.
(should
(equal '(0 1)
(org-test-with-parsed-data "
| a | b | c |
|---+---+---|
| d | e | f |"
(org-element-map tree 'table-row
(lambda (row) (org-export-table-row-number row info)) info))))
;; Number ignores special rows.
(should
(equal '(0 1)
(org-test-with-parsed-data "
| / | < | > |
| | b | c |
|---+-----+-----|
| | <c> | <c> |
| | e | f |"
(org-element-map tree 'table-row
(lambda (row) (org-export-table-row-number row info)) info)))))
(ert-deftest test-org-export/table-cell-width ()
"Test `org-export-table-cell-width' specifications."
;; 1. Width is primarily determined by width cookies. If no cookie
;; is found, cell's width is nil.
(org-test-with-parsed-data "
| / | <l> | <6> | <l7> |
| | a | b | c |"
(should
(equal
'(nil 6 7)
(mapcar (lambda (cell) (org-export-table-cell-width cell info))
(org-element-map tree 'table-cell 'identity info)))))
;; 2. The last width cookie has precedence.
(org-test-with-parsed-data "
| <6> |
| <7> |
| a |"
(should
(equal
'(7)
(mapcar (lambda (cell) (org-export-table-cell-width cell info))
(org-element-map tree 'table-cell 'identity info)))))
;; 3. Valid width cookies must have a specific row.
(org-test-with-parsed-data "| <6> | cell |"
(should
(equal
'(nil nil)
(mapcar (lambda (cell) (org-export-table-cell-width cell info))
(org-element-map tree 'table-cell 'identity))))))
(ert-deftest test-org-export/table-cell-alignment ()
"Test `org-export-table-cell-alignment' specifications."
(let ((org-table-number-fraction 0.5)
(org-table-number-regexp "^[0-9]+$"))
;; 1. Alignment is primarily determined by alignment cookies.
(org-test-with-temp-text "| <l> | <c> | <r> |"
(let* ((tree (org-element-parse-buffer))
(info `(:parse-tree ,tree)))
(should
(equal
'(left center right)
(mapcar (lambda (cell) (org-export-table-cell-alignment cell info))
(org-element-map tree 'table-cell 'identity))))))
;; 2. The last alignment cookie has precedence.
(org-test-with-parsed-data "
| <l8> |
| cell |
| <r9> |"
(should
(equal
'(right right right)
(mapcar (lambda (cell) (org-export-table-cell-alignment cell info))
(org-element-map tree 'table-cell 'identity)))))
;; 3. If there's no cookie, cell's contents determine alignment.
;; A column mostly made of cells containing numbers will align
;; its cells to the right.
(org-test-with-parsed-data "
| 123 |
| some text |
| 12345 |"
(should
(equal
'(right right right)
(mapcar (lambda (cell)
(org-export-table-cell-alignment cell info))
(org-element-map tree 'table-cell 'identity)))))
;; 4. Otherwise, they will be aligned to the left.
(org-test-with-parsed-data "
| text |
| some text |
| \alpha |"
(should
(equal
'(left left left)
(mapcar (lambda (cell)
(org-export-table-cell-alignment cell info))
(org-element-map tree 'table-cell 'identity)))))))
(ert-deftest test-org-export/table-cell-borders ()
"Test `org-export-table-cell-borders' specifications."
;; 1. Recognize various column groups indicators.
(org-test-with-parsed-data "| / | < | > | <> |"
(should
(equal
'((right bottom top) (left bottom top) (right bottom top)
(right left bottom top))
(mapcar (lambda (cell)
(org-export-table-cell-borders cell info))
(org-element-map tree 'table-cell 'identity)))))
;; 2. Accept shortcuts to define column groups.
(org-test-with-parsed-data "| / | < | < |"
(should
(equal
'((right bottom top) (right left bottom top) (left bottom top))
(mapcar (lambda (cell)
(org-export-table-cell-borders cell info))
(org-element-map tree 'table-cell 'identity)))))
;; 3. A valid column groups row must start with a "/".
(org-test-with-parsed-data "
| | < |
| a | b |"
(should
(equal '((top) (top) (bottom) (bottom))
(mapcar (lambda (cell)
(org-export-table-cell-borders cell info))
(org-element-map tree 'table-cell 'identity)))))
;; 4. Take table rules into consideration.
(org-test-with-parsed-data "
| 1 |
|---|
| 2 |"
(should
(equal '((below top) (bottom above))
(mapcar (lambda (cell)
(org-export-table-cell-borders cell info))
(org-element-map tree 'table-cell 'identity)))))
;; 5. Top and (resp. bottom) rules induce both `top' and `above'
;; (resp. `bottom' and `below') borders. Any special row is
;; ignored.
(org-test-with-parsed-data "
|---+----|
| / | |
| | 1 |
|---+----|"
(should
(equal '((bottom below top above))
(last
(mapcar (lambda (cell)
(org-export-table-cell-borders cell info))
(org-element-map tree 'table-cell 'identity)))))))
(ert-deftest test-org-export/table-dimensions ()
"Test `org-export-table-dimensions' specifications."
;; 1. Standard test.
(org-test-with-parsed-data "
| 1 | 2 | 3 |
| 4 | 5 | 6 |"
(should
(equal '(2 . 3)
(org-export-table-dimensions
(org-element-map tree 'table 'identity info 'first-match) info))))
;; 2. Ignore horizontal rules and special columns.
(org-test-with-parsed-data "
| / | < | > |
| 1 | 2 | 3 |
|---+---+---|
| 4 | 5 | 6 |"
(should
(equal '(2 . 3)
(org-export-table-dimensions
(org-element-map tree 'table 'identity info 'first-match) info)))))
(ert-deftest test-org-export/table-cell-address ()
"Test `org-export-table-cell-address' specifications."
;; 1. Standard test: index is 0-based.
(org-test-with-parsed-data "| a | b |"
(should
(equal '((0 . 0) (0 . 1))
(org-element-map tree 'table-cell
(lambda (cell) (org-export-table-cell-address cell info))
info))))
;; 2. Special column isn't counted, nor are special rows.
(org-test-with-parsed-data "
| / | <> |
| | c |"
(should
(equal '(0 . 0)
(org-export-table-cell-address
(car (last (org-element-map tree 'table-cell 'identity info)))
info))))
;; 3. Tables rules do not count either.
(org-test-with-parsed-data "
| a |
|---|
| b |
|---|
| c |"
(should
(equal '(2 . 0)
(org-export-table-cell-address
(car (last (org-element-map tree 'table-cell 'identity info)))
info))))
;; 4. Return nil for special cells.
(org-test-with-parsed-data "| / | a |"
(should-not
(org-export-table-cell-address
(org-element-map tree 'table-cell 'identity nil 'first-match)
info))))
(ert-deftest test-org-export/get-table-cell-at ()
"Test `org-export-get-table-cell-at' specifications."
;; 1. Address ignores special columns, special rows and rules.
(org-test-with-parsed-data "
| / | <> |
| | a |
|---+----|
| | b |"
(should
(equal '("b")
(org-element-contents
(org-export-get-table-cell-at
'(1 . 0)
(org-element-map tree 'table 'identity info 'first-match)
info)))))
;; 2. Return value for a non-existent address is nil.
(org-test-with-parsed-data "| a |"
(should-not
(org-export-get-table-cell-at
'(2 . 2)
(org-element-map tree 'table 'identity info 'first-match)
info)))
(org-test-with-parsed-data "| / |"
(should-not
(org-export-get-table-cell-at
'(0 . 0)
(org-element-map tree 'table 'identity info 'first-match)
info))))
(ert-deftest test-org-export/table-cell-starts-colgroup-p ()
"Test `org-export-table-cell-starts-colgroup-p' specifications."
;; 1. A cell at a beginning of a row always starts a column group.
(org-test-with-parsed-data "| a |"
(should
(org-export-table-cell-starts-colgroup-p
(org-element-map tree 'table-cell 'identity info 'first-match)
info)))
;; 2. Special column should be ignored when determining the
;; beginning of the row.
(org-test-with-parsed-data "
| / | |
| | a |"
(should
(org-export-table-cell-starts-colgroup-p
(org-element-map tree 'table-cell 'identity info 'first-match)
info)))
;; 2. Explicit column groups.
(org-test-with-parsed-data "
| / | | < |
| a | b | c |"
(should
(equal
'(yes no yes)
(org-element-map tree 'table-cell
(lambda (cell)
(if (org-export-table-cell-starts-colgroup-p cell info) 'yes 'no))
info)))))
(ert-deftest test-org-export/table-cell-ends-colgroup-p ()
"Test `org-export-table-cell-ends-colgroup-p' specifications."
;; 1. A cell at the end of a row always ends a column group.
(org-test-with-parsed-data "| a |"
(should
(org-export-table-cell-ends-colgroup-p
(org-element-map tree 'table-cell 'identity info 'first-match)
info)))
;; 2. Special column should be ignored when determining the
;; beginning of the row.
(org-test-with-parsed-data "
| / | |
| | a |"
(should
(org-export-table-cell-ends-colgroup-p
(org-element-map tree 'table-cell 'identity info 'first-match)
info)))
;; 3. Explicit column groups.
(org-test-with-parsed-data "
| / | < | |
| a | b | c |"
(should
(equal
'(yes no yes)
(org-element-map tree 'table-cell
(lambda (cell)
(if (org-export-table-cell-ends-colgroup-p cell info) 'yes 'no))
info)))))
(ert-deftest test-org-export/table-row-starts-rowgroup-p ()
"Test `org-export-table-row-starts-rowgroup-p' specifications."
;; 1. A row at the beginning of a table always starts a row group.
;; So does a row following a table rule.
(org-test-with-parsed-data "
| a |
|---|
| b |"
(should
(equal
'(yes no yes)
(org-element-map tree 'table-row
(lambda (row)
(if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
info))))
;; 2. Special rows should be ignored when determining the beginning
;; of the row.
(org-test-with-parsed-data "
| / | < |
| | a |
|---+---|
| / | < |
| | b |"
(should
(equal
'(yes no yes)
(org-element-map tree 'table-row
(lambda (row)
(if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
info)))))
(ert-deftest test-org-export/table-row-ends-rowgroup-p ()
"Test `org-export-table-row-ends-rowgroup-p' specifications."
;; 1. A row at the end of a table always ends a row group. So does
;; a row preceding a table rule.
(org-test-with-parsed-data "
| a |
|---|
| b |"
(should
(equal
'(yes no yes)
(org-element-map tree 'table-row
(lambda (row)
(if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
info))))
;; 2. Special rows should be ignored when determining the beginning
;; of the row.
(org-test-with-parsed-data "
| | a |
| / | < |
|---+---|
| | b |
| / | < |"
(should
(equal
'(yes no yes)
(org-element-map tree 'table-row
(lambda (row)
(if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
info)))))
(ert-deftest test-org-export/table-row-starts-header-p ()
"Test `org-export-table-row-starts-header-p' specifications."
;; 1. Only the row starting the first row group starts the table
;; header.
(org-test-with-parsed-data "
| a |
| b |
|---|
| c |"
(should
(equal
'(yes no no no)
(org-element-map tree 'table-row
(lambda (row)
(if (org-export-table-row-starts-header-p row info) 'yes 'no))
info))))
;; 2. A row cannot start an header if there's no header in the
;; table.
(org-test-with-parsed-data "
| a |
|---|"
(should-not
(org-export-table-row-starts-header-p
(org-element-map tree 'table-row 'identity info 'first-match)
info))))
(ert-deftest test-org-export/table-row-ends-header-p ()
"Test `org-export-table-row-ends-header-p' specifications."
;; 1. Only the row starting the first row group starts the table
;; header.
(org-test-with-parsed-data "
| a |
| b |
|---|
| c |"
(should
(equal
'(no yes no no)
(org-element-map tree 'table-row
(lambda (row)
(if (org-export-table-row-ends-header-p row info) 'yes 'no))
info))))
;; 2. A row cannot start an header if there's no header in the
;; table.
(org-test-with-parsed-data "
| a |
|---|"
(should-not
(org-export-table-row-ends-header-p
(org-element-map tree 'table-row 'identity info 'first-match)
info))))
\f
;;; Templates
(ert-deftest test-org-export/inner-template ()
"Test `inner-template' translator specifications."
(should
(equal "Success!"
(let (org-export-registered-backends)
(org-export-define-backend 'test
'((inner-template . (lambda (contents info) "Success!"))
(headline . (lambda (h c i) "Headline"))))
(org-test-with-temp-text "* Headline"
(org-export-as 'test)))))
;; Inner template is applied even in a "body-only" export.
(should
(equal "Success!"
(let (org-export-registered-backends)
(org-export-define-backend 'test
'((inner-template . (lambda (contents info) "Success!"))
(headline . (lambda (h c i) "Headline"))))
(org-test-with-temp-text "* Headline"
(org-export-as 'test nil nil 'body-only))))))
(ert-deftest test-org-export/template ()
"Test `template' translator specifications."
(should
(equal "Success!"
(let (org-export-registered-backends)
(org-export-define-backend 'test
'((template . (lambda (contents info) "Success!"))
(headline . (lambda (h c i) "Headline"))))
(org-test-with-temp-text "* Headline"
(org-export-as 'test)))))
;; Template is not applied in a "body-only" export.
(should-not
(equal "Success!"
(let (org-export-registered-backends)
(org-export-define-backend 'test
'((template . (lambda (contents info) "Success!"))
(headline . (lambda (h c i) "Headline"))))
(org-test-with-temp-text "* Headline"
(org-export-as 'test nil nil 'body-only))))))
\f
;;; Topology
(ert-deftest test-org-export/get-next-element ()
"Test `org-export-get-next-element' specifications."
;; Standard test.
(should
(equal "b"
(org-test-with-parsed-data "* Headline\n*a* b"
(org-export-get-next-element
(org-element-map tree 'bold 'identity info t) info))))
;; Return nil when no previous element.
(should-not
(org-test-with-parsed-data "* Headline\na *b*"
(org-export-get-next-element
(org-element-map tree 'bold 'identity info t) info)))
;; Non-exportable elements are ignored.
(should-not
(let ((org-export-with-timestamps nil))
(org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
(org-export-get-next-element
(org-element-map tree 'entity 'identity info t) info))))
;; Find next element in secondary strings.
(should
(eq 'verbatim
(org-test-with-parsed-data "* a =verb="
(org-element-type
(org-export-get-next-element
(org-element-map tree 'plain-text 'identity info t) info)))))
;; Find next element in document keywords.
(should
(eq 'verbatim
(org-test-with-parsed-data "#+TITLE: a =verb="
(org-element-type
(org-export-get-next-element
(org-element-map
(plist-get info :title) 'plain-text 'identity info t) info)))))
;; Find next element in parsed affiliated keywords.
(should
(eq 'verbatim
(org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
(org-element-type
(org-export-get-next-element
(org-element-map tree 'plain-text 'identity info t nil t) info)))))
;; With optional argument N, return a list containing all the
;; following elements.
(should
(equal
'(bold code underline)
(org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
(mapcar 'car
(org-export-get-next-element
(org-element-map tree 'italic 'identity info t) info t)))))
;; When N is a positive integer, return a list containing up to
;; N following elements.
(should
(equal
'(bold code)
(org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
(mapcar 'car
(org-export-get-next-element
(org-element-map tree 'italic 'identity info t) info 2))))))
(ert-deftest test-org-export/get-previous-element ()
"Test `org-export-get-previous-element' specifications."
;; Standard test.
(should
(equal "a "
(org-test-with-parsed-data "* Headline\na *b*"
(org-export-get-previous-element
(org-element-map tree 'bold 'identity info t) info))))
;; Return nil when no previous element.
(should-not
(org-test-with-parsed-data "* Headline\n*a* b"
(org-export-get-previous-element
(org-element-map tree 'bold 'identity info t) info)))
;; Non-exportable elements are ignored.
(should-not
(let ((org-export-with-timestamps nil))
(org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
(org-export-get-previous-element
(org-element-map tree 'entity 'identity info t) info))))
;; Find previous element in secondary strings.
(should
(eq 'verbatim
(org-test-with-parsed-data "* =verb= a"
(org-element-type
(org-export-get-previous-element
(org-element-map tree 'plain-text 'identity info t) info)))))
;; Find previous element in document keywords.
(should
(eq 'verbatim
(org-test-with-parsed-data "#+TITLE: =verb= a"
(org-element-type
(org-export-get-previous-element
(org-element-map
(plist-get info :title) 'plain-text 'identity info t) info)))))
;; Find previous element in parsed affiliated keywords.
(should
(eq 'verbatim
(org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
(org-element-type
(org-export-get-previous-element
(org-element-map tree 'plain-text 'identity info t nil t) info)))))
;; With optional argument N, return a list containing up to
;; N previous elements.
(should
(equal '(underline italic bold)
(org-test-with-parsed-data "_a_ /b/ *c* ~d~"
(mapcar 'car
(org-export-get-previous-element
(org-element-map tree 'code 'identity info t) info t)))))
;; When N is a positive integer, return a list containing up to
;; N previous elements.
(should
(equal '(italic bold)
(org-test-with-parsed-data "_a_ /b/ *c* ~d~"
(mapcar 'car
(org-export-get-previous-element
(org-element-map tree 'code 'identity info t) info 2))))))
(provide 'test-ox)
;;; test-org-export.el end here
|