add object literal test

This commit is contained in:
2026-02-10 17:28:59 -06:00
parent fe5dc6ecc9
commit ddf3fc1c77
5 changed files with 761 additions and 515 deletions

61
test.ce
View File

@@ -331,14 +331,34 @@ function run_tests(package_name, specific_test) {
var _test_error = null
var end_time = null
var _run_one = null
var all_keys = null
var fn_count = 0
var null_count = 0
var other_count = 0
var first_null_key = null
var first_other_key = null
if (is_function(test_mod)) {
push(tests, {name: 'main', fn: test_mod})
} else if (is_object(test_mod)) {
arrfor(array(test_mod), function(k) {
all_keys = array(test_mod)
log.console(` Found ${length(all_keys)} test entries`)
arrfor(all_keys, function(k) {
if (is_function(test_mod[k])) {
fn_count = fn_count + 1
push(tests, {name: k, fn: test_mod[k]})
} else if (is_null(test_mod[k])) {
null_count = null_count + 1
if (!first_null_key) first_null_key = k
} else {
other_count = other_count + 1
if (!first_other_key) first_other_key = k
}
})
log.console(` functions=${fn_count} nulls=${null_count} other=${other_count}`)
if (first_other_key) {
log.console(` first other key: ${first_other_key}`)
log.console(` is_number=${is_number(test_mod[first_other_key])} is_text=${is_text(test_mod[first_other_key])} is_logical=${is_logical(test_mod[first_other_key])} is_object=${is_object(test_mod[first_other_key])}`)
}
}
if (length(tests) > 0) {
@@ -354,6 +374,7 @@ function run_tests(package_name, specific_test) {
start_time = time.number()
_test_error = null
log.console(` RUN ${t.name}`)
_run_one = function() {
var ret = t.fn()
@@ -367,8 +388,6 @@ function run_tests(package_name, specific_test) {
test_entry.status = "passed"
log.console(` PASS ${t.name}`)
pkg_result.passed++
file_result.passed++
} disruption {
var e = _test_error
test_entry.status = "failed"
@@ -386,16 +405,22 @@ function run_tests(package_name, specific_test) {
if (test_entry.error.stack) {
log.console(` ${text(array(test_entry.error.stack, '\n'), '\n ')}`)
}
pkg_result.failed++
file_result.failed++
}
_run_one()
end_time = time.number()
test_entry.duration_ns = round((end_time - start_time) * 1000000000)
// Update counters at _load_file level (not inside _run_one)
if (test_entry.status == "passed") {
pkg_result.passed = pkg_result.passed + 1
file_result.passed = file_result.passed + 1
} else {
pkg_result.failed = pkg_result.failed + 1
file_result.failed = file_result.failed + 1
}
push(file_result.tests, test_entry)
pkg_result.total++
pkg_result.total = pkg_result.total + 1
if (gc_after_each_test) {
dbg.gc()
}
@@ -591,22 +616,22 @@ function finalize_results() {
}
push(file_result.tests, r)
pkg_result.total++
pkg_result.total = pkg_result.total + 1
if (r.status == "passed") {
pkg_result.passed++
file_result.passed++
pkg_result.passed = pkg_result.passed + 1
file_result.passed = file_result.passed + 1
} else {
pkg_result.failed++
file_result.failed++
pkg_result.failed = pkg_result.failed + 1
file_result.failed = file_result.failed + 1
}
}
// Calculate totals
var totals = { total: 0, passed: 0, failed: 0 }
for (i = 0; i < length(all_results); i++) {
totals.total += all_results[i].total
totals.passed += all_results[i].passed
totals.failed += all_results[i].failed
totals.total = totals.total + all_results[i].total
totals.passed = totals.passed + all_results[i].passed
totals.failed = totals.failed + all_results[i].failed
}
log.console(`----------------------------------------`)
@@ -621,9 +646,9 @@ var totals = null
if (length(all_actor_tests) == 0) {
totals = { total: 0, passed: 0, failed: 0 }
for (i = 0; i < length(all_results); i++) {
totals.total += all_results[i].total
totals.passed += all_results[i].passed
totals.failed += all_results[i].failed
totals.total = totals.total + all_results[i].total
totals.passed = totals.passed + all_results[i].passed
totals.failed = totals.failed + all_results[i].failed
}
log.console(`----------------------------------------`)