(require 'ert)

(require 'scxml-geometry-span)

(ert-deftest scxml-geometry-span-contains-scalar ()
  (let ((span (scxml-span :start 1.0 :end 2.0))
        (left 1.0)
        (right 2.0)
        (middle 1.5))
    (should (scxml-contains span left))
    (should (scxml-contains span left nil))
    (should (scxml-contains span left 'stacked))
    (should-not (scxml-contains span left 'strict))

    (should (scxml-contains span middle))
    (should (scxml-contains span middle nil))
    (should (scxml-contains span middle 'stacked))
    (should (scxml-contains span middle 'strict))

    (should (scxml-contains span right))
    (should (scxml-contains span right nil))
    (should-not (scxml-contains span right 'stacked))
    (should-not (scxml-contains span right 'strict))))

(ert-deftest scxml-geometry-span-contains-span ()
  (let ((span (scxml-span :start 1.0 :end 2.0)))
    (let ((inside (scxml-span :start 1.1 :end 1.9)))
      (should (scxml-contains span inside))
      (should (scxml-contains span inside nil))
      (should (scxml-contains span inside 'stacked))
      (should (scxml-contains span inside 'strict)))
    (let ((inside-flipped (scxml-span :start 1.9 :end 1.1)))
      (should (scxml-contains span inside-flipped))
      (should (scxml-contains span inside-flipped nil))
      (should (scxml-contains span inside-flipped 'stacked))
      (should (scxml-contains span inside-flipped 'strict)))
    (let ((not-strict (scxml-span :start 1.0 :end 1.9)))
      (should (scxml-contains span not-strict))
      (should (scxml-contains span not-strict nil))
      (should (scxml-contains span not-strict 'stacked))
      (should-not (scxml-contains span not-strict 'strict)))
    (let ((not-strict-flipped (scxml-span :start 1.9 :end 1.0)))
      (should (scxml-contains span not-strict-flipped))
      (should (scxml-contains span not-strict-flipped nil))
      (should (scxml-contains span not-strict-flipped 'stacked))
      (should-not (scxml-contains span not-strict-flipped 'strict)))))

(provide 'scxml-geometry-span-test)
