From 342b273234405ab76dc159d2e402bfb1ddfa1d8f Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 3 Oct 2011 14:48:05 -0700 Subject: First commit - very basic features. --- tests/test-String.cc | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/test-String.cc (limited to 'tests/test-String.cc') diff --git a/tests/test-String.cc b/tests/test-String.cc new file mode 100644 index 0000000..36c87e4 --- /dev/null +++ b/tests/test-String.cc @@ -0,0 +1,50 @@ +#include +#include + +BALAU_STARTUP; + +using namespace Balau; + +int Application::startup() throw (Balau::GeneralException) { + Printer::log(M_STATUS, "Test::String running."); + + String x = "foobar"; + Assert(x == "foobar"); + Assert(x != "barfoo"); + + String y = "xyz"; + + x = "abcdef"; Assert(x < y); Assert(x + y == "abcdefxyz"); + x.set("x:%i", 42); Assert(x == "x:42"); + + x = "foobar"; Assert(x == "foobar"); + + y = x.extract(3); Assert(y == "bar"); + y = x.extract(1, 3); Assert(y == "oob"); + + y = " foo bar "; + x = y; x.do_ltrim(); Assert(x == "foo bar "); + x = y; x.do_rtrim(); Assert(x == " foo bar"); + x = y; x.do_trim(); Assert(x == "foo bar"); + + x = "42"; Assert(x.to_int() == 42); + x = "0x42"; Assert(x.to_int() == 0x42); + x = "42"; Assert(x.to_int(16) == 0x42); + x = "4.2"; Assert(x.to_double() == 4.2); + + x = "foobar"; + Assert(x[0] == 'f'); + Assert(x[5] == 'r'); + Assert(x.strlen() == 6); + Assert(x.strchr('o') == 1); + Assert(x.strrchr('o') == 2); + Assert(x.strchrcnt('o') == 2); + Assert(x.strstr("bar") == 3); + + x = "\xc3\xa9"; + y = x.iconv("UTF-8", "Latin1"); + Assert(((unsigned char) y[0]) == 0xe9); + + Printer::log(M_STATUS, "Test::String passed."); + return 0; +} -- cgit v1.2.3