PageRenderTime 64ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 1ms

/src/test/test_ext_mb.cpp

https://github.com/kevlund/hiphop-php
C++ | 580 lines | 463 code | 79 blank | 38 comment | 0 complexity | 5b47c3f5254da73c007366866f9384e1 MD5 | raw file
  1. /*
  2. +----------------------------------------------------------------------+
  3. | HipHop for PHP |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 2010- Facebook, Inc. (http://www.facebook.com) |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. */
  16. #include <test/test_ext_mb.h>
  17. #include <runtime/ext/ext_mb.h>
  18. #include <runtime/ext/ext_string.h>
  19. #include <runtime/ext/ext_array.h>
  20. ///////////////////////////////////////////////////////////////////////////////
  21. bool TestExtMb::RunTests(const std::string &which) {
  22. bool ret = true;
  23. f_mb_internal_encoding("UTF-8");
  24. RUN_TEST(test_mb_list_encodings);
  25. RUN_TEST(test_mb_list_encodings_alias_names);
  26. RUN_TEST(test_mb_list_mime_names);
  27. RUN_TEST(test_mb_check_encoding);
  28. RUN_TEST(test_mb_convert_case);
  29. RUN_TEST(test_mb_convert_encoding);
  30. RUN_TEST(test_mb_convert_kana);
  31. RUN_TEST(test_mb_convert_variables);
  32. RUN_TEST(test_mb_decode_mimeheader);
  33. RUN_TEST(test_mb_decode_numericentity);
  34. RUN_TEST(test_mb_detect_encoding);
  35. RUN_TEST(test_mb_detect_order);
  36. RUN_TEST(test_mb_encode_mimeheader);
  37. RUN_TEST(test_mb_encode_numericentity);
  38. RUN_TEST(test_mb_ereg_match);
  39. RUN_TEST(test_mb_ereg_replace);
  40. RUN_TEST(test_mb_ereg_search_getpos);
  41. RUN_TEST(test_mb_ereg_search_getregs);
  42. RUN_TEST(test_mb_ereg_search_init);
  43. RUN_TEST(test_mb_ereg_search_pos);
  44. RUN_TEST(test_mb_ereg_search_regs);
  45. RUN_TEST(test_mb_ereg_search_setpos);
  46. RUN_TEST(test_mb_ereg_search);
  47. RUN_TEST(test_mb_ereg);
  48. RUN_TEST(test_mb_eregi_replace);
  49. RUN_TEST(test_mb_eregi);
  50. RUN_TEST(test_mb_get_info);
  51. RUN_TEST(test_mb_http_input);
  52. RUN_TEST(test_mb_http_output);
  53. RUN_TEST(test_mb_internal_encoding);
  54. RUN_TEST(test_mb_language);
  55. RUN_TEST(test_mb_output_handler);
  56. RUN_TEST(test_mb_parse_str);
  57. RUN_TEST(test_mb_preferred_mime_name);
  58. RUN_TEST(test_mb_regex_encoding);
  59. RUN_TEST(test_mb_regex_set_options);
  60. RUN_TEST(test_mb_send_mail);
  61. RUN_TEST(test_mb_split);
  62. RUN_TEST(test_mb_strcut);
  63. RUN_TEST(test_mb_strimwidth);
  64. RUN_TEST(test_mb_stripos);
  65. RUN_TEST(test_mb_stristr);
  66. RUN_TEST(test_mb_strlen);
  67. RUN_TEST(test_mb_strpos);
  68. RUN_TEST(test_mb_strrchr);
  69. RUN_TEST(test_mb_strrichr);
  70. RUN_TEST(test_mb_strripos);
  71. RUN_TEST(test_mb_strrpos);
  72. RUN_TEST(test_mb_strstr);
  73. RUN_TEST(test_mb_strtolower);
  74. RUN_TEST(test_mb_strtoupper);
  75. RUN_TEST(test_mb_strwidth);
  76. RUN_TEST(test_mb_substitute_character);
  77. RUN_TEST(test_mb_substr_count);
  78. RUN_TEST(test_mb_substr);
  79. return ret;
  80. }
  81. ///////////////////////////////////////////////////////////////////////////////
  82. bool TestExtMb::test_mb_list_encodings() {
  83. VERIFY(!same(f_array_search("UTF-8", f_mb_list_encodings()), false));
  84. return Count(true);
  85. }
  86. bool TestExtMb::test_mb_list_encodings_alias_names() {
  87. VS(f_mb_list_encodings_alias_names()["Quoted-Printable"],
  88. CREATE_VECTOR1("qprint"));
  89. return Count(true);
  90. }
  91. bool TestExtMb::test_mb_list_mime_names() {
  92. VS(f_mb_list_mime_names()["UUENCODE"], "x-uuencode");
  93. return Count(true);
  94. }
  95. bool TestExtMb::test_mb_check_encoding() {
  96. VERIFY(f_mb_check_encoding("Pr\xC3\x9C\xC3\x9D""fung", "UTF-8"));
  97. return Count(true);
  98. }
  99. bool TestExtMb::test_mb_convert_case() {
  100. String str = "mary had a Little lamb and she loved it so";
  101. str = f_mb_convert_case(str, k_MB_CASE_UPPER, "UTF-8");
  102. VS(str, "MARY HAD A LITTLE LAMB AND SHE LOVED IT SO");
  103. str = f_mb_convert_case(str, k_MB_CASE_TITLE, "UTF-8");
  104. VS(str, "Mary Had A Little Lamb And She Loved It So");
  105. return Count(true);
  106. }
  107. bool TestExtMb::test_mb_convert_encoding() {
  108. String str = "Pr\xC3\x9C""fung";
  109. VS(f_mb_convert_encoding(str, "ISO-8859-1", "UTF-8"), "Pr\xDC""fung");
  110. VS(f_mb_convert_encoding(str, "ISO-8859-1", "UTF-8, JIS"), "Pr\xDC""fung");
  111. VS(f_mb_convert_encoding(str, "ISO-8859-1", "auto"), "Pr\xDC""fung");
  112. return Count(true);
  113. }
  114. bool TestExtMb::test_mb_convert_kana() {
  115. VS(f_mb_convert_kana("foo"), "foo");
  116. return Count(true);
  117. }
  118. bool TestExtMb::test_mb_convert_variables() {
  119. Variant str = "Pr\xC3\x9C""fung";
  120. Variant str1 = "Pr\xC3\x9C""fung";
  121. Variant str2 = "Pr\xC3\x9C""fung";
  122. Variant inputenc = f_mb_convert_variables(5, "ISO-8859-1", "UTF-8", ref(str),
  123. CREATE_VECTOR2(ref(str1),
  124. ref(str2)));
  125. VS(str, "Pr\xDC""fung");
  126. VS(str1, "Pr\xDC""fung");
  127. VS(str2, "Pr\xDC""fung");
  128. return Count(true);
  129. }
  130. bool TestExtMb::test_mb_decode_mimeheader() {
  131. f_mb_internal_encoding("ISO-8859-1");
  132. VS(f_mb_decode_mimeheader("Subject: =?UTF-8?B?UHLDnGZ1bmcgUHLDnGZ1bmc=?=\n"),
  133. "Subject: Pr\xDC""fung Pr\xDC""fung");
  134. f_mb_internal_encoding("UTF-8");
  135. return Count(true);
  136. }
  137. bool TestExtMb::test_mb_decode_numericentity() {
  138. Array convmap = CREATE_VECTOR4(0x0, 0x2FFFF, 0, 0xFFFF);
  139. VS(f_mb_decode_numericentity("&#8217;&#7936;&#226;", convmap, "UTF-8"),
  140. "\xe2\x80\x99\xe1\xbc\x80\xc3\xa2");
  141. return Count(true);
  142. }
  143. bool TestExtMb::test_mb_detect_encoding() {
  144. String str = "Pr\xC3\x9C\xC3\x9D""fung";
  145. /* Detect character encoding with current detect_order */
  146. VS(f_mb_detect_encoding(str), "UTF-8");
  147. /* "auto" is expanded to "ASCII,JIS,UTF-8,EUC-JP,SJIS" */
  148. VS(f_mb_detect_encoding(str, "auto"), "UTF-8");
  149. /* Specify encoding_list character encoding by comma separated list */
  150. VS(f_mb_detect_encoding(str, "JIS, eucjp-win, sjis-win"), "SJIS-win");
  151. /* Use array to specify encoding_list */
  152. Array ary = CREATE_VECTOR3("ASCII", "JIS", "EUC-JP");
  153. VS(f_mb_detect_encoding(str, ary), "EUC-JP");
  154. return Count(true);
  155. }
  156. bool TestExtMb::test_mb_detect_order() {
  157. String str = "Pr\xC3\x9C\xC3\x9D""fung";
  158. /* Set detection order by enumerated list */
  159. {
  160. f_mb_detect_order("eucjp-win,sjis-win,UTF-8");
  161. VS(f_mb_detect_encoding(str), "SJIS-win");
  162. f_mb_detect_order("eucjp-win,UTF-8,sjis-win");
  163. VS(f_mb_detect_encoding(str), "UTF-8");
  164. }
  165. /* Set detection order by array */
  166. {
  167. f_mb_detect_order(CREATE_VECTOR3("eucjp-win", "sjis-win", "UTF-8"));
  168. VS(f_mb_detect_encoding(str), "SJIS-win");
  169. f_mb_detect_order(CREATE_VECTOR3("eucjp-win", "UTF-8", "sjis-win"));
  170. VS(f_mb_detect_encoding(str), "UTF-8");
  171. }
  172. /* Display current detection order */
  173. VS(f_implode(", ", f_mb_detect_order()), "eucJP-win, UTF-8, SJIS-win");
  174. return Count(true);
  175. }
  176. bool TestExtMb::test_mb_encode_mimeheader() {
  177. f_mb_internal_encoding("ISO-8859-1");
  178. VS(f_mb_encode_mimeheader("Subject: Pr\xDC""fung Pr\xDC""fung",
  179. "UTF-8", "B"),
  180. "Subject: =?UTF-8?B?UHLDnGZ1bmcgUHLDnGZ1bmc=?=");
  181. f_mb_internal_encoding("UTF-8");
  182. return Count(true);
  183. }
  184. bool TestExtMb::test_mb_encode_numericentity() {
  185. Array convmap = CREATE_VECTOR4(0x0, 0x2FFFF, 0, 0xFFFF);
  186. VS(f_mb_encode_numericentity("\xe2\x80\x99\xe1\xbc\x80\xc3\xa2",
  187. convmap, "UTF-8"),
  188. "&#8217;&#7936;&#226;");
  189. return Count(true);
  190. }
  191. bool TestExtMb::test_mb_ereg_match() {
  192. VERIFY(!f_mb_ereg_match("a", "some apples"));
  193. VERIFY(f_mb_ereg_match("a", "a kiwi"));
  194. VERIFY(f_mb_ereg_match(".*a", "some apples"));
  195. return Count(true);
  196. }
  197. bool TestExtMb::test_mb_ereg_replace() {
  198. {
  199. String str = "This is a test";
  200. VS(f_str_replace(" is", " was", str), "This was a test");
  201. VS(f_mb_ereg_replace("( )is", "\\1was", str), "This was a test");
  202. VS(f_mb_ereg_replace("(( )is)", "\\2was", str), "This was a test");
  203. }
  204. {
  205. int num = 4;
  206. String str = "This string has four words.";
  207. str = f_mb_ereg_replace("four", num, str);
  208. VS(str, "This string has 4 words.");
  209. }
  210. {
  211. String test = "http://test.com/test";
  212. test = f_mb_ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",
  213. "<a href=\"\\0\">\\0</a>", test);
  214. VS(test, "<a href=\"http://test.com/test\">http://test.com/test</a>");
  215. }
  216. return Count(true);
  217. }
  218. bool TestExtMb::test_mb_ereg_search_getpos() {
  219. String str = "Pr\xC3\x9C\xC3\x9D""fung abc p\xC3\x9C";
  220. String reg = "\\w+";
  221. f_mb_regex_encoding("UTF-8");
  222. f_mb_ereg_search_init(str, reg);
  223. Variant r = f_mb_ereg_search();
  224. r = f_mb_ereg_search_getregs(); // get first result
  225. VS(r, CREATE_VECTOR1("Pr\xC3\x9C\xC3\x9D""fung"));
  226. VS(f_mb_ereg_search_getpos(), 10);
  227. return Count(true);
  228. }
  229. bool TestExtMb::test_mb_ereg_search_getregs() {
  230. String str = "Pr\xC3\x9C\xC3\x9D""fung abc p\xC3\x9C";
  231. String reg = "\\w+";
  232. f_mb_regex_encoding("UTF-8");
  233. f_mb_ereg_search_init(str, reg);
  234. Variant r = f_mb_ereg_search();
  235. r = f_mb_ereg_search_getregs(); // get first result
  236. VS(r, CREATE_VECTOR1("Pr\xC3\x9C\xC3\x9D""fung"));
  237. return Count(true);
  238. }
  239. bool TestExtMb::test_mb_ereg_search_init() {
  240. VERIFY(f_mb_ereg_search_init("abcdefabcdabc", "abc"));
  241. return Count(true);
  242. }
  243. bool TestExtMb::test_mb_ereg_search_pos() {
  244. String str = "Pr\xC3\x9C\xC3\x9D""fung abc p\xC3\x9C";
  245. String reg = "\\w+";
  246. f_mb_regex_encoding("UTF-8");
  247. f_mb_ereg_search_init(str, reg);
  248. Variant r = f_mb_ereg_search();
  249. r = f_mb_ereg_search_getregs(); // get first result
  250. VS(r, CREATE_VECTOR1("Pr\xC3\x9C\xC3\x9D""fung"));
  251. VS(f_mb_ereg_search_pos(), CREATE_VECTOR2(11, 3));
  252. return Count(true);
  253. }
  254. bool TestExtMb::test_mb_ereg_search_regs() {
  255. String str = "Pr\xC3\x9C\xC3\x9D""fung abc p\xC3\x9C";
  256. String reg = "\\w+";
  257. f_mb_regex_encoding("UTF-8");
  258. f_mb_ereg_search_init(str, reg);
  259. Variant r = f_mb_ereg_search();
  260. r = f_mb_ereg_search_getregs(); // get first result
  261. VS(r, CREATE_VECTOR1("Pr\xC3\x9C\xC3\x9D""fung"));
  262. r = f_mb_ereg_search_regs(); // get next result
  263. VS(r, CREATE_VECTOR1("abc"));
  264. return Count(true);
  265. }
  266. bool TestExtMb::test_mb_ereg_search_setpos() {
  267. String str = "Pr\xC3\x9C\xC3\x9D""fung abc p\xC3\x9C";
  268. String reg = "\\w+";
  269. f_mb_regex_encoding("UTF-8");
  270. f_mb_ereg_search_init(str, reg);
  271. Variant r = f_mb_ereg_search();
  272. r = f_mb_ereg_search_getregs(); // get first result
  273. VS(r, CREATE_VECTOR1("Pr\xC3\x9C\xC3\x9D""fung"));
  274. VERIFY(f_mb_ereg_search_setpos(15));
  275. r = f_mb_ereg_search_regs(); // get next result
  276. VS(r, CREATE_VECTOR1("p\xC3\x9C"));
  277. return Count(true);
  278. }
  279. bool TestExtMb::test_mb_ereg_search() {
  280. String str = "Pr\xC3\x9C\xC3\x9D""fung abc p\xC3\x9C";
  281. String reg = "\\w+";
  282. f_mb_regex_encoding("UTF-8");
  283. f_mb_ereg_search_init(str, reg);
  284. Variant r = f_mb_ereg_search();
  285. r = f_mb_ereg_search_getregs(); // get first result
  286. VS(r, CREATE_VECTOR1("Pr\xC3\x9C\xC3\x9D""fung"));
  287. return Count(true);
  288. }
  289. bool TestExtMb::test_mb_ereg() {
  290. Variant regs;
  291. String date = "1973-04-30";
  292. VERIFY(f_mb_ereg("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", date, ref(regs)));
  293. VS(regs[3], "30");
  294. VS(regs[2], "04");
  295. VS(regs[1], "1973");
  296. VS(regs[0], "1973-04-30");
  297. return Count(true);
  298. }
  299. bool TestExtMb::test_mb_eregi_replace() {
  300. String pattern = "(>[^<]*)(suffix)";
  301. String replacement = "\\1<span class=\"search\">\\2</span>";
  302. String body = ">whateversuffix";
  303. body = f_mb_eregi_replace(pattern, replacement, body);
  304. VS(body, ">whatever<span class=\"search\">suffix</span>");
  305. return Count(true);
  306. }
  307. bool TestExtMb::test_mb_eregi() {
  308. String str = "XYZ";
  309. VERIFY(f_mb_eregi("z", str));
  310. return Count(true);
  311. }
  312. bool TestExtMb::test_mb_get_info() {
  313. VERIFY(!f_mb_get_info()["detect_order"].toArray().empty());
  314. return Count(true);
  315. }
  316. bool TestExtMb::test_mb_http_input() {
  317. // TODO: test this in TestServer
  318. VS(f_mb_http_input(), false);
  319. return Count(true);
  320. }
  321. bool TestExtMb::test_mb_http_output() {
  322. // TODO: test this in TestServer
  323. VS(f_mb_http_output(), "pass");
  324. return Count(true);
  325. }
  326. bool TestExtMb::test_mb_internal_encoding() {
  327. /* Set internal character encoding to UTF-8 */
  328. f_mb_internal_encoding("UTF-8");
  329. /* Display current internal character encoding */
  330. VS(f_mb_internal_encoding(), "UTF-8");
  331. return Count(true);
  332. }
  333. bool TestExtMb::test_mb_language() {
  334. VS(f_mb_language(), "uni");
  335. return Count(true);
  336. }
  337. bool TestExtMb::test_mb_output_handler() {
  338. // TODO: test this in TestServer
  339. return Count(true);
  340. }
  341. bool TestExtMb::test_mb_parse_str() {
  342. Variant output;
  343. f_mb_parse_str("first=value&arr[]=foo+bar&arr[]=baz", ref(output));
  344. VS(output["first"], "value");
  345. VS(output["arr[]"], "baz"); // bug in mb_parse_str not following PHP's
  346. return Count(true);
  347. }
  348. bool TestExtMb::test_mb_preferred_mime_name() {
  349. VS(f_mb_preferred_mime_name("sjis-win"), "Shift_JIS");
  350. return Count(true);
  351. }
  352. bool TestExtMb::test_mb_regex_encoding() {
  353. VERIFY(f_mb_regex_encoding("UTF-8"));
  354. VS(f_mb_regex_encoding(), "UTF-8");
  355. return Count(true);
  356. }
  357. bool TestExtMb::test_mb_regex_set_options() {
  358. VS(f_mb_regex_set_options(), "pr");
  359. VERIFY(f_mb_regex_set_options("pz"));
  360. VS(f_mb_regex_set_options(), "pz");
  361. return Count(true);
  362. }
  363. bool TestExtMb::test_mb_send_mail() {
  364. //VERIFY(f_mb_send_mail("hzhao@facebook.com", __func__, "test");
  365. return Count(true);
  366. }
  367. bool TestExtMb::test_mb_split() {
  368. String date = "04/30/1973";
  369. Array ret = f_mb_split("[/.-]", date);
  370. VS(ret[0], "04");
  371. VS(ret[1], "30");
  372. VS(ret[2], "1973");
  373. return Count(true);
  374. }
  375. bool TestExtMb::test_mb_strcut() {
  376. VS(f_mb_strcut("abcdef", 1), "bcdef");
  377. VS(f_mb_strcut("abcdef", 1, 3), "bcd");
  378. VS(f_mb_strcut("abcdef", 0, 4), "abcd");
  379. VS(f_mb_strcut("abcdef", 0, 8), "abcdef");
  380. VS(f_mb_strcut("abcdef", -1, 1), "f");
  381. VS(f_mb_strcut("\xC3\x9C""bcdef", 2), "bcdef");
  382. VS(f_mb_strcut("\xC3\x9C""bcdef", 2, 3), "bcd");
  383. VS(f_mb_strcut("\xC3\x9C""bcdef", 0, 4), "\xC3\x9C""bc");
  384. VS(f_mb_strcut("\xC3\x9C""bcdef", 0, 8), "\xC3\x9C""bcdef");
  385. VS(f_mb_strcut("\xC3\x9C""bcdef", -1, 1), "f");
  386. return Count(true);
  387. }
  388. bool TestExtMb::test_mb_strimwidth() {
  389. VS(f_mb_strimwidth("long string", 0, 6, "..>"), "lon..>");
  390. VS(f_mb_strimwidth("\xC3\x9C""long string", 0, 6, "..>"), "\xC3\x9C""lo..>");
  391. return Count(true);
  392. }
  393. bool TestExtMb::test_mb_stripos() {
  394. VS(f_mb_stripos("abcdef abcdef", "A", 1), 7);
  395. VS(f_mb_stripos("abcdef\xC3\x9C""abcdef", "A", 1), 7);
  396. return Count(true);
  397. }
  398. bool TestExtMb::test_mb_stristr() {
  399. VS(f_mb_stristr("Hello World!", "earth"), false);
  400. return Count(true);
  401. }
  402. bool TestExtMb::test_mb_strlen() {
  403. VS(f_mb_strlen("test"), 4);
  404. VS(f_mb_strlen("Pr\xC3\x9C\xC3\x9D""fung"), 8);
  405. return Count(true);
  406. }
  407. bool TestExtMb::test_mb_strpos() {
  408. VS(f_mb_strpos("abcdef abcdef", "a", 1), 7);
  409. VS(f_mb_strpos("abcdef\xC3\x9C""abcdef", "a", 1), 7);
  410. VS(f_mb_strpos("abcdef\xC3\x9C""abcdef", "A", 1), false);
  411. return Count(true);
  412. }
  413. bool TestExtMb::test_mb_strrchr() {
  414. {
  415. String text = "Line 1\nLine 2\nLine 3";
  416. VS(f_mb_strrchr(text, "\n"), "\nLine 3");
  417. }
  418. {
  419. String text = "Line 1\nLine 2\xC3\x9C""Line 3";
  420. VS(f_strrchr(text, "\x9C"), "\x9C""Line 3");
  421. // f_mb_strrchr behaves differently in different versions of
  422. // libmbfl (https://github.com/facebook/hiphop-php/issues/68)
  423. VERIFY(f_mb_strrchr(text, "\x9C").same(false) ||
  424. f_mb_strrchr(text, "\x9C").same("Line 3"));
  425. }
  426. return Count(true);
  427. }
  428. bool TestExtMb::test_mb_strrichr() {
  429. {
  430. String text = "Line 1\nLine 2\nLine 3";
  431. VS(f_mb_strrichr(text, "l"), "Line 3");
  432. }
  433. return Count(true);
  434. }
  435. bool TestExtMb::test_mb_strripos() {
  436. VS(f_mb_strripos("abcdef abcdef", "A"), 7);
  437. VS(f_mb_strripos("abcdef\xC3\x9C""abcdef", "A"), 7);
  438. return Count(true);
  439. }
  440. bool TestExtMb::test_mb_strrpos() {
  441. VS(f_mb_strrpos("abcdef abcdef", "a"), 7);
  442. VS(f_mb_strrpos("abcdef\xC3\x9C""abcdef", "a"), 7);
  443. return Count(true);
  444. }
  445. bool TestExtMb::test_mb_strstr() {
  446. String email = "name@example.com";
  447. VS(f_mb_strstr(email, "@"), "@example.com");
  448. return Count(true);
  449. }
  450. bool TestExtMb::test_mb_strtolower() {
  451. String str = "Mary Had A Little Lamb and She LOVED It So";
  452. str = f_mb_strtolower(str);
  453. VS(str, "mary had a little lamb and she loved it so");
  454. VS(f_mb_strtolower("ABC"), "abc");
  455. return Count(true);
  456. }
  457. bool TestExtMb::test_mb_strtoupper() {
  458. String str = "Mary Had A Little Lamb and She LOVED It So";
  459. str = f_mb_strtoupper(str);
  460. VS(str, "MARY HAD A LITTLE LAMB AND SHE LOVED IT SO");
  461. VS(f_mb_strtoupper("abc"), "ABC");
  462. return Count(true);
  463. }
  464. bool TestExtMb::test_mb_strwidth() {
  465. VS(f_mb_strwidth("Pr\xC3\x9C""fung"), 7);
  466. return Count(true);
  467. }
  468. bool TestExtMb::test_mb_substitute_character() {
  469. /* Set with Unicode U+3013 (GETA MARK) */
  470. f_mb_substitute_character(0x3013);
  471. VS(f_mb_substitute_character(), 0x3013);
  472. /* Set hex format */
  473. f_mb_substitute_character("long");
  474. /* Display current setting */
  475. VS(f_mb_substitute_character(), "long");
  476. return Count(true);
  477. }
  478. bool TestExtMb::test_mb_substr_count() {
  479. VS(f_mb_substr_count("This is a test", "is"), 2);
  480. String text = "This is a test";
  481. VS(f_mb_substr_count(text, "is"), 2);
  482. // different from substr_count
  483. // f_mb_strrchr behaves differently in different versions of
  484. // libmbfl (https://github.com/facebook/hiphop-php/issues/68)
  485. VERIFY(f_mb_substr_count("gcdgcdgcd", "gcdgcd").same(2) ||
  486. f_mb_substr_count("gcdgcdgcd", "gcdgcd").same(1));
  487. return Count(true);
  488. }
  489. bool TestExtMb::test_mb_substr() {
  490. VS(f_mb_substr("abcdef", 1), "bcdef");
  491. VS(f_mb_substr("abcdef", 1, 3), "bcd");
  492. VS(f_mb_substr("abcdef", 0, 4), "abcd");
  493. VS(f_mb_substr("abcdef", 0, 8), "abcdef");
  494. VS(f_mb_substr("abcdef", -1, 1), "f");
  495. VS(f_mb_substr("\xC3\x9C""bcdef", 1), "bcdef");
  496. VS(f_mb_substr("\xC3\x9C""bcdef", 1, 3), "bcd");
  497. VS(f_mb_substr("\xC3\x9C""bcdef", 0, 4), "\xC3\x9C""bcd");
  498. VS(f_mb_substr("\xC3\x9C""bcdef", 0, 8), "\xC3\x9C""bcdef");
  499. VS(f_mb_substr("\xC3\x9C""bcdef", -1, 1), "f");
  500. return Count(true);
  501. }