hare-xdg/locale/locale_test.ha

144 lines
3.8 KiB
Hare

use fmt;
use errors;
use strings;
@test fn parse_full() void = {
let local = match(parse("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);
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")) {
case let local: locale => yield local;
case => abort("error");
};
fmt::printf("[{}]\n", local.lang)!;
assert(strings::compare(local.lang, "lang") == 0);
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")) {
case let local: locale => yield local;
case => abort("error");
};
fmt::printf("[{}]\n", local.lang)!;
assert(strings::compare(local.lang, "lang") == 0);
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")) {
case let local: locale => yield local;
case => abort("error");
};
fmt::printf("[{}]\n", local.lang)!;
assert(strings::compare(local.lang, "lang") == 0);
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")) {
case errors::invalid => void;
case => abort("error");
};
};
@test fn format_a() void = {
let string = format(locale {
lang = "lang",
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",
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",
...
});
defer free(string);
fmt::printf("[{}]\n", string)!;
assert(strings::compare(string, "lang") == 0);
};
@test fn equal() void = {
assert(equal(locale {
lang = "lang",
country = "COUNTRY",
encoding = "ENCODING",
modifier = "MODIFIER",
},
locale {
lang = "lang",
country = "COUNTRY",
encoding = "ENCODING",
modifier = "MODIFIER",
}));
assert(!equal(locale {
lang = "lang",
country = "COUNTRY",
encoding = "ENCODING",
modifier = "MODIFIER",
},
locale {
lang = "foo",
country = "COUNTRY",
encoding = "ENCODING",
modifier = "MODIFIER",
}));
assert(!equal(locale {
lang = "lang",
encoding = "ENCODING",
modifier = "MODIFIER",
...
},
locale {
lang = "lang",
country = "COUNTRY",
encoding = "ENCODING",
...
}));
};