-
Notifications
You must be signed in to change notification settings - Fork 0
/
org-to-tree-sitter-corpus-tests.el
135 lines (126 loc) · 3.2 KB
/
org-to-tree-sitter-corpus-tests.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
;;; org-to-tree-sitter-corpus-tests.el --- Tests for org-to-tree-sitter-corpus -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2021 Gerry Agbobada
;;
;; Author: Gerry Agbobada <https://github.com/gagbo>
;; Maintainer: Gerry Agbobada <gerry@gagbo.net>
;; Homepage: https://github.com/gagbo/org-to-tree-sitter-corpus
;;
;; This file is not part of GNU Emacs.
;;
;;; Commentary:
;; Just a test file
;;
;;; Code:
(require 'org-to-tree-sitter-corpus)
(require 'org)
(require 'subr-x)
(defun ottsct--make-tree (content)
"Build an org-element AST with CONTENT."
(with-temp-buffer
(insert content)
(org-element-parse-buffer)))
(defun ottsct--make-test (content ts-tree)
"Return a test that asserts that CONTENT is transformed to TS-TREE."
(let ((actual-tree (thread-first content (string-trim-left) (ottsct--make-tree) (org-to-tree-sitter-corpus-transform-tree))))
(should (equal actual-tree ts-tree))))
(ert-deftest ottsc-test-headline ()
"Assert that headlines are correctly transformed."
(ottsct--make-test
"*"
'(org_data (headline (stars))))
(ottsct--make-test
"* Title"
'(org_data
(headline (stars) (title))))
(ottsct--make-test
"* Title with tags :tag1:"
'(org_data
(headline (stars) (title) (tags))))
(ottsct--make-test
"* COMMENT Title"
'(org_data
(headline (stars) (comment_marker) (title))))
;; TODO: Enable this test and fix it
;; (ottsct--make-test "* TODO Title" '(org_data (headline (stars) (todo) (title))))
;; TODO: Make this pass, if it's legal org
;; (ottsct--make-test
;; "* :tag1:"
;; '(org_data
;; (headline (stars) (tags))))
)
(ert-deftest ottsc-test-paragraph ()
"Assert that paragraphs are correctly transformed."
(ottsct--make-test
"
*
Sample text"
'(org_data (headline (stars) (section (paragraph)))))
(ottsct--make-test
"
#+RESULTS: test
Sample text"
'(org_data
(section
(results)))))
(ert-deftest ottsc-test-keyword ()
"Assert that keywords are correctly transformed."
(ottsct--make-test
"#+TITLE: Some title"
'(org_data (keyword (key) (value))))
(ottsct--make-test
"
#+TITLE: Some title
#+SUBTITLE: I'm not over"
'(org_data (keyword (key) (value))
(keyword (key) (value)))))
;; TODO: Add support for those
(ert-deftest ottsc-test-drawers ()
"Assert that drawers are correctly transformed."
(ottsct--make-test
"
* Random drawer
Text at the beginning
:CUSTOM:
Hidden arbitrary drawer
:END:
Another paragraph"
'(org_data
(headline
(stars)
(section
(paragraph)
(drawer (paragraph))
(paragraph)))))
;; Misplaced Properties drawer is still a drawer
(ottsct--make-test
"
* Random drawer
Text at the beginning
:PROPERTIES:
Hidden arbitrary drawer
:END:
Another paragraph"
'(org_data
(headline
(stars)
(section
(paragraph)
(drawer (paragraph))
(paragraph)))))
(ottsct--make-test
"
* Random drawer
:PROPERTIES:
:key: Value
:END:
The paragraph"
'(org_data
(headline
(stars)
(section
(property_drawer (node_property (key) (value)))
(drawer (paragraph))
(paragraph))))))
(provide 'org-to-tree-sitter-corpus-tests)
;;; org-to-tree-sitter-corpus-tests.el ends here