using System; unit_test void stringTest() { string empty; #assert(empty.IsEmpty()); #assert(empty.Length() == 0); #assert(*empty.Chars() == '\0'); #assert(empty == ""); #assert(empty.StartsWith("a") == false); #assert(empty.EndsWith("a") == false); #assert(empty.Find('a') == -1); #assert(empty.RFind('a') == -1); #assert(empty.Find("a") == -1); #assert(empty.RFind("a") == -1); string emptyCopy = empty; #assert(emptyCopy.IsEmpty()); #assert(emptyCopy.Length() == 0); #assert(*emptyCopy.Chars() == '\0'); #assert(emptyCopy == empty); #assert(emptyCopy == ""); string emptyRvalue = Rvalue(empty); #assert(empty.IsEmpty()); #assert(empty.Length() == 0); #assert(*empty.Chars() == '\0'); #assert(emptyRvalue.IsEmpty()); #assert(emptyRvalue.Length() == 0); #assert(*emptyRvalue.Chars() == '\0'); #assert(emptyRvalue == empty); #assert(emptyRvalue == ""); string one('a'); #assert(!one.IsEmpty()); #assert(one.Length() == 1); #assert(*one.Chars() == 'a'); #assert(one == "a"); #assert(one[0] == 'a'); #assert(one.StartsWith("a") == true); #assert(one.StartsWith("b") == false); #assert(one.StartsWith("ab") == false); #assert(one.EndsWith("a") == true); #assert(one.EndsWith("b") == false); #assert(one.EndsWith("ab") == false); #assert(one.Find('a') == 0); #assert(one.Find('b') == -1); #assert(one.RFind('a') == 0); #assert(one.RFind('b') == -1); #assert(one.Find("a") == 0); #assert(one.Find("b") == -1); #assert(one.Find("ab") == -1); #assert(one.RFind("a") == 0); #assert(one.RFind("b") == -1); #assert(one.RFind("ab") == -1); string oneCopy = one; #assert(!oneCopy.IsEmpty()); #assert(oneCopy.Length() == 1); #assert(*oneCopy.Chars() == 'a'); #assert(oneCopy == one); #assert(oneCopy == "a"); #assert(oneCopy[0] == 'a'); string oneRvalue = Rvalue(one); #assert(one.IsEmpty()); #assert(one.Length() == 0); #assert(*one.Chars() == '\0'); #assert(one == ""); #assert(!oneRvalue.IsEmpty()); #assert(oneRvalue.Length() == 1); #assert(*oneRvalue.Chars() == 'a'); #assert(oneRvalue[0] == 'a'); string two("ab"); #assert(!two.IsEmpty()); #assert(two.Length() == 2); #assert(*two.Chars() == 'a'); #assert(two == "ab"); #assert(two[0] == 'a'); #assert(two[1] == 'b'); #assert(two.StartsWith("a") == true); #assert(two.StartsWith("ab") == true); #assert(two.StartsWith("b") == false); #assert(two.StartsWith("abc") == false); #assert(two.EndsWith("a") == false); #assert(two.EndsWith("b") == true); #assert(two.EndsWith("ab") == true); #assert(two.EndsWith("abc") == false); #assert(two.Find('a') == 0); #assert(two.Find('b') == 1); #assert(two.Find('c') == -1); #assert(two.RFind('a') == 0); #assert(two.RFind('b') == 1); #assert(two.RFind('c') == -1); #assert(two.Find("a") == 0); #assert(two.Find("ab") == 0); #assert(two.Find("abc") == -1); #assert(two.Find("b") == 1); #assert(two.Find("c") == -1); #assert(two.RFind("a") == 0); #assert(two.RFind("ab") == 0); #assert(two.RFind("abc") == -1); #assert(two.RFind("b") == 1); #assert(two.RFind("c") == -1); string twoCopy = two; #assert(!twoCopy.IsEmpty()); #assert(twoCopy.Length() == 2); #assert(*twoCopy.Chars() == 'a'); #assert(twoCopy == "ab"); #assert(twoCopy[0] == 'a'); #assert(twoCopy[1] == 'b'); #assert(twoCopy == two); string twoRvalue = Rvalue(two); #assert(two.IsEmpty()); #assert(two.Length() == 0); #assert(*two.Chars() == '\0'); #assert(two == ""); #assert(twoRvalue.Length() == 2); #assert(*twoRvalue.Chars() == 'a'); #assert(twoRvalue == "ab"); #assert(twoRvalue[0] == 'a'); #assert(twoRvalue[1] == 'b'); #assert(twoRvalue == twoCopy); string ten; for (int i = 0; i < 10; ++i) { ten.Append(cast<char>(cast<int>('0') + i)); } #assert(!ten.IsEmpty()); #assert(ten.Length() == 10); for (int i = 0; i < 10; ++i) { #assert(ten[i] == cast<char>(cast<int>('0') + i)); } #assert(ten.StartsWith("0") == true); #assert(ten.StartsWith("01") == true); #assert(ten.StartsWith("012") == true); #assert(ten.StartsWith("1") == false); #assert(ten.StartsWith("12") == false); #assert(ten.StartsWith("123") == false); #assert(ten.EndsWith("9") == true); #assert(ten.EndsWith("89") == true); #assert(ten.EndsWith("789") == true); #assert(ten.EndsWith("8") == false); #assert(ten.EndsWith("78") == false); #assert(ten.EndsWith("678") == false); #assert(ten.Find('0') == 0); #assert(ten.Find('1') == 1); #assert(ten.Find('9') == 9); #assert(ten.Find('a') == -1); #assert(ten.RFind('0') == 0); #assert(ten.RFind('1') == 1); #assert(ten.RFind('9') == 9); #assert(ten.RFind('a') == -1); string tenCopy = ten; #assert(!tenCopy.IsEmpty()); #assert(tenCopy.Length() == 10); #assert(*tenCopy.Chars() == '0'); #assert(tenCopy == ten); string tenRvalue = Rvalue(ten); #assert(ten.IsEmpty()); #assert(!tenRvalue.IsEmpty()); #assert(tenRvalue.Length() == 10); #assert(*tenRvalue.Chars() == '0'); #assert(tenRvalue == tenCopy); string abradacabra = "abradacabra"; #assert(!abradacabra.IsEmpty()); #assert(abradacabra.Length() == 11); #assert(abradacabra.StartsWith("a")); #assert(abradacabra.StartsWith("abra")); #assert(!abradacabra.StartsWith("bra")); #assert(abradacabra.EndsWith("a")); #assert(abradacabra.EndsWith("abra")); #assert(!abradacabra.EndsWith("abr")); #assert(abradacabra.Find('a') == 0); #assert(abradacabra.Find('b') == 1); #assert(abradacabra.Find('r') == 2); #assert(abradacabra.Find("a") == 0); #assert(abradacabra.Find("abra") == 0); #assert(abradacabra.Find("daca") == 4); #assert(abradacabra.RFind('a') == 10); #assert(abradacabra.RFind('r') == 9); #assert(abradacabra.RFind('b') == 8); #assert(abradacabra.RFind("a") == 10); #assert(abradacabra.RFind("abra") == 7); #assert(abradacabra.RFind("daca") == 4); abradacabra[0] = 'i'; #assert(abradacabra == "ibradacabra"); string öhkömömmö = "öhkömömmö"; #assert(!öhkömömmö.IsEmpty()); #assert(öhkömömmö.Length() == 13); // UTF-8 encoded so length != number of chars #assert(öhkömömmö.StartsWith("öhkö")); #assert(öhkömömmö.EndsWith("mömmö")); #assert(öhkömömmö.Find("ö") == 0); #assert(öhkömömmö.Find("öhkö") == 0); #assert(öhkömömmö.Find("mömmö") == 6); #assert(öhkömömmö.RFind("ö") == 11); #assert(öhkömömmö.RFind("öhkö") == 0); #assert(öhkömömmö.RFind("mömmö") == 6); }