diff --git a/source/dub/compilers/buildsettings.d b/source/dub/compilers/buildsettings.d index 16de290..3da87b1 100644 --- a/source/dub/compilers/buildsettings.d +++ b/source/dub/compilers/buildsettings.d @@ -108,8 +108,9 @@ void removeOptions(in BuildOption[] value...) { foreach (v; value) this.options &= ~v; } void removeOptions(in BuildOptions value) { this.options &= ~value; } +private: // Adds vals to arr without adding duplicates. - private void add(ref string[] arr, in string[] vals, bool no_duplicates = true) + static void add(ref string[] arr, in string[] vals, bool no_duplicates = true) { if (!no_duplicates) { arr ~= vals; @@ -127,7 +128,16 @@ } } - private void prepend(ref string[] arr, in string[] vals, bool no_duplicates = true) + unittest + { + auto ary = ["-dip1000", "-vgc"]; + BuildSettings.add(ary, ["-dip1000", "-vgc"]); + assert(ary == ["-dip1000", "-vgc"]); + BuildSettings.add(ary, ["-dip1001", "-vgc"], false); + assert(ary == ["-dip1000", "-vgc", "-dip1001", "-vgc"]); + } + + static void prepend(ref string[] arr, in string[] vals, bool no_duplicates = true) { if (!no_duplicates) { arr = vals ~ arr; @@ -145,8 +155,17 @@ } } + unittest + { + auto ary = ["-dip1000", "-vgc"]; + BuildSettings.prepend(ary, ["-dip1000", "-vgc"]); + assert(ary == ["-dip1000", "-vgc"]); + BuildSettings.prepend(ary, ["-dip1001", "-vgc"], false); + assert(ary == ["-dip1001", "-vgc", "-dip1000", "-vgc"]); + } + // add string import files (avoids file name duplicates in addition to path duplicates) - private void addSI(ref string[] arr, in string[] vals) + static void addSI(ref string[] arr, in string[] vals) { bool[string] existing; foreach (v; arr) existing[Path(v).head.toString()] = true; @@ -159,7 +178,16 @@ } } - private void removePaths(ref string[] arr, in string[] vals) + unittest + { + auto ary = ["path/foo.txt"]; + BuildSettings.addSI(ary, ["path2/foo2.txt"]); + assert(ary == ["path/foo.txt", "path2/foo2.txt"]); + BuildSettings.addSI(ary, ["path2/foo.txt"]); // no duplicate basenames + assert(ary == ["path/foo.txt", "path2/foo2.txt"]); + } + + static void removePaths(ref string[] arr, in string[] vals) { bool matches(string s) { @@ -171,7 +199,18 @@ arr = arr.filter!(s => !matches(s))().array(); } - private void remove(ref string[] arr, in string[] vals) + unittest + { + auto ary = ["path1", "root/path1", "root/path2", "root2/path1"]; + BuildSettings.removePaths(ary, ["path1"]); + assert(ary == ["root/path1", "root/path2", "root2/path1"]); + BuildSettings.removePaths(ary, ["*/path1"]); + assert(ary == ["root/path2"]); + BuildSettings.removePaths(ary, ["foo", "bar", "root/path2"]); + assert(ary == []); + } + + static void remove(ref string[] arr, in string[] vals) { bool matches(string s) { @@ -182,6 +221,21 @@ } arr = arr.filter!(s => !matches(s))().array(); } + + unittest + { + import std.string : join; + + auto ary = ["path1", "root/path1", "root/path2", "root2/path1"]; + BuildSettings.remove(ary, ["path1"]); + assert(ary == ["root/path1", "root/path2", "root2/path1"]); + BuildSettings.remove(ary, ["root/path*"]); + assert(ary == ["root/path1", "root/path2", "root2/path1"]); + BuildSettings.removePaths(ary, ["foo", "root/path2", "bar", "root2/path1"]); + assert(ary == ["root/path1"]); + BuildSettings.remove(ary, ["root/path1", "foo"]); + assert(ary == []); + } } enum BuildSetting {