hare-xdg/locale/locale_test.ha

143 lines
3.7 KiB
Hare
Raw Permalink Normal View History

2024-10-03 17:52:06 -06:00
use fmt;
use strings;
@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");
};
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);
};
@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");
};
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);
};
@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");
};
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);
};
@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");
};
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);
};
@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
};
};
@test fn format_a() void = {
let string = format(locale {
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);
};
@test fn format_b() void = {
let string = format(locale {
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);
};
@test fn format_c() void = {
let string = format(locale {
lang = "lang",
2024-10-03 17:52:06 -06:00
...
});
defer free(string);
fmt::printf("[{}]\n", string)!;
assert(strings::compare(string, "lang") == 0);
};
@test fn equal() void = {
assert(equal(locale {
lang = "lang",
2024-10-03 17:52:06 -06:00
country = "COUNTRY",
encoding = "ENCODING",
modifier = "MODIFIER",
},
locale {
lang = "lang",
2024-10-03 17:52:06 -06:00
country = "COUNTRY",
encoding = "ENCODING",
modifier = "MODIFIER",
}));
assert(!equal(locale {
lang = "lang",
2024-10-03 17:52:06 -06:00
country = "COUNTRY",
encoding = "ENCODING",
modifier = "MODIFIER",
},
locale {
lang = "foo",
2024-10-03 17:52:06 -06:00
country = "COUNTRY",
encoding = "ENCODING",
modifier = "MODIFIER",
}));
assert(!equal(locale {
lang = "lang",
2024-10-03 17:52:06 -06:00
encoding = "ENCODING",
modifier = "MODIFIER",
...
},
locale {
lang = "lang",
2024-10-03 17:52:06 -06:00
country = "COUNTRY",
encoding = "ENCODING",
...
}));
};