Sha256: 698f3726596a03482807c52eea7975279e10832a31ebc030d0af9c1a683ca1bc

Contents?: true

Size: 1.88 KB

Versions: 16

Compression:

Stored size: 1.88 KB

Contents

#include "unittest.hpp"
#include "rice/String.hpp"
#include "rice/global_function.hpp"

using namespace Rice;

TESTSUITE(String);

SETUP(String)
{
  ruby_init();
}

TESTCASE(default_construct)
{
  String s;
  ASSERT_EQUAL(T_STRING, rb_type(s));
  ASSERT_EQUAL("", RSTRING_PTR(s.value()));
}

TESTCASE(construct_from_value)
{
  String s(rb_str_new2("foo"));
  ASSERT_EQUAL(T_STRING, rb_type(s));
  ASSERT_EQUAL("foo", RSTRING_PTR(s.value()));
}

TESTCASE(construct_from_object)
{
  Object o(rb_str_new2("foo"));
  String s(o);
  ASSERT_EQUAL(T_STRING, rb_type(s));
  ASSERT_EQUAL("foo", RSTRING_PTR(s.value()));
}

TESTCASE(construct_from_identifier)
{
  String s(Identifier("foo"));
  ASSERT_EQUAL(T_STRING, rb_type(s));
  ASSERT_EQUAL("foo", RSTRING_PTR(s.value()));
}

TESTCASE(construct_from_c_string)
{
  String s("foo");
  ASSERT_EQUAL(T_STRING, rb_type(s));
  ASSERT_EQUAL("foo", RSTRING_PTR(s.value()));
}

TESTCASE(construct_from_std_string)
{
  String s(std::string("foo"));
  ASSERT_EQUAL(T_STRING, rb_type(s));
  ASSERT_EQUAL("foo", RSTRING_PTR(s.value()));
}

TESTCASE(format)
{
  String s(String::format("%s %d", "foo", 42));
  ASSERT_EQUAL(T_STRING, rb_type(s));
  ASSERT_EQUAL("foo 42", RSTRING_PTR(s.value()));
}

TESTCASE(length)
{
  String s("foo");
  ASSERT_EQUAL(3u, s.length());
}

TESTCASE(bracket)
{
  String s("foo");
  ASSERT_EQUAL('f', s[0]);
  ASSERT_EQUAL('o', s[1]);
  ASSERT_EQUAL('o', s[2]);
}

TESTCASE(c_str)
{
  String s("foo");
  ASSERT_EQUAL(RSTRING_PTR(s.value()), s.c_str());
}

TESTCASE(str)
{
  String s("foo");
  ASSERT_EQUAL(std::string("foo"), s.str());
}

TESTCASE(intern)
{
  String s("foo");
  ASSERT_EQUAL(Identifier("foo"), s.intern());
}

/**
 * Issue 59 - Copy constructor compilation problem.
 */

namespace {
  void testStringArg(Object self, String string) {
  }
}

TESTCASE(use_string_in_wrapped_function) {
  define_global_function("test_string_arg", &testStringArg);
}

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
rice2-2.2.1 test/test_String.cpp
rice2-2.2.0 test/test_String.cpp
rice-2.2.0 test/test_String.cpp
rice-2.1.3 test/test_String.cpp
rice-2.1.2 test/test_String.cpp
rice-2.1.1 test/test_String.cpp
rice-2.1.0 test/test_String.cpp
rice-2.0.0 test/test_String.cpp
rice-1.7.0 test/test_String.cpp
rice-1.6.3 test/test_String.cpp
rice-1.6.2 test/test_String.cpp
rice-1.6.1 test/test_String.cpp
rice-1.6.0 test/test_String.cpp
rice-1.6.0.pre test/test_String.cpp
rice-1.5.3 test/test_String.cpp
rice-1.5.2 test/test_String.cpp