summaryrefslogtreecommitdiff
path: root/test/pdf-sync-test.el
blob: 544f99b64b1fc22cbbb3f46d45838a8a9e2dbae9 (plain)
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


;; * ================================================================== *
;; * Tests for pdf-sync.el
;; * ================================================================== *

(require 'ert)
(require 'pdf-sync)

(ert-deftest pdf-sync-backward--source-strip-comments ()
  (should-not (cl-remove-if
               (lambda (ch)
                 (memq ch '(?\\ ?\s ?\n)))
               (append (pdf-sync-backward--source-strip-comments
                        (concat "%comment\n"
                                "     %comment\n"
                                "\\\\%comment\n"
                                "\\\\   %comment\n"
                                "      \\\\   %comment\n"
                                "      \\\\%comment\n"))
                       nil)))
  (let ((source (concat "\\%comment\n"
                        "     \\%comment\n"
                        "\\   %comment\n"
                        "      \\   %comment\n"
                        "      \\%comment\n")))
    (should (equal (pdf-sync-backward--source-strip-comments source)
                   source))))

(ert-deftest pdf-sync-backward--get-text-context ()
  (pdf-test-with-test-pdf
    (should (= 3 (length (pdf-sync-backward--get-text-context 1 0.5 0.25))))
    ;; Empty page
    (should (equal '(-1 0 nil)
                   (pdf-sync-backward--get-text-context 6 0.5 0.5)))))

(ert-deftest pdf-sync-backward--get-source-context ()
  (with-temp-buffer
    (should-not (pdf-sync-backward--get-source-context))
    (insert "\\begin{foo}\nsource\n\\end{foo}")
    (should (cl-every 'stringp (pdf-sync-backward--get-source-context)))))

(ert-deftest pdf-sync-backward--find-position ()
  (let ((context '(3 2 ("000" "1111" "222222" "333333" "4444" "55555")))
        (prefix "000 XXXX 222222 YYYY 333")
        (suffix "333 4444 XXXX"))
    (with-temp-buffer
      (insert prefix suffix)
      (should (progn (pdf-sync-backward--find-position 1 -1 context)
                     (eq (length prefix) (point)))))))