1 module dud.pkgdescription.jsontests; 2 3 import std.array : front; 4 import std.algorithm.searching : canFind; 5 import std.conv : to; 6 import std.json; 7 import std.stdio; 8 import std.format : format; 9 10 import dud.pkgdescription.json; 11 import dud.pkgdescription.output; 12 import dud.pkgdescription.helper; 13 import dud.semver.semver : SemVer; 14 import dud.semver.parse : parseSemVer; 15 import dud.semver.versionrange; 16 import dud.pkgdescription; 17 import dud.pkgdescription.validation; 18 import dud.pkgdescription.duplicate : ddup = dup; 19 20 unittest { 21 string toParse = ` 22 { 23 "authors": [ 24 "Robert burner Schadek" 25 ], 26 "copyright": "Copyright © 2019, Symmetry Investments", 27 "description": "A dub replacement", 28 "license": "LGPL3", 29 "targetType": "library", 30 "name": "dud", 31 "dependencies" : { 32 "semver": { "path" : "../semver", "optional": false, "version" : ">=0.0.1" }, 33 "path": { "path" : "../path", "default": true }, 34 "pkgdescription": { "path" : "../../pkgdescription" }, 35 "dmd": ">=2.80.0" 36 }, 37 "configurations": [ 38 { "name" : "foo" 39 , "targetType" : "executable" 40 } 41 ], 42 "targetPath" : "/bin/dud" 43 }`; 44 45 PackageDescription pkg = jsonToPackageDescription(toParse); 46 assert(pkg.description == "A dub replacement", pkg.description); 47 assert(pkg.license == "LGPL3", pkg.license); 48 //assert(pkg.version_ == parseSemVer("1.0.0"), pkg.version_.toString); 49 assert(pkg.targetPath.path == "/bin/dud", 50 format("%s", pkg.targetPath)); 51 assert(pkg.configurations.length == 1); 52 assert(pkg.dependencies.length == 4, to!string(pkg.dependencies.length)); 53 assert(pkg.dependencies.canFind!(dep => dep.name == "semver"), 54 to!string(pkg.dependencies)); 55 assert(pkg.dependencies.canFind!(dep => dep.name == "path"), 56 to!string(pkg.dependencies)); 57 assert(pkg.dependencies.canFind!(dep => dep.name == "pkgdescription"), 58 to!string(pkg.dependencies)); 59 assert(pkg.dependencies.canFind!(dep => dep.name == "dmd"), 60 to!string(pkg.dependencies)); 61 62 JSONValue n = pkg.toJSON(); 63 JSONValue o = parseJSON(toParse); 64 assert(n == o, format("\nexp:\n%s\ngot:\n%s", o.toPrettyString(), 65 n.toPrettyString())); 66 67 PackageDescription pkgFromJ = jsonToPackageDescription(n); 68 assert(pkg == pkgFromJ, format("\nexp:\n%s\ngot:\n%s", pkg, pkgFromJ)); 69 70 PackageDescription copy = ddup(pkg); 71 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 72 73 validate(copy); 74 } 75 76 unittest { 77 string toParse = ` 78 { 79 "name" : "Foo", 80 "authors": [ 81 "Robert burner Schadek" 82 ], 83 "copyright": "Copyright © 2019, Symmetry Investments", 84 "targetName": "dudposix" 85 }`; 86 87 PackageDescription pkg = jsonToPackageDescription(toParse); 88 assert(pkg.targetName); 89 assert(pkg.targetName == "dudposix", 90 format("\ngot:\n%s\nexp:\n%s", pkg.targetName, "dudposix")); 91 92 JSONValue n = pkg.toJSON(); 93 PackageDescription pkgFromJ = jsonToPackageDescription(n); 94 assert(pkg == pkgFromJ, format("\nexp:\n%s\ngot:\n%s", pkg, pkgFromJ)); 95 96 PackageDescription copy = ddup(pkg); 97 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 98 99 validate(copy); 100 } 101 102 unittest { 103 string toParse = ` 104 { 105 "name" : "Foo", 106 "dependencies" : { 107 "semver": { "path" : "../semver", "optional": false, "version" : ">=0.0.1" }, 108 "path": { "path" : "../path", "default": true } 109 }, 110 "dependencies-posix" : { 111 "pkgdescription": { "path" : "../../pkgdescription" }, 112 "dmd": ">=2.80.0" 113 } 114 }`; 115 116 PackageDescription pkg = jsonToPackageDescription(toParse); 117 118 JSONValue n = pkg.toJSON(); 119 JSONValue o = parseJSON(toParse); 120 assert(n == o, format("\nexp:\n%s\ngot:\n%s", o.toPrettyString(), 121 n.toPrettyString())); 122 123 PackageDescription pkgFromJ = jsonToPackageDescription(n); 124 assert(pkg == pkgFromJ, format("\nexp:\n%s\ngot:\n%s", pkg, pkgFromJ)); 125 JSONValue n2 = pkgFromJ.toJSON(); 126 assert(n2 == o, format("\nexp:\n%s\ngot:\n%s", o.toPrettyString(), 127 n2.toPrettyString())); 128 129 PackageDescription copy = ddup(pkg); 130 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 131 132 validate(copy); 133 } 134 135 unittest { 136 string toParse = ` 137 { 138 "name" : "Foo", 139 "postBuildCommands-windows" : [ 140 "format C:", 141 "install linux" 142 ], 143 "postBuildCommands-linux" : [ 144 "echo \"You are good\"" 145 ] 146 }`; 147 148 PackageDescription pkg = jsonToPackageDescription(toParse); 149 150 JSONValue n = pkg.toJSON(); 151 JSONValue o = parseJSON(toParse); 152 assert(n == o, format("\nexp:\n%s\ngot:\n%s", o.toPrettyString(), 153 n.toPrettyString())); 154 155 PackageDescription pkgFromJ = jsonToPackageDescription(n); 156 assert(pkg == pkgFromJ, format("\nexp:\n%s\ngot:\n%s", pkg, pkgFromJ)); 157 JSONValue n2 = pkgFromJ.toJSON(); 158 assert(n2 == o, format("\nexp:\n%s\ngot:\n%s", o.toPrettyString(), 159 n2.toPrettyString())); 160 161 PackageDescription copy = ddup(pkg); 162 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 163 164 validate(copy); 165 } 166 167 unittest { 168 string toParse = ` 169 { 170 "name" : "Foo", 171 "subConfigurations" : { 172 "semver": "that", 173 "path": "this" 174 }, 175 176 "subConfigurations-x86_64" : { 177 "another" : "crazyConfig" 178 }, 179 180 "workingDirectory" : "/root" 181 182 }`; 183 184 PackageDescription pkg = jsonToPackageDescription(toParse); 185 186 JSONValue n = pkg.toJSON(); 187 JSONValue o = parseJSON(toParse); 188 assert(n == o, format("\nexp:\n%s\ngot:\n%s", o.toPrettyString(), 189 n.toPrettyString())); 190 191 PackageDescription pkgFromJ = jsonToPackageDescription(n); 192 assert(pkg == pkgFromJ, format("\nexp:\n%s\ngot:\n%s", pkg, pkgFromJ)); 193 JSONValue n2 = pkgFromJ.toJSON(); 194 assert(n2 == o, format("\nexp:\n%s\ngot:\n%s", o.toPrettyString(), 195 n2.toPrettyString())); 196 197 PackageDescription copy = ddup(pkg); 198 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 199 200 validate(copy); 201 } 202 203 unittest { 204 string toParse = ` 205 { 206 "name" : "Foo", 207 "buildRequirements" : [ "allowWarnings", "disallowDeprecations" ] 208 } 209 `; 210 211 PackageDescription pkg = jsonToPackageDescription(toParse); 212 JSONValue n = toJSON(pkg); 213 JSONValue o = parseJSON(toParse); 214 assert(n == o, format("\nexp:\n%s\ngot:\n%s", o.toPrettyString(), 215 n.toPrettyString())); 216 217 PackageDescription pkgFromJ = jsonToPackageDescription(n); 218 assert(pkg == pkgFromJ, format("\nexp:\n%s\ngot:\n%s", pkg, pkgFromJ)); 219 JSONValue n2 = pkgFromJ.toJSON(); 220 assert(n2 == o, format("\nexp:\n%s\ngot:\n%s", o.toPrettyString(), 221 n2.toPrettyString())); 222 223 PackageDescription copy = ddup(pkg); 224 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 225 226 validate(copy); 227 } 228 229 unittest { 230 string toParse = ` 231 { 232 "name" : "Foo", 233 "buildOptions" : [ "verbose" ], 234 "buildOptions-posix" : [ "inline", "property"], 235 "buildOptions-windows" : ["betterC" ] 236 } 237 `; 238 239 PackageDescription pkg = jsonToPackageDescription(toParse); 240 JSONValue n = toJSON(pkg); 241 JSONValue o = parseJSON(toParse); 242 assert(n == o, format("\nexp:\n%s\ngot:\n%s", o.toPrettyString(), 243 n.toPrettyString())); 244 245 PackageDescription pkgFromJ = jsonToPackageDescription(n); 246 assert(pkg == pkgFromJ, format("\nexp:\n%s\ngot:\n%s", pkg, pkgFromJ)); 247 JSONValue n2 = pkgFromJ.toJSON(); 248 assert(n2 == o, format("\nexp:\n%s\ngot:\n%s", o.toPrettyString(), 249 n2.toPrettyString())); 250 251 PackageDescription copy = ddup(pkg); 252 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 253 254 validate(copy); 255 } 256 257 unittest { 258 string toParse = ` 259 { 260 "name" : "Foo", 261 "subPackages" : [ 262 { 263 "name" : "sub1" 264 } 265 , { 266 "name" : "sub2", 267 "targetType" : "executable" 268 } 269 , "../some/sub/package" 270 271 ] 272 } 273 `; 274 275 PackageDescription pkg = jsonToPackageDescription(toParse); 276 assert(pkg.subPackages.length == 3); 277 assert(pkg.subPackages[0].inlinePkg.get().name == "sub1", 278 pkg.subPackages[0].inlinePkg.get().name); 279 assert(pkg.subPackages[1].inlinePkg.get().name == "sub2", 280 pkg.subPackages[1].inlinePkg.get().name); 281 JSONValue n = toJSON(pkg); 282 JSONValue o = parseJSON(toParse); 283 assert(n == o, format("\nexp:\n%s\ngot:\n%s", o.toPrettyString(), 284 n.toPrettyString())); 285 286 PackageDescription pkgFromJ = jsonToPackageDescription(n); 287 assert(pkg == pkgFromJ, format("\nexp:\n%s\ngot:\n%s", pkg, pkgFromJ)); 288 JSONValue n2 = pkgFromJ.toJSON(); 289 assert(n2 == o, format("\nexp:\n%s\ngot:\n%s", o.toPrettyString(), 290 n2.toPrettyString())); 291 292 PackageDescription copy = ddup(pkg); 293 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 294 295 validate(copy); 296 } 297 298 unittest { 299 string toParse = ` 300 { 301 "authors": [ 302 "Guillaume Piolat", 303 "Andrej Mitrovic", 304 "Sean M. Costello (Hilbert transformer)" 305 ], 306 "copyright": "Steinberg", 307 "description": "Audio plugins framework. VST client + host, AU client, UI widgets.", 308 "homepage": "http:\/\/github.com\/p0nce\/dplug\/", 309 "license": "VST", 310 "name": "dplug", 311 "subPackages": [ 312 { 313 "dependencies": { 314 "gfm:core": ">=6.0.0 <7.0.0" 315 }, 316 "importPaths": [ 317 "core" 318 ], 319 "name": "core", 320 "sourcePaths": [ 321 "core\/dplug\/core" 322 ] 323 }, 324 { 325 "dependencies": { 326 "dplug:core": ">=0.0.0", 327 "gfm:math": ">=6.0.0 <7.0.0" 328 }, 329 "importPaths": [ 330 "dsp" 331 ], 332 "name": "dsp", 333 "sourcePaths": [ 334 "dsp\/dplug\/dsp" 335 ] 336 }, 337 { 338 "dependencies": { 339 "dplug:core": ">=0.0.0" 340 }, 341 "importPaths": [ 342 "client" 343 ], 344 "name": "client", 345 "sourcePaths": [ 346 "client\/dplug\/client" 347 ] 348 }, 349 { 350 "dependencies": { 351 "derelict-util": ">=2.0.0 <3.0.0", 352 "dplug:core": ">=0.0.0", 353 "dplug:vst": ">=0.0.0" 354 }, 355 "importPaths": [ 356 "host" 357 ], 358 "name": "host", 359 "sourcePaths": [ 360 "host\/dplug\/host" 361 ] 362 }, 363 { 364 "dependencies": { 365 "dplug:client": ">=0.0.0" 366 }, 367 "importPaths": [ 368 "vst" 369 ], 370 "name": "vst", 371 "sourcePaths": [ 372 "vst\/dplug\/vst" 373 ] 374 }, 375 { 376 "dependencies": { 377 "dplug:client": ">=0.0.0" 378 }, 379 "dependencies-osx": { 380 "derelict-carbon": ">=0.0.0 <1.0.0", 381 "derelict-cocoa": ">=0.0.0 <1.0.0" 382 }, 383 "importPaths": [ 384 "au" 385 ], 386 "name": "au", 387 "sourcePaths": [ 388 "au\/dplug\/au" 389 ] 390 }, 391 { 392 "dependencies": { 393 "ae-graphics": ">=0.0.0 <1.0.0", 394 "dplug:core": ">=0.0.0", 395 "gfm:core": ">=6.0.0 <7.0.0", 396 "gfm:math": ">=6.0.0 <7.0.0" 397 }, 398 "dependencies-osx": { 399 "derelict-carbon": ">=0.0.0 <1.0.0", 400 "derelict-cocoa": ">=0.0.0 <1.0.0" 401 }, 402 "importPaths": [ 403 "window" 404 ], 405 "importPaths-windows": [ 406 "platforms\/windows" 407 ], 408 "libs-windows": [ 409 "gdi32", 410 "user32" 411 ], 412 "name": "window", 413 "sourcePaths": [ 414 "window\/dplug\/window" 415 ], 416 "sourcePaths-windows": [ 417 "platforms\/windows" 418 ] 419 }, 420 { 421 "dependencies": { 422 "ae-graphics": ">=0.0.0 <1.0.0", 423 "dplug:client": ">=0.0.0", 424 "dplug:core": ">=0.0.0", 425 "dplug:window": ">=0.0.0", 426 "gfm:math": ">=6.0.0 <7.0.0", 427 "imageformats": ">=6.0.0 <7.0.0" 428 }, 429 "importPaths": [ 430 "gui" 431 ], 432 "name": "gui", 433 "sourcePaths": [ 434 "gui\/dplug\/gui" 435 ] 436 } 437 ], 438 "targetType": "none" 439 } 440 `; 441 442 PackageDescription pkg = jsonToPackageDescription(toParse); 443 JSONValue n = toJSON(pkg); 444 JSONValue o = parseJSON(toParse); 445 assert(n == o, format("\nexp:\n%s\ngot:\n%s", o.toPrettyString(), 446 n.toPrettyString())); 447 448 PackageDescription pkgFromJ = jsonToPackageDescription(n); 449 assert(pkg == pkgFromJ, format("\nexp:\n%s\ngot:\n%s\n\n%s", pkg, pkgFromJ, 450 pkgCompare(pkg, pkgFromJ) 451 )); 452 JSONValue n2 = pkgFromJ.toJSON(); 453 assert(n2 == o, format("\nexp:\n%s\ngot:\n%s", o.toPrettyString(), 454 n2.toPrettyString())); 455 456 PackageDescription copy = ddup(pkg); 457 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 458 459 validate(copy); 460 } 461 462 unittest { 463 string toParse = ` 464 { 465 "name" : "Foo", 466 "-ddoxTool" : "ddoxFoo" 467 } 468 `; 469 470 PackageDescription pkg = jsonToPackageDescription(toParse); 471 assert(pkg.ddoxTool.platforms.front.str == "ddoxFoo"); 472 JSONValue n = toJSON(pkg); 473 JSONValue o = parseJSON(toParse); 474 assert(n == o, format("\nexp:\n%s\ngot:\n%s", o.toPrettyString(), 475 n.toPrettyString())); 476 477 PackageDescription pkgFromJ = jsonToPackageDescription(n); 478 assert(pkg == pkgFromJ, format("\nexp:\n%s\ngot:\n%s\n\n%s", pkg, pkgFromJ, 479 pkgCompare(pkg, pkgFromJ) 480 )); 481 JSONValue n2 = pkgFromJ.toJSON(); 482 assert(n2 == o, format("\nexp:\n%s\ngot:\n%s", o.toPrettyString(), 483 n2.toPrettyString())); 484 485 PackageDescription copy = ddup(pkg); 486 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 487 488 validate(copy); 489 } 490 491 unittest { 492 string toParse = ` 493 { 494 "name" : "Foo", 495 "toolchainRequirements" : { 496 "dud" : ">=1.0.0" 497 } 498 } 499 `; 500 501 PackageDescription pkg = jsonToPackageDescription(toParse); 502 JSONValue n = toJSON(pkg); 503 JSONValue o = parseJSON(toParse); 504 assert(n == o, format("\nexp:\n%s\ngot:\n%s", o.toPrettyString(), 505 n.toPrettyString())); 506 507 PackageDescription pkgFromJ = jsonToPackageDescription(n); 508 assert(pkg == pkgFromJ, format("\nexp:\n%s\ngot:\n%s\n\n%s", pkg, pkgFromJ, 509 pkgCompare(pkg, pkgFromJ) 510 )); 511 JSONValue n2 = pkgFromJ.toJSON(); 512 assert(n2 == o, format("\nexp:\n%s\ngot:\n%s", o.toPrettyString(), 513 n2.toPrettyString())); 514 515 PackageDescription copy = ddup(pkg); 516 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 517 518 validate(copy); 519 } 520 521 unittest { 522 string toParse = ` 523 { 524 "name" : "Foo", 525 "configurations": [ 526 { 527 "name": "winapi", 528 "platforms": [ 529 "windows-x86_64", 530 "windows-x86_mscoff" 531 ], 532 "targetType": "library", 533 "versions": [ 534 "EventcoreWinAPIDriver" 535 ] 536 }, 537 { 538 "name": "select", 539 "platforms": [ 540 "posix", 541 "windows-x86_64", 542 "windows-x86_mscoff" 543 ] 544 }, 545 { 546 "name": "epoll", 547 "platforms": [ 548 "linux" 549 ], 550 "targetType": "library", 551 "versions": [ 552 "EventcoreEpollDriver" 553 ] 554 } 555 ] 556 } 557 `; 558 559 PackageDescription pkg = jsonToPackageDescription(toParse); 560 JSONValue n = toJSON(pkg); 561 //JSONValue o = parseJSON(toParse); 562 563 PackageDescription pkgFromJ = jsonToPackageDescription(n); 564 assert(pkg == pkgFromJ, format("\nexp:\n%s\ngot:\n%s\n\n%s", pkg, pkgFromJ, 565 pkgCompare(pkg, pkgFromJ) 566 )); 567 JSONValue n2 = pkgFromJ.toJSON(); 568 569 PackageDescription copy = ddup(pkg); 570 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 571 572 validate(copy); 573 } 574 575 unittest { 576 string toParse = ` 577 { 578 "name" : "Foo", 579 "toolchainRequirements": { 580 "ldc": ">=1.15.0" 581 } 582 } 583 584 `; 585 586 PackageDescription pkg = jsonToPackageDescription(toParse); 587 PackageDescription copy = ddup(pkg); 588 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 589 590 validate(copy); 591 } 592 593 unittest { 594 string toParse = ` 595 { 596 "name" : "Foo", 597 "buildTypes": { 598 "release": {} 599 } 600 } 601 `; 602 603 PackageDescription pkg = jsonToPackageDescription(toParse); 604 JSONValue copy = toJSON(pkg); 605 PackageDescription pkg2 = jsonToPackageDescription(copy); 606 assert(pkg == pkg2, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 607 608 validate(pkg2); 609 }