void test_store_overwrites_previous() { TS_ASSERT_EQUALS(as<Integer>(tbl->entries())->to_native(), 0); tbl->store(state, cNil, Fixnum::from(47)); TS_ASSERT_EQUALS(as<Integer>(tbl->entries())->to_native(), 1); Object* out = tbl->aref(state, cNil); TS_ASSERT_EQUALS(as<Integer>(out)->to_native(), 47); tbl->store(state, cNil, Fixnum::from(42)); TS_ASSERT_EQUALS(as<Integer>(tbl->entries())->to_native(), 1); out = tbl->aref(state, cNil); TS_ASSERT_EQUALS(as<Integer>(out)->to_native(), 42); }
bool NativeFunction::ffi_arg_info(STATE, Object* type, FFIArgInfo* args_info) { if(type->fixnum_p()) { args_info->type = as<Fixnum>(type)->to_int(); args_info->enum_obj = NULL; args_info->callback = NULL; return true; } else if(type->symbol_p()) { LookupTable* tbl = try_as<LookupTable>(G(ffi)->get_const(state, "TypeDefs")); if(!tbl) return false; Fixnum* fix = try_as<Fixnum>(tbl->aref(state, type)); if(!fix) return false; args_info->type = fix->to_int(); args_info->enum_obj = NULL; args_info->callback = NULL; return true; } else if(NativeFunction* cb = try_as<NativeFunction>(type)) { args_info->type = RBX_FFI_TYPE_CALLBACK; args_info->enum_obj = NULL; args_info->callback = cb; return true; } else if(CBOOL(type->respond_to(state, state->symbol("[]"), cTrue))) { args_info->type = RBX_FFI_TYPE_ENUM; args_info->enum_obj = type; args_info->callback = NULL; return true; } return false; }
void test_store_fetch() { TS_ASSERT_EQUALS(as<Integer>(tbl->entries())->to_native(), 0); tbl->store(state, Qnil, Fixnum::from(47)); TS_ASSERT_EQUALS(as<Integer>(tbl->entries())->to_native(), 1); Object* out = tbl->aref(state, Qnil); TS_ASSERT_EQUALS(as<Integer>(out)->to_native(), 47); }
void test_store_resizes_table() { size_t i; size_t bins = tbl-> bins()->to_native(); for(i = 0; i < bins; i++) { tbl->store(state, Fixnum::from(i), Fixnum::from(i)); } TS_ASSERT_EQUALS(i, (size_t)as<Integer>(tbl->entries())->to_native()); TS_ASSERT((size_t)(tbl-> bins()->to_native()) > bins); for(i = 0; i < bins; i++) { TS_ASSERT_EQUALS(Fixnum::from(i), tbl->aref(state, Fixnum::from(i))); } }