Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/psrs-driver/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod operators;
mod partial_application;
mod scalars;
mod semigroup;
mod show;

fn lower_source_to_mir(source: &str) -> psrs_backend::mir::Module {
let core = lower_source_to_core("Main.purs", source).expect("source should lower to Core");
Expand Down
2 changes: 2 additions & 0 deletions crates/psrs-driver/src/tests/module_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ fn loads_the_standard_library_from_disk_in_trusted_order() {
"Data.Eq",
"Data.Ord",
"Data.Semiring",
"Data.Show",
"Effect",
"Effect.Console",
"Test.Assert",
Expand All @@ -131,6 +132,7 @@ fn loads_the_standard_library_from_disk_in_trusted_order() {
|| path.ends_with("lib/Data/Eq.purs")
|| path.ends_with("lib/Data/Ord.purs")
|| path.ends_with("lib/Data/Semiring.purs")
|| path.ends_with("lib/Data/Show.purs")
|| path.ends_with("lib/Effect.purs")
|| path.ends_with("lib/Effect/Console.purs")
|| path.ends_with("lib/Test/Assert.purs")
Expand Down
112 changes: 112 additions & 0 deletions crates/psrs-driver/src/tests/show.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
//! The library's `Show` class.
//!
//! These tests execute under Wasmtime. The strings are the official `Show`
//! spellings: `true`/`false`, decimal `Int`, `unit`, quoted `Char` and
//! `String` (with the official escapes), arrays without spaces, and `Number`
//! with a trailing `.0` on an integer token.

use super::*;

#[test]
fn show_renders_the_instances_the_corpus_prints() {
let source = r#"
module Main where

import Prelude
import Effect.Console (log)

checks :: Effect Unit
checks = do
log (show true)
log (show false)
log (show 0)
log (show 42)
log (show (0 - 7))
log (show ((0 - 2147483647) - 1))
log (show unit)
log (show "hi")
log (show "a\"b")
log (show "line\n")
log (show 'a')
log (show '\n')
log (show '\'')
log (show [1, 2, 3])
log (show [1.0, 2.0])
log (show 0.0)
log (show 1.0)
log (show (numberNeg 2.0))
log (show 1.5)
log (show 0.5)
log (show 0.25)
log (show 10000000000.0)
log (show 1.0e21)
log (show 1.0e-5)
log (show "é")
log (show "cafés")
pure unit

main = let ignored = runEffect checks in 0
"#;
let Some(output) = run_with_wasmtime(source) else {
eprintln!("skipping: wasmtime is not installed");
return;
};
assert_eq!(output.status.code(), Some(0), "{output:?}");
let stdout = String::from_utf8_lossy(&output.stdout);
let expected = concat!(
"true\n",
"false\n",
"0\n",
"42\n",
"-7\n",
"-2147483648\n",
"unit\n",
"\"hi\"\n",
"\"a\\\"b\"\n",
"\"line\\n\"\n",
"'a'\n",
"'\\n'\n",
"'\\''\n",
"[1,2,3]\n",
"[1.0,2.0]\n",
"0.0\n",
"1.0\n",
"-2.0\n",
"1.5\n",
"0.5\n",
"0.25\n",
"10000000000.0\n",
"1e+21\n",
"0.00001\n",
"\"é\"\n",
"\"cafés\"\n",
);
assert_eq!(
stdout.as_ref(),
expected,
"stdout:\n{stdout}\nstderr:\n{}",
String::from_utf8_lossy(&output.stderr)
);
}

#[test]
fn a_type_without_show_is_rejected() {
let source = r#"
module Main where

import Prelude

data Box = Box

main :: String
main = show Box
"#;
let errors = check_program_types_lenient_with_prelude(&[("Main.purs", source)])
.expect_err("Box is not a Show");
assert!(
errors
.iter()
.any(|error| error.diagnostic.code == Some("NoInstanceFound")),
"expected NoInstanceFound, got {errors:?}"
);
}
107 changes: 63 additions & 44 deletions docs/design/D-04-suite-roadmap.md

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions docs/design/D-15-compiler-builtins.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,13 @@ The remaining surface operators `-`, `/`, and `%` are still bound to the `Int`
intrinsics directly. `Data.Ring` and the Euclidean division class are the
follow-up.

`Show` is a library class in `Data.Show`, re-exported from `Prelude`, over the
same primitives. It does not add an intrinsic: integer, character, and string
rendering are written in the source language, and `Number` rendering is too.
That `Number` spelling is not a correctly rounded ECMAScript conversion. A pure
numeric formatter with canonical inputs and outputs is the open capability
question above, not a new `Intrinsic`.

## References

- [D-01 — Frontend and IR Boundaries](D-01-frontend-and-ir-boundaries.md).
Expand Down
Loading
Loading