haskell: deriving (Eq, Show) for ADTs (+11 tests, 565/565)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 34s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 34s
Parser parses optional deriving clause; only appended to AST when non-empty. hk-bind-decls! data arm generates dictShow_Con / dictEq_Con per constructor. hk-binop == and /= now deep-force both sides (SX dict equality is by reference — two thunks wrapping the same value compared as not-equal without this). Three token-type fixes in the deriving parser (lparen/rparen/comma, not "special"). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
84
lib/haskell/tests/deriving.sx
Normal file
84
lib/haskell/tests/deriving.sx
Normal file
@@ -0,0 +1,84 @@
|
||||
;; 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}
|
||||
Reference in New Issue
Block a user