rm string coercion

This commit is contained in:
2026-01-20 14:13:16 -06:00
parent 2841e91f40
commit b28ef39562
3 changed files with 188 additions and 201 deletions

View File

@@ -145,7 +145,7 @@ return {
if (!caught) throw "string + boolean should throw"
},
/* test_null_plus_string_throws: function() {
test_null_plus_string_throws: function() {
var caught = false
try {
var x = null + "hello"
@@ -164,7 +164,7 @@ return {
}
if (!caught) throw "string + null should throw"
},
*/
// ============================================================================
// COMPARISON OPERATORS
// ============================================================================
@@ -1076,14 +1076,14 @@ return {
if (parent.x != 10) throw "meme should not mutate parent"
},
/* test_meme_multiple_mixins: function() {
test_meme_multiple_mixins: function() {
var parent = {a: 1}
var mixin1 = {b: 2}
var mixin2 = {c: 3}
var child = meme(parent, mixin1, mixin2)
if (child.a != 1 || child.b != 2 || child.c != 3) throw "meme multiple mixins failed"
},
*/
// ============================================================================
// GLOBAL FUNCTIONS - PROTO
// ============================================================================
@@ -1551,12 +1551,12 @@ return {
if (search(str, "world") != 6) throw "string search failed"
if (search(str, "xyz") != null) throw "string search not found failed"
},
/*
test_string_lastIndexOf: function() {
var str = "hello hello"
if (search(str, "hello", 0, true) != 6) throw "string lastSearch failed"
},
*/
test_string_toLowerCase: function() {
var str = "HELLO"
if (lower(str) != "hello") throw "string toLowerCase failed"
@@ -1842,7 +1842,7 @@ return {
var result = a[null]
if (result != null) throw "array get with null key should return null"
},
/*
test_obj_get_number_key_returns_null: function() {
var o = {a: 1}
var result = o[5]
@@ -1892,7 +1892,7 @@ return {
}
if (!caught) throw "setting property on function should throw"
},
*/
test_function_bracket_access_throws: function() {
var fn = function() {}
var caught = false
@@ -2188,7 +2188,7 @@ return {
var result = reduce(arr, (a, b) => a + b)
if (result != "abc") throw "reduce string concat failed"
},
/*
test_reduce_to_object: function() {
var arr = ["a", "b", "c"]
var result = reduce(arr, (obj, val, i) => {
@@ -2197,7 +2197,7 @@ return {
}, {})
if (result.a != 0 || result.b != 1 || result.c != 2) throw "reduce to object failed"
},
*/
// ============================================================================
// SORT FUNCTION
// ============================================================================
@@ -2394,12 +2394,12 @@ return {
test_abs_float: function() {
if (abs(-3.14) != 3.14) throw "abs float failed"
},
/*
test_abs_non_number: function() {
if (abs("5") != null) throw "abs non-number should return null"
if (abs(null) != null) throw "abs null should return null"
},
*/
// ============================================================================
// FLOOR FUNCTION
// ============================================================================
@@ -2419,7 +2419,7 @@ return {
test_floor_zero: function() {
if (floor(0) != 0) throw "floor zero failed"
},
/*
test_floor_with_place: function() {
if (floor(12.3775, -2) != 12.37) throw "floor with place failed"
},
@@ -2427,7 +2427,7 @@ return {
test_floor_negative_with_place: function() {
if (floor(-12.3775, -2) != -12.38) throw "floor negative with place failed"
},
*/
// ============================================================================
// CEILING FUNCTION
// ============================================================================
@@ -2447,7 +2447,7 @@ return {
test_ceiling_zero: function() {
if (ceiling(0) != 0) throw "ceiling zero failed"
},
/*
test_ceiling_with_place: function() {
if (ceiling(12.3775, -2) != 12.38) throw "ceiling with place failed"
},
@@ -2471,7 +2471,7 @@ return {
test_round_half: function() {
if (round(3.5) != 4) throw "round half failed"
},
*/
test_round_negative: function() {
if (round(-3.5) != -3 && round(-3.5) != -4) throw "round negative failed"
},
@@ -2479,7 +2479,7 @@ return {
test_round_integer: function() {
if (round(5) != 5) throw "round integer failed"
},
/*
test_round_with_places: function() {
if (round(12.3775, -2) != 12.38) throw "round with places failed"
},
@@ -2487,7 +2487,7 @@ return {
test_round_to_tens: function() {
if (round(12.3775, 1) != 10) throw "round to tens failed"
},
*/
// ============================================================================
// TRUNC FUNCTION
// ============================================================================
@@ -2507,7 +2507,7 @@ return {
test_trunc_zero: function() {
if (trunc(0) != 0) throw "trunc zero failed"
},
/*
test_trunc_with_places: function() {
if (trunc(12.3775, -2) != 12.37) throw "trunc with places failed"
},
@@ -2515,7 +2515,7 @@ return {
test_trunc_negative_with_places: function() {
if (trunc(-12.3775, -2) != -12.37) throw "trunc negative with places failed"
},
*/
// ============================================================================
// SIGN FUNCTION
// ============================================================================
@@ -2536,11 +2536,11 @@ return {
if (sign(0.001) != 1) throw "sign positive float failed"
if (sign(-0.001) != -1) throw "sign negative float failed"
},
/*
test_sign_non_number: function() {
if (sign("5") != null) throw "sign non-number should return null"
},
*/
// ============================================================================
// WHOLE AND FRACTION FUNCTIONS
// ============================================================================
@@ -2556,7 +2556,7 @@ return {
test_whole_integer: function() {
if (whole(5) != 5) throw "whole integer failed"
},
/*
test_whole_non_number: function() {
if (whole("5") != null) throw "whole non-number should return null"
},
@@ -2565,7 +2565,7 @@ return {
var f = fraction(3.75)
if (f < 0.74 || f > 0.76) throw "fraction positive failed: " + f
},
*/
test_fraction_negative: function() {
var f = fraction(-3.75)
if (f > -0.74 || f < -0.76) throw "fraction negative failed: " + f
@@ -2574,11 +2574,11 @@ return {
test_fraction_integer: function() {
if (fraction(5) != 0) throw "fraction integer failed"
},
/*
test_fraction_non_number: function() {
if (fraction("5") != null) throw "fraction non-number should return null"
},
*/
// ============================================================================
// NEG FUNCTION
// ============================================================================
@@ -2598,11 +2598,11 @@ return {
test_neg_float: function() {
if (neg(3.14) != -3.14) throw "neg float failed"
},
/*
test_neg_non_number: function() {
if (neg("5") != null) throw "neg non-number should return null"
},
*/
// ============================================================================
// MODULO FUNCTION
// ============================================================================
@@ -2662,12 +2662,12 @@ return {
test_min_float: function() {
if (min(3.14, 2.71) != 2.71) throw "min float failed"
},
/*
test_min_non_number: function() {
if (min(3, "5") != null) throw "min non-number should return null"
if (min("3", 5) != null) throw "min first non-number should return null"
},
*/
test_max_basic: function() {
if (max(3, 5) != 5) throw "max basic failed"
},
@@ -2687,11 +2687,11 @@ return {
test_max_float: function() {
if (max(3.14, 2.71) != 3.14) throw "max float failed"
},
/*
test_max_non_number: function() {
if (max(3, "5") != null) throw "max non-number should return null"
},
*/
test_min_max_constrain: function() {
var val = 8
var constrained = min(max(val, 0), 10)
@@ -2859,12 +2859,12 @@ return {
test_text_number_negative: function() {
if (text(-456) != "-456") throw "text number negative failed"
},
/*
test_text_number_float: function() {
var result = text(3.14)
if (search(result, "3.14") != 0) throw "text number float failed"
},
*/
test_text_array_join: function() {
var result = text([1, 2, 3], ",")
if (result != "1,2,3") throw "text array join failed"
@@ -3289,13 +3289,13 @@ return {
var result = array(arr, (x, i) => `${x}${i}`)
if (result[0] != "a0" || result[1] != "b1") throw "array map with index failed"
},
/*
test_array_map_reverse: function() {
var arr = [1, 2, 3]
var result = array(arr, x => x * 2, true)
if (result[0] != 6 || result[2] != 2) throw "array map reverse failed"
},
*/
test_array_map_with_exit: function() {
var arr = [1, 2, 3, 4, 5]
var result = array(arr, x => {