144 lines
3.9 KiB
Hare
144 lines
3.9 KiB
Hare
|
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.language)!;
|
||
|
assert(strings::compare(local.language, "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_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.language)!;
|
||
|
assert(strings::compare(local.language, "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_locale_sparse_b() void = {
|
||
|
let local = match(parse_locale("lang.ENCODING")) {
|
||
|
case let local: locale => yield local;
|
||
|
case => abort("error");
|
||
|
};
|
||
|
fmt::printf("[{}]\n", local.language)!;
|
||
|
assert(strings::compare(local.language, "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_locale_sparse_c() void = {
|
||
|
let local = match(parse_locale("lang")) {
|
||
|
case let local: locale => yield local;
|
||
|
case => abort("error");
|
||
|
};
|
||
|
fmt::printf("[{}]\n", local.language)!;
|
||
|
assert(strings::compare(local.language, "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_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 {
|
||
|
language = "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_locale_b() void = {
|
||
|
let string = format_locale(locale {
|
||
|
language = "lang",
|
||
|
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 {
|
||
|
language = "lang",
|
||
|
...
|
||
|
});
|
||
|
defer free(string);
|
||
|
fmt::printf("[{}]\n", string)!;
|
||
|
assert(strings::compare(string, "lang") == 0);
|
||
|
};
|
||
|
|
||
|
@test fn locale_equal() void = {
|
||
|
assert(locale_equal(locale {
|
||
|
language = "lang",
|
||
|
country = "COUNTRY",
|
||
|
encoding = "ENCODING",
|
||
|
modifier = "MODIFIER",
|
||
|
},
|
||
|
locale {
|
||
|
language = "lang",
|
||
|
country = "COUNTRY",
|
||
|
encoding = "ENCODING",
|
||
|
modifier = "MODIFIER",
|
||
|
}));
|
||
|
assert(!locale_equal(locale {
|
||
|
language = "lang",
|
||
|
country = "COUNTRY",
|
||
|
encoding = "ENCODING",
|
||
|
modifier = "MODIFIER",
|
||
|
},
|
||
|
locale {
|
||
|
language = "foo",
|
||
|
country = "COUNTRY",
|
||
|
encoding = "ENCODING",
|
||
|
modifier = "MODIFIER",
|
||
|
}));
|
||
|
assert(!locale_equal(locale {
|
||
|
language = "lang",
|
||
|
encoding = "ENCODING",
|
||
|
modifier = "MODIFIER",
|
||
|
...
|
||
|
},
|
||
|
locale {
|
||
|
language = "lang",
|
||
|
country = "COUNTRY",
|
||
|
encoding = "ENCODING",
|
||
|
...
|
||
|
}));
|
||
|
};
|