-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.rkt
2612 lines (2114 loc) · 67.3 KB
/
test.rkt
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
#lang racket/base
(require racket/list
racket/file
racket/path
racket/pretty
racket/string
;errortrace ; FIXME this is useless for debugging the parser
; also VERY slow, profile was spending 95% of its time there
; the only other thing that even comes close is something from stxparam
; ah, the slowness in racket-mode is because error-trace is enabled by default
; FIXME consider (compile-context-preservation-enabled) ??
laundry/parser
(only-in laundry/tokenizer
laundry-tokenizer-debug
laundry-make-tokenizer
laundry-final-port
bind-runtime-todo-keywords)
(only-in laundry/expander) ; hack to pull expander for compile since in testing we only invoke at runtime
(rename-in (only-in laundry/heading make-rule-parser)
[make-rule-parser heading-rule-parser])
syntax/strip-context
(for-syntax
racket/base
(only-in racket/port with-output-to-string)
syntax/parse))
(provide dotest dotest-q dotest-file dotest-quiet)
(define testing-parse (make-parameter parse))
(define testing-token (make-parameter laundry-make-tokenizer))
(define dotest-prefix (make-parameter #f))
(define dotest-suffix (make-parameter #f))
(define dotest-quiet (make-parameter #t)) ; parameters across require ... ?
(define-syntax (current-module-path stx)
(syntax-parse stx
[(_)
#`(displayln
#,(datum->syntax
stx
(with-output-to-string
(λ ()
(display "Running tests in module: ")
(display (variable-reference->module-path-index (#%variable-reference)))))))]))
#;
(define testing-parse-to-datum (make-parameter parse-to-datum))
(define (rec-cont tree atom)
; I'm lazy and not going to write a proper bfs
(string-contains? (pretty-format tree) (symbol->string atom)))
(define-namespace-anchor anc-test)
(define ns-test (namespace-anchor->namespace anc-test))
(define (dotest test-value
#:eq [eq #f] #:eq-root [eq-root #f]
#:nt [nt #f] #:node-type [node-type nt]
#:nte [nte #f] #:node-type-expanded [node-type-expanded nte]
#:quiet [quiet #f]
#:parse-to-datum [parse-to-datum #f]
#:port-count-lines? [port-count-lines #t]
; FIXME parameterize do-expand (define test-expand (make-parameter #t))
#:expand? [do-expand #t])
(define test-value-inner
(let ([p (dotest-prefix)]
[s (dotest-suffix)])
(let ([prepended (if p (string-append p test-value) test-value)])
(if s (string-append prepended s) prepended))))
(define (t) ((testing-token)
(let ([port (open-input-string test-value-inner)])
(when port-count-lines
(port-count-lines! port))
port)))
(define hrm ((if parse-to-datum ; used for debug
parse-to-datum
(compose syntax->datum (testing-parse)))
(t)))
(when (and node-type (not (rec-cont hrm node-type)))
(error (format "parse of ~s does not contain ~s" test-value node-type)))
(when (and eq (not (equal? eq hrm)))
(error (format "foo ~s ~s" test-value-inner hrm)))
; WAIT!? setting a parameter modifies the parent in module+ but not
; if you actually require the module !? ARGH!
(unless (or quiet (dotest-quiet))
(pretty-write (list 'dotest: hrm)))
(if (or do-expand node-type-expanded)
(when (or do-expand node-type-expanded) ; LOL when x vs begin ...
(define modname (string->symbol (format "org-module-~a" (gensym))))
(define hrms
(strip-context ; required to avoid hygene errors in expand and eval-syntax below
; for some reason raco make doesn't seem to care
#`(module #,modname laundry/expander
#,(parameterize ([laundry-final-port #f])
((testing-parse) ; watch out for the 2 arity case in the case-lambda here
#; ; NAH just a completely insane case-lambda
; that causes the call to revert to the full grammar
(format "test-source ~s" test-value-inner)
(t))))))
(parameterize ([current-namespace ns-test])
(unless (or quiet (dotest-quiet)) ; FIXME this logic is broken
(pretty-write (list 'expanded:
(syntax->datum (expand hrms)))))
#; ; FIXME for whatever reason drracket cannot manage to use eval-syntax here
; so we use eval syntax->datum instead, sigh
(eval-syntax hrms)
(eval (syntax->datum hrms))
(define root (dynamic-require (list 'quote modname) 'root))
(when (and node-type-expanded (not (rec-cont root node-type-expanded)))
(error (format "expansion of ~s does not contain ~s" test-value node-type-expanded)))
(when (and eq-root (not (equal? eq-root root)))
(error (format "foo ~s ~s" test-value-inner root)))
(unless (or eq-root node-type node-type-expanded)
root)))
(unless (or eq node-type)
hrm)))
#;
(require debug/repl)
(define (dotest-q test-value)
(dotest test-value #:quiet #t))
(define (dotest-fail test-value)
(unless (with-handlers ([exn? (λ (exn) #t)])
(dotest test-value)
#f)
(error "Should have failed.")))
(define (dotest-file path #:eq [eq #f] #:parse-to-datum [parse-to-datum #f])
; FIXME super inefficient
#;
(define (t) (laundry-make-tokenizer (open-input-string (file->string (string->path path) #:mode 'text))))
(define hrm
(with-input-from-file (expand-user-path (string->path path))
(λ ()
(port-count-lines! (current-input-port)) ; XXXXXXXXXXXXXX YAY this is what causes our backtracking issues :D :D
(parameterize ([laundry-final-port #f])
(let ([t (laundry-make-tokenizer (current-input-port))])
((if parse-to-datum
parse-to-datum
(compose syntax->datum (testing-parse)))
path
t))))
#:mode 'text))
(if eq
(unless (equal? eq hrm)
(error (format "path bar ~s" path)))
#;
(pretty-print hrm)
hrm))
(module+ test-bof
(current-module-path)
; fooing annoying as foo having to duplicate the whole fooing grammar
; just for this one fooing little special case FOO
(dotest "")
(dotest " ")
(dotest " \n")
(dotest "* ") ; XXX broken in the rework due to bof eof combo issues
(dotest "* Headline") ; XXX broken in the rework due to bof eof combo issues
(dotest "* Headline\n:properties:\n:poop: foo\n:end:") ; LOL broken again after it was fixed woo ambiguity
(dotest "Paragraph foo poop.")
(dotest "1. ordered list")
(dotest "- descriptive list")
(dotest "| table ")
; bof eof same line problem
(dotest ":drawer:\n:end:") ; so this one works with bof-eof
(dotest "\n:drawer:\n:end:") ; FIXME but now this one is wrong?
(dotest ":drawer:\n:end:\n")
)
(module+ test-wat
(current-module-path)
(dotest "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")
(dotest "x. ")
(dotest "x ")
(dotest "abc1")
(dotest "abcd")
(dotest "a.. ")
(dotest "a. ") ; XXX
(dotest ":d:\n* \n:end:")
(dotest "\n:d:\n* \n:end:")
(dotest " \t ")
(dotest " ")
(dotest " ") ; XXX
(dotest " ") ; XXX
(dotest " ") ; XXX
(dotest " ") ; XXX
(dotest " ") ; XXX
(dotest "x. ") ; XXX
(dotest "x. \n")
)
(module+ test-list
(current-module-path)
(define node-type 'plain-list-line)
(dotest "0." #:node-type node-type)
(dotest "0)" #:node-type node-type)
(dotest "0. " #:node-type node-type)
(dotest "0. " #:node-type node-type) ; XXX neg srcloc
(dotest " * poop" #:node-type node-type)
(dotest " - foo" #:node-type node-type)
(dotest "A. " #:node-type node-type)
(dotest "A. " #:node-type node-type) ; XXX neg srcloc
(dotest "A. asdf" #:node-type node-type)
(dotest "a. " #:node-type node-type)
(dotest "1. \n 2. " #:node-type node-type) ; XXX neg srcloc
(dotest " A. asdf" #:node-type node-type)
(dotest " a. " #:node-type node-type)
(dotest "1. \n a. " #:node-type node-type) ; XXX neg srcloc
(dotest "1. There\n a. asdf" #:node-type node-type) ; XXX
(dotest "1. There\n A. asdf" #:node-type node-type) ; XXX
(dotest "1. There\n A. asdf\n" #:node-type node-type)
(laundry-tokenizer-debug #f)
(dotest " f
- g
h
")
)
(module+ test-npnn
(current-module-path)
(dotest "asdf" #:node-type 'paragraph)
(dotest ";alksdjf;l jd; j;1oj;oij10j [p0j asd;foja ;kjas.d/f a.ldfjaoiejf01923jOAJ--1!@@#$%^&*[]{}\\/" #:node-type 'paragraph)
(dotest "\n")
(dotest "\t")
(dotest " ")
(dotest "|" #:node-type 'table)
)
(module+ test-cell
(current-module-path)
; from this it seems that we can't do PIPE? at the end because it will be eaten
; nope, not true, the PIPE? takes precednece so that does work in the limited case
(dotest "|" #:eq-root '(org-file (table (table-row (table-cell)))))
(dotest "||" #:eq-root '(org-file (table (table-row (table-cell)))))
(dotest "|||" #:eq-root '(org-file (table (table-row (table-cell) (table-cell)))))
(dotest "||||")
(dotest "|||||")
(dotest "|||||||||||||||||||||||||||||||||||||")
(dotest "||||||||||||||||||||||||||||||||||||||")
(dotest "|a")
(dotest "|a|")
(dotest "|a||")
(dotest "||a|")
(dotest "||a|b")
(dotest "||a|b|")
(dotest "|||oops|||oops|||oops oops|||")
(dotest "|a\n")
(dotest "| hello there")
(dotest "|a ")
(dotest "\n|a")
(dotest "| a | yo")
(dotest "| a | yo |")
(dotest "| \\| |")
(dotest "| - |")
(dotest "| oh it is *bad /yes/ _it_ =is=* <https://> [[(oh-boy)]] |")
)
(module+ test-row
(current-module-path)
(dotest "|\n|" #:eq-root '(org-file (table (table-row (table-cell)) (table-row (table-cell)))))
(dotest "||\n|")
(dotest "||\n||")
(dotest "|a|\n||")
(dotest "|a|\n|c|")
(dotest "|a|b\n|c|")
(dotest "|a|b\n|c|d")
(dotest "|a|b|\n|c|d|")
)
(module+ test-span-misalignment
; FIXME I think I'm triggering a bug in brag
; but it is happened because somehow the newline at eof is not triggering
; not a bug in brag, it was a -1 file position
; so I thik that this is happening because start-pos and end-pos are
; not in order resulting in a negative span, this is in brag-lib/codegen.rkt
; whole-rule-loc
; positions->srcloc
; rule-components->syntax
(dotest "|\nq") ; oooh that's bad
(dotest "|\nqq") ; oooh that's bad
(dotest "|\nq\n")
(dotest "|\nqq\n")
(dotest "xx")
(dotest "\n|\nyy\n")
(dotest "|\nzz\n")
(dotest "\n|\npp")
)
(module+ test-table
(current-module-path)
(define t 'table)
(dotest "|\nx ")
(dotest "|\n\nx")
(dotest "|\nxx") ; oooh that's bad XXX 99% that this is a newline at eof related issue
(dotest "|\nxx\n")
(dotest "|\nx x")
; test to make sure that the stop before clause does zero or more not newlines
(dotest " |\nx")
(dotest "|\nx")
(dotest " |\nx\n")
(dotest "|\nx\n")
(dotest "\n |\n x\n")
(dotest "\n |\n !\n")
(dotest "\n |\n x| \n")
(dotest "\n |\n x|")
(dotest "\nwat\n|\nx")
(dotest "\n|\nx")
(dotest "|\n")
(dotest "|" #:nte t)
(dotest "| ")
(dotest " |")
(dotest " | ")
(dotest "|t\n|2\n|-\n|3")
(dotest "|i|am|a|table")
(dotest "|i |am|a|table ")
(dotest "| t")
(dotest "| t")
(dotest "| t|")
(dotest "|t|")
(dotest "|t|\n")
(dotest "|t ")
(dotest "|table ")
(dotest "|table")
(dotest "|ta")
(dotest "|t")
(dotest "|t\n")
(dotest "|t\n|2")
(dotest "|t\n|2|")
(dotest "|\n")
(dotest "|\n|")
(dotest "|\n|\n")
(dotest "|\n|\n||")
(dotest "|\n|\n|||")
(dotest "|\n|\n|||\n|")
(dotest "||")
(dotest "||\n||")
(dotest "\n| the foo")
; FIXME the bug here is that these should all be one table but show
; up as multiple tables possibly due to ambiguity in the grammar
(dotest "|ah poop| wut\n|is going| on here| oh hai mark") ;x
(dotest "|ah-poop|-wut\n|is-going|-on-here|-oh-hai-mark") ;x
(dotest "* \n|a|b | c | d \n|e f g | hi|j|k\n|l\n|m|n\n|o\n|p") ;x
(dotest "* \n|a|b | c | d \n|e f g | hi|j|k\n|l\n|m|n\n|o\n|p") ;x
(dotest "* \n|a|b | c | d \n|e f g | hi|j|k\n|l\n|m|n\n|o\n") ;x
(dotest "* \n|a|b | c | d \n|e f g | hi|j|k\n|l\n|m|n\n") ;x
(dotest "* \n|a|b | c | d \n|e f g | hi|j|k\n|l") ;x
(dotest "*
|a|b | c | d
|e f g | hi|j|k") ; broken
(dotest "||\n|||") ;ok
(dotest "||\n|c|d|e") ;ok
(dotest "||b\n|c|d| e") ;ok
(dotest "|a|b\n|c|d| e") ;bad WAT XXX seriously wat
(dotest "* \n|a|b | c | d ")
(dotest "* \n|a|b | c | d |")
(dotest "* \n|a|b | c")
(dotest "* \n|a|b")
(dotest "* \n|a")
(dotest "* \n|a\n")
(dotest "* \n|a\n|b")
(dotest "* \n|a\n|b c")
(dotest "|tables\n|-\n|rule!")
(dotest "|a\n|b\n|c\n\n|d\n|e") ; FIXME this should be two nodes
(dotest "|\n\n|")
(dotest "|\n\n\n|")
(dotest "|a\n\nb|c")
(dotest "|a\nb|c") ; tests stop-before correction
(dotest "|a \n b|c")
; FIXME can't repro from test.org
(dotest "
| can you have newlines in cells?
this seems strange to me? | no, you can't
")
; test eof and table-element lex abbrev issues
(dotest "|\n\n|\nx|")
(dotest "\n|\n\n|\nx|")
(dotest "\n|\n\n|\n x|\n")
(dotest "\n|\n\n|\n x|")
(dotest "|\n x|")
(dotest "|\n x|\n\nwat")
(dotest "\n|x|")
(dotest "\n\n|x|")
(dotest "\n:end:\n* \n|\nx|") ; can't repro
(dotest "\n:end:\n* \n|\n x|") ; can't repro
(dotest "\n:end:\n** \n|\n x|") ; can't repro
(dotest "#lang org\n:end:\n*** \n|\nx|") ; can't repro
(dotest "* \n:end:\n* \n|\nx|") ; can't repro
(dotest ":a:\n* \n:b:\n* ") ; XXX this repros now
(dotest "\n:a:\n* \n:b:\n* ") ; cant' seem to repro
(dotest "
:a:
* b
:c:
* d
:e:
* f
")
(dotest "#lang org
:a:
* b
:c:
* d
:e:
* f
")
)
(module+ test-headline-content
(current-module-path)
(parameterize ([testing-parse
; XXX watch out for the 2 arg part of case-lambda produced by make-rule-parser
(heading-rule-parser --test--heading-rest)]
[testing-token (bind-runtime-todo-keywords '("TODO" "DONE" "FUTURE"))]
[laundry-tokenizer-debug #f]
[dotest-prefix " "]
[dotest-suffix "\n"])
(dotest "")
(dotest ":")
(dotest ": ")
(dotest ":t:")
(dotest ":n: :t:") ;
(dotest "TODO")
(dotest "DONE")
(dotest "FUTURE")
(dotest "DONE :t:")
(dotest "DONE:t:") ;
(dotest "DONE :n: :t:") ;
(dotest "DONE T")
(dotest "DONE COMMENT T")
(dotest "DONE [#P] COMMENT T")
(dotest "DONE [#P] COMMENT T :n: :t:") ;
(dotest "DONE [#P] COMMENT Title")
(dotest "DONE [#P] COMMENT Title :n: :t:") ;
(dotest "DONE[#P] COMMENT Title")
(dotest "DONE[#P] COMMENT Title :tag:")
(dotest "DONE[#P] COMMENT T :t:")
(dotest "DONE[#P] COMMENT T :t:")
(dotest "DONE Title")
(dotest "DONE Title :t:")
(dotest "T :n: :t:")
(dotest "T :t:")
(dotest "T n:t:")
))
(module+ test-planning ; FIXME very broken now
(current-module-path)
(dotest "* H\nDEADLINE:")
(dotest "* H\nSCHEDULED:")
(dotest "* H\nCLOSED:")
(dotest "* H\nDEADLINE:SCHEDULED:CLOSED:")
(dotest "* H\nDEADLINE: SCHEDULED: CLOSED:")
(dotest "* H\nDEADLINE: <2020-08-11> SCHEDULED: <0100-03-01> CLOSED: <1873-09-12>")
(dotest "* H\nOPENED:")
(dotest "* H\nOPENED: DEADLINE: SCHEDULED: CLOSED:")
(dotest "* H\nOPENED: <2012-09-16> DEADLINE: <2020-08-11> SCHEDULED: <0100-03-01> CLOSED: <1873-09-12>")
(dotest "* H\nDEADLINE: <2020>") ;x FIXME shouldn't parse fail should -> malformed line but I think we can't quite do that
(dotest "* H\nDEADLINE: <2020-11>") ;x
(dotest "* H\nDEADLINE: <2020-11-1>") ;x
(dotest "* H\nDEADLINE: <2020-11-01>")
(dotest "* H\nDEADLINE: <2020-11-01 ASDF>")
)
(module+ test-priority
(dotest "* [#A]")
(dotest "* [#A]Title")
(dotest "* [#A]:not_a_tag:")
(dotest "* [#A] :a_tag:") ; FIXME why no hyphen? opporunity for regularization or what is going on?
(dotest "* TODO [#A]")
(dotest "* x [#A]")
)
(module+ test-headline
(current-module-path)
; FIXME not sure what COMMENT breaks things ?!
;(define test-value "this is ORG MODE\n* headline\n YEAH\n** COMMENT comment headline\nstuff\n* hl2 :tag:\n")
; ok, so BOF and EOF are causing annoying edge cases
#;
(dotest-quiet #f)
(dotest "** COMMENT[#A]")
(dotest "** COMMENT [#A] COMMENT")
(dotest "* :x:") ; catch perf issues
(dotest "* " #:node-type 'headline)
(dotest (string-append (make-string 99 #\*) " "))
(dotest "* H")
(dotest "* H ") ; how the foo does this work
(dotest "* He") ; and this work
(dotest "* He ") ; but this fail?
(dotest "* T n:t:")
(dotest "* [#P]:t:")
(dotest "* [#P] :t:")
(dotest "* H [#P]:t:") ; x
(dotest "* H [#P] :t:") ; x
; not the immediate issue
(dotest "* [#P]:ta:")
(dotest "* [#P]:t:1:")
(dotest "* [#P]COMMENTT") ; ok
(dotest "* [#P]COMMENTTi") ; ok
(dotest "* [#P]COMMENTTi :t:") ; broken
(dotest "* [#P]COMMENTT :t:") ; broken
(dotest "* [#P]COMMENTT :t: ") ; broken
(dotest "* [#P]COMMENTT :wat:asdf: ") ; broken
(dotest "* [#P]COMMENTT :ARCHIVE:") ; ok !?
(dotest "* Headline [#P]COMMENT Title")
(dotest "* H [#P]COMMENT T")
(dotest "* H [#P]COMMENT Ti")
(dotest "* H [#P]COMMENT Ti :t:")
(dotest "* H [#P]COMMENT T :t:")
(dotest "* H [#P]COMMENT :t:")
(dotest "* H [#P]COMMENT:t:")
(dotest "* H [#P]COMMENT:ta:")
(dotest "* H [#P]COMMENT:t: ")
(dotest "* H [#P]COMMENT:ARCHIVE:")
; the behavior of org-export is clear here, no spaces -> title
(dotest "* TODO[#P]COMMENT T")
(dotest "* TODO[#P]COMMENT Ti")
(dotest "* TODO[#P]COMMENT Ti :t:")
(dotest "* TODO[#P]COMMENT T :t:")
(dotest "* TODO[#P]COMMENT :t:")
(dotest "* TODO[#P]COMMENT:t:")
(dotest "* TODO[#P]COMMENT:ta:")
(dotest "* TODO[#P]COMMENT:t: ")
(dotest "* TODO[#P]COMMENT:ARCHIVE:")
(dotest "* COMMENTARY") ; the poor sods
(dotest "* TODO:tag:")
; wow wtf these are max spook
(dotest "* H [#P]COMMENTT")
(dotest "* H [#P]COMMENTTi")
(dotest "* H [#P]COMMENTT :t:")
(dotest "* [#P]COMMENT Sigh")
(dotest "* H [#P]COMMENT Sigh :tag:")
(dotest "* [#P] COMMENT Sigh")
(dotest "* [#P] COMMENT Sigh")
(dotest "* H [#P] COMMENT Sigh :tag:")
(dotest "* H [#P]\n") ; broken again
(dotest "* H [#P] \n") ; broken again
; still amgibuous
(dotest "* H [#P] T\n")
(dotest "* H [#P] T :tag:\n")
(dotest "* H [#P] :tag:\n")
; FIXME this should parse with the todo keyword ???? XXX fixed now, the clauses were out of order (duh) ; XXX FIXME broke it again
; because we don't know the actual TODO keyword values at runtime AND because title will gobble
; the priority ... this is tricky ... yes ... yes it is
; ok
(dotest "* [#B] COMMENT YEAHH!!!!\n")
(dotest "* [#H] COMMENT a a1 aaa :tag: \n") ; (ref:break-1)
(dotest "* [#M] COMMENT wat :tag: \n")
(dotest "* [#O] COMMENT wat :tag: \n")
(dotest "* [#N] COMMENT wat 1 :tag: \n") ; WAT a todo keyword !? also LOL this can actually happen
(dotest "* [#P] COMMENT wat :tag: \n") ; WAT a todo keyword ?! also LOL this can actually happen
;; annoyingly inconsistent
(dotest "* [#G] COMMENT :tag: \n")
; behavior doesn't matches elisp but that behavior is not consistent with null title
; I have moved h-comment to its own element not nested inside the title and then opened
; up the possibility to have tags that are ending
(dotest "* [#C] COMMENT :some:tag:\n") ; wait what the foo?
; ambig
(dotest "* [#A] Urg\n")
(dotest "* [#D] Urg :tag:tag:tag:\n")
(dotest "* [#I] aaaaaaaaa a1aaaaaa aaaaaaa :tag: \n")
(dotest "* [#J] wat :tag: \n")
(dotest "* [#K] wat wat :tag: \n")
; so there is some seriously broken poop going on here? there is NO way that
; adding an additional wat should break any of this ...
(dotest "* [#L] wat wat wat :tag: \n")
(dotest "* [#K] wat wat wat :tag: \n")
; always ambig since we don't use title unprefixed
(dotest "** Headline level 2\n" #:nte 'heading)
(dotest "why can't we share this newline?\n** Headline level 2\n" #:nte 'heading)
;; broken
(dotest "* Headline Sigh\n") ; this should hit todo-keyword but is gobbled just the title
(dotest "* [#F] so apparently this tag is valid :tag: \n") ; how the foo is this broekn again
(dotest "* [#E] NOOOO :1:2:3: derp\n") ; broken !?
(dotest "* Headline [#Z] Sigh :T:A:G:S:\n") ; FIXME SOMEHOW adding tags makes the todo-keyword work !??!?!
(dotest "* Headline [#Z] :T:A:G:S:\n")
(dotest "* Headline [#Z]Sigh") ; broken
(dotest "* Headline [#Z]Sigh :t:\n") ; now broken
(dotest "* : H")
(dotest "* : H ")
(dotest "* [ H")
(dotest "* [ H ")
(dotest "* ] H")
(dotest "* ] H ")
(dotest "* :")
(dotest "* : ")
(dotest "* [")
(dotest "* [ ")
(dotest "* ]")
(dotest "* ] ")
(dotest "*
**
***
****
******
*******
********
********* ")
; watch out for negated patterns that don't include a newline in the negated set >_<
(dotest "a\nb\nc\nd\n* \ne\nf\ng\n****** h\ni" #:nte 'heading)
(dotest "* \ne\nf\ng\n****** h\ni" #:nte 'heading)
(dotest "g\n****** h" #:nte 'heading)
(dotest "g\n***** h" #:nte 'heading)
(dotest "\n****** h\ni" #:nte 'heading) ; this one ok in most cases anyway
)
(module+ test-paragraph-start
(current-module-path)
(laundry-tokenizer-debug #f)
(dotest " #+begin_src")
(dotest " #+begin_srclol" #:node-type 'paragraph)
(dotest " #+begin_src\n")
(dotest " #+begin_")
(dotest " #+begin_-") ; -> block
(dotest " #+begin_:") ; -> block FIXME keyword line confict XXX ambig
(dotest "#+end_ " #:node-type 'malformed) ; ok
(dotest " #+begin_src oops not a thing") ; ok
(dotest " #+begin_ more" #:node-type 'paragraph) ; ok
; FIXME dynamic block weirdness
(dotest "#+end:" #:node-type 'keyword) ; -> keyword
(dotest " #+end:" #:node-type 'keyword)
(dotest " #+end") ; FIXME dynamic block end, possibly a bug in the dynamic bock spec
(dotest "#+end")
(dotest " #+end_")
(dotest "#+end_")
(dotest "#+end_srclol" #:nte 'paragraph)
(dotest "#+:end::properties::end: lol" #:node-type 'keyword) ; -> keyword
(dotest "#+:end:" #:node-type 'keyword) ; -> keyword
(dotest "#+:properties:" #:node-type 'keyword) ; -> keyword
(dotest "#+:end::asdf")
#; ; in our current implementation this is a keyword-line what the key and value actually parse to ???
(dotest "#+:end::asdf" #:node-type 'paragraph) ; XXX inconsistnet org element says keyword, font locking and spec say paragraph
(dotest (make-string 99 #\*)) ; FIXME ideally nested markup should issue a warning and not nest in the tree
; now fixed and blazingly fast but
; but wow NAME+ has horrible performance, probably need to move more of this stuff to the lexer
; LOL at 99 it is bad, at 999 THIS IS A DISASTER for performnace and memory usage
(dotest " *********")
(dotest " ********* ")
(dotest " ** ")
(dotest "*********")
(dotest " *\n")
(dotest " *")
(dotest " * ")
(dotest "*")
(dotest " #" #:node-type 'comment) ; -> comment XXX FIXME broken comment element should be matching this
(dotest "#" #:node-type 'comment) ; -> comment
(dotest "# " #:node-type 'comment) ; -> comment
(dotest " #a" #:node-type 'paragraph)
(dotest "#a" #:node-type 'paragraph)
(dotest " #+")
(dotest "#+")
(dotest "#+:")
(dotest "#+:aaaa:")
#; ; correct but not fully implemented yet
(dotest "#+:aaaa:" #:eq-root '(org-file (keyword (keyword-key ":aaaa"))))
(dotest "#+:aaaa")
(dotest "#+::")
(dotest "#+: :")
(dotest "#+ :")
(dotest "#+a :")
(dotest "#+a : asdf :")
(dotest "#+a hello there: YEAH")
; ugh big tokes and drawer tokens
(dotest " #+call:")
(dotest " #+call:eeeeeeeeee")
(dotest " #+calla") ; XXX TODO malformed case
(dotest "#+:end")
(dotest "#+:end: lol: oops") ; -> keyword
(dotest "#+:end: asdf") ; -> keyword
(dotest "#+:end:lol: oops") ; -> keyword
(dotest "#+:properties: lol: oops") ; -> keyword
(dotest "#+:properties:lol: oops") ; -> keyword
(dotest " -") ; -> descriptive-list
(dotest "-") ; -> descriptive-list
(dotest " -a")
(dotest "-a")
(dotest " +") ; -> descriptive-list
(dotest "+") ; -> descriptive-list
(dotest " +a")
(dotest "+a")
(dotest " *") ; -> descriptive-list
(dotest "*" #:node-type 'paragraph) ; interestingly this parses as a paragraph line in elisp too, it can't ever be a plain list
(dotest " *a" #:node-type 'paragraph)
(dotest "*a" #:node-type 'paragraph)
(dotest "* ") ; -> headline
(dotest " |" #:node-type 'table)
(dotest "|" #:node-type 'table)
(dotest "|lol" #:node-type 'table)
(dotest "0")
(dotest " 9")
(dotest " 9.") ; -> ordered list
(dotest "9.") ; -> ordered list
(dotest " 9)") ; -> ordered list
(dotest "9)") ; -> ordered list
(dotest " 9.a")
(dotest "9.a")
(dotest " 9)a")
(dotest "9)a")
(dotest "9)#+end:")
(dotest "9)ARCHIVE")
(dotest " 9999999." #:nte 'ordered-list-line) ; -> ordered list XXX FIXME broken ??!
(dotest "9.") ; -> ordered list
(dotest "99")
(dotest "99._")
(dotest "99 _")
(dotest "999999 hello world")
(dotest "99. ") ; -> ordered list
(dotest "99." #:nte 'ordered-list-line) ; -> ordered list
(dotest "999.") ; -> ordered list
(dotest "9999.") ; -> ordered list
(dotest "99999.") ; -> ordered list
(dotest "999999.") ; -> ordered list
(dotest "9999999." #:nte 'ordered-list-line) ; -> ordered list
(dotest " 9999999.a")
(dotest "9999999.a")
(dotest " COMMENT")
(dotest "COMMENT")
(dotest "COMMENT more")
(dotest " ARCHIVE")
(dotest "ARCHIVE")
(dotest "ARCHIVE more")
(dotest " :ARCHIVE")
(dotest ":ARCHIVE")
(dotest ":ARCHIVE more")
(dotest " (a)" #:node-type 'paragraph)
(dotest " (" #:node-type 'paragraph)
(dotest " )" #:node-type 'paragraph)
(dotest " _" #:node-type 'paragraph)
(dotest ".\n," #:node-type 'paragraph)
(dotest ".\n ," #:node-type 'paragraph)
(dotest "," #:node-type 'paragraph)
(dotest "." #:node-type 'paragraph)
(dotest ".a" #:node-type 'paragraph)
(dotest ".ab" #:node-type 'paragraph)
(dotest " .a" #:node-type 'paragraph)
(dotest " .ab" #:node-type 'paragraph)
)
(module+ test-paragraphs
(current-module-path)
(define nte 'paragraph)
(dotest "***nasdf" #:nte nte)
(dotest "aaaaaaaaa paragraph" #:nte nte)
(dotest "p11\np12\n\np21"
#:eq-root
'(org-file (paragraph "p11\np12\n") (paragraph "\np21")))
(dotest "\nIf nothing else this is a paragraph." #:nte nte)
(dotest "p" #:nte nte) ; sigh bof
(dotest "\np")
(dotest "\np\n")
(dotest "\np a r a g p\n")
(dotest "p a r a g p")
(dotest "aaaaaaaaaaa")
(dotest "aaaaaaaaaaaa")
(dotest "0123456789")
(dotest "0123456789A")
(dotest "01234567890")
(dotest "0123456789")
(dotest "0123456789A")
(dotest "I'm sorry I really just do not understand what the issue is here.")
(dotest "
* I don't get it
Seriously what the foo?
")
(dotest "\n#+NAME: hello there\nGeneral Kenobi")
(dotest "\n#+ATTR_HTML: hello there\nGeneral Kenobi")
(dotest "
#+ATTR_FOO: POO
AAAAAAAAAAAAAAAAAAAAAAA
* Why is this so fooed?
asdf")
; the parser reads everything twice the only difference in the token stream
; is whether or not the newline is there what the foo?
(dotest "\n\np\n\n")
(dotest "\n0123456789A")
(dotest "0123456789A")
(dotest "paragraph\n")
)
(module+ test-cite
; from test-org-element
(dotest "[cite:@key]" #:nte 'citation)
(dotest "[cite:-@key]" #:nte 'citation)
(dotest "[cite:text]") ; not key
(dotest "[cite/style:@key]" #:nte 'citation)
#; ; TODO ?
(dotest "[cite/elyts:@key]" #:nte 'style) ; element property should be style
(dotest "[cite:@a;@b;@c]" #:nte 'citation)
#; ; TODO not sure of the distinction
(dotest "[cite:@a;@b;@c]" #:nte 'citation-reference)
(dotest "[cite:@a;-@b]")
(dotest "[cite:common-prefix@a]") ; ??? what should this be
(dotest "[cite:common-prefix;@a]")
(dotest "[cite:@a;common-suffix]")
(dotest "[cite: common-prefix ;@a]")
(dotest "[cite: @a; common-suffix]")
(dotest "[cite: @a ; common-suffix]") ; ???
(dotest "[cite:common-prefix;@a;common-suffix]")
(dotest "[cite:@[]]") ; not key
(dotest "[cite:@a:.#$%&-+?<>~/1]" #:nte 'citation)
(dotest "[cite:@;]") ; not citation-reference ? XXX
(dotest "[cite: pre @key post]")
(dotest "[cite: pre @key]")
(dotest "[cite:@key post]")
(dotest "[cite: pre1 @k1 post1; pre2 @k2 post2]")
(dotest "[cite: pre1 @k1;pre2 @k2 post2]")
(dotest "[cite: pre1 @k1 post1;@k2 post2]")
(dotest "[cite:@k1 post1; pre2 @k2]")
)
(module+ test-footnotes
(dotest "[fn::]")
(dotest "[fn::")
; series
(dotest "[fn::a][fn::b]")
; series nested
(dotest "[fn::c[fn::a][fn::b]]")
; nested
(dotest "[fn::a[fn::b]]")
; deeply nested
(dotest "[fn::[fn::[fn::[fn::[fn::[fn::]]]]]]")
; XXX divergece, fortunately it is relxaing a constraint
(dotest "[fn:: =]= ]")
(dotest "[fn:: =[= ]")
; FIXME these have annoying failure modes which push
; the tokenizer to parser as paragraphs
(dotest "[fn:a] b\nc\n* d e\nf")
(dotest "[fn:a] b\nc\n[fn:d] e\nf")
(dotest "[fn:a]\n\n\n\n")
(dotest "[fn:a] b\n|t\n\n")
(dotest "[fn:a] b\n\nc\n\nd\n* \n")
(dotest "[fn:a] b\n\nc\n\nd\n\n")
(dotest "[fn:x]\n*\n")
(dotest "[fn:x]\n* \n")
(dotest "[fn:def] always a definition")
; cursed
; elisp font locking gets this wrong, export gets it right, the issue is the lack fo leading whitespace
; among other things
(dotest "[fn:: =x= ]")
(dotest "[fn::=]=]")
(dotest "[fn:: =]= ]") ; XXX divergence
(dotest "[fn:: x =]= y ]") ; XXX divergence
(dotest "[fn::=[=]") ; =[= is not verbatim because the pre or post do not meet the requirements
(dotest "[fn:: [ x =]= y ]") ; XXX divergence
(dotest "[fn:: =[= x ] y ]") ; XXX divergence
(dotest "[fn:: =[= x =]= y ]") ; consistent
(dotest "[fn:: =[= x [ ] =]= y ]") ; consistent
; un-marked up brackets pair? no ... ugh, everything a mess here
; cursed part 2
(dotest " [fn::=]=]")
(dotest " [fn:: =]= ]")
(dotest " [fn:: x =]= y ]")
(dotest " [fn::=[=]")
(dotest " [fn:: [ x =]= y ]")
(dotest " [fn:: =[= x ] y ]")
(dotest " [fn:: =[= x =]= y ]")
; from/to [fn:: ] and (:~ [ ) ?? doesn't help with the nested cases though
; right now markup wins when fighting with footnotes
(dotest "=[= [fn:: x =]= y ]") ; FIXME this one gets the interaction between footnotes and markup
; turns out that the elisp implementation has the same issue, it highlights as both the terminal
; for a footnote and verbatim in fontlocking but org export gets it right
; cursed anchor