rm top level fns

This commit is contained in:
2026-01-15 17:56:33 -06:00
parent 5018901acb
commit ac91495679
30 changed files with 340 additions and 451 deletions

View File

@@ -24,7 +24,7 @@ function deepCompare(expected, actual, path) {
if (isNaN(expected) && isNaN(actual))
return { passed: true, messages: [] };
var diff = number.abs(expected - actual);
var diff = abs(expected - actual);
if (diff <= EPSILON)
return { passed: true, messages: [] };
@@ -104,7 +104,7 @@ function makeTest(test) {
var compareResult = deepCompare(expected, decoded);
if (!compareResult.passed) {
throw compareResult.messages.join('; ');
throw text(compareResult.messages, '; ');
}
};
}

View File

@@ -1556,7 +1556,7 @@ return {
test_array_slice: function() {
var arr = [1, 2, 3, 4, 5]
var sliced = arr.slice(1, 3)
var sliced = array(arr, 1, 3)
if (length(sliced) != 2) throw "array slice length failed"
if (sliced[0] != 2) throw "array slice first failed"
if (sliced[1] != 3) throw "array slice second failed"
@@ -1573,12 +1573,8 @@ return {
test_array_join: function() {
var arr = [1, 2, 3]
var caught = false
try {
var str = arr.join(",")
} catch (e) {
caught = true
}
var str = text(arr, ",")
if (str != "1,2,3") throw "array join with text() failed"
},
test_array_indexOf: function() {
@@ -1620,8 +1616,8 @@ return {
test_string_slice: function() {
var str = "hello"
if (str.slice(1, 4) != "ell") throw "string slice failed"
if (str.slice(-2) != "lo") throw "string slice negative failed"
if (text(str, 1, 4) != "ell") throw "string slice failed"
if (text(str, -2) != "lo") throw "string slice negative failed: " + text(str, -2)
},
test_string_indexOf: function() {
@@ -2043,8 +2039,8 @@ return {
test_builtin_function_properties_still_work: function() {
// Built-in functions like number, text, array should still have properties
var min_result = number.min(5, 3)
if (min_result != 3) throw "number.min should work"
var min_result = min(5, 3)
if (min_result != 3) throw "min should work"
},
// ============================================================================
@@ -2108,7 +2104,7 @@ return {
var proxy = function(name, args) {
if (is_function(my_record[name])) {
return fn.apply(my_record[name], args)
return apply(my_record[name], args)
}
throw `unknown method: ${name}`
}

View File

@@ -14,7 +14,7 @@ function deep_compare(expected, actual, path) {
if (is_number(expected) && is_number(actual)) {
if (isNaN(expected) && isNaN(actual)) return { passed: true, messages: [] }
var diff = number.abs(expected - actual)
var diff = abs(expected - actual)
if (diff <= EPSILON) return { passed: true, messages: [] }
return { passed: false, messages: [`Value mismatch at ${path}: ${expected} vs ${actual} (diff ${diff})`] }
}
@@ -115,7 +115,7 @@ function make_test(t) {
var dec = wota.decode(enc)
var cmp = deep_compare(t.input, dec)
if (!cmp.passed) throw cmp.messages.join('; ')
if (!cmp.passed) throw text(cmp.messages, '; ')
}
}