diff --git a/README.md b/README.md index 1a09cf6..201cd6a 100644 --- a/README.md +++ b/README.md @@ -156,21 +156,17 @@ A little diagram because [uniline](https://github.com/tbanel/uniline) is fun: │ ▽ │ ▽ resume │ ▽ ╭─────╮ ╭─────╮ ╭┴──┴─────┴───┴────╮ ╭─┴─────────┴─╮ ╭────╮ │start├──▷┤setup├──────▷┤speed-type session├───▷┤complete/menu├────▷┤quit│ - ╰─────╯ ╰─┬───╯ ╰─┬──────────────┬─╯ │╰──────┬──────╯ ╰────╯ - △ │ △ save │ - │ ▽ │ │ - │ ╭─┴──────────────┴─╮ │ - │ │add words on error│ │ - │ ╰──────────────────╯ │ - │ ▽ - │ ╭─────────────┴──────╮ - ╰────────────────────────────┤replay/next/continue│ - ╰────────────────────╯ - - + ╰─────╯ ╰─┬───╯ ╰─┬──────────────┬─╯ │╰───┬───┬───┬─╯ ╰────╯ + △ │ △ save │ │ △ + │ ▽ │ │ ▽ │ + │ ╭─┴──────────────┴─╮ │ ├───┴──────────╮ + │ │add words on error│ │ │toggle preview│ + │ ╰──────────────────╯ │ ╰──────────────╯ + │ │ + │ ╭────────────────────╮ │ + ╰──────────┤replay/next/continue├─-◁────╯ + ╰────────────────────╯ ``` - - ### Start The flow is started by calling one of the autoloaded commands: - `speed-type-text` @@ -229,8 +225,8 @@ To color the characters a overlay is used: #### Text Properties: - speed-type-orig-pos: Used for "continue" and add new words - - car: start - - cdr: end + - car: start of word + - cdr: end of word - speed-type-char-status: Used to ignore characters and determine complete - ignore - correct @@ -288,6 +284,14 @@ After setup is complete it kills the completed `speed-type-buffer` and `speed-type-preview-buffer`. It may reuse the existing content-buffer for the new speed-type session. +### Toggle Preview +Toggles the display of the preview buffer. It opens a little window +below the speed-type buffer. + +If the preview buffer is already displayed, will delete the window. +The buffer stays open in the background until the speed-type buffer is +quit. + ### Median Stats Calculates and displays the median stats of various buffer-local vars from current and previous speed-type sessions. diff --git a/speed-type.el b/speed-type.el index 42ec062..16d821b 100644 --- a/speed-type.el +++ b/speed-type.el @@ -207,7 +207,7 @@ beginning." :type 'boolean) (defcustom speed-type-downcase nil - "Toggle downcasing of mistyped words." + "If t will downcase content." :type 'boolean) (defcustom speed-type-point-motion-on-error 'point-move @@ -363,7 +363,8 @@ Median Non-consecutive errors: %d") "d" #'speed-type--display-statistic "r" #'speed-type-replay "n" #'speed-type-play-next - "c" #'speed-type-play-continue) + "c" #'speed-type-play-continue + "t" #'speed-type-toggle-preview) (defvar-keymap speed-type-mode-map :doc "Keymap for `speed-type-mode'." @@ -790,6 +791,9 @@ leave buffer in read-only mode." (when (not (eq 'never speed-type-save-statistic-option)) (insert (format " [%s]isplay statistic\n" (propertize "d" 'face 'highlight)))) + (when (not (null speed-type-provide-preview-option)) + (insert (format " [%s]oggle preview\n" + (propertize "t" 'face 'highlight)))) (when speed-type--go-next-fn (insert (format " [%s]ext random sample\n" (propertize "n" 'face 'highlight)))) @@ -1058,6 +1062,20 @@ If the length is uneven will return symbol `uneven'." 0) 'uneven)) +(defun speed-type--check-same-str (a b) + "Return non-nil if A and B are identical or both whitespace. + +Whitespace is determined using `char-syntax'." + (when (not (= (length a) (length b))) (user-error "A(%d) and B(%d) must be the same" a b)) + (let ((still-correct t) + (i 0) + (length-a (length a))) + (while (and (< i length-a) still-correct) + (setq still-correct (speed-type--check-same i a b)) + (setq i (1+ i))) + still-correct)) + + (defun speed-type--check-same (pos a b) "Return non-nil if A[POS] and B[POS] are identical or both whitespace. @@ -1081,6 +1099,24 @@ Whitespace is determined using `char-syntax'." (eq q 'error)) (cl-decf speed-type--entries)))))) +(defun speed-type-toggle-preview () + "Toggle preview of speed-type session in `current-buffer'. + +If preview is currently display in some window will delete that window. +Else if there is no such window, `split-window' and display the preview +in new window." + (interactive) + (unless (derived-mode-p 'speed-type-mode) (user-error "Not in a speed-type buffer: cannot open preview")) + (unless (and (boundp 'speed-type--preview-buffer) speed-type--preview-buffer) (user-error "Preview buffer not defined please configure `speed-type-provide-preview-option'")) + (let ((bw (get-buffer-window speed-type--preview-buffer))) + (if bw (delete-window bw) + (let ((sw (selected-window)) + (pw (split-window nil 5 'above)) + (buf (current-buffer))) + (set-window-buffer sw speed-type--preview-buffer) + (set-window-buffer pw buf) + (select-window pw))))) + (defun speed-type--display-statistic () "Display median values from current and past entries." (interactive) @@ -1180,6 +1216,52 @@ ENTRIES ERRORS NON-CONSECUTIVE-ERRORS CORRECTIONS SECONDS." (speed-type--elapsed-time speed-type--time-register))) (speed-type-display-menu)))) +(defun speed-type-preview-buffer-insert (orig new new-last-pos face) + "Insert NEW at the end of preview-buffer and set given FACE as overlay. + +ORIG is inserted below, when it doesn't match NEW. + +POS is used to access the focused char. + +NEW-LAST-POS is `point' in `current-buffer', it's used to determine if +movement-commands were used since last insert. + +When `current-buffer' has no variable `speed-type--preview-buffer' with non-nil +value return nil." + (when (and (boundp 'speed-type--preview-buffer) speed-type--preview-buffer) + (with-current-buffer speed-type--preview-buffer + (unwind-protect + (save-excursion + (goto-char (point-min)) + (end-of-line) + (when-let* ((win (get-buffer-window (current-buffer)))) + (set-window-point win (point))) + (read-only-mode -1) + (when (and (not (= speed-type--last-position 0)) + (> (abs (- new-last-pos speed-type--last-position)) 2)) + (let ((point-movement-str (concat "[ " (symbol-name last-command) "(" (number-to-string speed-type--last-position) ") → (" (number-to-string (1- new-last-pos)) ") ]"))) + (insert point-movement-str) + (let ((overlay (make-overlay (- (point) (length point-movement-str)) (point)))) + (overlay-put overlay 'priority 1) + (overlay-put overlay 'face 'speed-type-info-face)))) + (insert (string-replace "\t" "⇥" (string-replace " " "·" (string-replace "\n" "⏎" new)))) + (let ((overlay (make-overlay (- (point) (length new)) (point)))) + (overlay-put overlay 'priority 1) + (overlay-put overlay 'face face)) + (setq-local speed-type--insert-position (point)) + (when (not (speed-type--check-same-str orig new)) + (let ((inhibit-message t)) + (end-of-line) + (let ((cc (1- (current-column)))) + (or (search-forward "\n" nil t 1) (insert "\n")) + (move-to-column cc t)) + (insert (string-replace "\t" "⇥" (string-replace " " "·" (string-replace "\n" "⏎" orig)))) + (let ((overlay (make-overlay (- (point) (length orig)) (point)))) + (overlay-put overlay 'priority 1) + (overlay-put overlay 'face 'speed-type-correct-face)))) + (setq-local speed-type--last-position new-last-pos)) + (read-only-mode))))) + (defun speed-type--diff (orig new start end) "Synchronise local buffer state with buffer-content by comparing ORIG and NEW. ORIG is the original text. NEW is the new text. @@ -1211,9 +1293,11 @@ END is a point where the check stops to scan for diff." (speed-type-add-extra-words (+ (or speed-type-add-extra-words-on-error 0) (or (and non-consecutive-error-p speed-type-add-extra-words-on-non-consecutive-errors) 0))))) (cl-incf speed-type--entries) - (let ((overlay (make-overlay pos (1+ pos)))) - (overlay-put overlay 'priority 1) - (overlay-put overlay 'face (if is-same 'speed-type-correct-face (if non-consecutive-error-p 'speed-type-error-face 'speed-type-consecutive-error-face)))))) + (let ((f (if is-same 'speed-type-correct-face (if non-consecutive-error-p 'speed-type-error-face 'speed-type-consecutive-error-face)))) + (let ((overlay (make-overlay pos (1+ pos)))) + (overlay-put overlay 'priority 1) + (overlay-put overlay 'face f)) + (speed-type-preview-buffer-insert (char-to-string (aref orig i)) (char-to-string (aref new i)) pos f)))) (if (or (eq speed-type-point-motion-on-error 'point-move) (string= new "") (not any-error)) @@ -1237,27 +1321,10 @@ are color coded and stats are gathered about the typing performance." (if (< start (point-max)) (let* ((end (if (> end (point-max)) (point-max) end)) (orig (buffer-substring start end))) - (when speed-type--preview-buffer - (let ((new-last-pos start)) - (with-current-buffer speed-type--preview-buffer - (unwind-protect - (save-excursion - (goto-char (point-max)) - (when-let* ((win (get-buffer-window (current-buffer)))) - (set-window-point win (point))) - (read-only-mode -1) - (when (and (not (= speed-type--last-position 0)) - (> (abs (- new-last-pos speed-type--last-position)) 2)) - (let ((point-movement-str (concat "[ " (symbol-name last-command) "(" (number-to-string speed-type--last-position) ") → (" (number-to-string (1- new-last-pos)) ") ]"))) - (insert point-movement-str) - (let ((overlay (make-overlay (- (point) (length point-movement-str)) (point)))) - (overlay-put overlay 'priority 1) - (overlay-put overlay 'face 'speed-type-info-face)))) - (insert (cond ((eq this-command (key-binding (kbd ""))) "⌦") - ((eq this-command (key-binding (kbd "DEL"))) "⌫") - (t (string-replace "\t" "⇥" (string-replace " " "·" (string-replace "\n" "⏎" new-text)))))) - (setq-local speed-type--last-position new-last-pos)) - (read-only-mode))))) + (when-let ((special-char (cond ((eq this-command (key-binding (kbd ""))) "->") + ((eq this-command (key-binding (kbd "DEL"))) "<-") + (t nil)))) + (speed-type-preview-buffer-insert special-char special-char start 'speed-type-info-face)) (when-let* ((overlay (and (equal new-text "") (car (overlays-at end))))) (move-overlay overlay (1- (overlay-end overlay)) (overlay-end overlay)) (current-buffer)) @@ -1380,7 +1447,7 @@ CALLBACK is called when the setup process has been completed." (with-current-buffer speed-type--preview-buffer (setq-local speed-type--buffer buf speed-type--last-position 0 - truncate-lines nil) + truncate-lines t) (speed-type-mode) (add-hook 'kill-buffer-hook #'speed-type--kill-preview-buffer-hook nil t) (read-only-mode)) diff --git a/test/speed-type-test.el b/test/speed-type-test.el index 7924a7b..91efc39 100644 --- a/test/speed-type-test.el +++ b/test/speed-type-test.el @@ -45,10 +45,10 @@ ;; :add-extra-word-content-fn ;; :replay-fn ;; (speed-type--setup buf -;; (buffer-substring-no-properties start end) -;; :author (user-full-name) -;; :title title -;; :replay-fn #'speed-type--get-replay-fn)))) +;; (buffer-substring-no-properties start end) +;; :author (user-full-name) +;; :title title +;; :replay-fn #'speed-type--get-replay-fn)))) (ert-deftest speed-type-test/stop-words-p-supply-garbage () (should-error (speed-type--stop-word-p nil)) @@ -68,11 +68,11 @@ (setq speed-type-stop-words (concat (temporary-file-directory) "/stop-words.txt")) (let ((buffer (find-file-noselect speed-type-stop-words))) (unwind-protect - (progn (with-current-buffer buffer - (insert "word\n") - (insert "otherWord\n") - (save-buffer)) - (should (string= (speed-type--stop-word-p "word") "word"))) + (progn (with-current-buffer buffer + (insert "word\n") + (insert "otherWord\n") + (save-buffer)) + (should (string= (speed-type--stop-word-p "word") "word"))) (delete-file (buffer-file-name buffer)) (kill-buffer buffer)))) @@ -125,8 +125,8 @@ TEST-IN-BUF is a lambda which is executed within the speed-type-buffer." (let ((content text) - (speed-type-save-statistic-option-b speed-type-save-statistic-option) - (speed-type-statistic-filename (concat (temporary-file-directory) "speed-type-statistic.el")) + (speed-type-save-statistic-option-b speed-type-save-statistic-option) + (speed-type-statistic-filename (concat (temporary-file-directory) "speed-type-statistic.el")) (speed-type-randomize-b speed-type-randomize)) (with-temp-buffer (insert content) @@ -134,28 +134,29 @@ TEST-IN-BUF is a lambda which is executed within the speed-type-buffer." (setq speed-type-save-statistic-option 'never speed-type-randomize t) (let ((buf (speed-type-buffer nil))) - (unwind-protect - (with-current-buffer buf - (funcall test-in-buf)) - (setq speed-type-save-statistic-option speed-type-save-statistic-option-b + (unwind-protect + (with-current-buffer buf + (funcall test-in-buf)) + (setq speed-type-save-statistic-option speed-type-save-statistic-option-b speed-type-randomize speed-type-randomize-b) - (kill-buffer buf)))))) + (kill-buffer buf)))))) (defun speed-type-test-region (test-in-buf) "Setup a speed-type-region for testing. TEST-IN-BUF is a lambda which is executed within the speed-type-buffer." (let ((content "abcde") - (mode (nth (random 2) '(fundamental-mode emacs-lisp-mode))) - (speed-type-statistic-filename (concat (temporary-file-directory) "speed-type-statistic.el"))) + (mode (nth (random 2) '(fundamental-mode emacs-lisp-mode))) + (speed-type-provide-preview-option t) + (speed-type-statistic-filename (concat (temporary-file-directory) "speed-type-statistic.el"))) (with-temp-buffer (insert content) (funcall mode) (let ((buf (speed-type-region (point-min) (point-max)))) - (unwind-protect - (with-current-buffer buf - (funcall test-in-buf)) - (kill-buffer buf)))))) + (unwind-protect + (with-current-buffer buf + (funcall test-in-buf)) + (kill-buffer buf)))))) (ert-deftest speed-type-test/times-is-empty-when-no-input () "Test the time-register-variable is empty for flow: session-start -> complete." @@ -210,60 +211,60 @@ TEST-IN-BUF is a lambda which is executed within the speed-type-buffer." "Test if points stays and error are counted correctly." (let ((b-speed-type-point-motion-on-error speed-type-point-motion-on-error)) (unwind-protect - (progn - (setq speed-type-point-motion-on-error 'point-stay) - (speed-type-test-region - (lambda () - (should (= (point) 1)) - (should (= speed-type--errors 0)) - (should (= speed-type--non-consecutive-errors 0)) - (insert "b") - (should (= speed-type--errors 1)) - (should (= speed-type--non-consecutive-errors 1)) - (should (= (point) 1)) - (insert "c") - (should (= speed-type--errors 2)) - (should (= speed-type--non-consecutive-errors 1)) - (should (= (point) 1)) - (insert "a") - (should (= speed-type--errors 2)) - (should (= speed-type--non-consecutive-errors 1)) - (should (= (point) 2)) - (funcall (keymap-lookup nil "DEL") 1) - (should (= (point) 1)) - (insert "a") - (should (= speed-type--errors 2)) - (should (= speed-type--corrections 1)) - (should (= speed-type--non-consecutive-errors 1)) - (should (= (point) 2))))) + (progn + (setq speed-type-point-motion-on-error 'point-stay) + (speed-type-test-region + (lambda () + (should (= (point) 1)) + (should (= speed-type--errors 0)) + (should (= speed-type--non-consecutive-errors 0)) + (insert "b") + (should (= speed-type--errors 1)) + (should (= speed-type--non-consecutive-errors 1)) + (should (= (point) 1)) + (insert "c") + (should (= speed-type--errors 2)) + (should (= speed-type--non-consecutive-errors 1)) + (should (= (point) 1)) + (insert "a") + (should (= speed-type--errors 2)) + (should (= speed-type--non-consecutive-errors 1)) + (should (= (point) 2)) + (funcall (keymap-lookup nil "DEL") 1) + (should (= (point) 1)) + (insert "a") + (should (= speed-type--errors 2)) + (should (= speed-type--corrections 1)) + (should (= speed-type--non-consecutive-errors 1)) + (should (= (point) 2))))) (setq speed-type-point-motion-on-error b-speed-type-point-motion-on-error)))) (ert-deftest speed-type-test/point-motion-move () "Test if points move and error are counted correctly." (let ((b-speed-type-point-motion-on-error speed-type-point-motion-on-error)) (unwind-protect - (progn - (setq speed-type-point-motion-on-error 'point-move) - (speed-type-test-region - (lambda () - (should (= (point) 1)) - (should (= speed-type--errors 0)) - (should (= speed-type--non-consecutive-errors 0)) - (insert "b") - (should (= speed-type--errors 1)) - (should (= speed-type--non-consecutive-errors 1)) - (should (= (point) 2)) - (insert "c") - (should (= speed-type--errors 2)) - (should (= speed-type--non-consecutive-errors 1)) - (should (= (point) 3)) - (funcall (keymap-lookup nil "DEL") 1) - (should (= (point) 2)) - (insert "b") - (should (= speed-type--errors 2)) - (should (= speed-type--corrections 1)) - (should (= speed-type--non-consecutive-errors 1)) - (should (= (point) 3))))) + (progn + (setq speed-type-point-motion-on-error 'point-move) + (speed-type-test-region + (lambda () + (should (= (point) 1)) + (should (= speed-type--errors 0)) + (should (= speed-type--non-consecutive-errors 0)) + (insert "b") + (should (= speed-type--errors 1)) + (should (= speed-type--non-consecutive-errors 1)) + (should (= (point) 2)) + (insert "c") + (should (= speed-type--errors 2)) + (should (= speed-type--non-consecutive-errors 1)) + (should (= (point) 3)) + (funcall (keymap-lookup nil "DEL") 1) + (should (= (point) 2)) + (insert "b") + (should (= speed-type--errors 2)) + (should (= speed-type--corrections 1)) + (should (= speed-type--non-consecutive-errors 1)) + (should (= (point) 3))))) (setq speed-type-point-motion-on-error b-speed-type-point-motion-on-error)))) (ert-deftest speed-type-test/test-chars-downcased () @@ -271,121 +272,121 @@ TEST-IN-BUF is a lambda which is executed within the speed-type-buffer." Also assure when that added words are downcased too." (let ((b-speed-type-downcase speed-type-downcase) - (b-speed-type-add-extra-words-on-error speed-type-add-extra-words-on-error) - (b-speed-type-add-extra-words-on-non-consecutive-errors speed-type-add-extra-words-on-non-consecutive-errors)) + (b-speed-type-add-extra-words-on-error speed-type-add-extra-words-on-error) + (b-speed-type-add-extra-words-on-non-consecutive-errors speed-type-add-extra-words-on-non-consecutive-errors)) (setq speed-type-downcase t - speed-type-add-extra-words-on-error 1 - speed-type-add-extra-words-on-non-consecutive-errors 0) + speed-type-add-extra-words-on-error 1 + speed-type-add-extra-words-on-non-consecutive-errors 0) (unwind-protect - (speed-type-test-buffer - "ASDF" - (lambda () - (should (string= "asdf" (buffer-string))) - (insert "b") - (sleep-for 0.1) - (should (string= "asdf asdf" (buffer-string))) - (with-current-buffer speed-type--content-buffer - (should (string= "ASDF" (buffer-string)))))) + (speed-type-test-buffer + "ASDF" + (lambda () + (should (string= "asdf" (buffer-string))) + (insert "b") + (sleep-for 0.1) + (should (string= "asdf asdf" (buffer-string))) + (with-current-buffer speed-type--content-buffer + (should (string= "ASDF" (buffer-string)))))) (setq speed-type-downcase b-speed-type-downcase - speed-type-add-extra-words-on-error b-speed-type-add-extra-words-on-error - speed-type-add-extra-words-on-non-consecutive-errors b-speed-type-add-extra-words-on-non-consecutive-errors)))) + speed-type-add-extra-words-on-error b-speed-type-add-extra-words-on-error + speed-type-add-extra-words-on-non-consecutive-errors b-speed-type-add-extra-words-on-non-consecutive-errors)))) - ; assure preview buffer in general region - ; test continue feature + ; assure preview buffer in general region + ; test continue feature ;; complete a typing session and restart the same example ;; test variation with random - ; test top word iterator/calculation - ; test top word file and source file is written + ; test top word iterator/calculation + ; test top word file and source file is written (ert-deftest speed-type-test/general-region () "Do a general test with `speed-type-region' with fundamental mode and a prog-mode, checking content, overlays, point and point-motion, buffer-variables and statistic file." (let ((content "abcde") - (mode (nth (random 2) '(fundamental-mode emacs-lisp-mode))) - (speed-type-statistic-filename (concat (temporary-file-directory) "speed-type-statistic.el"))) + (mode (nth (random 2) '(fundamental-mode emacs-lisp-mode))) + (speed-type-statistic-filename (concat (temporary-file-directory) "speed-type-statistic.el"))) (with-temp-buffer (insert content) (funcall mode) (let ((buf (speed-type-region (point-min) (point-max))) - (content-buf speed-type--content-buffer)) - (unwind-protect - (with-current-buffer buf - (insert "a") - (insert "b") - (insert "a") - (insert "a") - (funcall (keymap-lookup nil "DEL") 1) - (funcall (keymap-lookup nil "DEL") 1) - (insert "c") - (insert "!") - (insert "!") - ; (should (= speed-type--start-time 1753299414.2124302)) - (should (eq speed-type--buffer (current-buffer))) - ; (should (eq speed-type--content-buffer (get-buffer "*speed-type-content-buffer*"))) - (should (= speed-type--entries 5)) - (should (= speed-type--errors 4)) - (should (= speed-type--non-consecutive-errors 2)) - (should (= speed-type--corrections 1)) - ; (should (string= speed-type--title (buffer-name))) - (should (string= speed-type--author (user-full-name))) - (should (eq speed-type--lang nil)) - (should (eq speed-type--n-words nil)) - (should (eq speed-type--add-extra-word-content-fn nil)) - (should (eq speed-type--extra-words-animation-timer nil)) - (should (eq speed-type--extra-word-quote nil)) - (should (eq speed-type--go-next-fn nil)) - (should (eq speed-type--replay-fn 'speed-type--get-replay-fn)) - (should (eq speed-type--extra-word-quote nil)) - (dotimes (i 3) - (should (eq (overlay-get (car (overlays-at (1+ i))) 'face) 'speed-type-correct-face))) - (should (eq (overlay-get (car (overlays-at 4)) 'face) 'speed-type-error-face)) - (should (eq (overlay-get (car (overlays-at 5)) 'face) 'speed-type-consecutive-error-face)) - ) - (kill-buffer buf) - (should (eq (buffer-live-p content-buf) nil))))))) + (content-buf speed-type--content-buffer)) + (unwind-protect + (with-current-buffer buf + (insert "a") + (insert "b") + (insert "a") + (insert "a") + (funcall (keymap-lookup nil "DEL") 1) + (funcall (keymap-lookup nil "DEL") 1) + (insert "c") + (insert "!") + (insert "!") + ; (should (= speed-type--start-time 1753299414.2124302)) + (should (eq speed-type--buffer (current-buffer))) + ; (should (eq speed-type--content-buffer (get-buffer "*speed-type-content-buffer*"))) + (should (= speed-type--entries 5)) + (should (= speed-type--errors 4)) + (should (= speed-type--non-consecutive-errors 2)) + (should (= speed-type--corrections 1)) + ; (should (string= speed-type--title (buffer-name))) + (should (string= speed-type--author (user-full-name))) + (should (eq speed-type--lang nil)) + (should (eq speed-type--n-words nil)) + (should (eq speed-type--add-extra-word-content-fn nil)) + (should (eq speed-type--extra-words-animation-timer nil)) + (should (eq speed-type--extra-word-quote nil)) + (should (eq speed-type--go-next-fn nil)) + (should (eq speed-type--replay-fn 'speed-type--get-replay-fn)) + (should (eq speed-type--extra-word-quote nil)) + (dotimes (i 3) + (should (eq (overlay-get (car (overlays-at (1+ i))) 'face) 'speed-type-correct-face))) + (should (eq (overlay-get (car (overlays-at 4)) 'face) 'speed-type-error-face)) + (should (eq (overlay-get (car (overlays-at 5)) 'face) 'speed-type-consecutive-error-face)) + ) + (kill-buffer buf) + (should (eq (buffer-live-p content-buf) nil))))))) (ert-deftest speed-type-test/general-file-ref () "Do a general test with `speed-type-region' and different modes, checking content, overlays, point and point-motion, buffer-variables and statistic file." (let ((content "abcde") - (mode (nth 0 '(hexl-mode))) - (speed-type-statistic-filename (concat (temporary-file-directory) "speed-type-statistic.el"))) + (mode (nth 0 '(hexl-mode))) + (speed-type-statistic-filename (concat (temporary-file-directory) "speed-type-statistic.el"))) (with-temp-buffer (insert content) (write-file "test.bin") (funcall mode) (let ((buf (speed-type-region (point-min) (point-max)))) - (unwind-protect - (with-current-buffer buf - (insert "0") - (insert "0") - (insert "a") - (insert "b") - (funcall (keymap-lookup nil "DEL") 1) - (funcall (keymap-lookup nil "DEL") 1) - (insert "0") - (insert "!") - (insert "!") - (should (eq speed-type--buffer (current-buffer))) - (should (= speed-type--entries 5)) - (should (= speed-type--errors 4)) - (should (= speed-type--non-consecutive-errors 2)) - (should (= speed-type--corrections 1)) - (should (string= speed-type--author (user-full-name))) - (should (eq speed-type--lang nil)) - (should (eq speed-type--n-words nil)) - (should (eq speed-type--add-extra-word-content-fn nil)) - (should (eq speed-type--extra-words-animation-timer nil)) - (should (eq speed-type--extra-word-quote nil)) - (should (eq speed-type--go-next-fn nil)) - (should (eq speed-type--replay-fn 'speed-type--get-replay-fn)) - (should (eq speed-type--extra-word-quote nil)) - (dotimes (i 3) - (should (eq (overlay-get (car (overlays-at (1+ i))) 'face) 'speed-type-correct-face))) - (should (eq (overlay-get (car (overlays-at 4)) 'face) 'speed-type-error-face)) - (should (eq (overlay-get (car (overlays-at 5)) 'face) 'speed-type-consecutive-error-face)) - (let ((offset 5)) - (dotimes (i (- 51 offset)) - (should (eq (car (overlays-at (+ (1+ offset) i))) nil)))) - (speed-type-complete)) - (kill-buffer buf)))))) + (unwind-protect + (with-current-buffer buf + (insert "0") + (insert "0") + (insert "a") + (insert "b") + (funcall (keymap-lookup nil "DEL") 1) + (funcall (keymap-lookup nil "DEL") 1) + (insert "0") + (insert "!") + (insert "!") + (should (eq speed-type--buffer (current-buffer))) + (should (= speed-type--entries 5)) + (should (= speed-type--errors 4)) + (should (= speed-type--non-consecutive-errors 2)) + (should (= speed-type--corrections 1)) + (should (string= speed-type--author (user-full-name))) + (should (eq speed-type--lang nil)) + (should (eq speed-type--n-words nil)) + (should (eq speed-type--add-extra-word-content-fn nil)) + (should (eq speed-type--extra-words-animation-timer nil)) + (should (eq speed-type--extra-word-quote nil)) + (should (eq speed-type--go-next-fn nil)) + (should (eq speed-type--replay-fn 'speed-type--get-replay-fn)) + (should (eq speed-type--extra-word-quote nil)) + (dotimes (i 3) + (should (eq (overlay-get (car (overlays-at (1+ i))) 'face) 'speed-type-correct-face))) + (should (eq (overlay-get (car (overlays-at 4)) 'face) 'speed-type-error-face)) + (should (eq (overlay-get (car (overlays-at 5)) 'face) 'speed-type-consecutive-error-face)) + (let ((offset 5)) + (dotimes (i (- 51 offset)) + (should (eq (car (overlays-at (+ (1+ offset) i))) nil)))) + (speed-type-complete)) + (kill-buffer buf)))))) (ert-deftest speed-type--stats-test () (should (= 3 (speed-type--seconds-to-minutes 180))) @@ -430,7 +431,7 @@ Also assure when that added words are downcased too." (let ((speed-type-directory (temporary-file-directory))) (unwind-protect (progn - (kill-buffer (get-file-buffer filename-expected)) + (kill-buffer (get-file-buffer filename-expected)) (delete-file filename-expected) (funcall test)) (kill-buffer (get-file-buffer filename-expected)) @@ -440,7 +441,7 @@ Also assure when that added words are downcased too." (let ((speed-type-directory (temporary-file-directory))) (unwind-protect (progn - (kill-buffer (get-file-buffer filename-expected)) + (kill-buffer (get-file-buffer filename-expected)) (delete-file filename-expected) (with-temp-buffer (write-file filename-expected))