1 module dud.pkgdescription.joiningtest; 2 3 import std.algorithm.searching : canFind; 4 import std.stdio; 5 import std.format : format; 6 import std.typecons : nullable, Nullable; 7 8 import dud.semver.versionrange; 9 import dud.pkgdescription; 10 import dud.pkgdescription.compare; 11 import dud.pkgdescription.joining; 12 13 unittest { 14 string toParse = ` 15 { 16 "authors": [ 17 "Robert burner Schadek" 18 ], 19 "copyright": "Copyright © 2019, Symmetry Investments", 20 "description": "A dub replacement", 21 "license": "LGPL3", 22 "targetType": "library", 23 "name": "dud", 24 "dependencies" : { 25 "semver": { "path" : "../semver", "optional": false, "version" : ">=0.0.1" }, 26 "path": { "path" : "../path", "default": true }, 27 "pkgdescription": { "path" : "../../pkgdescription" }, 28 "dmd": ">=2.80.0" 29 }, 30 "subConfigurations" : { 31 "doesNotExist" : "noIdea", 32 "semver" : "confA", 33 "path" : "confB" 34 }, 35 "subConfigurations-posix" : { 36 "pkgdescription" : "confC", 37 "someStrangeThing" : "args" 38 }, 39 "configurations": [ 40 { "name" : "foo" 41 , "dependencies" : { 42 "semver": { "path" : "../semver", "optional": true, "version" : ">=0.0.3" }, 43 "path": { "path" : "../path", "default": false } 44 } 45 , "dependencies-posix" : { 46 "pkgdescription": { "path" : "../../pkgdescription" 47 , "version" : ">=1.0.0" 48 }, 49 "dmd": ">=2.81.0" 50 } 51 , "subConfigurations" : { 52 "semver" : "confA2", 53 "path" : "confB2", 54 "dmd" : "newCTFE" 55 } 56 , "subConfigurations-posix" : { 57 "pkgdescription" : "confC2" 58 } 59 } 60 ], 61 "targetPath" : "/bin/dud" 62 }`; 63 PackageDescription pkg = jsonToPackageDescription(toParse); 64 PackageDescription foo = expandConfiguration(pkg, "foo"); 65 auto deps = [ 66 depBuild("semver", ">=0.0.3", "../semver", nullable(true)), 67 depBuild("path", "../path", Nullable!(bool).init, nullable(false)), 68 depBuild("dmd", parseVersionRange(">=2.80.0")), 69 depBuild("pkgdescription", "../../pkgdescription"), 70 depBuild("pkgdescription", parseVersionRange(">=1.0.0"), 71 "../../pkgdescription", Nullable!(bool).init, 72 Nullable!(bool).init, [Platform.posix]), 73 depBuild("dmd", parseVersionRange(">=2.81.0"), 74 "", Nullable!(bool).init, 75 Nullable!(bool).init, [Platform.posix]) 76 ]; 77 foreach(dep; deps) { 78 const bool cf = canFind!((g, h) => areEqual(g, h)) 79 (foo.dependencies, dep); 80 assert(cf, format("\n\t%s\nnot in\n%(\t%s\n%)", dep, foo.dependencies)); 81 } 82 83 assert(foo.dependencies.length == deps.length, format("%s != %s", 84 foo.dependencies.length, deps.length)); 85 86 string[string] unspecificSubContig = 87 [ "semver" : "confA2", "path" : "confB2", "dmd" : "newCTFE" 88 , "doesNotExist" : "noIdea" 89 ]; 90 assert(foo.subConfigurations.unspecifiedPlatform == unspecificSubContig, 91 format("\nexp: %s\ngot: %s", unspecificSubContig, 92 foo.subConfigurations.unspecifiedPlatform)); 93 94 assert(foo.subConfigurations.configs.length == 1); 95 auto key = [Platform.posix]; 96 assert(key in foo.subConfigurations.configs); 97 string[string] posix = foo.subConfigurations.configs[key]; 98 string[string] posixExp = 99 [ "pkgdescription" : "confC2", "someStrangeThing" : "args" ]; 100 101 assert(posix == posixExp, format("\nexp: %s\ngot: %s", posixExp, posix)); 102 } 103 104 Dependency depBuild(string n, string pa, 105 Nullable!bool optional = Nullable!(bool).init, 106 Nullable!bool default_ = Nullable!(bool).init, 107 Platform[] p = null) 108 { 109 return depBuild(n, Nullable!(VersionRange).init, pa, optional, 110 default_, p); 111 } 112 113 Dependency depBuild(string n, string v, string pa, 114 Nullable!bool optional = Nullable!(bool).init, 115 Nullable!bool default_ = Nullable!(bool).init, 116 Platform[] p = null) 117 { 118 return depBuild(n, parseVersionRange(v), pa, optional, default_, p); 119 } 120 121 Dependency depBuild(string n, Nullable!VersionRange v, string pa = "", 122 Nullable!bool optional = Nullable!(bool).init, 123 Nullable!bool default_ = Nullable!(bool).init, 124 Platform[] p = null) 125 { 126 Dependency ret; 127 ret.name = n; 128 ret.version_ = v; 129 ret.path = UnprocessedPath(pa); 130 ret.platforms = p; 131 ret.optional = optional; 132 ret.default_ = default_; 133 return ret; 134 } 135