fix tests
This commit is contained in:
@@ -1323,6 +1323,10 @@ TEST(cell_not) {
|
||||
CELL CORE FUNCTION TESTS
|
||||
============================================================================ */
|
||||
|
||||
static JSValue cfunc_returns_99(JSContext *ctx, JSValue this_val, int argc, JSValue *argv) {
|
||||
return JS_NewInt32(ctx, 99);
|
||||
}
|
||||
|
||||
TEST(cell_length_array) {
|
||||
JSGCRef arr_ref;
|
||||
JS_PushGCRef(ctx, &arr_ref);
|
||||
@@ -1343,6 +1347,81 @@ TEST(cell_length_string) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
TEST(cell_length_blob) {
|
||||
uint8_t data[] = {0xAA, 0xBB, 0xCC};
|
||||
JSValue blob = js_new_blob_stoned_copy(ctx, data, 3);
|
||||
JSValue result = JS_CellLength(ctx, blob);
|
||||
/* blob length is in bits: 3 bytes = 24 bits */
|
||||
ASSERT_INT(result, 24);
|
||||
return 1;
|
||||
}
|
||||
|
||||
TEST(cell_length_null) {
|
||||
JSValue result = JS_CellLength(ctx, JS_NULL);
|
||||
ASSERT(JS_IsNull(result));
|
||||
return 1;
|
||||
}
|
||||
|
||||
TEST(cell_length_logical) {
|
||||
JSValue result_t = JS_CellLength(ctx, JS_TRUE);
|
||||
JSValue result_f = JS_CellLength(ctx, JS_FALSE);
|
||||
ASSERT(JS_IsNull(result_t));
|
||||
ASSERT(JS_IsNull(result_f));
|
||||
return 1;
|
||||
}
|
||||
|
||||
TEST(cell_length_number) {
|
||||
JSValue result = JS_CellLength(ctx, JS_NewInt32(ctx, 42));
|
||||
ASSERT(JS_IsNull(result));
|
||||
return 1;
|
||||
}
|
||||
|
||||
TEST(cell_length_function_arity) {
|
||||
JSGCRef func_ref;
|
||||
JS_PushGCRef(ctx, &func_ref);
|
||||
func_ref.val = JS_NewCFunction(ctx, cfunc_add, "add", 2);
|
||||
JSValue result = JS_CellLength(ctx, func_ref.val);
|
||||
JS_PopGCRef(ctx, &func_ref);
|
||||
ASSERT_INT(result, 2);
|
||||
return 1;
|
||||
}
|
||||
|
||||
TEST(cell_length_object_no_length) {
|
||||
JSGCRef obj_ref;
|
||||
JS_PushGCRef(ctx, &obj_ref);
|
||||
obj_ref.val = JS_NewObject(ctx);
|
||||
JS_SetPropertyStr(ctx, obj_ref.val, "x", JS_NewInt32(ctx, 10));
|
||||
JSValue result = JS_CellLength(ctx, obj_ref.val);
|
||||
JS_PopGCRef(ctx, &obj_ref);
|
||||
ASSERT(JS_IsNull(result));
|
||||
return 1;
|
||||
}
|
||||
|
||||
TEST(cell_length_object_number) {
|
||||
JSGCRef obj_ref;
|
||||
JS_PushGCRef(ctx, &obj_ref);
|
||||
obj_ref.val = JS_NewObject(ctx);
|
||||
JS_SetPropertyStr(ctx, obj_ref.val, "length", JS_NewInt32(ctx, 7));
|
||||
JSValue result = JS_CellLength(ctx, obj_ref.val);
|
||||
JS_PopGCRef(ctx, &obj_ref);
|
||||
ASSERT_INT(result, 7);
|
||||
return 1;
|
||||
}
|
||||
|
||||
TEST(cell_length_object_function) {
|
||||
JSGCRef obj_ref, func_ref;
|
||||
JS_PushGCRef(ctx, &obj_ref);
|
||||
JS_PushGCRef(ctx, &func_ref);
|
||||
obj_ref.val = JS_NewObject(ctx);
|
||||
func_ref.val = JS_NewCFunction(ctx, cfunc_returns_99, "length", 0);
|
||||
JS_SetPropertyStr(ctx, obj_ref.val, "length", func_ref.val);
|
||||
JSValue result = JS_CellLength(ctx, obj_ref.val);
|
||||
JS_PopGCRef(ctx, &func_ref);
|
||||
JS_PopGCRef(ctx, &obj_ref);
|
||||
ASSERT_INT(result, 99);
|
||||
return 1;
|
||||
}
|
||||
|
||||
TEST(cell_reverse_array) {
|
||||
JSGCRef arr_ref;
|
||||
JS_PushGCRef(ctx, &arr_ref);
|
||||
@@ -2245,6 +2324,14 @@ int run_c_test_suite(JSContext *ctx)
|
||||
printf("\nCell Core Functions:\n");
|
||||
RUN_TEST(cell_length_array);
|
||||
RUN_TEST(cell_length_string);
|
||||
RUN_TEST(cell_length_blob);
|
||||
RUN_TEST(cell_length_null);
|
||||
RUN_TEST(cell_length_logical);
|
||||
RUN_TEST(cell_length_number);
|
||||
RUN_TEST(cell_length_function_arity);
|
||||
RUN_TEST(cell_length_object_no_length);
|
||||
RUN_TEST(cell_length_object_number);
|
||||
RUN_TEST(cell_length_object_function);
|
||||
RUN_TEST(cell_reverse_array);
|
||||
RUN_TEST(cell_reverse_string);
|
||||
RUN_TEST(cell_meme_shallow);
|
||||
|
||||
Reference in New Issue
Block a user