2024-10-03 17:52:06 -06:00
|
|
|
use fmt;
|
|
|
|
use strings;
|
|
|
|
|
2024-10-04 21:17:45 -06:00
|
|
|
@test fn parse_full() void = {
|
|
|
|
let local = match(parse("lang_COUNTRY.ENCODING@MODIFIER")) {
|
2024-10-03 17:52:06 -06:00
|
|
|
case let local: locale => yield local;
|
|
|
|
case => abort("error");
|
|
|
|
};
|
2024-10-04 11:26:37 -06:00
|
|
|
fmt::printf("[{}]\n", local.lang)!;
|
|
|
|
assert(strings::compare(local.lang, "lang") == 0);
|
2024-10-03 17:52:06 -06:00
|
|
|
fmt::printf("[{}]\n", local.country)!;
|
|
|
|
assert(strings::compare(local.country, "COUNTRY") == 0);
|
|
|
|
fmt::printf("[{}]\n", local.encoding)!;
|
|
|
|
assert(strings::compare(local.encoding, "ENCODING") == 0);
|
|
|
|
fmt::printf("[{}]\n", local.modifier)!;
|
|
|
|
assert(strings::compare(local.modifier, "MODIFIER") == 0);
|
|
|
|
};
|
|
|
|
|
2024-10-04 21:17:45 -06:00
|
|
|
@test fn parse_sparse_a() void = {
|
|
|
|
let local = match(parse("lang.ENCODING@MODIFIER")) {
|
2024-10-03 17:52:06 -06:00
|
|
|
case let local: locale => yield local;
|
|
|
|
case => abort("error");
|
|
|
|
};
|
2024-10-04 11:26:37 -06:00
|
|
|
fmt::printf("[{}]\n", local.lang)!;
|
|
|
|
assert(strings::compare(local.lang, "lang") == 0);
|
2024-10-03 17:52:06 -06:00
|
|
|
fmt::printf("[{}]\n", local.country)!;
|
|
|
|
assert(strings::compare(local.country, "") == 0);
|
|
|
|
fmt::printf("[{}]\n", local.encoding)!;
|
|
|
|
assert(strings::compare(local.encoding, "ENCODING") == 0);
|
|
|
|
fmt::printf("[{}]\n", local.modifier)!;
|
|
|
|
assert(strings::compare(local.modifier, "MODIFIER") == 0);
|
|
|
|
};
|
|
|
|
|
2024-10-04 21:17:45 -06:00
|
|
|
@test fn parse_sparse_b() void = {
|
|
|
|
let local = match(parse("lang.ENCODING")) {
|
2024-10-03 17:52:06 -06:00
|
|
|
case let local: locale => yield local;
|
|
|
|
case => abort("error");
|
|
|
|
};
|
2024-10-04 11:26:37 -06:00
|
|
|
fmt::printf("[{}]\n", local.lang)!;
|
|
|
|
assert(strings::compare(local.lang, "lang") == 0);
|
2024-10-03 17:52:06 -06:00
|
|
|
fmt::printf("[{}]\n", local.country)!;
|
|
|
|
assert(strings::compare(local.country, "") == 0);
|
|
|
|
fmt::printf("[{}]\n", local.encoding)!;
|
|
|
|
assert(strings::compare(local.encoding, "ENCODING") == 0);
|
|
|
|
fmt::printf("[{}]\n", local.modifier)!;
|
|
|
|
assert(strings::compare(local.modifier, "") == 0);
|
|
|
|
};
|
|
|
|
|
2024-10-04 21:17:45 -06:00
|
|
|
@test fn parse_sparse_c() void = {
|
|
|
|
let local = match(parse("lang")) {
|
2024-10-03 17:52:06 -06:00
|
|
|
case let local: locale => yield local;
|
|
|
|
case => abort("error");
|
|
|
|
};
|
2024-10-04 11:26:37 -06:00
|
|
|
fmt::printf("[{}]\n", local.lang)!;
|
|
|
|
assert(strings::compare(local.lang, "lang") == 0);
|
2024-10-03 17:52:06 -06:00
|
|
|
fmt::printf("[{}]\n", local.country)!;
|
|
|
|
assert(strings::compare(local.country, "") == 0);
|
|
|
|
fmt::printf("[{}]\n", local.encoding)!;
|
|
|
|
assert(strings::compare(local.encoding, "") == 0);
|
|
|
|
fmt::printf("[{}]\n", local.modifier)!;
|
|
|
|
assert(strings::compare(local.modifier, "") == 0);
|
|
|
|
};
|
|
|
|
|
2024-10-04 21:17:45 -06:00
|
|
|
@test fn parse_error() void = {
|
|
|
|
let local = match(parse("_COUNTRY.ENCODING@MODIFIER")) {
|
2024-10-12 21:51:52 -06:00
|
|
|
case invalid => void;
|
|
|
|
case => abort("no error");
|
2024-10-03 17:52:06 -06:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-10-04 21:17:45 -06:00
|
|
|
@test fn format_a() void = {
|
|
|
|
let string = format(locale {
|
2024-10-04 11:26:37 -06:00
|
|
|
lang = "lang",
|
2024-10-03 17:52:06 -06:00
|
|
|
country = "COUNTRY",
|
|
|
|
encoding = "ENCODING",
|
|
|
|
modifier = "MODIFIER",
|
|
|
|
});
|
|
|
|
defer free(string);
|
|
|
|
fmt::printf("[{}]\n", string)!;
|
|
|
|
assert(strings::compare(string, "lang_COUNTRY.ENCODING@MODIFIER") == 0);
|
|
|
|
};
|
|
|
|
|
2024-10-04 21:17:45 -06:00
|
|
|
@test fn format_b() void = {
|
|
|
|
let string = format(locale {
|
2024-10-04 11:26:37 -06:00
|
|
|
lang = "lang",
|
2024-10-03 17:52:06 -06:00
|
|
|
country = "COUNTRY",
|
|
|
|
modifier = "MODIFIER",
|
|
|
|
...
|
|
|
|
});
|
|
|
|
defer free(string);
|
|
|
|
fmt::printf("[{}]\n", string)!;
|
|
|
|
assert(strings::compare(string, "lang_COUNTRY@MODIFIER") == 0);
|
|
|
|
};
|
|
|
|
|
2024-10-04 21:17:45 -06:00
|
|
|
@test fn format_c() void = {
|
|
|
|
let string = format(locale {
|
2024-10-04 11:26:37 -06:00
|
|
|
lang = "lang",
|
2024-10-03 17:52:06 -06:00
|
|
|
...
|
|
|
|
});
|
|
|
|
defer free(string);
|
|
|
|
fmt::printf("[{}]\n", string)!;
|
|
|
|
assert(strings::compare(string, "lang") == 0);
|
|
|
|
};
|
|
|
|
|
2024-10-04 21:17:45 -06:00
|
|
|
@test fn equal() void = {
|
|
|
|
assert(equal(locale {
|
2024-10-04 11:26:37 -06:00
|
|
|
lang = "lang",
|
2024-10-03 17:52:06 -06:00
|
|
|
country = "COUNTRY",
|
|
|
|
encoding = "ENCODING",
|
|
|
|
modifier = "MODIFIER",
|
|
|
|
},
|
|
|
|
locale {
|
2024-10-04 11:26:37 -06:00
|
|
|
lang = "lang",
|
2024-10-03 17:52:06 -06:00
|
|
|
country = "COUNTRY",
|
|
|
|
encoding = "ENCODING",
|
|
|
|
modifier = "MODIFIER",
|
|
|
|
}));
|
2024-10-04 21:17:45 -06:00
|
|
|
assert(!equal(locale {
|
2024-10-04 11:26:37 -06:00
|
|
|
lang = "lang",
|
2024-10-03 17:52:06 -06:00
|
|
|
country = "COUNTRY",
|
|
|
|
encoding = "ENCODING",
|
|
|
|
modifier = "MODIFIER",
|
|
|
|
},
|
|
|
|
locale {
|
2024-10-04 11:26:37 -06:00
|
|
|
lang = "foo",
|
2024-10-03 17:52:06 -06:00
|
|
|
country = "COUNTRY",
|
|
|
|
encoding = "ENCODING",
|
|
|
|
modifier = "MODIFIER",
|
|
|
|
}));
|
2024-10-04 21:17:45 -06:00
|
|
|
assert(!equal(locale {
|
2024-10-04 11:26:37 -06:00
|
|
|
lang = "lang",
|
2024-10-03 17:52:06 -06:00
|
|
|
encoding = "ENCODING",
|
|
|
|
modifier = "MODIFIER",
|
|
|
|
...
|
|
|
|
},
|
|
|
|
locale {
|
2024-10-04 11:26:37 -06:00
|
|
|
lang = "lang",
|
2024-10-03 17:52:06 -06:00
|
|
|
country = "COUNTRY",
|
|
|
|
encoding = "ENCODING",
|
|
|
|
...
|
|
|
|
}));
|
|
|
|
};
|