hare-xdg/format/desktop_entry/desktop_entry_test.ha

102 lines
3.0 KiB
Hare
Raw Normal View History

use fmt;
use io;
use locale;
use os;
@test fn parse() void = {
let file = os::open("format/desktop_entry/test_data/foo_full.desktop")!;
defer io::close(file)!;
let file = parse(file)!;
defer file_finish(&file);
assert(file.typ == "Application");
assert(file.version == "1.0");
assert(locale_string_equal(file.name, [
(locale::c, "Foo Viewer"),
]));
assert(locale_string_equal(file.generic_name, [
(locale::c, "Foo Viewer"),
(locale::parse("xx_XX.UTF-8")!, "Sneep glorp"),
]));
assert(file.no_display == false);
assert(locale_string_equal(file.comment, [
(locale::c, "The best viewer for Foo objects available!"),
]));
assert(locale_string_equal(file.icon, [
(locale::c, "fooview"),
]));
assert(file.hidden == false);
assert(strings_equal(file.only_show_in, ["MATE", "KDE"]));
assert(strings_equal(file.not_show_in, ["GNOME"]));
assert(file.dbus_activatable == false);
assert(file.try_exec == "fooview");
assert(file.exec == "fooview %F");
assert(file.path == "");
assert(file.terminal == false);
assert(strings_equal(file.mime_type, ["image/x-foo"]));
assert(strings_equal(file.categories, ["Graphics", "Utility"]));
assert(strings_equal(file.implements, [
"com.example.Example",
"com.example.OtherExample",
]));
assert(locale_strings_equal(file.keywords, [
(locale::c, ["foo", "image", "view", "viewer"]),
]));
assert(file.startup_notify == false);
assert(file.url == "");
assert(file.prefers_non_default_gpu == false);
assert(file.single_main_window == false);
for (let actio .. file.actions) switch (actio.key) {
case "Gallery" =>
assert(locale_string_equal(actio.name, [
(locale::c, "Browse Gallery"),
]));
assert(locale_string_equal(actio.icon, []));
assert(actio.exec == "fooview --gallery");
case "Create" =>
assert(locale_string_equal(actio.name, [
(locale::c, "Create a new Foo!"),
(locale::parse("en_US")!, "Create a new Foo!"),
(locale::parse("xx_XX.UTF-8")!, "Zweep zoop flooble glorp"),
]));
assert(locale_string_equal(actio.icon, [
(locale::c, "fooview-new"),
]));
assert(actio.exec == "fooview --create-new");
case =>
fmt::println("unexpected action", actio.key)!;
abort("unexpected action");
};
};
fn strings_equal(a: []str, b: []str) bool = {
if (len(a) != len(b)) return false;
for (let index = 0z; index < len(a); index += 1) {
if (a[index] != b[index]) return false;
};
return true;
};
fn locale_string_equal(a: locale::string, b: locale::string) bool = {
if (len(a) != len(b)) return false;
for (let index = 0z; index < len(a); index += 1) {
let a = a[index];
let b = b[index];
if (!locale::equal(a.0, b.0)) return false;
if (a.1 != b.1 ) return false;
};
return true;
};
fn locale_strings_equal(a: locale::strings, b: locale::strings) bool = {
if (len(a) != len(b)) return false;
for (let index = 0z; index < len(a); index += 1) {
let a = a[index];
let b = b[index];
if (!locale::equal(a.0, b.0)) return false;
if (!strings_equal(a.1, b.1)) return false;
};
return true;
};