2024-10-22 11:17:21 -06:00
|
|
|
use fmt;
|
|
|
|
use io;
|
|
|
|
use locale;
|
|
|
|
use os;
|
|
|
|
|
|
|
|
@test fn parse() void = {
|
2024-10-22 11:39:40 -06:00
|
|
|
let file = os::open("format/desktop_entry/test_data/foo_full.desktop")!;
|
2024-10-22 11:17:21 -06:00
|
|
|
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"),
|
|
|
|
]));
|
2024-10-22 11:39:40 -06:00
|
|
|
assert(locale_string_equal(file.generic_name, [
|
|
|
|
(locale::c, "Foo Viewer"),
|
|
|
|
(locale::parse("xx_XX.UTF-8")!, "Sneep glorp"),
|
|
|
|
]));
|
2024-10-22 11:17:21 -06:00
|
|
|
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);
|
2024-10-22 11:39:40 -06:00
|
|
|
assert(strings_equal(file.only_show_in, ["MATE", "KDE"]));
|
|
|
|
assert(strings_equal(file.not_show_in, ["GNOME"]));
|
2024-10-22 11:17:21 -06:00
|
|
|
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"]));
|
2024-10-22 11:39:40 -06:00
|
|
|
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"]),
|
|
|
|
]));
|
2024-10-22 11:17:21 -06:00
|
|
|
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"),
|
|
|
|
]));
|
2024-10-22 11:39:40 -06:00
|
|
|
assert(locale_string_equal(actio.icon, []));
|
2024-10-22 11:17:21 -06:00
|
|
|
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;
|
|
|
|
};
|