test/utils.lisp @ aacf9ee4fddc

Port some of the '99 Prolog Problems' to Bones as unit tests

Also fixes a bug that they uncovered.
author Steve Losh <steve@stevelosh.com>
date Sun, 17 Jul 2016 00:50:25 +0000
parents (none)
children 4abb7eda96cb
(in-package #:bones-test.utils)


;;;; Utils
(defun result= (x y)
  (set-equal (plist-alist x)
             (plist-alist y)
             :test #'equal))

(defun results= (r1 r2)
  (set-equal r1 r2 :test #'result=))


(defmacro should-fail (&body queries)
  `(progn
     ,@(loop :for query :in queries :collect
             `(is (results= nil (query-all ,query))))))

(defmacro should-return (&body queries)
  `(progn
    ,@(loop :for (query . results) :in queries
            :collect
            `(is (results= ',(cond
                               ((equal results '(empty))
                                (list nil))
                               ((equal results '(fail))
                                nil)
                               (t results))
                           (query-all ,query))))))