hare-xdg/locale/locale_test.ha

144 lines
3.9 KiB
Hare
Raw Normal View History

2024-10-03 17:52:06 -06:00
use fmt;
use errors;
use strings;
@test fn parse_locale_full() void = {
let local = match(parse_locale("lang_COUNTRY.ENCODING@MODIFIER")) {
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_locale_sparse_a() void = {
let local = match(parse_locale("lang.ENCODING@MODIFIER")) {
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_locale_sparse_b() void = {
let local = match(parse_locale("lang.ENCODING")) {
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_locale_sparse_c() void = {
let local = match(parse_locale("lang")) {
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_locale_error() void = {
let local = match(parse_locale("_COUNTRY.ENCODING@MODIFIER")) {
case errors::invalid => void;
case => abort("error");
};
};
@test fn format_locale_a() void = {
let string = format_locale(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_locale_b() void = {
let string = format_locale(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_locale_c() void = {
let string = format_locale(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 locale_equal() void = {
assert(locale_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(!locale_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(!locale_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",
...
}));
};