;; lib/minikanren/tests/project.sx — Phase 5 piece B tests for `project`.

;; --- project rebinds vars to ground values for SX use ---

(mk-test
  "project-square-via-host"
  (run* q (fresh (n) (== n 5) (project (n) (== q (* n n)))))
  (list 25))

(mk-test
  "project-multi-vars"
  (run*
    q
    (fresh
      (a b)
      (== a 3)
      (== b 4)
      (project (a b) (== q (+ a b)))))
  (list 7))

(mk-test
  "project-with-string-host-op"
  (run* q (fresh (s) (== s "hello") (project (s) (== q (str s "!")))))
  (list "hello!"))

;; --- project nested inside conde ---

(mk-test
  "project-inside-conde"
  (run*
    q
    (fresh
      (n)
      (conde ((== n 3)) ((== n 4)))
      (project (n) (== q (* n 10)))))
  (list 30 40))

;; --- project body can be multiple goals (mk-conj'd) ---

(mk-test
  "project-multi-goal-body"
  (run*
    q
    (fresh
      (n)
      (== n 7)
      (project (n) (== q (+ n 1)) (== q (+ n 1)))))
  (list 8))

(mk-test
  "project-multi-goal-body-conflict"
  (run*
    q
    (fresh
      (n)
      (== n 7)
      (project (n) (== q (+ n 1)) (== q (+ n 2)))))
  (list))

(mk-tests-run!)
