haskell: Phase 8 — tests/show.sx expanded to 26/26 (full audit coverage)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 57s

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-07 01:04:52 +00:00
parent d8dec07df3
commit bb134b88e3
2 changed files with 98 additions and 5 deletions

View File

@@ -1,9 +1,11 @@
;; show.sx — tests for the Show class plumbing. ;; show.sx — tests for the Show / Read class plumbing.
;; ;;
;; Covers: ;; Covers Phase 8:
;; - showsPrec / showParen / shows / showString stubs (Phase 8) ;; - showsPrec / showParen / shows / showString stubs
;; - Eventually expanded to ≥12 tests covering the full audit (Phase 8 ☐). ;; - Read class stubs (reads / readsPrec / read)
;; - direct show coverage (Int, Bool, String, list, tuple, Maybe, ADT, ...)
;; ── ShowS / showsPrec / showParen stubs ──────────────────────
(hk-test (hk-test
"shows: prepends show output" "shows: prepends show output"
(hk-deep-force (hk-run "main = shows 5 \"abc\"")) (hk-deep-force (hk-run "main = shows 5 \"abc\""))
@@ -41,6 +43,7 @@
"buildJust3 s = showString \"Just \" (shows 3 s)\nmain = showParen True buildJust3 \"\"")) "buildJust3 s = showString \"Just \" (shows 3 s)\nmain = showParen True buildJust3 \"\""))
"(Just 3)") "(Just 3)")
;; ── Read stubs ───────────────────────────────────────────────
(hk-test (hk-test
"reads: stub returns empty list (null-check)" "reads: stub returns empty list (null-check)"
(hk-deep-force (hk-run "main = show (null (reads \"42\"))")) (hk-deep-force (hk-run "main = show (null (reads \"42\"))"))
@@ -56,4 +59,82 @@
(hk-deep-force (hk-run "main = show (length (reads \"abc\"))")) (hk-deep-force (hk-run "main = show (length (reads \"abc\"))"))
"0") "0")
;; ── Direct `show` audit coverage ─────────────────────────────
(hk-test "show Int" (hk-deep-force (hk-run "main = show 42")) "42")
(hk-test
"show negative Int"
(hk-deep-force (hk-run "main = show (negate 5)"))
"-5")
(hk-test "show Bool True" (hk-deep-force (hk-run "main = show True")) "True")
(hk-test
"show Bool False"
(hk-deep-force (hk-run "main = show False"))
"False")
(hk-test
"show String quotes the value"
(hk-deep-force (hk-run "main = show \"hello\""))
"\"hello\"")
(hk-test
"show list of Int"
(hk-deep-force (hk-run "main = show [1,2,3]"))
"[1,2,3]")
(hk-test
"show empty list"
(hk-deep-force (hk-run "main = show (drop 5 [1,2,3])"))
"[]")
(hk-test
"show pair tuple"
(hk-deep-force (hk-run "main = show (1, True)"))
"(1,True)")
(hk-test
"show triple tuple"
(hk-deep-force (hk-run "main = show (1, 2, 3)"))
"(1,2,3)")
(hk-test
"show Maybe Nothing"
(hk-deep-force (hk-run "main = show Nothing"))
"Nothing")
(hk-test
"show Maybe Just"
(hk-deep-force (hk-run "main = show (Just 3)"))
"Just 3")
(hk-test
"show nested Just wraps inner in parens"
(hk-deep-force (hk-run "main = show (Just (Just 3))"))
"Just (Just 3)")
(hk-test
"show Just (negate 3) wraps negative in parens"
(hk-deep-force (hk-run "main = show (Just (negate 3))"))
"Just (-3)")
(hk-test
"show custom nullary ADT"
(hk-deep-force
(hk-run "data Day = Mon | Tue | Wed deriving (Show)\nmain = show Tue"))
"Tue")
(hk-test
"show custom multi-constructor ADT"
(hk-deep-force
(hk-run
"data Shape = Pt | Sq Int | Rect Int Int deriving (Show)\nmain = show (Rect 3 4)"))
"Rect 3 4")
(hk-test
"show list of Maybe wraps each element"
(hk-deep-force (hk-run "main = show [Just 1, Nothing, Just 2]"))
"[Just 1,Nothing,Just 2]")
{:fails hk-test-fails :pass hk-test-pass :fail hk-test-fail} {:fails hk-test-fails :pass hk-test-pass :fail hk-test-fail}

View File

@@ -110,9 +110,11 @@ No OCaml changes are needed. The view type is fully representable as an SX dict.
- [x] `showsPrec` / `showParen` stubs so hand-written Show instances compile. - [x] `showsPrec` / `showParen` stubs so hand-written Show instances compile.
- [x] `Read` class stub — just enough for `reads :: String -> [(a,String)]` to - [x] `Read` class stub — just enough for `reads :: String -> [(a,String)]` to
type-check; no real parser needed yet. type-check; no real parser needed yet.
- [ ] Tests in `lib/haskell/tests/show.sx` (≥ 12 tests: show Int, show Bool, - [x] Tests in `lib/haskell/tests/show.sx` (≥ 12 tests: show Int, show Bool,
show Char, show String, show list, show tuple, show Maybe, show custom ADT, show Char, show String, show list, show tuple, show Maybe, show custom ADT,
deriving Show on multi-constructor type, nested constructor parens). deriving Show on multi-constructor type, nested constructor parens).
_Char tests deferred: Char = Int representation; show on a Char is currently
`"97"` not `"'a'"`._
- [ ] Conformance programs: - [ ] Conformance programs:
- `showadt.hs``data Expr = Lit Int | Add Expr Expr | Mul Expr Expr` - `showadt.hs``data Expr = Lit Int | Add Expr Expr | Mul Expr Expr`
with `deriving Show`; prints a tree. with `deriving Show`; prints a tree.
@@ -287,6 +289,16 @@ No OCaml changes are needed. The view type is fully representable as an SX dict.
_Newest first._ _Newest first._
**2026-05-07** — Phase 8 `tests/show.sx` expanded to full audit coverage (26/26):
- 16 new direct `show` tests: Int (positive + negative), Bool (T/F), String,
list of Int, empty list, pair tuple, triple tuple, Maybe Nothing, Maybe Just,
nested Just (paren wrapping), Just (negate 3) (negative wrapping), nullary
ADT, multi-constructor ADT with args, list of Maybe.
- `show ([] :: [Int])` would be the natural empty-list test but our parser
doesn't yet support type ascription; used `show (drop 5 [1,2,3])` instead.
Char `'a'` → `"'a'"` deferred to Char-tagging design (Char = Int currently
yields `"97"`).
**2026-05-07** — Phase 8 `Read` class stub (`reads`, `readsPrec`, `read`): **2026-05-07** — Phase 8 `Read` class stub (`reads`, `readsPrec`, `read`):
- Three lines added to `hk-prelude-src`: `reads s = []`, `readsPrec _ s = reads s`, - Three lines added to `hk-prelude-src`: `reads s = []`, `readsPrec _ s = reads s`,
`read s = fst (head (reads s))`. The stubs let user code that mentions `read s = fst (head (reads s))`. The stubs let user code that mentions