;; deriving.sx — tests for deriving (Eq, Show) on ADTs.

;; ─── Show ────────────────────────────────────────────────────────────────────

(hk-test
  "deriving Show: nullary constructor"
  (hk-deep-force
    (hk-run "data Color = Red | Green | Blue deriving (Show)\nmain = show Red"))
  "Red")

(hk-test
  "deriving Show: constructor with arg"
  (hk-deep-force
    (hk-run "data Wrapper = Wrap Int deriving (Show)\nmain = show (Wrap 42)"))
  "(Wrap 42)")

(hk-test
  "deriving Show: nested constructors"
  (hk-deep-force
    (hk-run
      "data Tree = Leaf | Node Int Tree Tree deriving (Show)\nmain = show (Node 1 Leaf Leaf)"))
  "(Node 1 Leaf Leaf)")

(hk-test
  "deriving Show: second constructor"
  (hk-deep-force
    (hk-run
      "data Color = Red | Green | Blue deriving (Show)\nmain = show Green"))
  "Green")

;; ─── Eq ──────────────────────────────────────────────────────────────────────

(hk-test
  "deriving Eq: same constructor"
  (hk-deep-force
    (hk-run
      "data Color = Red | Green | Blue deriving (Eq)\nmain = show (Red == Red)"))
  "True")

(hk-test
  "deriving Eq: different constructors"
  (hk-deep-force
    (hk-run
      "data Color = Red | Green | Blue deriving (Eq)\nmain = show (Red == Blue)"))
  "False")

(hk-test
  "deriving Eq: /= same"
  (hk-deep-force
    (hk-run
      "data Color = Red | Green | Blue deriving (Eq)\nmain = show (Red /= Red)"))
  "False")

(hk-test
  "deriving Eq: /= different"
  (hk-deep-force
    (hk-run
      "data Color = Red | Green | Blue deriving (Eq)\nmain = show (Red /= Blue)"))
  "True")

;; ─── combined Eq + Show ───────────────────────────────────────────────────────

(hk-test
  "deriving Eq Show: combined in parens"
  (hk-deep-force
    (hk-run
      "data Shape = Circle Int | Square Int deriving (Eq, Show)\nmain = show (Circle 5)"))
  "(Circle 5)")

(hk-test
  "deriving Eq Show: eq on constructor with arg"
  (hk-deep-force
    (hk-run
      "data Shape = Circle Int | Square Int deriving (Eq, Show)\nmain = show (Circle 3 == Circle 3)"))
  "True")

(hk-test
  "deriving Eq Show: different constructors with args"
  (hk-deep-force
    (hk-run
      "data Shape = Circle Int | Square Int deriving (Eq, Show)\nmain = show (Circle 3 == Square 3)"))
  "False")

{:fails hk-test-fails :pass hk-test-pass :fail hk-test-fail}
