pdf-sync-test.el (2034B)
1 ;; -*- lexical-binding: t; -*- 2 3 ;; * ================================================================== * 4 ;; * Tests for pdf-sync.el 5 ;; * ================================================================== * 6 7 (require 'ert) 8 (require 'pdf-sync) 9 10 (ert-deftest pdf-sync-backward--source-strip-comments () 11 (should-not (cl-remove-if 12 (lambda (ch) 13 (memq ch '(?\\ ?\s ?\n))) 14 (append (pdf-sync-backward--source-strip-comments 15 (concat "%comment\n" 16 " %comment\n" 17 "\\\\%comment\n" 18 "\\\\ %comment\n" 19 " \\\\ %comment\n" 20 " \\\\%comment\n")) 21 nil))) 22 (let ((source (concat "\\%comment\n" 23 " \\%comment\n" 24 "\\ %comment\n" 25 " \\ %comment\n" 26 " \\%comment\n"))) 27 (should (equal (pdf-sync-backward--source-strip-comments source) 28 source)))) 29 30 (ert-deftest pdf-sync-backward--get-text-context () 31 (pdf-test-with-test-pdf 32 (should (= 3 (length (pdf-sync-backward--get-text-context 1 0.5 0.25)))) 33 ;; Empty page 34 (should (equal '(-1 0 nil) 35 (pdf-sync-backward--get-text-context 6 0.5 0.5))))) 36 37 (ert-deftest pdf-sync-backward--get-source-context () 38 (with-temp-buffer 39 (should-not (pdf-sync-backward--get-source-context)) 40 (insert "\\begin{foo}\nsource\n\\end{foo}") 41 (should (cl-every 'stringp (pdf-sync-backward--get-source-context))))) 42 43 (ert-deftest pdf-sync-backward--find-position () 44 (let ((context '(3 2 ("000" "1111" "222222" "333333" "4444" "55555"))) 45 (prefix "000 XXXX 222222 YYYY 333") 46 (suffix "333 4444 XXXX")) 47 (with-temp-buffer 48 (insert prefix suffix) 49 (should (progn (pdf-sync-backward--find-position 1 -1 context) 50 (eq (length prefix) (point)))))))