forked from ahmed-shariff/org-noter
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathorg-noter-test-utils.el
158 lines (121 loc) · 5.08 KB
/
org-noter-test-utils.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
(require 'log4e)
;; org-noter-test logger = ont
(log4e:deflogger "ont" "ont %t [%l] %m" "%H:%M:%S")
(ont--log-enable-logging)
(ont--log-enable-debugging)
(ont--log-enable-messaging)
(ont--log-set-level 'info)
(ont--log-debug "ont")
(defvar mock-contents-simple-notes-file
"
:PROPERTIES:
:ID: FAKE_1
:END:
#+TITLE: Test book notes (simple)
* solove-nothing-to-hide
:PROPERTIES:
:NOTER_DOCUMENT: pubs/solove-nothing-to-hide.pdf
:END:
")
(defvar mock-contents-simple-notes-file-with-a-single-note
":PROPERTIES:
:ID: FAKE_90283
:END:
#+TITLE: Test book notes
* solove-nothing-to-hide
:PROPERTIES:
:NOTER_DOCUMENT: pubs/solove-nothing-to-hide.pdf
:END:
** Note from page 1
:PROPERTIES:
:NOTER_PAGE: 99
:END:
"
)
;;;;;;;;;;;
;; helpers
(defun org-noter-core-test-create-session ()
"Call this manually with an existing notes buffer to generate a new session"
(org-noter--create-session (org-noter--parse-root) "pubs/solove-nothing-to-hide.pdf" org-noter-test-file))
(defun with-mock-contents (contents lambda)
"Create a real buffer with CONTENTS and then execute the LAMBDA"
(ont--log-debug "\n--------------------------------------------")
;; TODO: when an assert fails in buttercup, an exception (??) is thrown,
;; so temp file isnt being cleaned up. This is the sledgehammer approach.
;; Needs to be fixed so that it's cleaned up properly.
(when (boundp 'org-noter-test-file)
(progn
(ont--log-debug (format "Removing org-noter-test-file: %s\n" org-noter-test-file))
(delete-file org-noter-test-file)))
(let* ((tempfile (make-temp-file "Notes" nil ".org" contents)))
(ont--log-debug (format "Creating a tempfile: %s\n" tempfile))
(setq org-noter-test-file tempfile)
(ont--log-debug "Opening the file..")
(org-mode)
(find-file tempfile)
(org-mode)
(ont--log-debug "Starting the test..")
(ont--log-debug "%s" (buffer-string))
(funcall lambda)
(ont--log-debug "About to kill buffer..")
(kill-current-buffer)
(ont--log-debug (format "Removing tempfile %s" tempfile))
(delete-file tempfile)
(ont--log-debug "+++++++++++++++++++++++++++++++++++++++++")
))
;;;;;;;;;;;;;;;;;;;;;;;;;;
;; hooks - org-noter calls these
(defun org-noter-test-get-selected-text (mode)
"⚠️org-noter-core-test-return-text
org-noter-core-test-return-text
org-noter-core-test-return-text
org-noter-core-test-return-text
org-noter-core-test-return-text
")
(defun org-noter-core-test-document-property (&optional param)
org-noter-test-file)
(defun org-noter-core-test-view-setup-handler (&optional param)
t)
(defun org-noter-core-test-open-document-functions (&optional doc)
(find-file (org-noter-core-test-document-property)))
(defun org-noter-core-test-approx-location (major-mode &optional precise-info _force-new-ref)
(cons 99 precise-info))
(defun org-noter-core-test-get-current-view (mode)
t)
;; TODO This doesn't look right
(defun org-noter-core-test-get-precise-info (mode window)
(list 1 2 3 4))
(defun org-noter-core-test-pretty-print-location (location)
(format "%s" location))
(defun org-noter-core-test-add-highlight (major-mode precise-info)
t)
(defun org-noter-core-test-get-current-view (mode)
'org-noter-core-test-view)
(defun org-noter-core-test-get-highlight-location ()
"HARDCODED_HIGHLIGHT_LOCATION")
(defun org-noter-core-test-pretty-print-location-for-title (location)
"TEST PRETTY PRINT LOCATION")
(defun create-org-noter-test-session ()
;; if this is not set; make-session fails and the test crashes with a stack overflow.
(setq org-noter-always-create-frame nil)
(setq org-noter-highlight-selected-text t)
;; setup spies so we can verify that things have been called
(spy-on 'org-noter-test-get-selected-text :and-call-through)
(spy-on 'org-noter-core-test-approx-location :and-call-through)
(spy-on 'org-noter-core-test-get-precise-info :and-call-through)
(spy-on 'org-noter-core-test-add-highlight :and-call-through)
(spy-on 'org-noter-core-test-get-current-view :and-call-through)
;; register all the hooks so we can fake a org-noter-test mode
(add-to-list 'org-noter-get-selected-text-hook #'org-noter-test-get-selected-text)
(add-to-list 'org-noter-parse-document-property-hook #'org-noter-core-test-document-property)
(add-to-list 'org-noter-set-up-document-hook #'org-noter-core-test-view-setup-handler)
(add-to-list 'org-noter-open-document-functions #'org-noter-core-test-open-document-functions)
(add-to-list 'org-noter--doc-approx-location-hook #'org-noter-core-test-approx-location)
(add-to-list 'org-noter--get-current-view-hook #'org-noter-core-test-get-current-view)
(add-to-list 'org-noter--get-precise-info-hook #'org-noter-core-test-get-precise-info)
(add-to-list 'org-noter--pretty-print-location-hook #'org-noter-core-test-pretty-print-location)
(add-to-list 'org-noter--pretty-print-location-for-title-hook #'org-noter-core-test-pretty-print-location-for-title)
(add-to-list 'org-noter--add-highlight-hook #'org-noter-core-test-add-highlight)
(add-to-list 'org-noter--get-highlight-location-hook #'org-noter-core-test-get-highlight-location)
)
(provide 'org-noter-test-utils)