// -*-mode: C; coding: sjis; -*- void test_strings(void) { int i; float f; string s; bool b; 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"); // S_MOD // int test_string("%d % 42", "%d" % 42, "42"); test_string("abc%d % 42", "abc%d" % 42, "abc42"); test_string("%dabc % 42", "%dabc" % 42, "42abc"); test_string("abc%ddef % 42", "abc%ddef" % 42, "abc42def"); test_string("abc%4ddef % 42", "abc%4ddef" % 42, "abc 42def"); test_string("abc%04ddef % 42", "abc%04ddef" % 42, "abc0042def"); test_string("abc%Ddef % 42", "abc%Ddef" % 42, "abc42def"); test_string("abc%4Ddef % 42", "abc%4Ddef" % 42, "abc  42def"); test_string("abc%04Ddef % 42", "abc%04Ddef" % 42, "abc0042def"); test_string("\"%d %d\" % 42 % 43", "%d %d" % 42 % 43, "42 43"); test_string("%s %d % 42", "%s %d" % 42, "%s 42"); // float test_string("abc%fdef % 12.3", "abc%fdef" % 12.3, "abc12.300000def"); test_string("abc%.2fdef % 12.3", "abc%.2fdef" % 12.3, "abc12.30def"); test_string("abc%8.2fdef % 12.3", "abc%8.2fdef" % 12.3, "abc 12.30def"); test_string("abc%Fdef % 12.3", "abc%Fdef" % 12.3, "abc12.300000Fdef"); test_string("abc%.2Fdef % 12.3", "abc%.2Fdef" % 12.3, "abc12.30Fdef"); test_string("abc%8.2Fdef % 12.3", "abc%8.2Fdef" % 12.3, "abc   12.30Fdef"); // string test_string("abc%sdef % \"あいう\"", "abc%sdef" % "あいう", "abcあいうdef"); // char test_string("abc%cdef % 'あ'", "abc%cdef" % 'あ', "abcあdef"); // bool test_string("abc%bdef % 1", "abc%bdef" % (b = 1), "abctruedef"); test_string("abc%bdef % 0", "abc%bdef" % (b = 0), "abcfalsedef"); // type mismatch test_string("%s % 42", "%s" % 42, "%s"); // 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]), 'い'); test_equal("abc[3]", (s = "abc", s[3]), 0); test_equal("abあいう[5]", (s = "abあいう", s[5]), 0); test_equal("abあいう[8]", (s = "abあいう", s[8]), 0); // This throws // test_equal("abあいう[9]", (s = "abあいう", s[9]), 0); // 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う"); test_string("abあいう[5] = 'c'", (s = "abあいう", s[5] = 'c', s), "abあいう"); test_string("abあいう[7] = 'c'", (s = "abあいう", s[7] = 'c', s), "abあいう"); // This throws // test_string("abあいう[8] = 'c'", (s = "abあいう", s[8] = 'c', s), "abあいう"); // Assigning 0 to a character truncates the string. test_string("abあいう[3] = 0", (s = "abあいう", s[3] = 0, s), "abあ"); test_equal("(abあいう[3] = 0).Length", (s = "abあいう", s[3] = 0, s.Length()), 3); }