chsrc/test/xy.c

112 lines
4.1 KiB
C
Raw Normal View History

2023-09-09 16:57:06 +08:00
/** ------------------------------------------------------------
2024-06-21 10:51:49 +08:00
* SPDX-License-Identifier: MIT
* -------------------------------------------------------------
2024-05-24 16:33:32 +08:00
* File : xy.c
2023-09-09 16:57:06 +08:00
* License : MIT
* Authors : Aoran Zeng <ccmywish@qq.com>
* Created on : <2023-08-30>
2024-07-09 14:06:42 +08:00
* Last modified : <2024-07-09>
2023-09-09 16:57:06 +08:00
*
2024-06-21 10:51:49 +08:00
* xy.h
2023-09-09 16:57:06 +08:00
* ------------------------------------------------------------*/
2023-08-30 09:51:48 +08:00
2024-05-25 01:02:30 +08:00
#include "xy.h"
2023-08-30 09:51:48 +08:00
int
main (int argc, char const *argv[])
{
2024-04-18 22:15:02 +08:00
xy_useutf8 ();
puti (3);
2023-09-04 14:55:38 +08:00
double dbl = 3.1415;
2024-04-18 22:15:02 +08:00
putf (dbl);
2024-06-08 08:34:17 +08:00
say (xy_2strjoin ("Xi", "'an"));
say (xy_strjoin (2, "Xi", "'an"));
say (xy_strjoin (3, "屈身守分,", "以待天时,", "不可与命争也"));
say (xy_strjoin (4, "水落鱼梁浅,", "天寒梦泽深。", "羊公碑字在,", "读罢泪沾襟。"));
say (xy_strjoin (6, "楚山横地出,", "汉水接天回。", "冠盖非新里,", "章华即旧台。", "习池风景异,", "归路满尘埃。"));
2023-08-30 09:51:48 +08:00
2024-06-08 07:17:50 +08:00
print (xy_str_to_bold ("粗体"));
print (xy_str_to_faint ("浅体"));
print (xy_str_to_italic ("斜体"));
2024-04-18 22:15:02 +08:00
print (xy_str_to_underline ("下划线"));
2024-06-08 07:17:50 +08:00
print (xy_str_to_blink ("闪烁"));
print (xy_str_to_cross ("删除线"));
2023-09-04 21:15:16 +08:00
2024-06-08 07:17:50 +08:00
print (xy_str_to_red ("红色"));
print (xy_str_to_green ("绿色"));
print (xy_str_to_yellow ("黄色"));
print (xy_str_to_blue ("蓝色"));
2024-04-18 22:15:02 +08:00
print (xy_str_to_magenta ("紫色"));
2024-06-08 07:17:50 +08:00
print (xy_str_to_purple ("紫色"));
print (xy_str_to_cyan ("青色"));
2024-04-18 22:15:02 +08:00
puts ("");
2023-09-27 16:25:59 +08:00
2024-06-08 09:23:51 +08:00
xy_log ("普通", "输出普通内容");
xy_succ ("成功", "输出成功内容");
xy_info ("信息", "输出信息内容");
xy_warn ("警告", "输出警告内容");
xy_error ("错误", "输出错误内容");
xy_log_remarkably ("xy.h", "普通", "咸阳油泼面筋道十足辣子香");
xy_succ_remarkably ("xy.h", "成功", "西安花干鸡蛋肉夹馍已出炉");
xy_info_remarkably ("xy.h", "信息", "襄阳牛肉面搭配黄酒更美味");
xy_warn_remarkably ("xy.h", "警告", "兰州牛肉面,而非兰州拉面");
xy_error_remarkably ("xy.h", "错误", "西安肉丸胡辣汤里没有肉丸");
2024-06-08 07:13:55 +08:00
2024-04-18 22:15:02 +08:00
assert (false == xy_str_end_with ("abcdef", "abcdefg"));
assert (xy_str_end_with ("abcdef", "def"));
2023-09-27 16:38:18 +08:00
2024-04-18 22:15:02 +08:00
assert (xy_str_end_with ("abcdef", "bcdef"));
assert (xy_str_end_with ("abcdef", "abcdef"));
assert (xy_str_end_with ("abcdef", ""));
2023-09-27 16:38:18 +08:00
2024-04-18 22:15:02 +08:00
assert (false == xy_str_start_with ("abcdef", "abcdefg"));
assert (xy_str_start_with ("abcdef", "abc"));
assert (xy_str_start_with ("abcdef", "abcde"));
assert (xy_str_start_with ("abcdef", "abcdef"));
assert (xy_str_start_with ("abcdef", ""));
2023-09-27 16:38:18 +08:00
2024-04-18 22:15:02 +08:00
assert_str ("abcdefg", xy_str_delete_suffix ("abcdefg", "cdef"));
assert_str ("abcdefg", xy_str_delete_suffix ("abcdefg", "cdefgh"));
assert_str ("abcdefg", xy_str_delete_suffix ("abcdefg", ""));
2024-06-08 07:17:50 +08:00
assert_str ("abcd", xy_str_delete_suffix ("abcdefg", "efg"));
2023-09-27 16:38:18 +08:00
2024-04-18 22:15:02 +08:00
assert_str ("abcdefg", xy_str_delete_prefix ("abcdefg", "cdef"));
assert_str ("abcdefg", xy_str_delete_prefix ("abcdefg", "0abcde"));
assert_str ("abcdefg", xy_str_delete_prefix ("abcdefg", ""));
2024-06-08 07:17:50 +08:00
assert_str ("defg", xy_str_delete_prefix ("abcdefg", "abc"));
2023-09-27 16:38:18 +08:00
2024-06-08 07:17:50 +08:00
assert_str ("defdef", xy_str_gsub ("abcdefabcdef", "abc", "")); // 删除
2024-04-18 22:15:02 +08:00
assert_str ("6def6def", xy_str_gsub ("abcdefabcdef", "abc", "6")); // 缩小
assert_str ("XIANGdefXIANGdef",
xy_str_gsub ("abcdefabcdef", "abc", "XIANG")); // 扩张
assert_str ("DEFdefDEFdef",
xy_str_gsub ("abcdefabcdef", "abc", "DEF")); // 等量
2023-09-27 16:38:18 +08:00
2023-09-27 16:01:16 +08:00
2024-05-25 01:02:30 +08:00
assert (xy_file_exist ("./image/chsrc.png"));
2024-07-09 14:06:42 +08:00
assert (xy_dir_exist ("~"));
if (xy_on_windows)
{
assert (xy_file_exist (xy_win_powershell_profile));
assert (true == xy_file_exist (xy_win_powershellv5_profile));
assert (xy_dir_exist ("C:\\Users"));
}
else
{
assert (xy_file_exist ("~/.bashrc"));
assert (xy_dir_exist ("/etc"));
}
2023-09-10 13:15:34 +08:00
2024-04-18 22:15:02 +08:00
puts (xy_uniform_path (" \n ~/haha/test/123 \n\r "));
2024-06-08 07:17:50 +08:00
assert_str (xy_uniform_path ("~/haha/test"), xy_parent_dir (" ~/haha/test/123"));
2024-06-08 09:23:51 +08:00
xy_succ ("测试完成", "测试全部通过");
2024-06-21 10:51:49 +08:00
// xy_unimplement;
// xy_unsupport;
// xy_unreach;
2023-08-30 09:51:48 +08:00
return 0;
}