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

Configure Feed

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

Update tests

+32 -158
+32 -158
test/javascript_prelude/main.mjs
··· 1 1 import { 2 - BitString, 2 + BitArray, 3 3 CustomType, 4 - Empty, 5 4 Error, 6 5 List, 7 - NonEmpty, 8 6 Ok, 9 7 UtfCodepoint, 10 8 codepointBits, 11 9 divideFloat, 12 10 divideInt, 13 - inspect, 14 11 isEqual, 15 12 stringBits, 16 13 toBitArray, ··· 29 26 console.log(""); 30 27 console.assert(false, message); 31 28 failures++; 29 + } 30 + 31 + function inspect(a) { 32 + if (typeof a === "object" && a !== null && typeof a.inspect === "function") { 33 + return a.inspect(); 34 + } else { 35 + return JSON.stringify(a); 36 + } 32 37 } 33 38 34 39 function assertEqual(a, b) { ··· 128 133 assertNotEqual(List.fromArray([1]), List.fromArray([])); 129 134 assertNotEqual(List.fromArray([]), List.fromArray([1])); 130 135 136 + assertEqual(new BitArray(new Uint8Array([])), new BitArray(new Uint8Array([]))); 131 137 assertEqual( 132 - new BitString(new Uint8Array([])), 133 - new BitString(new Uint8Array([])) 134 - ); 135 - assertEqual( 136 - new BitString(new Uint8Array([1, 2, 3])), 137 - new BitString(new Uint8Array([1, 2, 3])) 138 + new BitArray(new Uint8Array([1, 2, 3])), 139 + new BitArray(new Uint8Array([1, 2, 3])) 138 140 ); 139 141 assertNotEqual( 140 - new BitString(new Uint8Array([1, 2])), 141 - new BitString(new Uint8Array([1, 2, 3])) 142 + new BitArray(new Uint8Array([1, 2])), 143 + new BitArray(new Uint8Array([1, 2, 3])) 142 144 ); 143 145 144 146 assertEqual(new UtfCodepoint(128013), new UtfCodepoint(128013)); ··· 146 148 147 149 // toBitArray 148 150 149 - assertEqual(new BitString(new Uint8Array([])), toBitArray([])); 151 + assertEqual(new BitArray(new Uint8Array([])), toBitArray([])); 150 152 151 153 assertEqual( 152 - new BitString(new Uint8Array([97, 98, 99])), 154 + new BitArray(new Uint8Array([97, 98, 99])), 153 155 toBitArray([stringBits("abc")]) 154 156 ); 155 157 156 158 assertEqual( 157 - new BitString(new Uint8Array([97])), 159 + new BitArray(new Uint8Array([97])), 158 160 toBitArray([codepointBits(new UtfCodepoint(97))]) 159 161 ); 160 162 161 163 assertEqual( 162 - new BitString(new Uint8Array([240, 159, 144, 141])), 164 + new BitArray(new Uint8Array([240, 159, 144, 141])), 163 165 toBitArray([codepointBits(new UtfCodepoint(128013))]) 164 166 ); 165 167 ··· 329 331 assertEqual(hasEqualsField, { ...hasEqualsField }); 330 332 assertNotEqual(hasEqualsField, hasEqualsField2); 331 333 332 - // Inspecting Gleam values 333 - 334 - assertEqual(inspect(true), "True"); 335 - assertEqual(inspect(false), "False"); 336 - assertEqual(inspect(undefined), "Nil"); 337 - 338 - assertEqual(inspect(0), "0"); 339 - assertEqual(inspect(1), "1"); 340 - assertEqual(inspect(2), "2"); 341 - assertEqual(inspect(-1), "-1"); 342 - assertEqual(inspect(-2), "-2"); 343 - 344 - assertEqual(inspect(0.23), "0.23"); 345 - assertEqual(inspect(1.23), "1.23"); 346 - assertEqual(inspect(2.23), "2.23"); 347 - assertEqual(inspect(-1.23), "-1.23"); 348 - assertEqual(inspect(-2.23), "-2.23"); 349 - 350 - assertEqual(inspect(new Ok(1)), "Ok(1)"); 351 - assertEqual(inspect(new Ok(true)), "Ok(True)"); 352 - assertEqual(inspect(new Ok(false)), "Ok(False)"); 353 - assertEqual(inspect(new Ok(undefined)), "Ok(Nil)"); 354 - 355 - assertEqual(inspect(new Error(2)), "Error(2)"); 356 - assertEqual(inspect(new Error(true)), "Error(True)"); 357 - assertEqual(inspect(new Error(false)), "Error(False)"); 358 - assertEqual(inspect(new Error(undefined)), "Error(Nil)"); 359 - 334 + assertEqual(new BitArray(new Uint8Array([1, 2, 3])).byteAt(0), 1); 335 + assertEqual(new BitArray(new Uint8Array([1, 2, 3])).byteAt(2), 3); 360 336 assertEqual( 361 - inspect(new ExampleRecordImpl(undefined, 1, 2.1)), 362 - "ExampleRecordImpl(Nil, detail: 1, boop: 2.1)" 363 - ); 364 - assertEqual( 365 - inspect(new ExampleRecordImpl(new Ok(1), 1, 2.1)), 366 - "ExampleRecordImpl(Ok(1), detail: 1, boop: 2.1)" 367 - ); 368 - 369 - assertEqual(inspect([]), "#()"); 370 - assertEqual(inspect([1, 2, 3]), "#(1, 2, 3)"); 371 - assertEqual(inspect([new Ok(1), new Ok(2)]), "#(Ok(1), Ok(2))"); 372 - 373 - assertEqual(inspect(List.fromArray([])), "[]"); 374 - assertEqual(inspect(List.fromArray([1, 2, 3])), "[1, 2, 3]"); 375 - assertEqual(inspect(List.fromArray([new Ok(1), new Ok(2)])), "[Ok(1), Ok(2)]"); 376 - 377 - assertEqual(inspect(new BitString(new Uint8Array([]))), "<<>>"); 378 - assertEqual(inspect(new BitString(new Uint8Array([1, 2, 3]))), "<<1, 2, 3>>"); 379 - 380 - assertEqual(new BitString(new Uint8Array([1, 2, 3])).byteAt(0), 1); 381 - assertEqual(new BitString(new Uint8Array([1, 2, 3])).byteAt(2), 3); 382 - assertEqual( 383 - new BitString(new Uint8Array([63, 240, 0, 0, 0, 0, 0, 0])).floatAt(0), 337 + new BitArray(new Uint8Array([63, 240, 0, 0, 0, 0, 0, 0])).floatAt(0), 384 338 1.0 385 339 ); 386 - assertEqual(new BitString(new Uint8Array([1, 2, 3])).intFromSlice(0, 1), 1); 387 - assertEqual(new BitString(new Uint8Array([1, 2, 3])).intFromSlice(0, 2), 258); 388 - assertEqual( 389 - new BitString(new Uint8Array([1, 2, 3])).sliceAfter(1), 390 - new BitString(new Uint8Array([2, 3])) 391 - ); 392 - 393 - assertEqual(inspect(new UtfCodepoint(128013)), "//utfcodepoint(🐍)"); 394 - 395 - assertEqual( 396 - inspect(() => undefined), 397 - "//fn() { ... }" 398 - ); 399 - 400 - assertEqual( 401 - inspect((a) => undefined), 402 - "//fn(a) { ... }" 403 - ); 404 - 405 - assertEqual( 406 - inspect((x, y) => undefined), 407 - "//fn(a, b) { ... }" 408 - ); 409 - 410 - assertEqual( 411 - inspect((x, y, z) => undefined), 412 - "//fn(a, b, c) { ... }" 413 - ); 414 - 415 - // Inspecting JavaScript values 416 - 417 - assertEqual(inspect(null), "//js(null)"); 418 - assertEqual(inspect({}), "//js({})"); 419 - assertEqual(inspect({ a: 1 }), '//js({ "a": 1 })'); 420 - assertEqual(inspect({ a: 1, b: 2 }), '//js({ "a": 1, "b": 2 })'); 421 - assertEqual(inspect({ a: 1, b: new Ok(1) }), '//js({ "a": 1, "b": Ok(1) })'); 422 - assertEqual( 423 - inspect(new globalThis.Error("Oh no")), 424 - '//js(Error { "message": "Oh no" })' 425 - ); 340 + assertEqual(new BitArray(new Uint8Array([1, 2, 3])).intFromSlice(0, 1), 1); 341 + assertEqual(new BitArray(new Uint8Array([1, 2, 3])).intFromSlice(0, 2), 258); 426 342 assertEqual( 427 - inspect( 428 - (() => { 429 - let error = new globalThis.Error("Oh no"); 430 - error.other = new Ok(1); 431 - return error; 432 - })() 433 - ), 434 - '//js(Error { "message": "Oh no", "other": Ok(1) })' 343 + new BitArray(new Uint8Array([1, 2, 3])).sliceAfter(1), 344 + new BitArray(new Uint8Array([2, 3])) 435 345 ); 436 346 437 - // Generic JS objects 438 - assertEqual(inspect(Promise.resolve(1)), "//js(Promise {})"); 439 - 440 - // Inspecting Dates 441 - assertEqual( 442 - inspect(new Date("1991-01-05")), 443 - '//js(Date("1991-01-05T00:00:00.000Z"))' 444 - ); 445 - 446 - // Inspecting RegExps 447 - assertEqual(inspect(/1[23]/g), "//js(/1[23]/g)"); 448 - 449 - // Inspecting Maps 450 - assertEqual( 451 - inspect( 452 - new Map([ 453 - [1, 2], 454 - [3, new Ok([1, 2])], 455 - ]) 456 - ), 457 - "//js(Map { 1: 2, 3: Ok(#(1, 2)) })" 458 - ); 459 - 460 - // Inspecting Sets 461 - assertEqual( 462 - inspect(new Set([1, 2, new Ok([1, 2])])), 463 - "//js(Set(1, 2, Ok(#(1, 2))))" 464 - ); 465 - 466 - // Inspecting objects that have the null prototype 467 - let nullPrototypeObject = Object.create(null); 468 - assertEqual(inspect(nullPrototypeObject), "//js({})"); 469 - nullPrototypeObject.one = 1; 470 - nullPrototypeObject.two = 2; 471 - assertEqual(inspect(nullPrototypeObject), '//js({ "one": 1, "two": 2 })'); 472 - 473 347 // Result.isOk 474 348 475 349 assertEqual(new Ok(1).isOk(), true); ··· 502 376 assertEqual([...toList([])], []); 503 377 assertEqual([...toList([1, 2, 3])], [1, 2, 3]); 504 378 505 - // BitString.length 379 + // BitArray.length 506 380 507 - assertEqual(new BitString(new Uint8Array([])).length, 0); 508 - assertEqual(new BitString(new Uint8Array([1, 2])).length, 2); 509 - assertEqual(new BitString(new Uint8Array([1, 2, 3, 4])).length, 4); 381 + assertEqual(new BitArray(new Uint8Array([])).length, 0); 382 + assertEqual(new BitArray(new Uint8Array([1, 2])).length, 2); 383 + assertEqual(new BitArray(new Uint8Array([1, 2, 3, 4])).length, 4); 510 384 511 385 // 512 386 // Division ··· 562 436 new ExampleRecordImpl(6, 5, 4) 563 437 ); 564 438 565 - // Test BitString can only be constructed from Uint8Array, not ArrayBuffer 566 - const bs1 = new BitString(new Uint8Array(new ArrayBuffer(8))); 439 + // Test BitArray can only be constructed from Uint8Array, not ArrayBuffer 440 + const bs1 = new BitArray(new Uint8Array(new ArrayBuffer(8))); 567 441 assertThrows("Should only construct BitArray from Uint8Array", () => { 568 - const bs = new BitString(new ArrayBuffer(8)); 442 + const bs = new BitArray(new ArrayBuffer(8)); 569 443 }); 570 444 571 445 //