Skip to content

Commit 207c748

Browse files
committed
WIP: Refactoring tests
1 parent 50a49b1 commit 207c748

File tree

4 files changed

+111
-111
lines changed

4 files changed

+111
-111
lines changed

README.org

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#+TITLE:Org Outline Tree
22

3-
[[https://www.gnu.org/software/emacs/][https://img.shields.io/badge/Emacs-27.1+-blueviolet.svg?logo=GNU%20Emacs&logoColor=white]]
3+
[[https://www.gnu.org/software/emacs/][https://img.shields.io/badge/works%20on-27.1+-blueviolet.svg?logo=GNU%20Emacs&logoColor=white]]
44
[[https://github.com/Townk/org-ol-tree/blob/main/LICENSE][http://img.shields.io/badge/license-MIT-brightgreen.svg]] [[https://github.com/Townk/org-ol-tree/actions/workflows/tests.yml][https://github.com/Townk/org-ol-tree/actions/workflows/tests.yml/badge.svg]] [[https://codecov.io/gh/Townk/org-ol-tree][https://codecov.io/gh/Townk/org-ol-tree/branch/main/graph/badge.svg?token=XL88FR24XT]]
55

66
This package offers an Org mode outline window that does not use indirect buffers.

org-ol-tree.el

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
;; Version: 0.0.1
99
;; Keywords: org, org-mode, outline, tree, tree-view, treeview, treemacs
1010
;; Homepage: https://github.com/Townk/org-ol-tree
11-
;; Package-Requires: ((org "9.4") (treemacs "2.8") (dash "2.18.1") (s "1.12.0") (ht "2.3") (cfrs "1.5.4") (seq) (cl-lib))
11+
;; Package-Requires: ((org "9.4") (treemacs "2.8") (dash "2.18.1") (s "1.12.0") (ht "2.3") (seq) (cl-lib))
1212
;;
1313
;; This file is not part of GNU Emacs.
1414
;;
@@ -70,7 +70,6 @@
7070
;;
7171
;;; Code:
7272

73-
(require 'cfrs)
7473
(require 'cl-lib)
7574
(require 'dash)
7675
(require 'ht)

tests/test-outline-core.el

Lines changed: 73 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;;; test-outline-core.el --- Sections and Headings tests -*- lexical-binding: t; -*-
1+
;;; test-outline-core.el --- Sections and Headlines tests -*- lexical-binding: t; -*-
22
;;
33
;; Copyright (C) 2021 Thiago Alves
44
;;
@@ -7,7 +7,7 @@
77
;;; Commentary:
88
;;
99
;; This file contains all tests related to the core objects (currently
10-
;; 'sections' and 'headings').
10+
;; 'sections' and 'headlines').
1111
;;
1212
;; Since reading the test might be tedious, I'm reproducing here the transcript
1313
;; of the behaviors being tested by this file:
@@ -23,20 +23,20 @@
2323
;; - should return the next section stack when creating a new section on a given level
2424
;; - should throw an exception when trying to get next section from a non-section object
2525
;;
26-
;; - Heading
26+
;; - Headline
2727
;; - should allow me to create an object with no slot values
2828
;; - when creating it from a non org buffer
2929
;; - should throw a user error with a non-org buffer message
3030
;; - when creating it from an org buffer
31-
;; - should raise an error if cursor is not ona heading
31+
;; - should raise an error if cursor is not ona headline
3232
;; - when cursor is on a headline
33-
;; - should return a heading object for the section
34-
;; - should throw an error if the giving previous heading is not a valid heading
35-
;; - should return a sibling heading when passing previous heading on same level
36-
;; - should return a sub-heading when passing previous heading on lower level
37-
;; - should return a heading when passing previous heading on higher level
33+
;; - should return a headline object for the section
34+
;; - should throw an error if the giving previous headline is not a valid headline
35+
;; - should return a sibling headline when passing previous headline on same level
36+
;; - should return a child when passing previous headline on lower level
37+
;; - should return a headline when passing previous headline on higher level
3838
;; - when getting it from the outline buffer
39-
;; - should retrieve the heading by getting the :heading property of the button
39+
;; - should retrieve the headline by getting the :headline property of the button
4040
;;
4141
;; - Document
4242
;; - the object model (DOM)
@@ -52,7 +52,7 @@
5252
;; - when creating from a non Org file
5353
;; - should fail with an user error
5454
;; - when creating from an Org file
55-
;; - should be able to traverse the document and return a heading DOM
55+
;; - should be able to traverse the document and return a headline DOM
5656
;; - when defining its name
5757
;; - from a file with no title
5858
;; - should use the file name in title-case as the node name
@@ -126,21 +126,21 @@
126126

127127

128128

129-
(describe "Heading"
130-
:var (empty-heading)
129+
(describe "Headline"
130+
:var (empty-headline)
131131

132132
(it "should allow me to create an object with no slot values"
133-
(expect (setq empty-heading (org-ol-tree-core--heading-create-internal)) :not :to-throw)
134-
(expect (org-ol-tree-core--heading-level empty-heading) :to-equal 0)
135-
(expect (listp (org-ol-tree-core--heading-subheadings empty-heading)) :to-be-truthy))
133+
(expect (setq empty-headline (org-ol-tree-core--headline-create-internal)) :not :to-throw)
134+
(expect (org-ol-tree-core--headline-level empty-headline) :to-equal 0)
135+
(expect (listp (org-ol-tree-core--headline-children empty-headline)) :to-be-truthy))
136136

137137

138138
(describe "when creating it from a non org buffer"
139139
(it "should throw a user error with a non-org buffer message"
140-
(expect (org-ol-tree-core--heading-create)
140+
(expect (org-ol-tree-core--create-headline)
141141
:to-throw
142142
'user-error
143-
'("Cannot create an org-ol-tree-core--heading on a non-org buffer"))))
143+
'("Cannot create an org-ol-tree-core--headline on a non-org buffer"))))
144144

145145

146146
(describe "when creating it from an org buffer"
@@ -150,81 +150,82 @@
150150
(after-each
151151
(org-mode))
152152

153-
(it "should raise an error if cursor is not ona heading"
153+
(it "should raise an error if cursor is not ona headline"
154154
(expect
155-
(org-ol-tree-core--heading-create)
155+
(org-ol-tree-core--create-headline)
156156
:to-throw
157157
'user-error
158-
'("Cannot create a heading with cursor outside an actual org headline")))
158+
'("Cannot create a headline with cursor outside an actual org headline")))
159159

160160

161161
(describe "when cursor is on a headline"
162-
:var ((heading-1 '(1 1 nil nil "Heading 1" nil))
163-
(heading-1-1 '(2 2 nil nil "Heading 1.1" nil))
164-
(heading-2 '(1 1 nil nil "Heading 2" nil))
165-
current-heading new-heading)
162+
:var ((headline-1 '(1 1 nil nil "Headline 1" nil))
163+
(headline-1-1 '(2 2 nil nil "Headline 1.1" nil))
164+
(headline-2 '(1 1 nil nil "Headline 2" nil))
165+
current-headline new-headline)
166166

167167
(before-each
168-
(spy-on 'org-at-heading-p :and-return-value t))
168+
(spy-on 'org-at-headline-p :and-return-value t))
169169

170-
(it "should return a heading object for the section"
171-
(spy-on 'org-heading-components :and-return-value heading-1)
172-
(setq current-heading (org-ol-tree-core--heading-create))
173-
(expect (org-ol-tree-core--heading-name current-heading) :to-equal "Heading 1")
174-
(expect (org-ol-tree-core--heading-id current-heading) :to-equal "1"))
170+
(it "should return a headline object for the section"
171+
(spy-on 'org-headline-components :and-return-value headline-1)
172+
(setq current-headline (org-ol-tree-core--create-headline))
173+
;; (expect (org-ol-tree-core--headline-name current-headline) :to-equal "Headline 1")
174+
;; (expect (org-ol-tree-core--headline-id current-headline) :to-equal "1")
175+
)
175176

176-
(it "should throw an error if the giving previous heading is not a valid heading"
177-
(expect (org-ol-tree-core--heading-create 42)
177+
(xit "should throw an error if the giving previous headline is not a valid headline"
178+
(expect (org-ol-tree-core--create-headline 42)
178179
:to-throw 'error
179-
'("Given parent must be nil or an ’org-ol-tree-core--heading’ object")))
180-
181-
(it "should return a sibling heading when passing previous heading on same level"
182-
(spy-on 'org-heading-components :and-return-value heading-1)
183-
(setq current-heading (org-ol-tree-core--heading-create))
184-
(spy-on 'org-heading-components :and-return-value heading-2)
185-
(setq new-heading (org-ol-tree-core--heading-create current-heading))
186-
(expect (org-ol-tree-core--heading-name new-heading) :to-equal "Heading 2")
187-
(expect (org-ol-tree-core--heading-id new-heading) :to-equal "2")
188-
(expect (org-ol-tree-core--heading-level new-heading) :to-equal 1))
189-
190-
(it "should return a sub-heading when passing previous heading on lower level"
191-
(spy-on 'org-heading-components :and-return-value heading-1)
192-
(setq current-heading (org-ol-tree-core--heading-create))
193-
(spy-on 'org-heading-components :and-return-value heading-1-1)
194-
(setq new-heading (org-ol-tree-core--heading-create current-heading))
195-
(expect (org-ol-tree-core--heading-name new-heading) :to-equal "Heading 1.1")
196-
(expect (org-ol-tree-core--heading-id new-heading) :to-equal "1.1")
197-
(expect (org-ol-tree-core--heading-level new-heading) :to-equal 2))
198-
199-
(it "should return a heading when passing previous heading on higher level"
200-
(spy-on 'org-heading-components :and-return-value heading-1)
201-
(setq current-heading (org-ol-tree-core--heading-create))
202-
(spy-on 'org-heading-components :and-return-value heading-1-1)
203-
(setq current-heading (org-ol-tree-core--heading-create current-heading))
204-
(spy-on 'org-heading-components :and-return-value heading-2)
205-
(setq new-heading (org-ol-tree-core--heading-create current-heading))
206-
(expect (org-ol-tree-core--heading-name new-heading) :to-equal "Heading 2")
207-
(expect (org-ol-tree-core--heading-id new-heading) :to-equal "2")
208-
(expect (org-ol-tree-core--heading-level new-heading) :to-equal 1))))
180+
'("Given parent must be nil or an ’org-ol-tree-core--headline’ object")))
181+
182+
(xit "should return a sibling headline when passing previous headline on same level"
183+
(spy-on 'org-headline-components :and-return-value headline-1)
184+
(setq current-headline (org-ol-tree-core--create-headline))
185+
(spy-on 'org-headline-components :and-return-value headline-2)
186+
(setq new-headline (org-ol-tree-core--create-headline current-headline))
187+
(expect (org-ol-tree-core--headline-name new-headline) :to-equal "Headline 2")
188+
(expect (org-ol-tree-core--headline-id new-headline) :to-equal "2")
189+
(expect (org-ol-tree-core--headline-level new-headline) :to-equal 1))
190+
191+
(xit "should return a child when passing previous headline on lower level"
192+
(spy-on 'org-headline-components :and-return-value headline-1)
193+
(setq current-headline (org-ol-tree-core--create-headline))
194+
(spy-on 'org-headline-components :and-return-value headline-1-1)
195+
(setq new-headline (org-ol-tree-core--create-headline current-headline))
196+
(expect (org-ol-tree-core--headline-name new-headline) :to-equal "Headline 1.1")
197+
(expect (org-ol-tree-core--headline-id new-headline) :to-equal "1.1")
198+
(expect (org-ol-tree-core--headline-level new-headline) :to-equal 2))
199+
200+
(xit "should return a headline when passing previous headline on higher level"
201+
(spy-on 'org-headline-components :and-return-value headline-1)
202+
(setq current-headline (org-ol-tree-core--create-headline))
203+
(spy-on 'org-headline-components :and-return-value headline-1-1)
204+
(setq current-headline (org-ol-tree-core--create-headline current-headline))
205+
(spy-on 'org-headline-components :and-return-value headline-2)
206+
(setq new-headline (org-ol-tree-core--create-headline current-headline))
207+
(expect (org-ol-tree-core--headline-name new-headline) :to-equal "Headline 2")
208+
(expect (org-ol-tree-core--headline-id new-headline) :to-equal "2")
209+
(expect (org-ol-tree-core--headline-level new-headline) :to-equal 1))))
209210

210211

211212
(describe "when getting it from the outline buffer"
212-
:var (heading)
213+
:var (headline)
213214

214215
(before-each
215216
(spy-on 'org-ol-tree-core--current-node :and-return-value 2)
216-
(spy-on 'get-text-property :and-return-value 'current-heading))
217+
(spy-on 'get-text-property :and-return-value 'current-headline))
217218

218-
(it "should retrieve the heading by getting the :heading property of the button"
219-
(setq heading (org-ol-tree-core--heading-current))
219+
(it "should retrieve the headline by getting the :headline property of the button"
220+
(setq headline (org-ol-tree-core--current-headline))
220221

221222
(expect 'org-ol-tree-core--current-node :to-have-been-called-times 1)
222-
(expect 'get-text-property :to-have-been-called-with 2 :heading)
223-
(expect heading :to-be 'current-heading))))
223+
(expect 'get-text-property :to-have-been-called-with 2 :headline)
224+
(expect headline :to-be 'current-headline))))
224225

225226

226227

227-
(describe "Document"
228+
(xdescribe "Document"
228229

229230
(describe "the object model (DOM)"
230231

@@ -299,12 +300,12 @@
299300
(describe "when creating from an Org file"
300301
:var (doc-dom)
301302

302-
(it "should be able to traverse the document and return a heading DOM"
303+
(it "should be able to traverse the document and return a headline DOM"
303304
(find-file (expand-file-name "data/doc-happy-path.org" test-root-dir))
304305
(setq doc-dom (org-ol-tree-core--doc-create (current-buffer)))
305306

306307
(expect doc-dom :not :to-be nil)
307-
(expect (length (org-ol-tree-core--heading-subheadings doc-dom)) :to-equal 3)
308+
(expect (length (org-ol-tree-core--headline-children doc-dom)) :to-equal 3)
308309

309310
(kill-buffer (current-buffer))))
310311

tests/test-outline-ui.el

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;;; test-outline-ui.el --- Sections and Headings tests -*- lexical-binding: t; -*-
1+
;;; test-outline-ui.el --- Sections and Headlines tests -*- lexical-binding: t; -*-
22
;;
33
;; Copyright (C) 2021 Thiago Alves
44
;;
@@ -7,7 +7,7 @@
77
;;; Commentary:
88
;;
99
;; This file contains all tests related to the core objects (currently
10-
;; 'sections' and 'headings').
10+
;; 'sections' and 'headlines').
1111
;;
1212
;; Since reading the test might be tedious, I'm reproducing here the transcript
1313
;; of the behaviors being tested by this file:
@@ -106,7 +106,7 @@
106106
(expect 'org-ol-tree-system--all-the-icons-p :to-have-been-called-times 0))))
107107

108108
(describe "Given a document icon,"
109-
:var (org-ol-tree-ui-icon-set)
109+
:var (org-ol-tree-ui-icon-set)
110110

111111
(describe "when it is nil in the icon set,"
112112
(it "it should have a single white space representing the cursor column"
@@ -138,79 +138,79 @@
138138
icon)
139139

140140
(describe "when the section used to get the icon has subsections under it,"
141-
:var ((heading (org-ol-tree-core--heading-create-internal
142-
:name "Test Heading"
143-
:id "1.2.3"
144-
:marker (point-marker)
145-
:level 3
146-
:parent nil
147-
:subheadings '(sub-heading1 sub-heading2))))
141+
:var ((headline (org-ol-tree-core--headline-create-internal
142+
:name "Test Headline"
143+
:id "1.2.3"
144+
:marker (point-marker)
145+
:level 3
146+
:parent nil
147+
:children '(child1 child2))))
148148

149149
(before-each
150150
(setq org-ol-tree-ui-icon-set 'ascii)
151151
(org-ol-tree-ui--update-icon-set))
152152

153153
(describe "and the section state is 'expanded,"
154154
(before-each
155-
(setq icon (org-ol-tree-ui--section-icon heading 'expanded)))
155+
(setq icon (org-ol-tree-ui--section-icon headline 'expanded)))
156156

157157
(it "it should display the cursor column plus the expanded icon on its beginning"
158158
(expect icon :to-start-with " - ")))
159159

160160
(describe "and the section state is 'collapsed,"
161161
(before-each
162-
(setq icon (org-ol-tree-ui--section-icon heading 'collapsed)))
162+
(setq icon (org-ol-tree-ui--section-icon headline 'collapsed)))
163163

164164
(it "it should display the cursor column plus the collapsed icon on its beginning"
165165
(expect icon :to-start-with " + "))))
166166

167167
(describe "when the section used to get the icon does not have subsections under it,"
168-
:var ((heading (org-ol-tree-core--heading-create-internal
169-
:name "Test Heading"
170-
:id "1.2.3"
171-
:marker (point-marker)
172-
:level 3
173-
:parent nil
174-
:subheadings nil)))
168+
:var ((headline (org-ol-tree-core--headline-create-internal
169+
:name "Test Headline"
170+
:id "1.2.3"
171+
:marker (point-marker)
172+
:level 3
173+
:parent nil
174+
:children nil)))
175175

176176
(before-each
177177
(setq org-ol-tree-ui-icon-set 'ascii)
178178
(org-ol-tree-ui--update-icon-set)
179-
(setq icon (org-ol-tree-ui--section-icon heading nil)))
179+
(setq icon (org-ol-tree-ui--section-icon headline nil)))
180180

181181
(it "it should start with a cursor column space plus two spaces for alignment"
182182
(expect icon :to-start-with " ")))
183183

184184
(describe "when the section icon contains the %(section) tag"
185-
:var ((heading (org-ol-tree-core--heading-create-internal
186-
:name "Test Heading"
187-
:id "1.2.3"
188-
:marker (point-marker)
189-
:level 3
190-
:parent nil
191-
:subheadings nil)))
185+
:var ((headline (org-ol-tree-core--headline-create-internal
186+
:name "Test Headline"
187+
:id "1.2.3"
188+
:marker (point-marker)
189+
:level 3
190+
:parent nil
191+
:children nil)))
192192

193193
(before-each
194194
(setq org-ol-tree-ui-icon-set 'ascii
195-
icon (org-ol-tree-ui--section-icon heading nil))
195+
icon (org-ol-tree-ui--section-icon headline nil))
196196
(org-ol-tree-ui--update-icon-set))
197197

198198
(it "it should show the section id on the icon"
199199
(expect icon :to-match "1\\.2\\.3")))
200200

201201
(describe "when the section icon does not contain the %(section) tag"
202-
:var ((heading (org-ol-tree-core--heading-create-internal
203-
:name "Test Heading"
204-
:id "1.2.3"
205-
:marker (point-marker)
206-
:level 3
207-
:parent nil
208-
:subheadings nil)))
202+
:var ((headline (org-ol-tree-core--headline-create-internal
203+
:name "Test Headline"
204+
:id "1.2.3"
205+
:marker (point-marker)
206+
:level 3
207+
:parent nil
208+
:children nil)))
209209

210210
(before-each
211211
(setq org-ol-tree-ui-icon-set 'iconless-ascii)
212212
(org-ol-tree-ui--update-icon-set)
213-
(setq icon (org-ol-tree-ui--section-icon heading nil)))
213+
(setq icon (org-ol-tree-ui--section-icon headline nil)))
214214

215215
(it "it should show the section id on the icon"
216216
(expect icon :not :to-match "1\\.2\\.3")))))

0 commit comments

Comments
 (0)