Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

Use node's nonsense extension

+712 -714
+1 -1
.github/workflows/ci.yaml
··· 196 196 # Assert that HTML docs have been written 197 197 ls build/dev/docs/lib_project/index.html 198 198 ls build/dev/docs/lib_project/index.css 199 - ls build/dev/docs/lib_project/gleam.js 199 + ls build/dev/docs/lib_project/gleam.mjs 200 200 ls build/dev/docs/lib_project/index.html 201 201 ls build/dev/docs/lib_project/lib_project.html
+2 -2
compiler-cli/src/run.rs
··· 59 59 let _ = command.arg("-pa").arg(entry.path().join("ebin")); 60 60 } 61 61 62 - // Run the main function. 63 62 let _ = command.arg("-eval"); 64 63 let _ = command.arg(format!("gleam@@main:run({})", &module)); 65 64 ··· 84 83 .join(module); 85 84 let mut command = Command::new("node"); 86 85 86 + // Run the main function. 87 87 let _ = command.arg("-e"); 88 88 let _ = command.arg(&format!( 89 - "import('./{}.js').then(module => module.main())", 89 + "import('./{}.mjs').then(module => module.main())", 90 90 module.to_string_lossy() 91 91 )); 92 92
+5 -5
compiler-core/src/build/package_compilation_tests.rs
··· 2569 2569 ], 2570 2570 Ok(vec![ 2571 2571 OutputFile { 2572 - path: PathBuf::from("_build/default/lib/the_package/gleam_src/gleam.js"), 2572 + path: PathBuf::from("_build/default/lib/the_package/gleam_src/gleam.mjs"), 2573 2573 text: javascript::PRELUDE.to_string(), 2574 2574 }, 2575 2575 OutputFile { 2576 - path: PathBuf::from("_build/default/lib/the_package/gleam_src/one/two.js"), 2577 - text: "import { CustomType } from \"../gleam.js\"; 2576 + path: PathBuf::from("_build/default/lib/the_package/gleam_src/one/two.mjs"), 2577 + text: "import { CustomType } from \"../gleam.mjs\"; 2578 2578 2579 2579 export class A extends CustomType {}\n" 2580 2580 .to_string(), 2581 2581 }, 2582 2582 OutputFile { 2583 - path: PathBuf::from("_build/default/lib/the_package/gleam_src/two.js"), 2584 - text: r#"import * as $two from "./one/two.js"; 2583 + path: PathBuf::from("_build/default/lib/the_package/gleam_src/two.mjs"), 2584 + text: r#"import * as $two from "./one/two.mjs"; 2585 2585 2586 2586 const x = new $two.A(); 2587 2587 "#
+2 -2
compiler-core/src/codegen.rs
··· 156 156 fn write_prelude(&self, writer: &impl FileSystemWriter) -> Result<()> { 157 157 tracing::debug!("Generated js prelude"); 158 158 writer 159 - .writer(&self.output_directory.join("gleam.js"))? 159 + .writer(&self.output_directory.join("gleam.mjs"))? 160 160 .str_write(javascript::PRELUDE)?; 161 161 Ok(()) 162 162 } ··· 167 167 module: &Module, 168 168 js_name: &str, 169 169 ) -> Result<()> { 170 - let name = format!("{}.js", js_name); 170 + let name = format!("{}.mjs", js_name); 171 171 let path = self.output_directory.join(&name); 172 172 let mut file = writer.writer(&path)?; 173 173 let line_numbers = LineNumbers::new(&module.code);
+3 -3
compiler-core/src/javascript.rs
··· 269 269 // TODO: strip shared prefixed between current module and imported 270 270 // module to avoid decending and climbing back out again 271 271 match self.module.name.len() { 272 - 1 => format!("./{}.js", path), 272 + 1 => format!("./{}.mjs", path), 273 273 _ => { 274 274 let prefix = "../".repeat(self.module.name.len() - 1); 275 - format!("{}{}.js", prefix, path) 275 + format!("{}{}.mjs", prefix, path) 276 276 } 277 277 } 278 278 } else { 279 279 // Different packages uses absolute imports 280 - format!("gleam-packages/{}/{}.js", package, path) 280 + format!("gleam-packages/{}/{}.mjs", package, path) 281 281 } 282 282 } 283 283
+5 -5
compiler-core/src/javascript/tests/externals.rs
··· 33 33 #[test] 34 34 fn same_module_multiple_imports() { 35 35 assert_js!( 36 - r#"pub external fn one() -> Nil = "./the/module.js" "one" 37 - pub external fn two() -> Nil = "./the/module.js" "two" 36 + r#"pub external fn one() -> Nil = "./the/module.mjs" "one" 37 + pub external fn two() -> Nil = "./the/module.mjs" "two" 38 38 "#, 39 39 ); 40 40 } ··· 42 42 #[test] 43 43 fn duplicate_import() { 44 44 assert_js!( 45 - r#"pub external fn one() -> Nil = "./the/module.js" "dup" 46 - pub external fn two() -> Nil = "./the/module.js" "dup" 45 + r#"pub external fn one() -> Nil = "./the/module.mjs" "dup" 46 + pub external fn two() -> Nil = "./the/module.mjs" "dup" 47 47 "#, 48 48 ); 49 49 } ··· 51 51 #[test] 52 52 fn name_to_escape() { 53 53 assert_js!( 54 - r#"pub external fn class() -> Nil = "./the/module.js" "one" 54 + r#"pub external fn class() -> Nil = "./the/module.mjs" "one" 55 55 "#, 56 56 ); 57 57 }
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__assignments__assert.snap
··· 3 3 expression: "fn go(x) { assert 1 = x }" 4 4 5 5 --- 6 - import { throwError } from "../gleam.js"; 6 + import { throwError } from "../gleam.mjs"; 7 7 8 8 function go(x) { 9 9 if (x !== 1) {
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__assignments__nested_binding.snap
··· 3 3 expression: "\nfn go(x) {\n let #(a, #(b, c, 2) as t, _, 1) = x\n}\n" 4 4 5 5 --- 6 - import { throwError } from "../gleam.js"; 6 + import { throwError } from "../gleam.mjs"; 7 7 8 8 function go(x) { 9 9 if (x[1][2] !== 2 || x[3] !== 1) {
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__assignments__returning_literal_subject.snap
··· 3 3 expression: "fn go(x) { assert 1 = x + 1 }" 4 4 5 5 --- 6 - import { throwError } from "../gleam.js"; 6 + import { throwError } from "../gleam.mjs"; 7 7 8 8 function go(x) { 9 9 let $ = x + 1;
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__assignments__tuple_matching.snap
··· 3 3 expression: "\nfn go(x) {\n let #(1, 2) = x\n}\n" 4 4 5 5 --- 6 - import { throwError } from "../gleam.js"; 6 + import { throwError } from "../gleam.mjs"; 7 7 8 8 function go(x) { 9 9 if (x[0] !== 1 || x[1] !== 2) {
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__assignments__variable_renaming.snap
··· 3 3 expression: "\n\nfn go(x, foo) {\n let a = 1\n foo(a)\n let a = 2\n foo(a)\n let #(a, 3) = x\n let b = a\n foo(b)\n let c = {\n let a = a\n #(a, b)\n }\n foo(a)\n // make sure arguments are counted in initial state\n let x = c\n x\n}\n" 4 4 5 5 --- 6 - import { throwError } from "../gleam.js"; 6 + import { throwError } from "../gleam.mjs"; 7 7 8 8 function go(x, foo) { 9 9 let a = 1;
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_strings__bit_string.snap
··· 3 3 expression: "\nfn go(x) {\n <<x:bit_string, \"Gleam\":utf8>>\n}\n" 4 4 5 5 --- 6 - import { toBitString, stringBits } from "../gleam.js"; 6 + import { toBitString, stringBits } from "../gleam.mjs"; 7 7 8 8 function go(x) { 9 9 return toBitString([x.buffer, stringBits("Gleam")]);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_strings__empty.snap
··· 3 3 expression: "\nfn go() {\n <<>>\n}\n" 4 4 5 5 --- 6 - import { toBitString } from "../gleam.js"; 6 + import { toBitString } from "../gleam.mjs"; 7 7 8 8 function go() { 9 9 return toBitString([]);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_strings__one.snap
··· 3 3 expression: "\nfn go() {\n <<256>>\n}\n" 4 4 5 5 --- 6 - import { toBitString } from "../gleam.js"; 6 + import { toBitString } from "../gleam.mjs"; 7 7 8 8 function go() { 9 9 return toBitString([256]);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_strings__two.snap
··· 3 3 expression: "\nfn go() {\n <<256, 4>>\n}\n" 4 4 5 5 --- 6 - import { toBitString } from "../gleam.js"; 6 + import { toBitString } from "../gleam.mjs"; 7 7 8 8 function go() { 9 9 return toBitString([256, 4]);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_strings__utf8.snap
··· 3 3 expression: "\nfn go(x) {\n <<256, 4, x, \"Gleam\":utf8>>\n}\n" 4 4 5 5 --- 6 - import { toBitString, stringBits } from "../gleam.js"; 6 + import { toBitString, stringBits } from "../gleam.mjs"; 7 7 8 8 function go(x) { 9 9 return toBitString([256, 4, x, stringBits("Gleam")]);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_strings__utf8_codepoint.snap
··· 3 3 expression: "\nfn go(x) {\n <<x:utf8_codepoint, \"Gleam\":utf8>>\n}\n" 4 4 5 5 --- 6 - import { toBitString, stringBits, codepointBits } from "../gleam.js"; 6 + import { toBitString, stringBits, codepointBits } from "../gleam.mjs"; 7 7 8 8 function go(x) { 9 9 return toBitString([codepointBits(x), stringBits("Gleam")]);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_strings__variable.snap
··· 3 3 expression: "\nfn go(x) {\n <<256, 4, x>>\n}\n" 4 4 5 5 --- 6 - import { toBitString } from "../gleam.js"; 6 + import { toBitString } from "../gleam.mjs"; 7 7 8 8 function go(x) { 9 9 return toBitString([256, 4, x]);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bools__assigning.snap
··· 3 3 expression: "\nfn go(x, y) {\n assert True = x\n assert False = x\n assert Nil = y\n}\n" 4 4 5 5 --- 6 - import { throwError } from "../gleam.js"; 6 + import { throwError } from "../gleam.mjs"; 7 7 8 8 function go(x, y) { 9 9 if (!x) {
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bools__case.snap
··· 3 3 expression: "\nfn go(a) {\n case a {\n True -> 1\n False -> 0\n }\n}\n" 4 4 5 5 --- 6 - import { throwError } from "../gleam.js"; 6 + import { throwError } from "../gleam.mjs"; 7 7 8 8 function go(a) { 9 9 if (a) {
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bools__nil_case.snap
··· 3 3 expression: "\nfn go(a) {\n case a {\n Nil -> 0\n }\n}\n" 4 4 5 5 --- 6 - import { throwError } from "../gleam.js"; 6 + import { throwError } from "../gleam.mjs"; 7 7 8 8 function go(a) { 9 9 if (!a) {
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bools__shadowed_bools_and_nil.snap
··· 3 3 expression: "\npub type True { True False Nil }\nfn go(x, y) {\n let True = x\n let False = x\n let Nil = y\n}\n" 4 4 5 5 --- 6 - import { CustomType, throwError } from "../gleam.js"; 6 + import { CustomType, throwError } from "../gleam.mjs"; 7 7 8 8 export class True extends CustomType {} 9 9
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__case__following_todo.snap
··· 3 3 expression: "\nfn go(x) {\n case x {\n True -> todo\n _ -> 1\n }\n}\n" 4 4 5 5 --- 6 - import { throwError } from "../gleam.js"; 6 + import { throwError } from "../gleam.mjs"; 7 7 8 8 function go(x) { 9 9 if (x) {
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__case__multi_subject_no_catch_all.snap
··· 3 3 expression: "\nfn go(x, y) {\n case x, y {\n True, _ -> 1\n _, True -> 2\n False, False -> 0\n }\n}\n" 4 4 5 5 --- 6 - import { throwError } from "../gleam.js"; 6 + import { throwError } from "../gleam.mjs"; 7 7 8 8 function go(x, y) { 9 9 if (x) {
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__case__pipe.snap
··· 3 3 expression: "\nfn go(x, f) {\n case x |> f {\n 0 -> Nil\n }\n}\n" 4 4 5 5 --- 6 - import { throwError } from "../gleam.js"; 6 + import { throwError } from "../gleam.mjs"; 7 7 8 8 function go(x, f) { 9 9 let $ = (() => {
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__case__result.snap
··· 3 3 expression: "\nfn go(x) {\n case x {\n Ok(_) -> 1\n Error(_) -> 0\n }\n}\n" 4 4 5 5 --- 6 - import { throwError } from "../gleam.js"; 6 + import { throwError } from "../gleam.mjs"; 7 7 8 8 function go(x) { 9 9 if (x.isOk()) {
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__case_clause_guards__eq_complex.snap
··· 3 3 expression: "pub fn main(xs, y) {\n case xs {\n #(x) if xs == y -> x\n _ -> 0\n }\n}\n" 4 4 5 5 --- 6 - import { isEqual } from "../gleam.js"; 6 + import { isEqual } from "../gleam.mjs"; 7 7 8 8 export function main(xs, y) { 9 9 if (isEqual(xs, y)) {
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__case_clause_guards__guards_cause_badmatch_to_render.snap
··· 3 3 expression: "pub fn main(x, y) {\n case x {\n 1 -> 1\n _ if y -> 0\n }\n}\n" 4 4 5 5 --- 6 - import { throwError } from "../gleam.js"; 6 + import { throwError } from "../gleam.mjs"; 7 7 8 8 export function main(x, y) { 9 9 if (x === 1) {
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__case_clause_guards__not_eq_complex.snap
··· 3 3 expression: "pub fn main(xs, y) {\n case xs {\n #(x) if xs != y -> x\n _ -> 0\n }\n}\n" 4 4 5 5 --- 6 - import { isEqual } from "../gleam.js"; 6 + import { isEqual } from "../gleam.mjs"; 7 7 8 8 export function main(xs, y) { 9 9 if (!isEqual(xs, y)) {
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__const_imported_ignoring_label.snap
··· 3 3 expression: "import other\npub const main = other.Two(1)\n" 4 4 5 5 --- 6 - import * as $other from "../other.js"; 6 + import * as $other from "../other.mjs"; 7 7 8 8 export const main = new $other.Two(1); 9 9
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__const_imported_multiple_fields.snap
··· 3 3 expression: "import other\npub const main = other.Two(b: 2, c: 3, a: 1)\n" 4 4 5 5 --- 6 - import * as $other from "../other.js"; 6 + import * as $other from "../other.mjs"; 7 7 8 8 export const main = new $other.Two(1, 2, 3); 9 9
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__const_imported_no_label.snap
··· 3 3 expression: "import other\npub const main = other.Two(1)\n" 4 4 5 5 --- 6 - import * as $other from "../other.js"; 6 + import * as $other from "../other.mjs"; 7 7 8 8 export const main = new $other.Two(1); 9 9
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__const_imported_using_label.snap
··· 3 3 expression: "import other\npub const main = other.Two(field: 1)\n" 4 4 5 5 --- 6 - import * as $other from "../other.js"; 6 + import * as $other from "../other.mjs"; 7 7 8 8 export const main = new $other.Two(1); 9 9
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__const_unqualified_imported_ignoring_label.snap
··· 3 3 expression: "import other.{Two}\npub const main = Two(1)\n" 4 4 5 5 --- 6 - import * as $other from "../other.js"; 7 - import { Two } from "../other.js"; 6 + import * as $other from "../other.mjs"; 7 + import { Two } from "../other.mjs"; 8 8 9 9 export const main = new Two(1); 10 10
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__const_unqualified_imported_multiple_fields.snap
··· 3 3 expression: "import other.{Two}\npub const main = Two(b: 2, c: 3, a: 1)\n" 4 4 5 5 --- 6 - import * as $other from "../other.js"; 7 - import { Two } from "../other.js"; 6 + import * as $other from "../other.mjs"; 7 + import { Two } from "../other.mjs"; 8 8 9 9 export const main = new Two(1, 2, 3); 10 10
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__const_unqualified_imported_no_label.snap
··· 3 3 expression: "import other.{Two}\npub const main = Two(1)\n" 4 4 5 5 --- 6 - import * as $other from "../other.js"; 7 - import { Two } from "../other.js"; 6 + import * as $other from "../other.mjs"; 7 + import { Two } from "../other.mjs"; 8 8 9 9 export const main = new Two(1); 10 10
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__const_unqualified_imported_using_label.snap
··· 3 3 expression: "import other.{Two}\npub const main = Two(field: 1)\n" 4 4 5 5 --- 6 - import * as $other from "../other.js"; 7 - import { Two } from "../other.js"; 6 + import * as $other from "../other.mjs"; 7 + import { Two } from "../other.mjs"; 8 8 9 9 export const main = new Two(1); 10 10
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__const_with_fields.snap
··· 3 3 expression: "\ntype Mine {\n Mine(a: Int, b: Int)\n}\n\nconst labels = Mine(b: 2, a: 1)\nconst no_labels = Mine(3, 4)\n" 4 4 5 5 --- 6 - import { CustomType } from "../gleam.js"; 6 + import { CustomType } from "../gleam.mjs"; 7 7 8 8 const labels = new Mine(1, 2); 9 9
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__const_zero_arity_imported.snap
··· 3 3 expression: "import other\nconst x = other.Two\n" 4 4 5 5 --- 6 - import * as $other from "../other.js"; 6 + import * as $other from "../other.mjs"; 7 7 8 8 const x = new $other.Two(); 9 9
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__const_zero_arity_imported_unqualified.snap
··· 3 3 expression: "import other.{Two}\nconst a = Two\n" 4 4 5 5 --- 6 - import * as $other from "../other.js"; 7 - import { Two } from "../other.js"; 6 + import * as $other from "../other.mjs"; 7 + import { Two } from "../other.mjs"; 8 8 9 9 const a = new Two(); 10 10
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__constructor_as_value.snap
··· 3 3 expression: "import other\npub fn main() {\n other.Two\n}" 4 4 5 5 --- 6 - import * as $other from "../other.js"; 6 + import * as $other from "../other.mjs"; 7 7 8 8 export function main() { 9 9 return (var0, var1, var2) => { return new $other.Two(var0, var1, var2); };
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__custom_type_with_named_fields.snap
··· 3 3 expression: "\ntype Cat {\n Cat(name: String, cuteness: Int)\n}\n\nconst felix = Cat(\"Felix\", 12)\nconst tom = Cat(cuteness: 1, name: \"Tom\")\n\nfn go() {\n Cat(\"Nubi\", 1)\n Cat(2, name: \"Nubi\")\n Cat(cuteness: 3, name: \"Nubi\")\n}\n\nfn update(cat) {\n Cat(..cat, name: \"Sid\")\n Cat(..cat, name: \"Bartholemew Wonder Puss the Fourth !!!!!!!!!!!!!!!!\")\n}\n\nfn access(cat: Cat) {\n cat.cuteness\n}\n" 4 4 5 5 --- 6 - import { CustomType } from "../gleam.js"; 6 + import { CustomType } from "../gleam.mjs"; 7 7 8 8 const felix = new Cat("Felix", 12); 9 9
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__destructure_custom_type_with_named_fields.snap
··· 3 3 expression: "\ntype Cat {\n Cat(name: String, cuteness: Int)\n}\n\nfn go(cat) {\n let Cat(x, y) = cat\n let Cat(name: x, ..) = cat\n let Cat(cuteness: 4, name: x) = cat\n x\n}\n\n" 4 4 5 5 --- 6 - import { CustomType, throwError } from "../gleam.js"; 6 + import { CustomType, throwError } from "../gleam.mjs"; 7 7 8 8 class Cat extends CustomType { 9 9 constructor(name, cuteness) {
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__imported_ignoring_label.snap
··· 3 3 expression: "import other\npub fn main() {\n other.Two(1)\n}" 4 4 5 5 --- 6 - import * as $other from "../other.js"; 6 + import * as $other from "../other.mjs"; 7 7 8 8 export function main() { 9 9 return new $other.Two(1);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__imported_multiple_fields.snap
··· 3 3 expression: "import other\npub fn main() {\n other.Two(b: 2, c: 3, a: 1)\n}" 4 4 5 5 --- 6 - import * as $other from "../other.js"; 6 + import * as $other from "../other.mjs"; 7 7 8 8 export function main() { 9 9 return new $other.Two(1, 2, 3);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__imported_no_label.snap
··· 3 3 expression: "import other\npub fn main() {\n other.Two(1)\n}" 4 4 5 5 --- 6 - import * as $other from "../other.js"; 6 + import * as $other from "../other.mjs"; 7 7 8 8 export function main() { 9 9 return new $other.Two(1);
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__imported_pattern.snap
··· 3 3 expression: "import other.{Two}\n\npub fn main(x) {\n case x {\n Two(a: 1, ..) -> 1\n other.Two(b: 2, c: c, ..) -> c\n _ -> 3\n }\n}\n" 4 4 5 5 --- 6 - import * as $other from "../other.js"; 7 - import { Two } from "../other.js"; 6 + import * as $other from "../other.mjs"; 7 + import { Two } from "../other.mjs"; 8 8 9 9 export function main(x) { 10 10 if (x instanceof Two && x.a === 1) {
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__imported_using_label.snap
··· 3 3 expression: "import other\npub fn main() {\n other.Two(field: 1)\n}" 4 4 5 5 --- 6 - import * as $other from "../other.js"; 6 + import * as $other from "../other.mjs"; 7 7 8 8 export function main() { 9 9 return new $other.Two(1);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__keyword_label_name.snap
··· 3 3 expression: "pub type Thing {\n Thing(in: Int, class: Nil)\n}\n" 4 4 5 5 --- 6 - import { CustomType } from "../gleam.js"; 6 + import { CustomType } from "../gleam.mjs"; 7 7 8 8 export class Thing extends CustomType { 9 9 constructor(in$, class$) {
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__long_name_variant_without_labels.snap
··· 3 3 expression: "\ntype TypeWithALongNameAndSeveralArguments{\n TypeWithALongNameAndSeveralArguments(String, String, String, String, String)\n}\n\n\nfn go() {\n TypeWithALongNameAndSeveralArguments\n}\n" 4 4 5 5 --- 6 - import { CustomType } from "../gleam.js"; 6 + import { CustomType } from "../gleam.mjs"; 7 7 8 8 class TypeWithALongNameAndSeveralArguments extends CustomType { 9 9 constructor(x0, x1, x2, x3, x4) {
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__nested_pattern_with_labels.snap
··· 3 3 expression: "pub type Box(x) { Box(a: Int, b: x) }\nfn go(x) {\n case x {\n Box(a: _, b: Box(a: a, b: b)) -> a + b\n _ -> 1\n }\n}\n" 4 4 5 5 --- 6 - import { CustomType } from "../gleam.js"; 6 + import { CustomType } from "../gleam.mjs"; 7 7 8 8 export class Box extends CustomType { 9 9 constructor(a, b) {
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__qualified.snap
··· 3 3 expression: "import other\n\npub fn main() {\n other.One\n}\n" 4 4 5 5 --- 6 - import * as $other from "../other.js"; 6 + import * as $other from "../other.mjs"; 7 7 8 8 export function main() { 9 9 return new $other.One();
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__unnamed_fields.snap
··· 3 3 expression: "\ntype Ip{\n Ip(String)\n}\n\nconst local = Ip(\"0.0.0.0\")\n\nfn build(x) {\n x(\"1.2.3.4\")\n}\n\nfn go() {\n build(Ip)\n Ip(\"5.6.7.8\")\n}\n\nfn destructure(x) {\n let Ip(raw) = x\n raw\n}\n" 4 4 5 5 --- 6 - import { CustomType, throwError } from "../gleam.js"; 6 + import { CustomType, throwError } from "../gleam.mjs"; 7 7 8 8 const local = new Ip("0.0.0.0"); 9 9
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__unqualified_constructor_as_value.snap
··· 3 3 expression: "import other.{Two}\npub fn main() {\n Two\n}" 4 4 5 5 --- 6 - import * as $other from "../other.js"; 7 - import { Two } from "../other.js"; 6 + import * as $other from "../other.mjs"; 7 + import { Two } from "../other.mjs"; 8 8 9 9 export function main() { 10 10 return (var0, var1, var2) => { return new Two(var0, var1, var2); };
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__unqualified_imported_ignoring_label.snap
··· 3 3 expression: "import other.{Two}\npub fn main() {\n Two(1)\n}" 4 4 5 5 --- 6 - import * as $other from "../other.js"; 7 - import { Two } from "../other.js"; 6 + import * as $other from "../other.mjs"; 7 + import { Two } from "../other.mjs"; 8 8 9 9 export function main() { 10 10 return new Two(1);
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__unqualified_imported_multiple_fields.snap
··· 3 3 expression: "import other.{Two}\npub fn main() {\n Two(b: 2, c: 3, a: 1)\n}" 4 4 5 5 --- 6 - import * as $other from "../other.js"; 7 - import { Two } from "../other.js"; 6 + import * as $other from "../other.mjs"; 7 + import { Two } from "../other.mjs"; 8 8 9 9 export function main() { 10 10 return new Two(1, 2, 3);
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__unqualified_imported_no_label.snap
··· 3 3 expression: "import other.{Two}\npub fn main() {\n Two(1)\n}" 4 4 5 5 --- 6 - import * as $other from "../other.js"; 7 - import { Two } from "../other.js"; 6 + import * as $other from "../other.mjs"; 7 + import { Two } from "../other.mjs"; 8 8 9 9 export function main() { 10 10 return new Two(1);
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__unqualified_imported_using_label.snap
··· 3 3 expression: "import other.{Two}\npub fn main() {\n Two(field: 1)\n}" 4 4 5 5 --- 6 - import * as $other from "../other.js"; 7 - import { Two } from "../other.js"; 6 + import * as $other from "../other.mjs"; 7 + import { Two } from "../other.mjs"; 8 8 9 9 export function main() { 10 10 return new Two(1);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__zero_arity_const.snap
··· 3 3 expression: "\ntype Mine {\n This\n ThatOneIsAMuchMuchMuchMuchMuchMuchMuchMuchMuchMuchMuchMuchLongerVariant\n}\n\nconst this = This;\nconst that = ThatOneIsAMuchMuchMuchMuchMuchMuchMuchMuchMuchMuchMuchMuchLongerVariant;\n" 4 4 5 5 --- 6 - import { CustomType } from "../gleam.js"; 6 + import { CustomType } from "../gleam.mjs"; 7 7 8 8 const this$ = new This(); 9 9
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__zero_arity_imported.snap
··· 3 3 expression: "import other\npub fn main() {\n other.Two\n}" 4 4 5 5 --- 6 - import * as $other from "../other.js"; 6 + import * as $other from "../other.mjs"; 7 7 8 8 export function main() { 9 9 return new $other.Two();
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__zero_arity_imported_unqualified.snap
··· 3 3 expression: "import other.{Two}\npub fn main() {\n Two\n}" 4 4 5 5 --- 6 - import * as $other from "../other.js"; 7 - import { Two } from "../other.js"; 6 + import * as $other from "../other.mjs"; 7 + import { Two } from "../other.mjs"; 8 8 9 9 export function main() { 10 10 return new Two();
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__zero_arity_imported_unqualified_aliased.snap
··· 3 3 expression: "import other.{Two as Three}\npub fn main() {\n Three\n}" 4 4 5 5 --- 6 - import * as $other from "../other.js"; 7 - import { Two as Three } from "../other.js"; 6 + import * as $other from "../other.mjs"; 7 + import { Two as Three } from "../other.mjs"; 8 8 9 9 export function main() { 10 10 return new Three();
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__zero_arity_literal.snap
··· 3 3 expression: "\ntype Mine {\n This\n ThatOneIsAMuchMuchMuchMuchMuchMuchMuchMuchMuchMuchMuchMuchLongerVariant\n}\n\nfn go() {\n This\n ThatOneIsAMuchMuchMuchMuchMuchMuchMuchMuchMuchMuchMuchMuchLongerVariant\n}\n" 4 4 5 5 --- 6 - import { CustomType } from "../gleam.js"; 6 + import { CustomType } from "../gleam.mjs"; 7 7 8 8 class This extends CustomType {} 9 9
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__externals__duplicate_import.snap
··· 1 1 --- 2 2 source: compiler-core/src/javascript/tests/externals.rs 3 - expression: "pub external fn one() -> Nil = \"./the/module.js\" \"dup\"\npub external fn two() -> Nil = \"./the/module.js\" \"dup\"\n" 3 + expression: "pub external fn one() -> Nil = \"./the/module.mjs\" \"dup\"\npub external fn two() -> Nil = \"./the/module.mjs\" \"dup\"\n" 4 4 5 5 --- 6 - import { dup as one, dup as two } from "./the/module.js"; 6 + import { dup as one, dup as two } from "./the/module.mjs"; 7 7 8 8 export { one, two }; 9 9
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__externals__name_to_escape.snap
··· 1 1 --- 2 2 source: compiler-core/src/javascript/tests/externals.rs 3 - expression: "pub external fn class() -> Nil = \"./the/module.js\" \"one\"\n" 3 + expression: "pub external fn class() -> Nil = \"./the/module.mjs\" \"one\"\n" 4 4 5 5 --- 6 - import { one as class$ } from "./the/module.js"; 6 + import { one as class$ } from "./the/module.mjs"; 7 7 8 8 export { class$ }; 9 9
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__externals__same_module_multiple_imports.snap
··· 1 1 --- 2 2 source: compiler-core/src/javascript/tests/externals.rs 3 - expression: "pub external fn one() -> Nil = \"./the/module.js\" \"one\"\npub external fn two() -> Nil = \"./the/module.js\" \"two\"\n" 3 + expression: "pub external fn one() -> Nil = \"./the/module.mjs\" \"one\"\npub external fn two() -> Nil = \"./the/module.mjs\" \"two\"\n" 4 4 5 5 --- 6 - import { one, two } from "./the/module.js"; 6 + import { one, two } from "./the/module.mjs"; 7 7 8 8 export { one, two }; 9 9
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__functions__reserved_word_imported.snap
··· 3 3 expression: "import for.{class}\n\npub fn export() {\n class()\n}\n" 4 4 5 5 --- 6 - import * as $for from "../for.js"; 7 - import { class$ } from "../for.js"; 6 + import * as $for from "../for.mjs"; 7 + import { class$ } from "../for.mjs"; 8 8 9 9 export function export$() { 10 10 return class$();
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__functions__reserved_word_imported_alias.snap
··· 3 3 expression: "import for.{class as while} as function\n\npub fn export() {\n let delete = function.class\n while()\n}\n" 4 4 5 5 --- 6 - import * as $function from "../for.js"; 7 - import { class$ as while$ } from "../for.js"; 6 + import * as $function from "../for.mjs"; 7 + import { class$ as while$ } from "../for.mjs"; 8 8 9 9 export function export$() { 10 10 let delete$ = $function.class$;
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__functions__tail_call.snap
··· 3 3 expression: "\npub fn count(xs, n) {\n case xs {\n [] -> n\n [_, ..xs] -> count(xs, n + 1)\n }\n}\n" 4 4 5 5 --- 6 - import { throwError } from "../gleam.js"; 6 + import { throwError } from "../gleam.mjs"; 7 7 8 8 export function count(loop$xs, loop$n) { 9 9 let xs = loop$xs;
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__functions__tail_call_doesnt_clobber_tail_position_tracking.snap
··· 3 3 expression: "\npub fn loop(indentation) {\n case indentation > 0 {\n True -> loop(indentation - 1)\n False -> Nil\n }\n}\n" 4 4 5 5 --- 6 - import { throwError } from "../gleam.js"; 6 + import { throwError } from "../gleam.mjs"; 7 7 8 8 export function loop(loop$indentation) { 9 9 let indentation = loop$indentation;
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__lists__equality.snap
··· 3 3 expression: "\nfn go() {\n [] == [1]\n [] != [1]\n}\n" 4 4 5 5 --- 6 - import { toList, isEqual } from "../gleam.js"; 6 + import { toList, isEqual } from "../gleam.mjs"; 7 7 8 8 function go() { 9 9 isEqual(toList([]), toList([1]));
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__lists__list_constants.snap
··· 3 3 expression: "\nconst a = []\nconst b = [1, 2, 3]\n" 4 4 5 5 --- 6 - import { toList } from "../gleam.js"; 6 + import { toList } from "../gleam.mjs"; 7 7 8 8 const a = toList([]); 9 9
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__lists__list_destructuring.snap
··· 3 3 expression: "\nfn go(x, y) {\n let [] = x\n let [a] = x\n let [1, 2] = x\n let [_, #(3, b)] = y\n let [head, ..tail] = y\n}\n" 4 4 5 5 --- 6 - import { throwError } from "../gleam.js"; 6 + import { throwError } from "../gleam.mjs"; 7 7 8 8 function go(x, y) { 9 9 if (!x.hasLength(0)) {
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__lists__list_literals.snap
··· 3 3 expression: "\nfn go(x) {\n []\n [1]\n [1, 2]\n [1, 2, ..x]\n}\n" 4 4 5 5 --- 6 - import { toList } from "../gleam.js"; 6 + import { toList } from "../gleam.mjs"; 7 7 8 8 function go(x) { 9 9 toList([]);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__lists__long_list_literals.snap
··· 3 3 expression: "\nfn go() {\n [111111111111111111111111111111111111111111111111111111111111111111111111]\n [11111111111111111111111111111111111111111111, 1111111111111111111111111111111111111111111]\n}\n" 4 4 5 5 --- 6 - import { toList } from "../gleam.js"; 6 + import { toList } from "../gleam.mjs"; 7 7 8 8 function go() { 9 9 toList([
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__lists__multi_line_list_literals.snap
··· 3 3 expression: "\nfn go(x) {\n [{True; 1}]\n}\n" 4 4 5 5 --- 6 - import { toList } from "../gleam.js"; 6 + import { toList } from "../gleam.mjs"; 7 7 8 8 function go(x) { 9 9 return toList([
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__modules__alias_constant.snap
··· 3 3 expression: "\nimport rocket_ship as boop\npub fn go() { boop.x }\n" 4 4 5 5 --- 6 - import * as $boop from "../rocket_ship.js"; 6 + import * as $boop from "../rocket_ship.mjs"; 7 7 8 8 export function go() { 9 9 return $boop.x;
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__modules__alias_fn_call.snap
··· 3 3 expression: "\nimport rocket_ship as boop\npub fn go() { boop.go() }\n" 4 4 5 5 --- 6 - import * as $boop from "../rocket_ship.js"; 6 + import * as $boop from "../rocket_ship.mjs"; 7 7 8 8 export function go() { 9 9 return $boop.go();
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__modules__aliased_unqualified_fn_call.snap
··· 3 3 expression: "import rocket_ship.{launch as boom_time}\npub fn go() { boom_time() }\n" 4 4 5 5 --- 6 - import * as $rocket_ship from "../rocket_ship.js"; 7 - import { launch as boom_time } from "../rocket_ship.js"; 6 + import * as $rocket_ship from "../rocket_ship.mjs"; 7 + import { launch as boom_time } from "../rocket_ship.mjs"; 8 8 9 9 export function go() { 10 10 return boom_time();
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__modules__constant.snap
··· 3 3 expression: "\nimport rocket_ship\npub fn go() { rocket_ship.x }\n" 4 4 5 5 --- 6 - import * as $rocket_ship from "../rocket_ship.js"; 6 + import * as $rocket_ship from "../rocket_ship.mjs"; 7 7 8 8 export function go() { 9 9 return $rocket_ship.x;
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__modules__different_package_import.snap
··· 3 3 expression: "import one\npub fn go() { one.go() }\n" 4 4 5 5 --- 6 - import * as $one from "gleam-packages/other_package/one.js"; 6 + import * as $one from "gleam-packages/other_package/one.mjs"; 7 7 8 8 export function go() { 9 9 return $one.go();
+3 -3
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__modules__imported_custom_types_dont_get_rendered.snap
··· 3 3 expression: "import one/two/three.{Custom, One, Two}\n\npub fn go() -> List(Custom) { [One, Two] }\n" 4 4 5 5 --- 6 - import { toList } from "../gleam.js"; 7 - import * as $three from "../one/two/three.js"; 8 - import { One, Two } from "../one/two/three.js"; 6 + import { toList } from "../gleam.mjs"; 7 + import * as $three from "../one/two/three.mjs"; 8 + import { One, Two } from "../one/two/three.mjs"; 9 9 10 10 export function go() { 11 11 return toList([new One(), new Two()]);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__modules__imported_external_types_dont_get_rendered.snap
··· 3 3 expression: "import one/two/three.{External}\n\npub fn go() { 1 }\n" 4 4 5 5 --- 6 - import * as $three from "../one/two/three.js"; 6 + import * as $three from "../one/two/three.mjs"; 7 7 8 8 export function go() { 9 9 return 1;
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__modules__imported_external_types_dont_get_rendered_with_value_of_same_name.snap
··· 3 3 expression: "import one/two/three.{Thingy}\n\ntype Dup { Thingy }\n\npub fn go(x: Thingy) -> List(Thingy) { [x, x] }\n" 4 4 5 5 --- 6 - import { toList, CustomType } from "../gleam.js"; 7 - import * as $three from "../one/two/three.js"; 6 + import { toList, CustomType } from "../gleam.mjs"; 7 + import * as $three from "../one/two/three.mjs"; 8 8 9 9 class Thingy extends CustomType {} 10 10
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__modules__multiple_unqualified_fn_call.snap
··· 3 3 expression: "import rocket_ship.{a,b as bb}\npub fn go() { a() + bb() }\n" 4 4 5 5 --- 6 - import * as $rocket_ship from "../rocket_ship.js"; 7 - import { a, b as bb } from "../rocket_ship.js"; 6 + import * as $rocket_ship from "../rocket_ship.mjs"; 7 + import { a, b as bb } from "../rocket_ship.mjs"; 8 8 9 9 export function go() { 10 10 return a() + bb();
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__modules__nested_fn_call.snap
··· 3 3 expression: "import one/two\npub fn go() { two.go() }" 4 4 5 5 --- 6 - import * as $two from "../one/two.js"; 6 + import * as $two from "../one/two.mjs"; 7 7 8 8 export function go() { 9 9 return $two.go();
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__modules__nested_nested_fn_call.snap
··· 3 3 expression: "import one/two/three\npub fn go() { three.go() }" 4 4 5 5 --- 6 - import * as $three from "../one/two/three.js"; 6 + import * as $three from "../one/two/three.mjs"; 7 7 8 8 export function go() { 9 9 return $three.go();
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__modules__nested_same_package.snap
··· 3 3 expression: "import one/two/three\npub fn go() { three.go() }\n" 4 4 5 5 --- 6 - import * as $three from "../one/two/three.js"; 6 + import * as $three from "../one/two/three.mjs"; 7 7 8 8 export function go() { 9 9 return $three.go();
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__modules__same_import_multiple_times.snap
··· 3 3 expression: "import one/two/three.{one}\nimport one/two/three.{two}\n\npub fn go() { one() + two() }\n" 4 4 5 5 --- 6 - import * as $three from "../one/two/three.js"; 7 - import { one, two } from "../one/two/three.js"; 6 + import * as $three from "../one/two/three.mjs"; 7 + import { one, two } from "../one/two/three.mjs"; 8 8 9 9 export function go() { 10 10 return one() + two();
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__modules__unqualified_fn_call.snap
··· 3 3 expression: "import rocket_ship.{launch}\npub fn go() { launch() }\n" 4 4 5 5 --- 6 - import * as $rocket_ship from "../rocket_ship.js"; 7 - import { launch } from "../rocket_ship.js"; 6 + import * as $rocket_ship from "../rocket_ship.mjs"; 7 + import { launch } from "../rocket_ship.mjs"; 8 8 9 9 export function go() { 10 10 return launch();
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__numbers__float_operators.snap
··· 3 3 expression: "\nfn go() {\n 1.0 +. 1.4 // => 2.4\n 5.0 -. 1.5 // => 3.5\n 5.0 /. 2.0 // => 2.5\n 3.0 *. 3.1 // => 9.3\n \n 2.0 >. 1.0 // => True\n 2.0 <. 1.0 // => False\n 2.0 >=. 1.0 // => True\n 2.0 <=. 1.0 // => False\n}\n" 4 4 5 5 --- 6 - import { divideFloat } from "../gleam.js"; 6 + import { divideFloat } from "../gleam.mjs"; 7 7 8 8 function go() { 9 9 1.0 + 1.4;
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__numbers__int_operators.snap
··· 3 3 expression: "\nfn go() {\n 1 + 1 // => 2\n 5 - 1 // => 4\n 5 / 2 // => 2\n 3 * 3 // => 9\n 5 % 2 // => 1\n 2 > 1 // => True\n 2 < 1 // => False\n 2 >= 1 // => True\n 2 <= 1 // => False\n}\n" 4 4 5 5 --- 6 - import { divideInt } from "../gleam.js"; 6 + import { divideInt } from "../gleam.mjs"; 7 7 8 8 function go() { 9 9 1 + 1;
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__numbers__int_patterns.snap
··· 3 3 expression: "\nfn go(x) {\n let 4 = x\n}\n" 4 4 5 5 --- 6 - import { throwError } from "../gleam.js"; 6 + import { throwError } from "../gleam.mjs"; 7 7 8 8 function go(x) { 9 9 if (x !== 4) {
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__numbers__wide_float_div.snap
··· 3 3 expression: "\nfn go() {\n 111111111111111111111111111111. /. 22222222222222222222222222222222222.\n}\n" 4 4 5 5 --- 6 - import { divideFloat } from "../gleam.js"; 6 + import { divideFloat } from "../gleam.mjs"; 7 7 8 8 function go() { 9 9 return divideFloat(
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__prelude__qualified_error.snap
··· 3 3 expression: "import gleam\npub fn go() { gleam.Error(1) }\n" 4 4 5 5 --- 6 - import * as $gleam from "../gleam.js"; 6 + import * as $gleam from "../gleam.mjs"; 7 7 8 8 export function go() { 9 9 return new $gleam.Error(1);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__prelude__qualified_nil.snap
··· 3 3 expression: "import gleam\npub fn go() { gleam.Nil }\n" 4 4 5 5 --- 6 - import * as $gleam from "../gleam.js"; 6 + import * as $gleam from "../gleam.mjs"; 7 7 8 8 export function go() { 9 9 return undefined;
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__prelude__qualified_ok.snap
··· 3 3 expression: "import gleam\npub fn go() { gleam.Ok(1) }\n" 4 4 5 5 --- 6 - import * as $gleam from "../gleam.js"; 6 + import * as $gleam from "../gleam.mjs"; 7 7 8 8 export function go() { 9 9 return new $gleam.Ok(1);
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__results__aliased_error.snap
··· 3 3 expression: "import gleam.{Error as Thing}\npub fn main() { Thing(1) }" 4 4 5 5 --- 6 - import * as $gleam from "../gleam.js"; 7 - import { Error as Thing } from "../gleam.js"; 6 + import * as $gleam from "../gleam.mjs"; 7 + import { Error as Thing } from "../gleam.mjs"; 8 8 9 9 export function main() { 10 10 return new Thing(1);
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__results__aliased_error_fn.snap
··· 3 3 expression: "import gleam.{Error as Thing}\npub fn main() { Thing }" 4 4 5 5 --- 6 - import * as $gleam from "../gleam.js"; 7 - import { Error as Thing } from "../gleam.js"; 6 + import * as $gleam from "../gleam.mjs"; 7 + import { Error as Thing } from "../gleam.mjs"; 8 8 9 9 export function main() { 10 10 return (var0) => { return new Thing(var0); };
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__results__aliased_ok.snap
··· 3 3 expression: "import gleam.{Ok as Thing}\npub fn main() { Thing(1) }" 4 4 5 5 --- 6 - import * as $gleam from "../gleam.js"; 7 - import { Ok as Thing } from "../gleam.js"; 6 + import * as $gleam from "../gleam.mjs"; 7 + import { Ok as Thing } from "../gleam.mjs"; 8 8 9 9 export function main() { 10 10 return new Thing(1);
+2 -2
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__results__aliased_ok_fn.snap
··· 3 3 expression: "import gleam.{Ok as Thing}\npub fn main() { Thing }" 4 4 5 5 --- 6 - import * as $gleam from "../gleam.js"; 7 - import { Ok as Thing } from "../gleam.js"; 6 + import * as $gleam from "../gleam.mjs"; 7 + import { Ok as Thing } from "../gleam.mjs"; 8 8 9 9 export function main() { 10 10 return (var0) => { return new Thing(var0); };
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__results__error.snap
··· 3 3 expression: "pub fn main() { Error(1) }" 4 4 5 5 --- 6 - import { Error } from "../gleam.js"; 6 + import { Error } from "../gleam.mjs"; 7 7 8 8 export function main() { 9 9 return new Error(1);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__results__error_fn.snap
··· 3 3 expression: "pub fn main() { Error }" 4 4 5 5 --- 6 - import { Error } from "../gleam.js"; 6 + import { Error } from "../gleam.mjs"; 7 7 8 8 export function main() { 9 9 return (var0) => { return new Error(var0); };
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__results__ok.snap
··· 3 3 expression: "pub fn main() { Ok(1) }" 4 4 5 5 --- 6 - import { Ok } from "../gleam.js"; 6 + import { Ok } from "../gleam.mjs"; 7 7 8 8 export function main() { 9 9 return new Ok(1);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__results__ok_fn.snap
··· 3 3 expression: "pub fn main() { Ok }" 4 4 5 5 --- 6 - import { Ok } from "../gleam.js"; 6 + import { Ok } from "../gleam.mjs"; 7 7 8 8 export function main() { 9 9 return (var0) => { return new Ok(var0); };
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__results__qualified_error.snap
··· 3 3 expression: "import gleam\npub fn main() { gleam.Error(1) }" 4 4 5 5 --- 6 - import * as $gleam from "../gleam.js"; 6 + import * as $gleam from "../gleam.mjs"; 7 7 8 8 export function main() { 9 9 return new $gleam.Error(1);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__results__qualified_error_fn.snap
··· 3 3 expression: "import gleam\npub fn main() { gleam.Error }" 4 4 5 5 --- 6 - import * as $gleam from "../gleam.js"; 6 + import * as $gleam from "../gleam.mjs"; 7 7 8 8 export function main() { 9 9 return (var0) => { return new $gleam.Error(var0); };
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__results__qualified_ok.snap
··· 3 3 expression: "import gleam\npub fn main() { gleam.Ok(1) }" 4 4 5 5 --- 6 - import * as $gleam from "../gleam.js"; 6 + import * as $gleam from "../gleam.mjs"; 7 7 8 8 export function main() { 9 9 return new $gleam.Ok(1);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__results__qualified_ok_fn.snap
··· 3 3 expression: "import gleam\npub fn main() { gleam.Ok }" 4 4 5 5 --- 6 - import * as $gleam from "../gleam.js"; 6 + import * as $gleam from "../gleam.mjs"; 7 7 8 8 export function main() { 9 9 return (var0) => { return new $gleam.Ok(var0); };
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__strings__string_patterns.snap
··· 3 3 expression: "\nfn go(x) {\n let \"Hello\" = x\n}\n" 4 4 5 5 --- 6 - import { throwError } from "../gleam.js"; 6 + import { throwError } from "../gleam.mjs"; 7 7 8 8 function go(x) { 9 9 if (x !== "Hello") {
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__todo__as_expression.snap
··· 3 3 expression: "\nfn go(f) {\n let boop = todo(\"I should do this\")\n f(todo(\"Boom\"))\n};\n" 4 4 5 5 --- 6 - import { throwError } from "../gleam.js"; 6 + import { throwError } from "../gleam.mjs"; 7 7 8 8 function go(f) { 9 9 let boop = (() => {
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__todo__with_message.snap
··· 3 3 expression: "\nfn go() {\n todo(\"I should do this\")\n};\n" 4 4 5 5 --- 6 - import { throwError } from "../gleam.js"; 6 + import { throwError } from "../gleam.mjs"; 7 7 8 8 function go() { 9 9 throwError("todo", "my/mod", 3, "go", "I should do this", {});
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__todo__without_message.snap
··· 3 3 expression: "\nfn go() {\n todo\n}\n" 4 4 5 5 --- 6 - import { throwError } from "../gleam.js"; 6 + import { throwError } from "../gleam.mjs"; 7 7 8 8 function go() { 9 9 throwError("todo", "my/mod", 3, "go", "This has not yet been implemented", {});
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__try___assert_in_block.snap
··· 3 3 expression: "pub fn main(x) {\n assert Ok(y) = {\n try z = x\n Ok(z + 1)\n }\n y\n}" 4 4 5 5 --- 6 - import { Ok, throwError } from "../gleam.js"; 6 + import { Ok, throwError } from "../gleam.mjs"; 7 7 8 8 export function main(x) { 9 9 let $ = (() => {
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__try___in_block.snap
··· 3 3 expression: "pub fn main(x) {\n let y = {\n try z = x\n Ok(z + 1)\n }\n y\n}" 4 4 5 5 --- 6 - import { Ok } from "../gleam.js"; 6 + import { Ok } from "../gleam.mjs"; 7 7 8 8 export function main(x) { 9 9 let y = (() => {
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__try___rebinding.snap
··· 3 3 expression: "pub fn main(x) {\n try x = x\n try x = x\n Ok(x)\n}" 4 4 5 5 --- 6 - import { Ok } from "../gleam.js"; 6 + import { Ok } from "../gleam.mjs"; 7 7 8 8 export function main(x) { 9 9 if (!x.isOk()) return x;
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__try___top.snap
··· 3 3 expression: "pub fn main(x) {\n try y = x\n try z = y\n Ok(z)\n}" 4 4 5 5 --- 6 - import { Ok } from "../gleam.js"; 6 + import { Ok } from "../gleam.mjs"; 7 7 8 8 export function main(x) { 9 9 if (!x.isOk()) return x;
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__try___with_subpattern.snap
··· 3 3 expression: "pub fn main(x) {\n try #(a, b) = x\n try #(1, 2) = x\n try #(a, 2) = Ok(#(1, 2))\n Ok(x)\n}" 4 4 5 5 --- 6 - import { Ok, throwError } from "../gleam.js"; 6 + import { Ok, throwError } from "../gleam.mjs"; 7 7 8 8 export function main(x) { 9 9 if (!x.isOk()) return x;
+1 -1
test/javascript_prelude/.gitignore
··· 1 - prelude.js 1 + prelude.*js
+3 -2
test/javascript_prelude/Makefile
··· 1 1 .PHONY: test 2 2 test: 3 3 @echo test/javascript_prelude 4 - @cp ../../compiler-core/templates/prelude.js . 5 - @node main.js 4 + @cp ../../compiler-core/templates/prelude.js prelude.mjs 5 + @node main.mjs 6 + @rm prelude.mjs
-545
test/javascript_prelude/main.js
··· 1 - import { 2 - BitString, 3 - CustomType, 4 - Empty, 5 - Error, 6 - List, 7 - NonEmpty, 8 - Ok, 9 - UtfCodepoint, 10 - codepointBits, 11 - divideFloat, 12 - divideInt, 13 - inspect, 14 - isEqual, 15 - stringBits, 16 - toBitString, 17 - toList, 18 - } from "./prelude.js"; 19 - 20 - let failures = 0; 21 - let passes = 0; 22 - 23 - function pass() { 24 - process.stdout.write(`\u001b[${32}m.\u001b[${0}m`); 25 - passes++; 26 - } 27 - 28 - function fail(message) { 29 - console.log(""); 30 - console.assert(false, message); 31 - failures++; 32 - } 33 - 34 - function assertEqual(a, b) { 35 - if (isEqual(a, b)) { 36 - pass(); 37 - } else { 38 - fail(`\n\t${inspect(a)}\n\t!=\n\t${inspect(b)}`); 39 - } 40 - } 41 - 42 - function assertNotEqual(a, b) { 43 - if (isEqual(a, b)) { 44 - fail(`\n\t${inspect(a)}\n\t==\n\t${inspect(b)}`); 45 - } else { 46 - pass(); 47 - } 48 - } 49 - 50 - class ExampleRecordImpl extends CustomType { 51 - constructor(first, detail, boop) { 52 - super(); 53 - this[0] = first; 54 - this.detail = detail; 55 - this.boop = boop; 56 - } 57 - } 58 - 59 - let fmt = new Intl.DateTimeFormat("en-GB", { timeStyle: "medium" }); 60 - console.log(`Running tests at ${fmt.format(new Date())}\n`); 61 - 62 - // Equality of Gleam values 63 - 64 - assertEqual(true, true); 65 - assertEqual(false, false); 66 - assertEqual(undefined, undefined); 67 - assertNotEqual(true, false); 68 - assertNotEqual(false, true); 69 - assertNotEqual(undefined, false); 70 - assertNotEqual(undefined, true); 71 - assertNotEqual(true, undefined); 72 - assertNotEqual(false, undefined); 73 - 74 - assertEqual(1, 1); 75 - assertNotEqual(1, 2); 76 - assertEqual(1.1, 1.1); 77 - assertNotEqual(2.1, 1.1); 78 - assertEqual(-1, -1); 79 - assertNotEqual(-1, 1); 80 - assertEqual(-1.1, -1.1); 81 - assertNotEqual(-1.1, 1.1); 82 - 83 - assertEqual("", ""); 84 - assertEqual("123", "123"); 85 - assertEqual("👽", "👽"); 86 - assertNotEqual("👽", "👾"); 87 - 88 - assertEqual(new Ok(1), new Ok(1)); 89 - assertEqual(new Ok(2), new Ok(2)); 90 - assertEqual(new Ok(new Ok(2)), new Ok(new Ok(2))); 91 - assertNotEqual(new Ok(1), new Ok(2)); 92 - assertNotEqual(new Ok(new Ok(2)), new Ok(new Ok(3))); 93 - 94 - assertEqual(new Error(1), new Error(1)); 95 - assertEqual(new Error(2), new Error(2)); 96 - assertEqual(new Error(new Error(2)), new Error(new Error(2))); 97 - assertNotEqual(new Error(2), new Error(3)); 98 - assertNotEqual(new Error(new Error(2)), new Error(new Error(3))); 99 - 100 - assertEqual( 101 - new ExampleRecordImpl(undefined, 1, new Ok(2.1)), 102 - new ExampleRecordImpl(undefined, 1, new Ok(2.1)) 103 - ); 104 - assertNotEqual( 105 - new ExampleRecordImpl(undefined, 1, new Ok("2.1")), 106 - new ExampleRecordImpl(undefined, 1, new Ok(2.1)) 107 - ); 108 - 109 - assertEqual(List.fromArray([]), List.fromArray([])); 110 - assertEqual( 111 - List.fromArray([1, 2, new Ok(1)]), 112 - List.fromArray([1, 2, new Ok(1)]) 113 - ); 114 - assertNotEqual( 115 - List.fromArray([1, 2, new Ok(1)]), 116 - List.fromArray([1, 2, new Ok(2)]) 117 - ); 118 - assertNotEqual(List.fromArray([1, 2]), List.fromArray([1, 2, new Ok(2)])); 119 - assertNotEqual(List.fromArray([1]), List.fromArray([])); 120 - assertNotEqual(List.fromArray([]), List.fromArray([1])); 121 - 122 - assertEqual( 123 - new BitString(new Uint8Array([])), 124 - new BitString(new Uint8Array([])) 125 - ); 126 - assertEqual( 127 - new BitString(new Uint8Array([1, 2, 3])), 128 - new BitString(new Uint8Array([1, 2, 3])) 129 - ); 130 - assertNotEqual( 131 - new BitString(new Uint8Array([1, 2])), 132 - new BitString(new Uint8Array([1, 2, 3])) 133 - ); 134 - 135 - assertEqual(new UtfCodepoint(128013), new UtfCodepoint(128013)); 136 - assertNotEqual(new UtfCodepoint(128013), new UtfCodepoint(128014)); 137 - 138 - // toBitString 139 - 140 - assertEqual(new BitString(new Uint8Array([])), toBitString([])); 141 - 142 - assertEqual( 143 - new BitString(new Uint8Array([97, 98, 99])), 144 - toBitString([stringBits("abc")]) 145 - ); 146 - 147 - assertEqual( 148 - new BitString(new Uint8Array([97])), 149 - toBitString([codepointBits(new UtfCodepoint(97))]) 150 - ); 151 - 152 - assertEqual( 153 - new BitString(new Uint8Array([240, 159, 144, 141])), 154 - toBitString([codepointBits(new UtfCodepoint(128013))]) 155 - ); 156 - 157 - // toList 158 - 159 - assertEqual(toList([]), List.fromArray([])); 160 - assertEqual(toList([1, 2, 3]), List.fromArray([1, 2, 3])); 161 - assertEqual(toList([1, 2], toList([3, 4])), List.fromArray([1, 2, 3, 4])); 162 - assertEqual(toList([1, 2, 3], toList([4, 5])), List.fromArray([1, 2, 3, 4, 5])); 163 - 164 - // Equality of JavaScript values 165 - 166 - assertEqual([], []); 167 - assertEqual([1, 2], [1, 2]); 168 - assertEqual([new Ok([1, 2])], [new Ok([1, 2])]); 169 - assertNotEqual([], [[]]); 170 - assertNotEqual([], [1, []]); 171 - assertNotEqual([1, []], []); 172 - 173 - assertEqual({}, {}); 174 - assertEqual({ a: 1 }, { a: 1 }); 175 - assertEqual({ a: 1, b: 2 }, { b: 2, a: 1 }); 176 - assertEqual({ a: new Ok(1) }, { a: new Ok(1) }); 177 - assertNotEqual({ a: new Ok(2) }, { a: new Ok(1) }); 178 - 179 - assertEqual(new Date(0), new Date(0)); 180 - assertNotEqual(new Date(1), new Date(0)); 181 - 182 - assertEqual(new Uint8Array([1, 2]), new Uint8Array([1, 2])); 183 - assertEqual(new Uint16Array([1, 2]), new Uint16Array([1, 2])); 184 - assertEqual(new Uint32Array([1, 2]), new Uint32Array([1, 2])); 185 - assertNotEqual(new Uint8Array([1, 3]), new Uint8Array([1, 2])); 186 - assertNotEqual(new Uint16Array([1, 3]), new Uint16Array([1, 2])); 187 - assertNotEqual(new Uint32Array([1, 3]), new Uint32Array([1, 2])); 188 - 189 - // Promises are not equal unless they have reference equality 190 - let promise = Promise.resolve(1); 191 - assertEqual(promise, promise); 192 - assertNotEqual(Promise.resolve(1), Promise.resolve(1)); 193 - 194 - // Functions are not equal unless they have reference equality 195 - let fun = () => 1; 196 - assertEqual(fun, fun); 197 - assertNotEqual( 198 - () => 1, 199 - () => 1 200 - ); 201 - 202 - // Maps are compared structurally 203 - let map = new Map([["a", 1]]); 204 - assertEqual(map, map); 205 - assertEqual(new Map([["a", 1]]), new Map([["a", 1]])); 206 - assertNotEqual( 207 - new Map([ 208 - ["a", 1], 209 - ["b", 2], 210 - ]), 211 - new Map([["a", 1]]) 212 - ); 213 - assertNotEqual( 214 - new Map([["a", 1]]), 215 - new Map([ 216 - ["a", 1], 217 - ["b", 2], 218 - ]) 219 - ); 220 - assertNotEqual(new Map([["a", 1]]), new Map([["b", 1]])); 221 - assertEqual( 222 - new Map([["a", new Map([["a", []]])]]), 223 - new Map([["a", new Map([["a", []]])]]) 224 - ); 225 - 226 - // Sets are compared structurally 227 - let set = new Set(["a", 1]); 228 - assertEqual(set, set); 229 - assertEqual(new Set(["a", 1]), new Set(["a", 1])); 230 - assertNotEqual(new Set(["a", 1]), new Set(["b", 1])); 231 - assertNotEqual(new Set(["a", 1, "b"]), new Set(["a", 1])); 232 - assertNotEqual(new Set(["a", 1]), new Set(["a", 1, "b"])); 233 - assertNotEqual( 234 - new Set(["a", new Map([["a", []]])]), 235 - new Set(["a", new Map([["a", []]])]) 236 - ); 237 - 238 - // WeakMaps are not equal unless they have reference equality 239 - let weak_map = new WeakMap([[map, 1]]); 240 - assertEqual(weak_map, weak_map); 241 - assertNotEqual(new WeakMap([[map, 1]]), new WeakMap([[map, 1]])); 242 - 243 - // WeakSets are not equal unless they have reference equality 244 - let weak_set = new WeakSet([map, set]); 245 - assertEqual(weak_set, weak_set); 246 - assertNotEqual(new WeakSet([map, set]), new WeakSet([map, set])); 247 - 248 - class ExampleA { 249 - constructor(x) { 250 - this.x = x; 251 - } 252 - } 253 - 254 - class ExampleB { 255 - constructor(x) { 256 - this.x = x; 257 - } 258 - } 259 - 260 - assertEqual(new ExampleA(1), new ExampleA(1)); 261 - assertEqual(new ExampleB(1), new ExampleB(1)); 262 - assertNotEqual(new ExampleA(1), new ExampleA(2)); 263 - assertNotEqual(new ExampleA(1), new ExampleB(1)); 264 - 265 - // Equality between Gleam prelude types from different packages 266 - // 267 - // The prelude is not global, each package gets one to fit into the JavaScript 268 - // module system. We work around this by having a single global 269 - // `globalThis.__gleam_prelude_variant` symbol and using this in place of the 270 - // constructor to check if Gleam values are of the same kind. 271 - // 272 - // In these tests we simulate a different prelude by creating new version of the 273 - // prelude types through inheritance. 274 - 275 - class AnotherEmpty extends Empty {} 276 - class AnotherNonEmpty extends NonEmpty {} 277 - class AnotherBitString extends BitString {} 278 - class AnotherOk extends Ok {} 279 - class AnotherError extends Error {} 280 - class AnotherUtfCodepoint extends UtfCodepoint {} 281 - 282 - assertEqual(List.fromArray([]), new AnotherEmpty()); 283 - assertEqual(List.fromArray([1]), new AnotherNonEmpty(1, new AnotherEmpty())); 284 - assertNotEqual(List.fromArray([1]), new AnotherEmpty()); 285 - assertEqual(new AnotherEmpty(), List.fromArray([])); 286 - assertEqual(new AnotherNonEmpty(1, new AnotherEmpty()), List.fromArray([1])); 287 - assertNotEqual(new AnotherEmpty(), List.fromArray([1])); 288 - 289 - assertEqual(new Ok(1), new AnotherOk(1)); 290 - assertEqual(new AnotherOk(1), new Ok(1)); 291 - assertNotEqual(new Ok(2), new AnotherOk(1)); 292 - assertNotEqual(new AnotherOk(2), new Ok(1)); 293 - 294 - assertEqual(new Error(1), new AnotherError(1)); 295 - assertEqual(new AnotherError(1), new Error(1)); 296 - assertNotEqual(new Error(2), new AnotherError(1)); 297 - assertNotEqual(new AnotherError(2), new Error(1)); 298 - 299 - assertEqual( 300 - new BitString(new Uint8Array([1, 2])), 301 - new AnotherBitString(new Uint8Array([1, 2])) 302 - ); 303 - assertEqual( 304 - new AnotherBitString(new Uint8Array([1, 2])), 305 - new BitString(new Uint8Array([1, 2])) 306 - ); 307 - assertNotEqual( 308 - new BitString(new Uint8Array([2, 2])), 309 - new AnotherBitString(new Uint8Array([1, 2])) 310 - ); 311 - assertNotEqual( 312 - new AnotherBitString(new Uint8Array([2, 2])), 313 - new BitString(new Uint8Array([1, 2])) 314 - ); 315 - 316 - assertEqual(new UtfCodepoint(128013), new AnotherUtfCodepoint(128013)); 317 - assertEqual(new AnotherUtfCodepoint(128013), new UtfCodepoint(128013)); 318 - assertNotEqual(new UtfCodepoint(128014), new AnotherUtfCodepoint(128013)); 319 - assertNotEqual(new AnotherUtfCodepoint(128014), new UtfCodepoint(128013)); 320 - 321 - // Inspecting Gleam values 322 - 323 - assertEqual(inspect(true), "True"); 324 - assertEqual(inspect(false), "False"); 325 - assertEqual(inspect(undefined), "Nil"); 326 - 327 - assertEqual(inspect(0), "0"); 328 - assertEqual(inspect(1), "1"); 329 - assertEqual(inspect(2), "2"); 330 - assertEqual(inspect(-1), "-1"); 331 - assertEqual(inspect(-2), "-2"); 332 - 333 - assertEqual(inspect(0.23), "0.23"); 334 - assertEqual(inspect(1.23), "1.23"); 335 - assertEqual(inspect(2.23), "2.23"); 336 - assertEqual(inspect(-1.23), "-1.23"); 337 - assertEqual(inspect(-2.23), "-2.23"); 338 - 339 - assertEqual(inspect(new Ok(1)), "Ok(1)"); 340 - assertEqual(inspect(new Ok(true)), "Ok(True)"); 341 - assertEqual(inspect(new Ok(false)), "Ok(False)"); 342 - assertEqual(inspect(new Ok(undefined)), "Ok(Nil)"); 343 - 344 - assertEqual(inspect(new Error(2)), "Error(2)"); 345 - assertEqual(inspect(new Error(true)), "Error(True)"); 346 - assertEqual(inspect(new Error(false)), "Error(False)"); 347 - assertEqual(inspect(new Error(undefined)), "Error(Nil)"); 348 - 349 - assertEqual( 350 - inspect(new ExampleRecordImpl(undefined, 1, 2.1)), 351 - "ExampleRecordImpl(Nil, detail: 1, boop: 2.1)" 352 - ); 353 - assertEqual( 354 - inspect(new ExampleRecordImpl(new Ok(1), 1, 2.1)), 355 - "ExampleRecordImpl(Ok(1), detail: 1, boop: 2.1)" 356 - ); 357 - 358 - assertEqual(inspect([]), "#()"); 359 - assertEqual(inspect([1, 2, 3]), "#(1, 2, 3)"); 360 - assertEqual(inspect([new Ok(1), new Ok(2)]), "#(Ok(1), Ok(2))"); 361 - 362 - assertEqual(inspect(List.fromArray([])), "[]"); 363 - assertEqual(inspect(List.fromArray([1, 2, 3])), "[1, 2, 3]"); 364 - assertEqual(inspect(List.fromArray([new Ok(1), new Ok(2)])), "[Ok(1), Ok(2)]"); 365 - 366 - assertEqual(inspect(new BitString(new Uint8Array([]))), "<<>>"); 367 - assertEqual(inspect(new BitString(new Uint8Array([1, 2, 3]))), "<<1, 2, 3>>"); 368 - 369 - assertEqual(inspect(new UtfCodepoint(128013)), "//utfcodepoint(🐍)"); 370 - 371 - assertEqual( 372 - inspect(() => undefined), 373 - "//fn() { ... }" 374 - ); 375 - 376 - assertEqual( 377 - inspect((a) => undefined), 378 - "//fn(a) { ... }" 379 - ); 380 - 381 - assertEqual( 382 - inspect((x, y) => undefined), 383 - "//fn(a, b) { ... }" 384 - ); 385 - 386 - assertEqual( 387 - inspect((x, y, z) => undefined), 388 - "//fn(a, b, c) { ... }" 389 - ); 390 - 391 - // Inspecting JavaScript values 392 - 393 - assertEqual(inspect(null), "//js(null)"); 394 - assertEqual(inspect({}), "//js({})"); 395 - assertEqual(inspect({ a: 1 }), '//js({ "a": 1 })'); 396 - assertEqual(inspect({ a: 1, b: 2 }), '//js({ "a": 1, "b": 2 })'); 397 - assertEqual(inspect({ a: 1, b: new Ok(1) }), '//js({ "a": 1, "b": Ok(1) })'); 398 - assertEqual( 399 - inspect(new globalThis.Error("Oh no")), 400 - '//js(Error { "message": "Oh no" })' 401 - ); 402 - assertEqual( 403 - inspect( 404 - (() => { 405 - let error = new globalThis.Error("Oh no"); 406 - error.other = new Ok(1); 407 - return error; 408 - })() 409 - ), 410 - '//js(Error { "message": "Oh no", "other": Ok(1) })' 411 - ); 412 - 413 - // Generic JS objects 414 - assertEqual(inspect(Promise.resolve(1)), "//js(Promise {})"); 415 - 416 - // Inspecting Dates 417 - assertEqual( 418 - inspect(new Date("1991-01-05")), 419 - '//js(Date("1991-01-05T00:00:00.000Z"))' 420 - ); 421 - 422 - // Inspecting RegExps 423 - assertEqual(inspect(/1[23]/g), "//js(/1[23]/g)"); 424 - 425 - // Inspecting Maps 426 - assertEqual( 427 - inspect( 428 - new Map([ 429 - [1, 2], 430 - [3, new Ok([1, 2])], 431 - ]) 432 - ), 433 - "//js(Map { 1: 2, 3: Ok(#(1, 2)) })" 434 - ); 435 - 436 - // Inspecting Sets 437 - assertEqual( 438 - inspect(new Set([1, 2, new Ok([1, 2])])), 439 - "//js(Set(1, 2, Ok(#(1, 2))))" 440 - ); 441 - 442 - // Result.isOk 443 - 444 - assertEqual(new Ok(1).isOk(), true); 445 - assertEqual(new Error(1).isOk(), false); 446 - 447 - // List.atLeastLength 448 - 449 - assertEqual(List.fromArray([]).atLeastLength(0), true); 450 - assertEqual(List.fromArray([]).atLeastLength(1), false); 451 - assertEqual(List.fromArray([]).atLeastLength(-1), true); 452 - assertEqual(List.fromArray([1]).atLeastLength(0), true); 453 - assertEqual(List.fromArray([1]).atLeastLength(1), true); 454 - assertEqual(List.fromArray([1]).atLeastLength(2), false); 455 - assertEqual(List.fromArray([1]).atLeastLength(-1), true); 456 - 457 - // List.hasLength 458 - 459 - assertEqual(toList([]).hasLength(0), true); 460 - assertEqual(toList([]).hasLength(1), false); 461 - assertEqual(toList([]).hasLength(-1), false); 462 - assertEqual(toList([1]).hasLength(0), false); 463 - assertEqual(toList([1]).hasLength(1), true); 464 - assertEqual(toList([1]).hasLength(2), false); 465 - assertEqual(toList([1, 1]).hasLength(1), false); 466 - assertEqual(toList([1, 1]).hasLength(2), true); 467 - assertEqual(toList([1, 1]).hasLength(3), false); 468 - 469 - // List iterable interface 470 - 471 - assertEqual([...toList([])], []); 472 - assertEqual([...toList([1, 2, 3])], [1, 2, 3]); 473 - 474 - // BitString.length 475 - 476 - assertEqual(new BitString(new Uint8Array([])).length, 0); 477 - assertEqual(new BitString(new Uint8Array([1, 2])).length, 2); 478 - assertEqual(new BitString(new Uint8Array([1, 2, 3, 4])).length, 4); 479 - 480 - // 481 - // Division 482 - // 483 - 484 - assertEqual(divideInt(1, 0), 0); 485 - assertEqual(divideInt(1, 1), 1); 486 - assertEqual(divideInt(1, 2), 0); 487 - assertEqual(divideInt(3, 2), 1); 488 - assertEqual(divideInt(11, 3), 3); 489 - assertEqual(divideInt(-1, 0), 0); 490 - assertEqual(divideInt(-1, 1), -1); 491 - assertEqual(divideInt(-1, 2), -0); 492 - assertEqual(divideInt(-3, 2), -1); 493 - assertEqual(divideInt(-11, 3), -3); 494 - assertEqual(divideInt(1, -1), -1); 495 - assertEqual(divideInt(1, -2), 0); 496 - assertEqual(divideInt(3, -2), -1); 497 - assertEqual(divideInt(11, -3), -3); 498 - assertEqual(divideInt(-1, -1), 1); 499 - assertEqual(divideInt(-1, -2), 0); 500 - assertEqual(divideInt(-3, -2), 1); 501 - assertEqual(divideInt(-11, -3), 3); 502 - 503 - assertEqual(divideFloat(1.5, 0.0), 0.0); 504 - assertEqual(divideFloat(1.5, 2.0), 0.75); 505 - assertEqual(divideFloat(1.5, 2.5), 0.6); 506 - assertEqual(divideFloat(-1.5, 0.0), -0.0); 507 - assertEqual(divideFloat(-1.5, 2.0), -0.75); 508 - assertEqual(divideFloat(-1.5, 2.5), -0.6); 509 - assertEqual(divideFloat(1.5, -0.0), -0.0); 510 - assertEqual(divideFloat(1.5, -2.0), -0.75); 511 - assertEqual(divideFloat(1.5, -2.5), -0.6); 512 - assertEqual(divideFloat(-1.5, -0.0), 0.0); 513 - assertEqual(divideFloat(-1.5, -2.0), 0.75); 514 - assertEqual(divideFloat(-1.5, -2.5), 0.6); 515 - 516 - // Record updates 517 - 518 - assertEqual(new Ok(1).withFields({ 0: 2 }), new Ok(2)); 519 - assertEqual(new Error(1).withFields({ 0: 2 }), new Error(2)); 520 - 521 - assertEqual( 522 - new ExampleRecordImpl(1, 2, 3).withFields({}), 523 - new ExampleRecordImpl(1, 2, 3) 524 - ); 525 - assertEqual( 526 - new ExampleRecordImpl(1, 2, 3).withFields({ boop: 6, 0: 40 }), 527 - new ExampleRecordImpl(40, 2, 6) 528 - ); 529 - assertEqual( 530 - new ExampleRecordImpl(1, 2, 3).withFields({ boop: 4, detail: 5, 0: 6 }), 531 - new ExampleRecordImpl(6, 5, 4) 532 - ); 533 - 534 - // 535 - // Summary 536 - // 537 - 538 - console.log(` 539 - 540 - ${passes + failures} tests 541 - ${passes} passes 542 - ${failures} failures 543 - `); 544 - 545 - if (failures) process.exit(1);
+545
test/javascript_prelude/main.mjs
··· 1 + import { 2 + BitString, 3 + CustomType, 4 + Empty, 5 + Error, 6 + List, 7 + NonEmpty, 8 + Ok, 9 + UtfCodepoint, 10 + codepointBits, 11 + divideFloat, 12 + divideInt, 13 + inspect, 14 + isEqual, 15 + stringBits, 16 + toBitString, 17 + toList, 18 + } from "./prelude.mjs"; 19 + 20 + let failures = 0; 21 + let passes = 0; 22 + 23 + function pass() { 24 + process.stdout.write(`\u001b[${32}m.\u001b[${0}m`); 25 + passes++; 26 + } 27 + 28 + function fail(message) { 29 + console.log(""); 30 + console.assert(false, message); 31 + failures++; 32 + } 33 + 34 + function assertEqual(a, b) { 35 + if (isEqual(a, b)) { 36 + pass(); 37 + } else { 38 + fail(`\n\t${inspect(a)}\n\t!=\n\t${inspect(b)}`); 39 + } 40 + } 41 + 42 + function assertNotEqual(a, b) { 43 + if (isEqual(a, b)) { 44 + fail(`\n\t${inspect(a)}\n\t==\n\t${inspect(b)}`); 45 + } else { 46 + pass(); 47 + } 48 + } 49 + 50 + class ExampleRecordImpl extends CustomType { 51 + constructor(first, detail, boop) { 52 + super(); 53 + this[0] = first; 54 + this.detail = detail; 55 + this.boop = boop; 56 + } 57 + } 58 + 59 + let fmt = new Intl.DateTimeFormat("en-GB", { timeStyle: "medium" }); 60 + console.log(`Running tests at ${fmt.format(new Date())}\n`); 61 + 62 + // Equality of Gleam values 63 + 64 + assertEqual(true, true); 65 + assertEqual(false, false); 66 + assertEqual(undefined, undefined); 67 + assertNotEqual(true, false); 68 + assertNotEqual(false, true); 69 + assertNotEqual(undefined, false); 70 + assertNotEqual(undefined, true); 71 + assertNotEqual(true, undefined); 72 + assertNotEqual(false, undefined); 73 + 74 + assertEqual(1, 1); 75 + assertNotEqual(1, 2); 76 + assertEqual(1.1, 1.1); 77 + assertNotEqual(2.1, 1.1); 78 + assertEqual(-1, -1); 79 + assertNotEqual(-1, 1); 80 + assertEqual(-1.1, -1.1); 81 + assertNotEqual(-1.1, 1.1); 82 + 83 + assertEqual("", ""); 84 + assertEqual("123", "123"); 85 + assertEqual("👽", "👽"); 86 + assertNotEqual("👽", "👾"); 87 + 88 + assertEqual(new Ok(1), new Ok(1)); 89 + assertEqual(new Ok(2), new Ok(2)); 90 + assertEqual(new Ok(new Ok(2)), new Ok(new Ok(2))); 91 + assertNotEqual(new Ok(1), new Ok(2)); 92 + assertNotEqual(new Ok(new Ok(2)), new Ok(new Ok(3))); 93 + 94 + assertEqual(new Error(1), new Error(1)); 95 + assertEqual(new Error(2), new Error(2)); 96 + assertEqual(new Error(new Error(2)), new Error(new Error(2))); 97 + assertNotEqual(new Error(2), new Error(3)); 98 + assertNotEqual(new Error(new Error(2)), new Error(new Error(3))); 99 + 100 + assertEqual( 101 + new ExampleRecordImpl(undefined, 1, new Ok(2.1)), 102 + new ExampleRecordImpl(undefined, 1, new Ok(2.1)) 103 + ); 104 + assertNotEqual( 105 + new ExampleRecordImpl(undefined, 1, new Ok("2.1")), 106 + new ExampleRecordImpl(undefined, 1, new Ok(2.1)) 107 + ); 108 + 109 + assertEqual(List.fromArray([]), List.fromArray([])); 110 + assertEqual( 111 + List.fromArray([1, 2, new Ok(1)]), 112 + List.fromArray([1, 2, new Ok(1)]) 113 + ); 114 + assertNotEqual( 115 + List.fromArray([1, 2, new Ok(1)]), 116 + List.fromArray([1, 2, new Ok(2)]) 117 + ); 118 + assertNotEqual(List.fromArray([1, 2]), List.fromArray([1, 2, new Ok(2)])); 119 + assertNotEqual(List.fromArray([1]), List.fromArray([])); 120 + assertNotEqual(List.fromArray([]), List.fromArray([1])); 121 + 122 + assertEqual( 123 + new BitString(new Uint8Array([])), 124 + new BitString(new Uint8Array([])) 125 + ); 126 + assertEqual( 127 + new BitString(new Uint8Array([1, 2, 3])), 128 + new BitString(new Uint8Array([1, 2, 3])) 129 + ); 130 + assertNotEqual( 131 + new BitString(new Uint8Array([1, 2])), 132 + new BitString(new Uint8Array([1, 2, 3])) 133 + ); 134 + 135 + assertEqual(new UtfCodepoint(128013), new UtfCodepoint(128013)); 136 + assertNotEqual(new UtfCodepoint(128013), new UtfCodepoint(128014)); 137 + 138 + // toBitString 139 + 140 + assertEqual(new BitString(new Uint8Array([])), toBitString([])); 141 + 142 + assertEqual( 143 + new BitString(new Uint8Array([97, 98, 99])), 144 + toBitString([stringBits("abc")]) 145 + ); 146 + 147 + assertEqual( 148 + new BitString(new Uint8Array([97])), 149 + toBitString([codepointBits(new UtfCodepoint(97))]) 150 + ); 151 + 152 + assertEqual( 153 + new BitString(new Uint8Array([240, 159, 144, 141])), 154 + toBitString([codepointBits(new UtfCodepoint(128013))]) 155 + ); 156 + 157 + // toList 158 + 159 + assertEqual(toList([]), List.fromArray([])); 160 + assertEqual(toList([1, 2, 3]), List.fromArray([1, 2, 3])); 161 + assertEqual(toList([1, 2], toList([3, 4])), List.fromArray([1, 2, 3, 4])); 162 + assertEqual(toList([1, 2, 3], toList([4, 5])), List.fromArray([1, 2, 3, 4, 5])); 163 + 164 + // Equality of JavaScript values 165 + 166 + assertEqual([], []); 167 + assertEqual([1, 2], [1, 2]); 168 + assertEqual([new Ok([1, 2])], [new Ok([1, 2])]); 169 + assertNotEqual([], [[]]); 170 + assertNotEqual([], [1, []]); 171 + assertNotEqual([1, []], []); 172 + 173 + assertEqual({}, {}); 174 + assertEqual({ a: 1 }, { a: 1 }); 175 + assertEqual({ a: 1, b: 2 }, { b: 2, a: 1 }); 176 + assertEqual({ a: new Ok(1) }, { a: new Ok(1) }); 177 + assertNotEqual({ a: new Ok(2) }, { a: new Ok(1) }); 178 + 179 + assertEqual(new Date(0), new Date(0)); 180 + assertNotEqual(new Date(1), new Date(0)); 181 + 182 + assertEqual(new Uint8Array([1, 2]), new Uint8Array([1, 2])); 183 + assertEqual(new Uint16Array([1, 2]), new Uint16Array([1, 2])); 184 + assertEqual(new Uint32Array([1, 2]), new Uint32Array([1, 2])); 185 + assertNotEqual(new Uint8Array([1, 3]), new Uint8Array([1, 2])); 186 + assertNotEqual(new Uint16Array([1, 3]), new Uint16Array([1, 2])); 187 + assertNotEqual(new Uint32Array([1, 3]), new Uint32Array([1, 2])); 188 + 189 + // Promises are not equal unless they have reference equality 190 + let promise = Promise.resolve(1); 191 + assertEqual(promise, promise); 192 + assertNotEqual(Promise.resolve(1), Promise.resolve(1)); 193 + 194 + // Functions are not equal unless they have reference equality 195 + let fun = () => 1; 196 + assertEqual(fun, fun); 197 + assertNotEqual( 198 + () => 1, 199 + () => 1 200 + ); 201 + 202 + // Maps are compared structurally 203 + let map = new Map([["a", 1]]); 204 + assertEqual(map, map); 205 + assertEqual(new Map([["a", 1]]), new Map([["a", 1]])); 206 + assertNotEqual( 207 + new Map([ 208 + ["a", 1], 209 + ["b", 2], 210 + ]), 211 + new Map([["a", 1]]) 212 + ); 213 + assertNotEqual( 214 + new Map([["a", 1]]), 215 + new Map([ 216 + ["a", 1], 217 + ["b", 2], 218 + ]) 219 + ); 220 + assertNotEqual(new Map([["a", 1]]), new Map([["b", 1]])); 221 + assertEqual( 222 + new Map([["a", new Map([["a", []]])]]), 223 + new Map([["a", new Map([["a", []]])]]) 224 + ); 225 + 226 + // Sets are compared structurally 227 + let set = new Set(["a", 1]); 228 + assertEqual(set, set); 229 + assertEqual(new Set(["a", 1]), new Set(["a", 1])); 230 + assertNotEqual(new Set(["a", 1]), new Set(["b", 1])); 231 + assertNotEqual(new Set(["a", 1, "b"]), new Set(["a", 1])); 232 + assertNotEqual(new Set(["a", 1]), new Set(["a", 1, "b"])); 233 + assertNotEqual( 234 + new Set(["a", new Map([["a", []]])]), 235 + new Set(["a", new Map([["a", []]])]) 236 + ); 237 + 238 + // WeakMaps are not equal unless they have reference equality 239 + let weak_map = new WeakMap([[map, 1]]); 240 + assertEqual(weak_map, weak_map); 241 + assertNotEqual(new WeakMap([[map, 1]]), new WeakMap([[map, 1]])); 242 + 243 + // WeakSets are not equal unless they have reference equality 244 + let weak_set = new WeakSet([map, set]); 245 + assertEqual(weak_set, weak_set); 246 + assertNotEqual(new WeakSet([map, set]), new WeakSet([map, set])); 247 + 248 + class ExampleA { 249 + constructor(x) { 250 + this.x = x; 251 + } 252 + } 253 + 254 + class ExampleB { 255 + constructor(x) { 256 + this.x = x; 257 + } 258 + } 259 + 260 + assertEqual(new ExampleA(1), new ExampleA(1)); 261 + assertEqual(new ExampleB(1), new ExampleB(1)); 262 + assertNotEqual(new ExampleA(1), new ExampleA(2)); 263 + assertNotEqual(new ExampleA(1), new ExampleB(1)); 264 + 265 + // Equality between Gleam prelude types from different packages 266 + // 267 + // The prelude is not global, each package gets one to fit into the JavaScript 268 + // module system. We work around this by having a single global 269 + // `globalThis.__gleam_prelude_variant` symbol and using this in place of the 270 + // constructor to check if Gleam values are of the same kind. 271 + // 272 + // In these tests we simulate a different prelude by creating new version of the 273 + // prelude types through inheritance. 274 + 275 + class AnotherEmpty extends Empty {} 276 + class AnotherNonEmpty extends NonEmpty {} 277 + class AnotherBitString extends BitString {} 278 + class AnotherOk extends Ok {} 279 + class AnotherError extends Error {} 280 + class AnotherUtfCodepoint extends UtfCodepoint {} 281 + 282 + assertEqual(List.fromArray([]), new AnotherEmpty()); 283 + assertEqual(List.fromArray([1]), new AnotherNonEmpty(1, new AnotherEmpty())); 284 + assertNotEqual(List.fromArray([1]), new AnotherEmpty()); 285 + assertEqual(new AnotherEmpty(), List.fromArray([])); 286 + assertEqual(new AnotherNonEmpty(1, new AnotherEmpty()), List.fromArray([1])); 287 + assertNotEqual(new AnotherEmpty(), List.fromArray([1])); 288 + 289 + assertEqual(new Ok(1), new AnotherOk(1)); 290 + assertEqual(new AnotherOk(1), new Ok(1)); 291 + assertNotEqual(new Ok(2), new AnotherOk(1)); 292 + assertNotEqual(new AnotherOk(2), new Ok(1)); 293 + 294 + assertEqual(new Error(1), new AnotherError(1)); 295 + assertEqual(new AnotherError(1), new Error(1)); 296 + assertNotEqual(new Error(2), new AnotherError(1)); 297 + assertNotEqual(new AnotherError(2), new Error(1)); 298 + 299 + assertEqual( 300 + new BitString(new Uint8Array([1, 2])), 301 + new AnotherBitString(new Uint8Array([1, 2])) 302 + ); 303 + assertEqual( 304 + new AnotherBitString(new Uint8Array([1, 2])), 305 + new BitString(new Uint8Array([1, 2])) 306 + ); 307 + assertNotEqual( 308 + new BitString(new Uint8Array([2, 2])), 309 + new AnotherBitString(new Uint8Array([1, 2])) 310 + ); 311 + assertNotEqual( 312 + new AnotherBitString(new Uint8Array([2, 2])), 313 + new BitString(new Uint8Array([1, 2])) 314 + ); 315 + 316 + assertEqual(new UtfCodepoint(128013), new AnotherUtfCodepoint(128013)); 317 + assertEqual(new AnotherUtfCodepoint(128013), new UtfCodepoint(128013)); 318 + assertNotEqual(new UtfCodepoint(128014), new AnotherUtfCodepoint(128013)); 319 + assertNotEqual(new AnotherUtfCodepoint(128014), new UtfCodepoint(128013)); 320 + 321 + // Inspecting Gleam values 322 + 323 + assertEqual(inspect(true), "True"); 324 + assertEqual(inspect(false), "False"); 325 + assertEqual(inspect(undefined), "Nil"); 326 + 327 + assertEqual(inspect(0), "0"); 328 + assertEqual(inspect(1), "1"); 329 + assertEqual(inspect(2), "2"); 330 + assertEqual(inspect(-1), "-1"); 331 + assertEqual(inspect(-2), "-2"); 332 + 333 + assertEqual(inspect(0.23), "0.23"); 334 + assertEqual(inspect(1.23), "1.23"); 335 + assertEqual(inspect(2.23), "2.23"); 336 + assertEqual(inspect(-1.23), "-1.23"); 337 + assertEqual(inspect(-2.23), "-2.23"); 338 + 339 + assertEqual(inspect(new Ok(1)), "Ok(1)"); 340 + assertEqual(inspect(new Ok(true)), "Ok(True)"); 341 + assertEqual(inspect(new Ok(false)), "Ok(False)"); 342 + assertEqual(inspect(new Ok(undefined)), "Ok(Nil)"); 343 + 344 + assertEqual(inspect(new Error(2)), "Error(2)"); 345 + assertEqual(inspect(new Error(true)), "Error(True)"); 346 + assertEqual(inspect(new Error(false)), "Error(False)"); 347 + assertEqual(inspect(new Error(undefined)), "Error(Nil)"); 348 + 349 + assertEqual( 350 + inspect(new ExampleRecordImpl(undefined, 1, 2.1)), 351 + "ExampleRecordImpl(Nil, detail: 1, boop: 2.1)" 352 + ); 353 + assertEqual( 354 + inspect(new ExampleRecordImpl(new Ok(1), 1, 2.1)), 355 + "ExampleRecordImpl(Ok(1), detail: 1, boop: 2.1)" 356 + ); 357 + 358 + assertEqual(inspect([]), "#()"); 359 + assertEqual(inspect([1, 2, 3]), "#(1, 2, 3)"); 360 + assertEqual(inspect([new Ok(1), new Ok(2)]), "#(Ok(1), Ok(2))"); 361 + 362 + assertEqual(inspect(List.fromArray([])), "[]"); 363 + assertEqual(inspect(List.fromArray([1, 2, 3])), "[1, 2, 3]"); 364 + assertEqual(inspect(List.fromArray([new Ok(1), new Ok(2)])), "[Ok(1), Ok(2)]"); 365 + 366 + assertEqual(inspect(new BitString(new Uint8Array([]))), "<<>>"); 367 + assertEqual(inspect(new BitString(new Uint8Array([1, 2, 3]))), "<<1, 2, 3>>"); 368 + 369 + assertEqual(inspect(new UtfCodepoint(128013)), "//utfcodepoint(🐍)"); 370 + 371 + assertEqual( 372 + inspect(() => undefined), 373 + "//fn() { ... }" 374 + ); 375 + 376 + assertEqual( 377 + inspect((a) => undefined), 378 + "//fn(a) { ... }" 379 + ); 380 + 381 + assertEqual( 382 + inspect((x, y) => undefined), 383 + "//fn(a, b) { ... }" 384 + ); 385 + 386 + assertEqual( 387 + inspect((x, y, z) => undefined), 388 + "//fn(a, b, c) { ... }" 389 + ); 390 + 391 + // Inspecting JavaScript values 392 + 393 + assertEqual(inspect(null), "//js(null)"); 394 + assertEqual(inspect({}), "//js({})"); 395 + assertEqual(inspect({ a: 1 }), '//js({ "a": 1 })'); 396 + assertEqual(inspect({ a: 1, b: 2 }), '//js({ "a": 1, "b": 2 })'); 397 + assertEqual(inspect({ a: 1, b: new Ok(1) }), '//js({ "a": 1, "b": Ok(1) })'); 398 + assertEqual( 399 + inspect(new globalThis.Error("Oh no")), 400 + '//js(Error { "message": "Oh no" })' 401 + ); 402 + assertEqual( 403 + inspect( 404 + (() => { 405 + let error = new globalThis.Error("Oh no"); 406 + error.other = new Ok(1); 407 + return error; 408 + })() 409 + ), 410 + '//js(Error { "message": "Oh no", "other": Ok(1) })' 411 + ); 412 + 413 + // Generic JS objects 414 + assertEqual(inspect(Promise.resolve(1)), "//js(Promise {})"); 415 + 416 + // Inspecting Dates 417 + assertEqual( 418 + inspect(new Date("1991-01-05")), 419 + '//js(Date("1991-01-05T00:00:00.000Z"))' 420 + ); 421 + 422 + // Inspecting RegExps 423 + assertEqual(inspect(/1[23]/g), "//js(/1[23]/g)"); 424 + 425 + // Inspecting Maps 426 + assertEqual( 427 + inspect( 428 + new Map([ 429 + [1, 2], 430 + [3, new Ok([1, 2])], 431 + ]) 432 + ), 433 + "//js(Map { 1: 2, 3: Ok(#(1, 2)) })" 434 + ); 435 + 436 + // Inspecting Sets 437 + assertEqual( 438 + inspect(new Set([1, 2, new Ok([1, 2])])), 439 + "//js(Set(1, 2, Ok(#(1, 2))))" 440 + ); 441 + 442 + // Result.isOk 443 + 444 + assertEqual(new Ok(1).isOk(), true); 445 + assertEqual(new Error(1).isOk(), false); 446 + 447 + // List.atLeastLength 448 + 449 + assertEqual(List.fromArray([]).atLeastLength(0), true); 450 + assertEqual(List.fromArray([]).atLeastLength(1), false); 451 + assertEqual(List.fromArray([]).atLeastLength(-1), true); 452 + assertEqual(List.fromArray([1]).atLeastLength(0), true); 453 + assertEqual(List.fromArray([1]).atLeastLength(1), true); 454 + assertEqual(List.fromArray([1]).atLeastLength(2), false); 455 + assertEqual(List.fromArray([1]).atLeastLength(-1), true); 456 + 457 + // List.hasLength 458 + 459 + assertEqual(toList([]).hasLength(0), true); 460 + assertEqual(toList([]).hasLength(1), false); 461 + assertEqual(toList([]).hasLength(-1), false); 462 + assertEqual(toList([1]).hasLength(0), false); 463 + assertEqual(toList([1]).hasLength(1), true); 464 + assertEqual(toList([1]).hasLength(2), false); 465 + assertEqual(toList([1, 1]).hasLength(1), false); 466 + assertEqual(toList([1, 1]).hasLength(2), true); 467 + assertEqual(toList([1, 1]).hasLength(3), false); 468 + 469 + // List iterable interface 470 + 471 + assertEqual([...toList([])], []); 472 + assertEqual([...toList([1, 2, 3])], [1, 2, 3]); 473 + 474 + // BitString.length 475 + 476 + assertEqual(new BitString(new Uint8Array([])).length, 0); 477 + assertEqual(new BitString(new Uint8Array([1, 2])).length, 2); 478 + assertEqual(new BitString(new Uint8Array([1, 2, 3, 4])).length, 4); 479 + 480 + // 481 + // Division 482 + // 483 + 484 + assertEqual(divideInt(1, 0), 0); 485 + assertEqual(divideInt(1, 1), 1); 486 + assertEqual(divideInt(1, 2), 0); 487 + assertEqual(divideInt(3, 2), 1); 488 + assertEqual(divideInt(11, 3), 3); 489 + assertEqual(divideInt(-1, 0), 0); 490 + assertEqual(divideInt(-1, 1), -1); 491 + assertEqual(divideInt(-1, 2), -0); 492 + assertEqual(divideInt(-3, 2), -1); 493 + assertEqual(divideInt(-11, 3), -3); 494 + assertEqual(divideInt(1, -1), -1); 495 + assertEqual(divideInt(1, -2), 0); 496 + assertEqual(divideInt(3, -2), -1); 497 + assertEqual(divideInt(11, -3), -3); 498 + assertEqual(divideInt(-1, -1), 1); 499 + assertEqual(divideInt(-1, -2), 0); 500 + assertEqual(divideInt(-3, -2), 1); 501 + assertEqual(divideInt(-11, -3), 3); 502 + 503 + assertEqual(divideFloat(1.5, 0.0), 0.0); 504 + assertEqual(divideFloat(1.5, 2.0), 0.75); 505 + assertEqual(divideFloat(1.5, 2.5), 0.6); 506 + assertEqual(divideFloat(-1.5, 0.0), -0.0); 507 + assertEqual(divideFloat(-1.5, 2.0), -0.75); 508 + assertEqual(divideFloat(-1.5, 2.5), -0.6); 509 + assertEqual(divideFloat(1.5, -0.0), -0.0); 510 + assertEqual(divideFloat(1.5, -2.0), -0.75); 511 + assertEqual(divideFloat(1.5, -2.5), -0.6); 512 + assertEqual(divideFloat(-1.5, -0.0), 0.0); 513 + assertEqual(divideFloat(-1.5, -2.0), 0.75); 514 + assertEqual(divideFloat(-1.5, -2.5), 0.6); 515 + 516 + // Record updates 517 + 518 + assertEqual(new Ok(1).withFields({ 0: 2 }), new Ok(2)); 519 + assertEqual(new Error(1).withFields({ 0: 2 }), new Error(2)); 520 + 521 + assertEqual( 522 + new ExampleRecordImpl(1, 2, 3).withFields({}), 523 + new ExampleRecordImpl(1, 2, 3) 524 + ); 525 + assertEqual( 526 + new ExampleRecordImpl(1, 2, 3).withFields({ boop: 6, 0: 40 }), 527 + new ExampleRecordImpl(40, 2, 6) 528 + ); 529 + assertEqual( 530 + new ExampleRecordImpl(1, 2, 3).withFields({ boop: 4, detail: 5, 0: 6 }), 531 + new ExampleRecordImpl(6, 5, 4) 532 + ); 533 + 534 + // 535 + // Summary 536 + // 537 + 538 + console.log(` 539 + 540 + ${passes + failures} tests 541 + ${passes} passes 542 + ${failures} failures 543 + `); 544 + 545 + if (failures) process.exit(1);
-3
test/javascript_prelude/package.json
··· 1 - { 2 - "type": "module" 3 - }
+4 -4
test/language/src/ffi.gleam
··· 1 1 if javascript { 2 2 pub external fn print(String) -> Nil = 3 - "./ffi_javascript.js" "print" 3 + "./ffi_javascript.mjs" "print" 4 4 5 5 pub external fn append(String, String) -> String = 6 - "./ffi_javascript.js" "append" 6 + "./ffi_javascript.mjs" "append" 7 7 8 8 pub external fn to_string(anything) -> String = 9 - "./ffi_javascript.js" "toString" 9 + "./ffi_javascript.mjs" "toString" 10 10 11 11 pub external fn ansi_green(String) -> String = 12 - "./ffi_javascript.js" "ansi_green" 12 + "./ffi_javascript.mjs" "ansi_green" 13 13 } 14 14 15 15 if erlang {
test/language/src/ffi_javascript.js test/language/src/ffi_javascript.mjs