Files
nunuhara_xsystem4/test/Source/strings.jaf
T

78 lines
3.8 KiB
C
Executable File

// -*-mode: C; coding: sjis; -*-
void test_strings(void)
{
int i;
float f;
string s;
test_bool("\"a\" == \"a\"", "a" == "a", true);
test_bool("\"a\" != \"b\"", "a" == "b", false);
test_bool("\"a\" < \"b\"", "a" < "b", true);
test_bool("\"a\" < \"a\"", "a" < "a", false);
test_bool("\"b\" < \"a\"", "b" < "a", false);
test_bool("\"a\" > \"b\"", "a" > "b", false);
test_bool("\"a\" > \"a\"", "a" > "a", false);
test_bool("\"b\" > \"a\"", "b" > "a", true);
test_bool("\"a\" <= \"b\"", "a" <= "b", true);
test_bool("\"a\" <= \"a\"", "a" <= "a", true);
test_bool("\"b\" <= \"a\"", "b" <= "a", false);
test_bool("\"a\" >= \"b\"", "a" >= "b", false);
test_bool("\"a\" >= \"a\"", "a" >= "a", true);
test_bool("\"b\" >= \"a\"", "b" >= "a", true);
test_bool("var = \"str\"", (s = "str", s == "str"), true);
test_string("foo += \"bar\"", (s = "foo", s += "bar"), "foobar");
// S_ADD
test_string("\"a\" + \"b\"", "a" + "b", "ab");
// S_LENGTH
test_equal("\"\".Length()", (s = "", s.Length()), 0);
test_equal("\"abc\".Length()", (s = "abc", s.Length()), 3);
test_equal("\"あbc\".Length()", (s = "あbc", s.Length()), 3);
// S_LENGTHBYTE
test_equal("\"\".LengthByte()", (s = "", s.LengthByte()), 0);
test_equal("\"abc\".LengthByte()", (s = "abc", s.LengthByte()), 3);
test_equal("\"あbc\".LengthByte()", (s = "あbc", s.LengthByte()), 4);
// S_EMPTY
test_bool("\"\".Empty()", (s = "", s.Empty()), true);
test_bool("\"a\".Empty()", (s = "a", s.Empty()), false);
// S_FIND
test_equal("\"abあいう\".Find(\"bあ\")", (s = "abあいう", s.Find("bあ")), 1);
test_equal("\"abあいう\".Find(\"bあ\")", (s = "abあいう", s.Find("い")), 3);
test_equal("\"abあいう\".Find(\"うえお\")", (s = "abあいう", s.Find("うえお")), -1);
// S_GETPART
test_string("\"abあいう\".GetPart(0, 0)", (s = "abあいう", s.GetPart(0, 0)), "");
test_string("\"abあいう\".GetPart(16, 2)", (s = "abあいう", s.GetPart(16, 2)), "");
test_string("\"abあいう\".GetPart(1, 3)", (s = "abあいう", s.GetPart(1, 3)), "bあい");
test_string("\"abあいう\".GetPart(-1, 3)", (s = "abあいう", s.GetPart(-1, 3)), "abあ");
test_string("\"abあいう\".GetPart(2, 16)", (s = "abあいう", s.GetPart(2, 16)), "あいう");
// S_PUSHBACK2
test_string("\"\".PushBack('a')", (s = "", s.PushBack('a'), s), "a");
test_string("\"あ\".PushBack('a')", (s = "あ", s.PushBack('a'), s), "あa");
// S_POPBACK2
test_string("\"あa\".PopBack()", (s = "あa", s.PopBack(), s), "あ");
test_string("\"あ\".PopBack()", (s = "あ", s.PopBack(), s), "");
// S_ERASE2
test_string("\"\".Erase(-1)", (s = "", s.Erase(-1), s), "");
test_string("\"\".Erase(0)", (s = "", s.Erase(0), s), "");
test_string("\"\".Erase(1)", (s = "", s.Erase(1), s), "");
test_string("\"a\".Erase(-1)", (s = "a", s.Erase(-1), s), "");
test_string("\"a\".Erase(0)", (s = "a", s.Erase(0), s), "");
test_string("\"a\".Erase(1)", (s = "a", s.Erase(1), s), "a");
test_string("\"あ\".Erase(-1)", (s = "あ", s.Erase(-1), s), "");
test_string("\"あ\".Erase(0)", (s = "あ", s.Erase(0), s), "");
test_string("\"あ\".Erase(1)", (s = "あ", s.Erase(1), s), "あ");
test_string("\"あbc\".Erase(1)", (s = "あbc", s.Erase(1), s), "あc");
// I_STRING
test_bool("(42).String()", (i = 42, i.String() == "42"), true);
// FTOS
test_bool("(4.2).String()", (f = 4.2, f.String() == "4.200000"), true);
test_bool("(4.222).String(2)", (f = 4.222, f.String(2) == "4.22"), true);
// C_REF
test_equal("abあいう[3]", (s = "abあいう", s[3]), 'い');
// C_ASSIGN
test_string("abあいう[1] = 'c'", (s = "abあいう", s[1] = 'c', s), "acあいう");
test_string("abあいう[3] = 'あ'", (s = "abあいう", s[3] = 'あ', s), "abああう");
test_string("abあいう[1] = 'あ'", (s = "abあいう", s[1] = 'あ', s), "aああいう");
test_string("abあいう[3] = 'c'", (s = "abあいう", s[3] = 'c', s), "abあcう");
}