Vim window logic, slimv

This commit is contained in:
Ian Keane 2020-02-24 20:27:04 -05:00
parent babcc9e44b
commit 515847d07e
791 changed files with 51552 additions and 86 deletions

View file

@ -0,0 +1,166 @@
(in-package :cl-user)
(defpackage t.prove
(:use :cl
:prove
:prove.t.utils))
(in-package :t.prove)
(setf *default-reporter* :list)
(plan 22)
(test-assertion "Successful OK"
(ok t)
"✓ T is expected to be T")
(test-assertion "Failed ok without description"
(ok nil)
"× NIL is expected to be T")
(test-assertion "Failed ok with description"
(ok nil "This supposed to be failed")
"
× This supposed to be failed
NIL is expected to be T")
(test-assertion "Simple number equality check"
(is 1 1)
"✓ 1 is expected to be 1")
(test-assertion "String and number shouldn't be equal"
(is "1" 1)
"× \"1\" is expected to be 1")
(test-assertion "String and number are not equal and isnt assertion returns OK"
(isnt "1" 1)
"✓ \"1\" is not expected to be 1")
(test-assertion "Subtest with diagnostic message"
(subtest "Subtest"
(diag "in subtest")
(is #\a #\a)
(like "truth" "^true"))
"
Subtest
in subtest
#\\a is expected to be #\\a
× \"truth\" is expected to be like \"^true\"")
(test-assertion "Check if (is-values ...) works propertly"
(is-values (values 1 2 nil 3)
'(1 2 nil 3))
"✓ (1 2 NIL 3) is expected to be (1 2 NIL 3)")
(test-assertion "Standalone diagnostic message"
(diag "comment")
"comment")
(test-assertion "Just a pass"
(pass "pass")
"✓ pass")
(test-assertion "Fail"
(fail "fail")
"
× fail
T is expected to be NIL")
(test-assertion "Pass with parameter"
(pass "<~S>")
"✓ <~S>")
(test-assertion "Equality for strings with formatting"
(is "<~S>" "<~S>")
"✓ \"<~S>\" is expected to be \"<~S>\"")
(test-assertion "\"Skip\" with reason as control-string with arguments should substitute arguments"
(skip 1 "Because ~A" 42)
"- Because 42 (Skipped)")
(test-assertion "\"Skip\" without reason have default message \"skipping\""
(skip 1 "skipping")
"- skipping (Skipped)")
(test-assertion "Assert is-print compares form's output to standart-output"
(is-print (princ "ABCDEFGH")
"ABCDEFGHIJKLMNO")
"× (PRINC \"ABCDEFGH\") is expected to output \"ABCDEFGHIJKLMNO\" (got \"ABCDEFGH\")")
(test-assertion "Type assertion fails if type mismatch"
(is-type 1 'string)
"× 1 is expected to be a type of STRING")
(test-assertion "Assertion \"is-error\" checks if condition of given type was thrown"
(is-error (error "Raising an error") 'simple-error)
"(?s)✓ \\(ERROR \"Raising an error\"\\) is expected to raise a condition SIMPLE-ERROR \\(got #<(a )?SIMPLE-ERROR.*>\\)")
(define-condition my-condition () ())
(test-assertion "If condition type mismatch, \"is-error\" fails"
(is-error (error 'my-condition) 'simple-error)
"(?s)× \\(ERROR ('MY-CONDITION|\\(QUOTE MY-CONDITION\\))\\) is expected to raise a condition SIMPLE-ERROR \\(got #<(a T.PROVE::)?MY-CONDITION.*>\\)")
(test-assertion
"All lines of multiline description should be indented"
(is 'blah 'blah
"Blah with multiline
description!")
"
Blah with multiline
description!")
(test-assertion
"Multiline indentation should work for nested tests"
(subtest "Outer testcase
with multiline
description."
(is 'blah 'blah
"Blah with multiline
description!")
(subtest "Inner testcase
with multiline description."
(is 'foo 'foo
"Foo with multiline
description!")))
"
Outer testcase
with multiline
description.
Blah with multiline
description!
Inner testcase
with multiline description.
Foo with multiline
description!")
(test-assertion "Check finalize's output without a plan"
(finalize)
"
Tests were run but no plan was declared.
0 tests completed (0ms)")
(finalize)

View file

@ -0,0 +1,118 @@
(in-package :cl-user)
(defpackage prove.t.utils
(:use :cl)
(:import-from :split-sequence
:split-sequence)
(:import-from :alexandria
:with-gensyms)
(:import-from :prove
:like
:subtest
:is)
(:export :test-assertion))
(in-package :prove.t.utils)
(defun empty-line-p (line)
"Checks if line of text is empty."
(equal line ""))
(defun get-indentation (line)
"Returns numbers of leading spaces for the line."
(loop
:for char :across line
:for num-spaces :upfrom 0
:when (not (equal char #\Space))
:do (return num-spaces)))
(defun left-remove-if (items predicate)
"Returns list skipping leftmost items
which match a predicate."
(do ()
((not (funcall predicate (car items))) items)
(setf items (cdr items))))
(defun right-remove-if (items predicate)
"Returns a new list, without rightmost items
which match a predicate."
(labels ((recur (items)
(destructuring-bind (head . tail) items
(if tail
(let ((tail (recur tail)))
(if tail
(cons head tail)
(unless (funcall predicate head)
(list head))))
(if (funcall predicate head)
nil
(list head))))))
(recur items)))
(defun deindent (text)
"Removes empty new lines at the begining and at the end of the text,
and removes common number of whitespaces from rest of the lines."
(let* ((all-lines (split-sequence
#\Newline
text))
;; remove empty lines at beginning
(left-trimmed (left-remove-if
all-lines
#'empty-line-p))
;; and at the end
(lines (right-remove-if
left-trimmed
#'empty-line-p))
;; calculate common indentation
(min-indent (apply #'min (mapcar #'get-indentation lines)))
;; remove common indentation from lines
(new-lines (loop :for line :in lines
:collect (subseq line min-indent))))
;; now join lines together and separate them with new-lines
(values (format nil "~{~a~^~%~}" new-lines)
min-indent)))
(defmacro test-assertion (title body expected
&aux (method (if (search ".*" expected)
'like
'is)))
"Tests that assertion result in prove's output
matches given regular expression.
Body evaluated and it's result is matched agains expected string,
using prove:like. Dangling spaces and newlines are trimmed from
the result before trying to match."
(with-gensyms (result trimmed-result deindented-expected)
`(subtest ,title
(let* ((,result
;; All output during the test, should be captured
;; to test against give regex
(with-output-to-string
(prove.output:*test-result-output*)
(let ( ;; Colors whould be turned off to
;; prevent Prove's reporter return
;; string with terminal sequences.
;; This way it will be easier to compare
;; results with usual strings
(prove.color:*enable-colors* nil)
;; We need to overide current suite, to prevent
;; tested assert-that macro from modifying real testsuite.
;; Otherwise it can increment failed or success tests count
;; and prove will output wrong data.
(prove.suite:*suite* (make-instance 'prove.suite:suite))
(prove.reporter::*debug-indentation* nil))
,body)))
(,trimmed-result (string-trim '(#\Space #\Newline)
(deindent ,result)))
(,deindented-expected (deindent ,expected)))
(,method ,trimmed-result
,deindented-expected)))))