-
-
Notifications
You must be signed in to change notification settings - Fork 189
/
utilities.lisp
26 lines (24 loc) · 1.02 KB
/
utilities.lisp
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
(defpackage :lem-tests/utilities
(:use :cl)
(:import-from :cl-ansi-text)
(:export :sample-file
:with-global-variable-value
:diff-text))
(in-package :lem-tests/utilities)
(defun sample-file (filename)
(asdf:system-relative-pathname :lem-tests (merge-pathnames filename "tests/sample-code/")))
(defun diff-text (text1 text2)
(string-trim
'(#\newline #\space #\tab)
(with-output-to-string (out)
(with-input-from-string (in1 text1)
(with-input-from-string (in2 text2)
(loop :with eof-value := '#:eof
:for line1 := (read-line in1 nil eof-value)
:for line2 := (read-line in2 nil eof-value)
:until (eq line1 eof-value)
:do (cond ((string= line1 line2)
(format out " ~A~%" line1))
(t
(write-string (cl-ansi-text:yellow (format nil "+~A~%" line1)) out)
(write-string (cl-ansi-text:cyan (format nil "-~A~%" line2)) out)))))))))