Skip to content

Commit

Permalink
Better coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeSlave committed Oct 1, 2015
1 parent 1e7b75b commit dd03c3c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
1 change: 0 additions & 1 deletion examples/desktoptest/dub.selections.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"fileVersion": 1,
"versions": {
"desktopfile": "0.5.0",
"standardpaths": "0.2.0",
"inilike": "0.2.2"
}
Expand Down
3 changes: 1 addition & 2 deletions examples/desktoptest/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ void main(string[] args)
version(OSX) {} else version(Posix) {
import standardpaths;

desktopDirs = applicationsPaths() ~ writablePath(StandardPath.Desktop);
desktopDirs = applicationsPaths() ~ writablePath(StandardPath.desktop);
} else version(Windows) {
try {
auto root = environment.get("SYSTEMDRIVE", "C:");
auto kdeDir = root ~ `\ProgramData\KDE\share\applications`;
writeln(kdeDir);
if (kdeDir.isDir) {
desktopDirs = [kdeDir];
}
Expand Down
50 changes: 45 additions & 5 deletions source/desktopfile.d
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ public:
unittest
{
auto df = new DesktopFile();
df.addGroup("Action");
assert(df.group("Action") !is null);
df.removeGroup("Action");
assert(df.group("Action") is null);
df.removeGroup("Desktop Entry");
assert(df.desktopEntry() !is null);
}
Expand Down Expand Up @@ -396,7 +400,10 @@ public:
assert(desktopFile.type == DesktopFile.Type.Directory);
}

/// Sets "Type" field to type
/**
* Sets "Type" field to type
* Note: Setting the Unknown type removes type field.
*/
@safe Type type(Type t) {
final switch(t) {
case Type.Application:
Expand All @@ -409,11 +416,27 @@ public:
this["Type"] = "Directory";
break;
case Type.Unknown:
this.removeEntry("Type");
break;
}
return t;
}

///
unittest
{
auto desktopFile = new DesktopFile();
desktopFile.type = DesktopFile.Type.Application;
assert(desktopFile.desktopEntry["Type"] == "Application");
desktopFile.type = DesktopFile.Type.Link;
assert(desktopFile.desktopEntry["Type"] == "Link");
desktopFile.type = DesktopFile.Type.Directory;
assert(desktopFile.desktopEntry["Type"] == "Directory");

desktopFile.type = DesktopFile.Type.Unknown;
assert(desktopFile.desktopEntry.value("Type").empty);
}

/**
* Specific name of the application, for example "Mozilla".
* Returns: The value associated with "Name" key.
Expand Down Expand Up @@ -841,9 +864,16 @@ Icon=folder`;
return execProcess(args, workingDirectory());
}

///ditto, but uses the only url.
@trusted Pid startApplication(string url, string locale = null, lazy string preferableTerminal = determineTerminalEmulator) const
///
unittest
{
auto df = new DesktopFile();
string[] urls;
assertThrown(df.startApplication(urls, null, "xterm"));
}

///ditto, but uses the only url.
@trusted Pid startApplication(string url, string locale = null, lazy string preferableTerminal = determineTerminalEmulator) const {
return startApplication([url], locale, preferableTerminal);
}

Expand All @@ -864,6 +894,13 @@ Icon=folder`;
return spawnProcess(["xdg-open", myurl], null, Config.none);
}

///
unittest
{
auto df = new DesktopFile();
assertThrown(df.startLink());
}

/**
* Starts application or open link depending on desktop entry type.
* Returns:
Expand Down Expand Up @@ -923,6 +960,7 @@ NotShowIn=KDE;
[Desktop Action OpenDirectory]
Name=Open directory
Name[ru]=Открыть папку
Icon=open
Exec=doublecmd %u
Expand All @@ -931,6 +969,7 @@ Icon=folder
[Desktop Action Settings]
Name=Settings
Name[ru]=Настройки
Icon=edit
Exec=doublecmd settings
Expand Down Expand Up @@ -959,8 +998,9 @@ Name=Notspecified Action`;
assert(equal(df.onlyShowIn(), ["GNOME", "XFCE", "LXDE"]));
assert(equal(df.notShowIn(), ["KDE"]));

assert(equal(df.byAction().map!(desktopAction => tuple(desktopAction.name(), desktopAction.iconName(), desktopAction.execString())),
[tuple("Open directory", "open", "doublecmd %u"), tuple("Settings", "edit", "doublecmd settings")]));
assert(equal(df.byAction().map!(desktopAction =>
tuple(desktopAction.name(), desktopAction.localizedName("ru"), desktopAction.iconName(), desktopAction.execString())),
[tuple("Open directory", "Открыть папку", "open", "doublecmd %u"), tuple("Settings", "Настройки", "edit", "doublecmd settings")]));

assert(df.action("NotPresented").group() is null);
assert(df.action("Notspecified").group() is null);
Expand Down

0 comments on commit dd03c3c

Please sign in to comment.