2019-06-14 18:36:17 +03:00
|
|
|
#include "TestHelpers.h"
|
2019-06-14 07:42:21 +03:00
|
|
|
#include <AK/AKString.h>
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2019-06-14 18:36:17 +03:00
|
|
|
EXPECT(String().is_null());
|
|
|
|
EXPECT(String().is_empty());
|
|
|
|
EXPECT(!String().characters());
|
2019-06-14 07:42:21 +03:00
|
|
|
|
2019-06-14 18:36:17 +03:00
|
|
|
EXPECT(!String("").is_null());
|
|
|
|
EXPECT(String("").is_empty());
|
|
|
|
EXPECT(String("").characters());
|
2019-06-14 08:40:36 +03:00
|
|
|
|
2019-06-14 18:36:17 +03:00
|
|
|
EXPECT(String("").impl() == String::empty().impl());
|
2019-06-14 07:42:21 +03:00
|
|
|
|
|
|
|
String test_string = "ABCDEF";
|
2019-06-14 18:36:17 +03:00
|
|
|
EXPECT(!test_string.is_empty());
|
|
|
|
EXPECT(!test_string.is_null());
|
|
|
|
EXPECT(test_string.length() == 6);
|
|
|
|
EXPECT(test_string.length() == (int)strlen(test_string.characters()));
|
|
|
|
EXPECT(test_string.characters());
|
|
|
|
EXPECT(!strcmp(test_string.characters(), "ABCDEF"));
|
2019-06-14 07:42:21 +03:00
|
|
|
|
2019-06-14 18:36:17 +03:00
|
|
|
EXPECT(test_string == "ABCDEF");
|
|
|
|
EXPECT(test_string != "ABCDE");
|
|
|
|
EXPECT(test_string != "ABCDEFG");
|
|
|
|
|
|
|
|
EXPECT(test_string[0] == 'A');
|
|
|
|
EXPECT(test_string[1] == 'B');
|
|
|
|
|
|
|
|
EXPECT(test_string.starts_with("AB"));
|
|
|
|
EXPECT(test_string.starts_with("ABCDEF"));
|
|
|
|
EXPECT(!test_string.starts_with("DEF"));
|
|
|
|
|
|
|
|
EXPECT(test_string.ends_with("EF"));
|
|
|
|
EXPECT(test_string.ends_with("ABCDEF"));
|
|
|
|
EXPECT(!test_string.ends_with("ABC"));
|
2019-06-14 08:40:36 +03:00
|
|
|
|
|
|
|
auto test_string_copy = test_string;
|
2019-06-14 18:36:17 +03:00
|
|
|
EXPECT(test_string == test_string_copy);
|
|
|
|
EXPECT(test_string.characters() == test_string_copy.characters());
|
2019-06-14 08:40:36 +03:00
|
|
|
|
|
|
|
auto test_string_move = move(test_string_copy);
|
2019-06-14 18:36:17 +03:00
|
|
|
EXPECT(test_string == test_string_move);
|
|
|
|
EXPECT(test_string_copy.is_null());
|
|
|
|
|
|
|
|
EXPECT(String::repeated('x', 0) == "");
|
|
|
|
EXPECT(String::repeated('x', 1) == "x");
|
|
|
|
EXPECT(String::repeated('x', 2) == "xx");
|
|
|
|
|
|
|
|
bool ok;
|
|
|
|
EXPECT(String("123").to_int(ok) == 123 && ok);
|
|
|
|
EXPECT(String("-123").to_int(ok) == -123 && ok);
|
|
|
|
|
|
|
|
EXPECT(String("ABC").to_lowercase() == "abc");
|
|
|
|
EXPECT(String("AbC").to_uppercase() == "ABC");
|
2019-06-14 08:40:36 +03:00
|
|
|
|
2019-06-14 07:42:21 +03:00
|
|
|
return 0;
|
|
|
|
}
|