Skip to content

Commit

Permalink
Finished tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyklay committed Mar 18, 2020
1 parent dc70738 commit bedc8e5
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 131 deletions.
128 changes: 0 additions & 128 deletions test/test-esup.el
Original file line number Diff line number Diff line change
Expand Up @@ -224,132 +224,4 @@
(make-esup-result "/fake14/baz.el" "(provide 'baz)"
:start-point 14 :end-point 28)))))))

;;
;; ;; Test Utilities

;; (defun esup-test--explain-esup-results-equal-p (ignoring-slots a b)
;; "Explain why `esup-results-equal-p' returned t or nil."
;; (pcase a
;; ;; Actual is nil, but expected is not.
;; ((guard (and (null a) (not (null b))))
;; `(actual is nil but expected ,b))

;; ;; Different types.
;; ((guard (not (equal (type-of a) (type-of b))))
;; `(different-types ,a ,b))

;; ;; A list of esup-results.
;; ((pred listp)
;; (esup-test--explain-list-of-esup-results ignoring-slots a b))

;; ;; A single esup-result.
;; ((app eieio-object-class esup-result)
;; (esup-test--explain-single-esup-result ignoring-slots a b))

;; ;; Unknown types.
;; (_ `(unknown-types ,a ,b))))
;; (put 'esup-results-equal-p 'ert-explainer
;; 'esup-test--explain-esup-results-equal-p)

;; (defun esup-test--explain-list-of-esup-results (ignoring-slots a b)
;; (cond
;; ((not (eq (length a) (length b)))
;; `(different-lengths ,a ,b))
;; (t
;; ;; Compare each index
;; (cl-loop
;; for (actual . expected) in (-zip-pair a b)
;; for i = 0 then (1+ i)
;; collect
;; `(index ,i ,@(esup-test--explain-single-esup-result
;; ignoring-slots actual expected))))))

;; (defun esup-test--explain-single-esup-result (ignoring-slots a b)
;; (if (esup-results-single-equal-p ignoring-slots a b)
;; 'MATCH
;; ;; Compare each slot
;; (-non-nil
;; (cl-loop for slot in (esup-test--all-slots)
;; collect
;; (cond
;; ((-contains? ignoring-slots slot)
;; `(,slot IGNORED))
;; ;; Got a match
;; ((equal (eieio-oref a slot) (eieio-oref b slot))
;; `(,slot MATCHED on ,(eieio-oref a slot)))
;; ;; Explain the mismatch
;; (t
;; `(,slot MISMATCH
;; actual was ,(eieio-oref b slot)
;; but expected ,(eieio-oref a slot))))))))
;; (put 'esup-results-single-equal-p 'ert-explainer
;; 'esup-test--explain-single-esup-result)

;;
;; ;; Test Utility Tests

;; (ert-deftest esup-results-single-equal-p__ignoring-no-slots__is-equal ()
;; (should
;; (esup-results-single-equal-p
;; '()
;; (make-esup-result "/fake/file-1.el" "(progn 'file-1)")
;; (make-esup-result "/fake/file-1.el" "(progn 'file-1)"))))

;; (ert-deftest esup-results-single-equal-p__sexp-mismatch__is-false ()
;; (should
;; (not
;; (esup-results-single-equal-p
;; '()
;; (make-esup-result "/fake/file-1.el" "(progn 'file-1)")
;; (make-esup-result "/fake/file-1.el" "(progn 'file-2)")))))

;; (ert-deftest esup-results-single-equal-p__ignoring-gc-time__is-equal ()
;; (should
;; (esup-results-single-equal-p
;; '(:gc-time)
;; (esup-result
;; :file "file" :expression-string "sexp" :end-point 20 :gc-time 444)
;; (esup-result
;; :file "file" :expression-string "sexp" :end-point 20 :gc-time 555))))

;; (ert-deftest esup-results-single-equal-p__gc-time-mismatch__is-false ()
;; (should
;; (not
;; (esup-results-single-equal-p
;; '()
;; (esup-result
;; :file "file" :expression-string "sexp" :end-point 20 :gc-time 444)
;; (esup-result
;; :file "file" :expression-string "sexp" :end-point 20 :gc-time 555)))))

;; (ert-deftest esup-results-single-equal-p__sexp-mismatch__is-false ()
;; (should
;; (not
;; (esup-results-single-equal-p
;; '()
;; (esup-result
;; :file "file" :expression-string "sexp")
;; (esup-result
;; :file "file" :expression-string "sexp2")))))

;; (ert-deftest make-esup-result__no-extra-args__is-same ()
;; (should
;; (equal
;; (make-esup-result "file" "sexp")
;; (esup-result
;; :file "file"
;; :expression-string "sexp"
;; :end-point 5))))

;; (ert-deftest make-esup-result__with-extra-args__is-same ()
;; (should
;; (equal
;; (make-esup-result "file" "sexp" :gc-time 20 :exec-time 40)
;; (esup-result
;; :file "file"
;; :expression-string "sexp"
;; :end-point 5
;; :gc-time 20
;; :exec-time 40))))

;;; test-esup.el ends here
63 changes: 63 additions & 0 deletions test/test-utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,67 @@
(list (make-esup-result "file" "sexp2")))))
(expect result :to-be nil))))

(describe "Calling esup-results-single-equal-p to compare esup-result objects"
(it "eaqual when ignoring slots are absent"
(should
(esup-results-single-equal-p
'()
(make-esup-result "/fake/file-1.el" "(progn 'file-1)")
(make-esup-result "/fake/file-1.el" "(progn 'file-1)"))))

(it "equal when ignoring :gc-time"
(should
(esup-results-single-equal-p
'(:gc-time)
(esup-result
:file "file" :expression-string "sexp" :end-point 20 :gc-time 444)
(esup-result
:file "file" :expression-string "sexp" :end-point 20 :gc-time 555))))

(it "NOT equal when sexps are mismatch (I)"
(let ((result (esup-results-single-equal-p
'()
(make-esup-result "/fake/file-1.el" "(progn 'file-1)")
(make-esup-result "/fake/file-1.el" "(progn 'file-2)"))))
(expect result :to-be nil)))

(it "NOT equal when sexps are mismatch (II)"
(let ((result-a (esup-result :file "file" :expression-string "sexp"))
(result-b (esup-result :file "file" :expression-string "sexp2")))
(expect (esup-results-single-equal-p '() result-a result-b)
:to-be nil)))

(it "NOT equal when :gc-time is mismatch"
(let ((result-a (esup-result
:file "file"
:expression-string "sexp"
:end-point 20
:gc-time 444))
(result-b (esup-result
:file "file"
:expression-string "sexp"
:end-point 20
:gc-time 555)))
(expect (esup-results-single-equal-p '() result-a result-b)
:to-be nil))))

(describe "Making esup-result objects"
(it "create the same object with NO extra args"
(let((actual (make-esup-result "file" "sexp"))
(expected (esup-result
:file "file"
:expression-string "sexp"
:end-point 5)))
(expect actual :to-equal expected)))

(it "create the same object with extra args"
(let ((actual (make-esup-result "file" "sexp" :gc-time 20 :exec-time 40))
(expected (esup-result
:file "file"
:expression-string "sexp"
:end-point 5
:gc-time 20
:exec-time 40)))
(expect actual :to-equal expected))))

;;; test-utils.el ends here
6 changes: 3 additions & 3 deletions test/utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ In addition apply rest ARGS if any."
args))

(defun esup-test--all-slots ()
"Return a list of all slots for an `esup-result'."
"Return a list of all possible slots for an `esup-result'."
(--map (intern (concat ":" (symbol-name it)))
(object-slots (make-instance 'esup-result))))

Expand All @@ -82,14 +82,14 @@ Create a new list with only the members of IGNORING-SLOTS that are not in

(defun esup-results-single-equal-p (ignoring-slots a b)
"Compare `esup-result' objects with an IGNORING-SLOTS.
A test for equality of A and B is performed by using `eq' defun."
A test for equality of A and B objects is performed by using `eq' defun."
(--all? (not (null it))
(--map (equal (eieio-oref a it) (eieio-oref b it))
(esup-test--slots-to-compare ignoring-slots))))

(defun esup-results-equal-p (ignoring-slots a b)
"Compare a list of `esup-result' objects with an IGNORING-SLOTS.
A test for equality of A and B is performed by using `eq' defun."
A test for equality of A and B objects is performed by using `eq' defun."
(and
(eq (length a) (length b))
(--all? (not (null it))
Expand Down

0 comments on commit bedc8e5

Please sign in to comment.