void test_set_byte() { ByteArray* b = String::create(state, "xyz")->data(); b->set_byte(state, Fixnum::from(0), Fixnum::from('1')); TS_ASSERT_EQUALS(b->get_byte(state, Fixnum::from(0)), Fixnum::from('1')); b->set_byte(state, Fixnum::from(2), Fixnum::from('2')); TS_ASSERT_EQUALS(b->get_byte(state, Fixnum::from(2)), Fixnum::from('2')); }
void test_set_byte() { ByteArray* b = new_bytearray("xyz"); b->set_byte(state, Fixnum::from(0), Fixnum::from('1')); TS_ASSERT_EQUALS(b->get_byte(state, Fixnum::from(0)), Fixnum::from('1')); b->set_byte(state, Fixnum::from(2), Fixnum::from('2')); TS_ASSERT_EQUALS(b->get_byte(state, Fixnum::from(2)), Fixnum::from('2')); }
void test_get_byte_index_out_of_bounds() { ByteArray* b = String::create(state, "xyz")->data(); native_int sz = b->size(state)->to_native(); TS_ASSERT_THROWS_ASSERT(b->get_byte(state, Fixnum::from(sz)), const RubyException &e, TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception))); TS_ASSERT_THROWS_ASSERT(b->get_byte(state, Fixnum::from(sz+1)), const RubyException &e, TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception))); TS_ASSERT_THROWS_ASSERT(b->get_byte(state, Fixnum::from(-1)), const RubyException &e, TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception))); }