|
|
diff --git a/vm/builtin_bytearray.cpp b/vm/builtin_bytearray.cpp
index 90b3ba6..cd6b17b 100644
--- a/vm/builtin_bytearray.cpp
+++ b/vm/builtin_bytearray.cpp
@@ -1,5 +1,14 @@
#include "builtin.hpp"
namespace rubinius {
+ ByteArray* ByteArray::create(STATE, size_t bytes) {
+ return (ByteArray*)state->om->new_object_bytes(G(bytearray), bytes);
+ }
+
void ByteArray::Info::mark(OBJECT t, ObjectMark& mark) { }
+
+ // Ruby.primitive :bytearray_size
+ INTEGER ByteArray::size(STATE) {
+ return Object::i2n(SIZE_OF_BODY(this));
+ }
}
diff --git a/vm/builtin_bytearray.hpp b/vm/builtin_bytearray.hpp
index 393a979..2636bc4 100644
--- a/vm/builtin_bytearray.hpp
+++ b/vm/builtin_bytearray.hpp
@@ -8,6 +8,7 @@ namespace rubinius {
const static object_type type = ByteArrayType;
static ByteArray* create(STATE, size_t bytes);
+ INTEGER size(STATE);
class Info : public TypeInfo {
public:
diff --git a/vm/builtin_string.cpp b/vm/builtin_string.cpp
index 0fdff1c..bb8164f 100644
--- a/vm/builtin_string.cpp
+++ b/vm/builtin_string.cpp
@@ -3,16 +3,13 @@
#include "objects.hpp"
#include "vm.hpp"
#include "objectmemory.hpp"
+#include "builtin_bytearray.hpp"
#define HashPrime 16777619
#define MASK_28 (((unsigned int)1<<28)-1)
namespace rubinius {
- ByteArray* ByteArray::create(STATE, size_t bytes) {
- return (ByteArray*)state->om->new_object_bytes(G(bytearray), bytes);
- }
-
String* String::create(STATE, const char* str, size_t bytes) {
String *so;
diff --git a/vm/test/test_bytearray.hpp b/vm/test/test_bytearray.hpp
new file mode 100644
index 0000000..bd3c744
--- /dev/null
+++ b/vm/test/test_bytearray.hpp
@@ -0,0 +1,42 @@
+#include "objects.hpp"
+#include "vm.hpp"
+#include "builtin_bytearray.hpp"
+
+#include
+
+using namespace rubinius;
+
+class TestByteArray : public CxxTest::TestSuite {
+ public:
+
+ VM * state;
+
+ void setUp() {
+ state = new VM();
+ }
+
+ void tearDown() {
+ delete state;
+ }
+
+ void test_size() {
+ ByteArray* b;
+
+ b = ByteArray::create(state, 0);
+ TS_ASSERT_EQUALS(b->size(state)->n2i(), 4);
+
+ b = ByteArray::create(state, 54);
+ TS_ASSERT_EQUALS(b->size(state)->n2i(), 56);
+
+ b = ByteArray::create(state, 55);
+ TS_ASSERT_EQUALS(b->size(state)->n2i(), 60);
+
+ b = ByteArray::create(state, 58);
+ TS_ASSERT_EQUALS(b->size(state)->n2i(), 60);
+
+ b = ByteArray::create(state, 59);
+ TS_ASSERT_EQUALS(b->size(state)->n2i(), 64);
+ }
+
+};
+
|