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
+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);