|
68 | 68 | ;; Javadoc: (javadoc java-object-or-class)
|
69 | 69 | ;; Exit: <C-c C-q>
|
70 | 70 | ;; Results: Stored in vars *1, *2, *3, an exception in *e;"))))
|
| 71 | + |
| 72 | +(defvar cider-testing-ansi-colors-vector |
| 73 | + ["black" "red3" "green3" "yellow3" "blue2" |
| 74 | + "magenta3" "cyan3" "gray90"] |
| 75 | + "Vector of translations for ansi color codes") |
| 76 | + |
| 77 | +(defmacro with-testing-ansi-table (colors &rest body) |
| 78 | + `(let* ((ansi-color-names-vector ,colors) |
| 79 | + (ansi-color-map (ansi-color-make-color-map))) |
| 80 | + ,@body)) |
| 81 | + |
| 82 | +(describe "multiple calls to cider-repl--emit-output-at-pos" |
| 83 | + (it "Multiple emit output calls set properties and emit text" |
| 84 | + (with-temp-buffer |
| 85 | + (with-testing-ansi-table cider-testing-ansi-colors-vector |
| 86 | + (cider-repl-reset-markers) |
| 87 | + |
| 88 | + (cider-repl--emit-output-at-pos (current-buffer) "[30ma[0m" 'cider-repl-stdout-face (point)) |
| 89 | + (cider-repl--emit-output-at-pos (current-buffer) "b" 'cider-repl-stdout-face (point)) |
| 90 | + (cider-repl--emit-output-at-pos (current-buffer) "[31mc" 'cider-repl-stdout-face (point)) |
| 91 | + (cider-repl--emit-output-at-pos (current-buffer) "d[0m" 'cider-repl-stdout-face (point)) |
| 92 | + |
| 93 | + (expect (buffer-string) :to-equal "a\nb\nc\nd\n") |
| 94 | + (expect (get-text-property 1 'font-lock-face) |
| 95 | + :to-equal '(foreground-color . "black")) |
| 96 | + (expect (get-text-property 3 'font-lock-face) |
| 97 | + :to-equal 'cider-repl-stdout-face) |
| 98 | + (expect (get-text-property 5 'font-lock-face) |
| 99 | + :to-equal '(foreground-color . "red3")) |
| 100 | + (expect (get-text-property 7 'font-lock-face) |
| 101 | + :to-equal '(foreground-color . "red3")))))) |
| 102 | + |
| 103 | +(defun simulate-cider-output (s property) |
| 104 | + "Return properties from cider-repl--emit-output-at-pos. |
| 105 | +PROPERTY shoudl be a symbol of either 'text, 'ansi-context or |
| 106 | +'properties." |
| 107 | + (with-temp-buffer |
| 108 | + (with-testing-ansi-table cider-testing-ansi-colors-vector |
| 109 | + (cider-repl-reset-markers) |
| 110 | + (cider-repl--emit-output-at-pos (current-buffer) s nil (point-min) nil)) |
| 111 | + (case property |
| 112 | + ('text (substring-no-properties (buffer-string))) |
| 113 | + ('ansi-context ansi-color-context) |
| 114 | + ('properties (substring (buffer-string)))))) |
| 115 | + |
| 116 | +(describe "cider-repl--emit-output-at-pos" |
| 117 | + (it "prints simple strings" |
| 118 | + (expect (simulate-cider-output "hi" 'text) |
| 119 | + :to-equal "hi\n")) |
| 120 | + |
| 121 | + (it "when invlaid escape code, doesn't hold string looking for close tag" |
| 122 | + (expect (simulate-cider-output "\033hi" 'text) |
| 123 | + :to-equal "\033hi\n") |
| 124 | + (expect (simulate-cider-output "\033hi" 'ansi-context) |
| 125 | + :to-equal nil)) |
| 126 | + |
| 127 | + (it "preserves context when valid" |
| 128 | + (let ((context (simulate-cider-output "[30ma[0mb[31mcd" 'ansi-context))) |
| 129 | + (expect context :to-equal '((31) nil))))) |
0 commit comments