test: update tests

This commit is contained in:
2026-05-02 14:31:17 +01:00
parent 15a9147e15
commit b072632499
7 changed files with 54 additions and 28 deletions
+3 -3
View File
@@ -7,7 +7,7 @@ static void test_string_create(CuTest *tc)
CuAssertPtrNotNull(tc, str);
CuAssertIntEquals(tc, 0, fx_string_get_size(str, FX_STRLEN_NORMAL));
CuAssertStrEquals(tc, "", fx_string_ptr(str));
CuAssertStrEquals(tc, "", fx_string_get_cstr(str));
fx_string_unref(str);
@@ -15,7 +15,7 @@ static void test_string_create(CuTest *tc)
CuAssertPtrNotNull(tc, str);
CuAssertIntEquals(tc, 8, fx_string_get_size(str, FX_STRLEN_NORMAL));
CuAssertStrEquals(tc, "AAAAAAAA", fx_string_ptr(str));
CuAssertStrEquals(tc, "AAAAAAAA", fx_string_get_cstr(str));
fx_string_unref(str);
@@ -23,7 +23,7 @@ static void test_string_create(CuTest *tc)
CuAssertPtrNotNull(tc, str);
CuAssertIntEquals(tc, 13, fx_string_get_size(str, FX_STRLEN_NORMAL));
CuAssertStrEquals(tc, "Hello, world!", fx_string_ptr(str));
CuAssertStrEquals(tc, "Hello, world!", fx_string_get_cstr(str));
fx_string_unref(str);
}
+3 -3
View File
@@ -7,21 +7,21 @@ int main(void)
{
printf("-------------\n");
fx_string *str = fx_string_create_from_cstr("Hello, world!\n");
printf("%s\n", fx_string_ptr(str));
printf("%s\n", fx_string_get_cstr(str));
printf("len:%zu, max:%zu\n", fx_string_get_size(str, FX_STRLEN_NORMAL),
fx_string_get_capacity(str));
fx_string_insert_cstr(str, "WOW!", 4);
printf("-------------\n");
printf("%s\n", fx_string_ptr(str));
printf("%s\n", fx_string_get_cstr(str));
printf("len:%zu, max:%zu\n", fx_string_get_size(str, FX_STRLEN_NORMAL),
fx_string_get_capacity(str));
fx_string_replace(str, 4, 4, "+");
printf("-------------\n");
printf("%s\n", fx_string_ptr(str));
printf("%s\n", fx_string_get_cstr(str));
printf("len:%zu, max:%zu\n", fx_string_get_size(str, FX_STRLEN_NORMAL),
fx_string_get_capacity(str));
printf("-------------\n");
+1 -1
View File
@@ -33,7 +33,7 @@ int main(void)
size_t i = 0;
fx_foreach(fx_dict_item *, item, it)
{
printf("item %zu: %s=%d\n", i++, fx_string_ptr(item->key),
printf("item %zu: %s=%d\n", i++, fx_string_get_cstr(item->key),
fx_number_get_int(item->value));
}
+1 -1
View File
@@ -7,7 +7,7 @@ int main(void)
{
printf("здравс\u26A0твуите\n");
fx_string *str = fx_string_create_from_cstr("здравствуите");
const char *s = fx_string_ptr(str);
const char *s = fx_string_get_cstr(str);
printf("%s\n", s);
printf("len: %zu\n", fx_string_get_size(str, FX_STRLEN_NORMAL));
printf("codepoints: %zu\n", fx_string_get_size(str, FX_STRLEN_CODEPOINTS));
+3 -3
View File
@@ -23,9 +23,9 @@ int main(int argc, const char **argv)
fx_serial_ctx *ctx = NULL;
fx_object *data;
fx_status status = fx_serial_ctx_deserialise(ctx, src, &data, 0);
if (!FX_OK(status)) {
fprintf(stderr, "cannot read data\n");
result = fx_serial_ctx_deserialise(ctx, src, &data, 0);
if (fx_result_is_error(result)) {
fx_throw(result);
return -1;
}
+40 -14
View File
@@ -19,7 +19,12 @@ void write_raw_string(const fx_string *data)
c -= 0x10000;
long hi = 0xD800 | ((c >> 10) & 0x3FF);
long lo = 0xDC00 | (c & 0x3FF);
fx_stream_write_fmt(fx_stdout, NULL, "\\u%04x\\u%04x", hi, lo);
fx_stream_write_fmt(
fx_stdout,
NULL,
"\\u%04x\\u%04x",
hi,
lo);
} else if (c <= 0x1F || c >= 0x7F) {
fx_stream_write_fmt(fx_stdout, NULL, "\\u%04x", c);
} else if (c == '\\' || c == '"') {
@@ -35,7 +40,10 @@ void write_raw_string(const fx_string *data)
void write_tagged_string(fx_string *data)
{
fx_stream_write_cstr(fx_stdout, "{ \"type\": \"string\", \"value\": ", NULL);
fx_stream_write_cstr(
fx_stdout,
"{ \"type\": \"string\", \"value\": ",
NULL);
write_raw_string(data);
@@ -45,7 +53,9 @@ void write_tagged_string(fx_string *data)
void write_tagged_integer(fx_number *data)
{
fx_stream_write_cstr(
fx_stdout, "{ \"type\": \"integer\", \"value\": \"", NULL);
fx_stdout,
"{ \"type\": \"integer\", \"value\": \"",
NULL);
if (fx_number_is_inf_positive(data)) {
fx_stream_write_cstr(fx_stdout, "inf", NULL);
@@ -57,7 +67,11 @@ void write_tagged_integer(fx_number *data)
fx_stream_write_cstr(fx_stdout, "-nan", NULL);
} else {
fx_stream_write_fmt(
fx_stdout, NULL, "%lld", fx_number_get_longlong(data), NULL);
fx_stdout,
NULL,
"%lld",
fx_number_get_longlong(data),
NULL);
}
fx_stream_write_cstr(fx_stdout, "\" }", NULL);
@@ -66,7 +80,9 @@ void write_tagged_integer(fx_number *data)
void write_tagged_float(fx_number *data)
{
fx_stream_write_cstr(
fx_stdout, "{ \"type\": \"float\", \"value\": \"", NULL);
fx_stdout,
"{ \"type\": \"float\", \"value\": \"",
NULL);
if (fx_number_is_inf_positive(data)) {
fx_stream_write_cstr(fx_stdout, "inf", NULL);
@@ -93,8 +109,11 @@ void write_tagged_bool(fx_number *data)
{
int v = fx_number_get_int8(data);
fx_stream_write_fmt(
fx_stdout, NULL, "{ \"type\": \"bool\", \"value\": \"%s\" }",
(v > 0) ? "true" : "false", NULL);
fx_stdout,
NULL,
"{ \"type\": \"bool\", \"value\": \"%s\" }",
(v > 0) ? "true" : "false",
NULL);
}
void write_tagged_datetime(fx_datetime *data)
@@ -107,20 +126,26 @@ void write_tagged_datetime(fx_datetime *data)
if (has_date && has_time) {
fx_stream_write_cstr(
fx_stdout, localtime ? "datetime-local" : "datetime", NULL);
fx_stdout,
localtime ? "datetime-local" : "datetime",
NULL);
} else if (has_date) {
fx_stream_write_cstr(
fx_stdout, localtime ? "date-local" : "date", NULL);
fx_stdout,
localtime ? "date-local" : "date",
NULL);
} else if (has_time) {
fx_stream_write_cstr(
fx_stdout, localtime ? "time-local" : "time", NULL);
fx_stdout,
localtime ? "time-local" : "time",
NULL);
}
fx_stream_write_cstr(fx_stdout, "\", \"value\": \"", NULL);
fx_string *new_data = fx_string_create();
fx_datetime_to_string(data, FX_DATETIME_FORMAT_RFC3339, new_data);
fx_stream_write_cstr(fx_stdout, fx_string_ptr(new_data), NULL);
fx_stream_write_cstr(fx_stdout, fx_string_get_cstr(new_data), NULL);
fx_stream_write_cstr(fx_stdout, "\" }", NULL);
@@ -207,9 +232,10 @@ int main(void)
fx_serial_ctx *ctx = fx_toml_serial_ctx_create();
fx_object *data;
fx_status status = fx_serial_ctx_deserialise(ctx, src, &data, 0);
if (!FX_OK(status)) {
return 1;
fx_result result = fx_serial_ctx_deserialise(ctx, src, &data, 0);
if (fx_result_is_error(result)) {
fx_throw(result);
return -1;
}
write_tagged_value(data);
+3 -3
View File
@@ -23,9 +23,9 @@ int main(int argc, const char **argv)
fx_serial_ctx *ctx = fx_toml_serial_ctx_create();
fx_object *data = NULL;
fx_status status = fx_serial_ctx_deserialise(ctx, src, &data, 0);
if (!FX_OK(status)) {
fprintf(stderr, "cannot read data\n");
result = fx_serial_ctx_deserialise(ctx, src, &data, 0);
if (fx_result_is_error(result)) {
fx_throw(result);
return -1;
}