memcheckVersion.c (22297B)
1 #include <stdlib.h> 2 #include <stdio.h> 3 #include <string.h> 4 5 #define ck_assert_str_eq(a,b) a;b; 6 #define ck_assert_str_ne(a,b) a;b; 7 #define ck_assert_ptr_eq(a,b) a;b; 8 #define ck_assert_ptr_ne(a,b) a;b; 9 #define ck_assert_uint_eq(a,b) a;b; 10 #define ck_assert_uint_ne(a,b) a;b; 11 #define ck_assert_int_eq(a,b) a;b; 12 #define ck_assert_int_ne(a,b) a;b; 13 #define ck_assert(a) a; 14 15 16 #include "libsheepyObject.h" 17 #include "shpPackages/short/short.h" 18 #include "version.h" 19 20 int argc; char **argv; 21 22 versiont ver; 23 24 25 void basetT(void) { 26 27 // STEPS 28 // init 29 // init allocate 30 // terminate 31 // allocate 32 // string 33 // duplicate 34 35 // init 36 initiateVersion(&ver); 37 freeO(&ver); 38 39 // init allocate 40 versiont *v; 41 initiateAllocateVersion(&v); 42 43 // terminate 44 terminateO(v); 45 46 // allocate 47 v = allocVersion(""); 48 49 // string 50 char *s = toStringO(v); 51 52 ck_assert_str_eq(s, "0.0.0"); 53 free(s); 54 55 // duplicate 56 versiont *oDup = duplicateO(v); 57 terminateO(oDup); 58 terminateO(v); 59 60 } 61 62 63 void validT(void) { 64 65 createVersion(ver); 66 67 ck_assert(validO(&ver, "1.2.3.0")); 68 ck_assert(validO(&ver, "10.2.3")); 69 ck_assert(validO(&ver, "0.2.3")); 70 ck_assert(validO(&ver, "0.2")); 71 ck_assert(validO(&ver, "0-p")); 72 ck_assert(validO(&ver, "0-p+b")); 73 ck_assert(validO(&ver, "0+b")); 74 ck_assert(validO(&ver, "0.2.3-p")); 75 ck_assert(validO(&ver, "0.2.3.0-p+b")); 76 ck_assert(validO(&ver, "0.2.3+b")); 77 ck_assert(validO(&ver, "0.2-pre")); 78 ck_assert(validO(&ver, "0.2-pre-234")); 79 ck_assert(validO(&ver, "0.2-pre+r3")); 80 ck_assert(validO(&ver, "0.2-pre+3-r")); 81 ck_assert(validO(&ver, "0.2-pre-234+r3r")); 82 ck_assert(validO(&ver, "0.2-pre.exp34")); 83 ck_assert(validO(&ver, "0.2-pre.exp-wd3-0")); 84 85 ck_assert(!validO(&ver, "0.2.3-+b")); 86 ck_assert(!validO(&ver, "0.2.3-.")); 87 ck_assert(!validO(&ver, "0.2.3--")); 88 ck_assert(!validO(&ver, "0.2.3.-p")); 89 ck_assert(!validO(&ver, "0.2.3.+b")); 90 ck_assert(!validO(&ver, "0.2.3+.")); 91 ck_assert(!validO(&ver, "0.2.3+-")); 92 ck_assert(!validO(&ver, "0.2.3+b.")); 93 ck_assert(!validO(&ver, "0.2.3+b-")); 94 ck_assert(!validO(&ver, "0.2.3+b+")); 95 ck_assert(!validO(&ver, "1.2-pre")); 96 ck_assert(!validO(&ver, "1.-pre")); 97 ck_assert(!validO(&ver, "1.2+b")); 98 ck_assert(!validO(&ver, "1.+b")); 99 ck_assert(!validO(&ver, "0.2-")); 100 ck_assert(!validO(&ver, "0.2-pre+")); 101 ck_assert(!validO(&ver, "0.2.3-")); 102 ck_assert(!validO(&ver, "0.2.3.0-+b")); 103 ck_assert(!validO(&ver, "0.2.3.0-p+")); 104 ck_assert(!validO(&ver, "0.2-pre+3r")); 105 ck_assert(!validO(&ver, "0.2-pre.exp-wd3-00")); 106 ck_assert(!validO(&ver, "0.2-0pre.exp-wd3")); 107 ck_assert(!validO(&ver, "0.2-pre.01-wd3")); 108 ck_assert(!validO(&ver, ".3.3")); 109 ck_assert(!validO(&ver, "3.3.")); 110 ck_assert(!validO(&ver, "0..3")); 111 ck_assert(!validO(&ver, "1.2.3.00")); 112 ck_assert(!validO(&ver, "00.2.3")); 113 ck_assert(!validO(&ver, "a.b.c")); 114 ck_assert(!validO(&ver, "=1.3.3")); 115 116 freeO(&ver); 117 118 } 119 120 void parseT(void) { 121 122 createVersion(ver); 123 124 ck_assert(parseO(&ver, "1.2.3.0")); 125 ck_assert(parseO(&ver, "10.2.3")); 126 ck_assert(parseO(&ver, "0.2.3")); 127 ck_assert(parseO(&ver, "0.2")); 128 ck_assert(parseO(&ver, "0-p")); 129 ck_assert(parseO(&ver, "0-p+b")); 130 ck_assert(parseO(&ver, "0+b")); 131 ck_assert(parseO(&ver, "0.2.3-p")); 132 ck_assert(parseO(&ver, "0.2.3.0-p+b")); 133 ck_assert(parseO(&ver, "0.2.3+b")); 134 ck_assert(parseO(&ver, "0.2-pre")); 135 ck_assert(parseO(&ver, "0.2-pre-234")); 136 ck_assert(parseO(&ver, "0.2-pre+r3")); 137 ck_assert(parseO(&ver, "0.2-pre+3-r")); 138 ck_assert(parseO(&ver, "0.2-pre-234+r3r")); 139 ck_assert(parseO(&ver, "0.2-pre.exp34")); 140 ck_assert(parseO(&ver, "0.2-pre.exp-wd3-0")); 141 ck_assert(parseO(&ver, "0.2.3+b-")); 142 ck_assert(parseO(&ver, "0.2.3+b+")); 143 ck_assert(parseO(&ver, "1.2-pre")); 144 ck_assert(parseO(&ver, "1.2+b")); 145 ck_assert(parseO(&ver, "0.2-")); 146 ck_assert(parseO(&ver, "0.2-pre+")); 147 ck_assert(parseO(&ver, "0.2.3-")); 148 ck_assert(parseO(&ver, "0.2.3.0-p+")); 149 ck_assert(parseO(&ver, ".3.3")); 150 ck_assert(parseO(&ver, "a.b.c")); 151 ck_assert(parseO(&ver, "=1.3.3")); 152 153 ck_assert(!parseO(&ver, "0.2-pre+3r")); 154 ck_assert(!parseO(&ver, "0.2.3-+b")); 155 ck_assert(!parseO(&ver, "0.2.3-.")); 156 ck_assert(!parseO(&ver, "0.2.3--")); 157 ck_assert(!parseO(&ver, "0.2.3.-p")); 158 ck_assert(!parseO(&ver, "0.2.3.+b")); 159 ck_assert(!parseO(&ver, "0.2.3+.")); 160 ck_assert(!parseO(&ver, "0.2.3+-")); 161 ck_assert(!parseO(&ver, "0.2.3+b.")); 162 ck_assert(!parseO(&ver, "1.-pre")); 163 ck_assert(!parseO(&ver, "1.+b")); 164 ck_assert(!parseO(&ver, "0.2.3.0-+b")); 165 ck_assert(!parseO(&ver, "0.2-pre.exp-wd3-00")); 166 ck_assert(!parseO(&ver, "0.2-0pre.exp-wd3")); 167 ck_assert(!parseO(&ver, "0.2-pre.01-wd3")); 168 ck_assert(!parseO(&ver, "3.3.")); 169 ck_assert(!parseO(&ver, "0..3")); 170 ck_assert(!parseO(&ver, "1.2.3.00")); 171 ck_assert(!parseO(&ver, "00.2.3")); 172 173 freeO(&ver); 174 175 } 176 177 void parseStrictT(void) { 178 179 createVersion(ver); 180 181 ck_assert(parseStrictO(&ver, "1.2.3.0")); 182 ck_assert(parseStrictO(&ver, "10.2.3")); 183 ck_assert(parseStrictO(&ver, "0.2.3")); 184 ck_assert(parseStrictO(&ver, "0.2")); 185 ck_assert(parseStrictO(&ver, "0-p")); 186 ck_assert(parseStrictO(&ver, "0-p+b")); 187 ck_assert(parseStrictO(&ver, "0+b")); 188 ck_assert(parseStrictO(&ver, "0.2.3-p")); 189 ck_assert(parseStrictO(&ver, "0.2.3.0-p+b")); 190 ck_assert(parseStrictO(&ver, "0.2.3+b")); 191 ck_assert(parseStrictO(&ver, "0.2-pre")); 192 ck_assert(parseStrictO(&ver, "0.2-pre-234")); 193 ck_assert(parseStrictO(&ver, "0.2-pre+r3")); 194 ck_assert(parseStrictO(&ver, "0.2-pre+3-r")); 195 ck_assert(parseStrictO(&ver, "0.2-pre-234+r3r")); 196 ck_assert(parseStrictO(&ver, "0.2-pre.exp34")); 197 ck_assert(parseStrictO(&ver, "0.2-pre.exp-wd3-0")); 198 ck_assert(parseStrictO(&ver, "=1.3.3")); 199 200 ck_assert(!parseStrictO(&ver, "0.2.3-+b")); 201 ck_assert(!parseStrictO(&ver, "0.2.3-.")); 202 ck_assert(!parseStrictO(&ver, "0.2.3--")); 203 ck_assert(!parseStrictO(&ver, "0.2.3.-p")); 204 ck_assert(!parseStrictO(&ver, "0.2.3.+b")); 205 ck_assert(!parseStrictO(&ver, "0.2.3+.")); 206 ck_assert(!parseStrictO(&ver, "0.2.3+-")); 207 ck_assert(!parseStrictO(&ver, "0.2.3+b.")); 208 ck_assert(!parseStrictO(&ver, "0.2.3+b-")); 209 ck_assert(!parseStrictO(&ver, "0.2.3+b+")); 210 ck_assert(!parseStrictO(&ver, "1.2-pre")); 211 ck_assert(!parseStrictO(&ver, "1.-pre")); 212 ck_assert(!parseStrictO(&ver, "1.2+b")); 213 ck_assert(!parseStrictO(&ver, "1.+b")); 214 ck_assert(!parseStrictO(&ver, "0.2-")); 215 ck_assert(!parseStrictO(&ver, "0.2-pre+")); 216 ck_assert(!parseStrictO(&ver, "0.2.3-")); 217 ck_assert(!parseStrictO(&ver, "0.2.3.0-+b")); 218 ck_assert(!parseStrictO(&ver, "0.2.3.0-p+")); 219 ck_assert(!parseStrictO(&ver, "0.2-pre+3r")); 220 ck_assert(!parseStrictO(&ver, "0.2-pre.exp-wd3-00")); 221 ck_assert(!parseStrictO(&ver, "0.2-0pre.exp-wd3")); 222 ck_assert(!parseStrictO(&ver, "0.2-pre.01-wd3")); 223 ck_assert(!parseStrictO(&ver, ".3.3")); 224 ck_assert(!parseStrictO(&ver, "3.3.")); 225 ck_assert(!parseStrictO(&ver, "0..3")); 226 ck_assert(!parseStrictO(&ver, "1.2.3.00")); 227 ck_assert(!parseStrictO(&ver, "00.2.3")); 228 ck_assert(!parseStrictO(&ver, "a.b.c")); 229 230 freeO(&ver); 231 232 } 233 234 235 236 void cleanT(void) { 237 238 createVersion(ver); 239 240 char *v = strdup("#$%23.34#4.53"); 241 242 ver.f->clean(&ver, v); 243 244 ck_assert_str_eq(v, "23.344.53"); 245 246 free(v); 247 freeO(&ver); 248 249 } 250 251 252 void equalT(void) { 253 254 createVersion(ver); 255 createVersion(ver2); 256 257 parseO(&ver, "v1"); 258 parseO(&ver2,"1.0.0"); 259 ck_assert(eqO(&ver, &ver2)); 260 261 incrO(&ver, releaseVer); 262 ck_assert(!eqO(&ver, &ver2)); 263 264 freeO(&ver2); 265 freeO(&ver); 266 267 } 268 269 void equalST(void) { 270 271 createVersion(ver); 272 273 parseO(&ver, "v1"); 274 ck_assert(eqSO(&ver, "1.0")); 275 276 incrO(&ver, releaseVer); 277 ck_assert(!eqSO(&ver, "1.0")); 278 279 freeO(&ver); 280 281 } 282 283 void equalSST(void) { 284 285 createVersion(ver); 286 287 ck_assert(eqSSO(&ver, "v1", "1.0")); 288 289 ck_assert(!eqSSO(&ver,"v1", "1.0-pre")); 290 291 freeO(&ver); 292 293 } 294 295 void cmpT(void) { 296 297 createVersion(ver); 298 createVersion(ver2); 299 300 parseO(&ver, "v1"); 301 parseO(&ver2,"1.0.0"); 302 ck_assert_int_eq(cmpO(&ver, &ver2), 0); 303 304 incrO(&ver, releaseVer); 305 ck_assert_int_eq(cmpO(&ver, &ver2), 1); 306 307 incrO(&ver2, releaseVer); 308 incrO(&ver2, releaseVer); 309 ck_assert_int_eq(cmpO(&ver, &ver2), -1); 310 311 freeO(&ver2); 312 freeO(&ver); 313 314 } 315 316 void cmpST(void) { 317 318 createVersion(ver); 319 320 parseO(&ver, "v1"); 321 ck_assert_int_eq(cmpSO(&ver, "1.0"), 0); 322 323 incrO(&ver, releaseVer); 324 ck_assert_int_eq(cmpSO(&ver, "1.0"), 1); 325 326 ck_assert_int_eq(cmpSO(&ver, "3.1"), -1); 327 328 freeO(&ver); 329 330 } 331 332 void cmpSST(void) { 333 334 createVersion(ver); 335 336 ck_assert_int_eq(cmpSSO(&ver, "v1", "1.0"), 0); 337 338 ck_assert_int_eq(cmpSSO(&ver, "1.1", "1.0"), 1); 339 340 ck_assert_int_eq(cmpSSO(&ver, "1.0", "1.1"), -1); 341 342 freeO(&ver); 343 344 } 345 346 void incrT(void) { 347 348 createVersion(ver); 349 350 parseO(&ver, "0.0.0"); 351 352 incrO(&ver, releaseVer); 353 ck_assert_int_eq(ver.release, 1); 354 ck_assert_int_eq(ver.major, 0); 355 ck_assert_int_eq(ver.minor, 0); 356 ck_assert_int_eq(ver.patch, 0); 357 358 incrO(&ver, majorVer); 359 ck_assert_int_eq(ver.release, 1); 360 ck_assert_int_eq(ver.major, 1); 361 ck_assert_int_eq(ver.minor, 0); 362 ck_assert_int_eq(ver.patch, 0); 363 364 incrO(&ver, minorVer); 365 ck_assert_int_eq(ver.release, 1); 366 ck_assert_int_eq(ver.major, 1); 367 ck_assert_int_eq(ver.minor, 1); 368 ck_assert_int_eq(ver.patch, 0); 369 370 incrO(&ver, patchVer); 371 ck_assert_int_eq(ver.release, 1); 372 ck_assert_int_eq(ver.major, 1); 373 ck_assert_int_eq(ver.minor, 1); 374 ck_assert_int_eq(ver.patch, 1); 375 376 freeO(&ver); 377 378 379 } 380 381 void sortT(void) { 382 383 createVersion(ver); 384 385 var arr = createSA("1.1+b.1", "1.1+b", "1.1", "2.0", "1.0", "1.1.1", "1.1-pr", "1.1-pr.1"); 386 var ref = createSA("1.0", "1.1-pr", "1.1-pr.1", "1.1", "1.1+b", "1.1+b.1", "1.1.1", "2.0"); 387 388 var sorted = vsortO(&ver, arr); 389 390 ck_assert(eqG(sorted, ref)); 391 392 terminateManyG(arr,sorted,ref); 393 394 freeO(&ver); 395 396 } 397 398 void satisfiesT(void) { 399 400 createVersion(ver); 401 402 parseO(&ver, "ver-1.1"); 403 404 ck_assert(satisfiesO(&ver, "1.1")); 405 ck_assert(satisfiesO(&ver, "=1.1")); 406 407 // the comparator >=1.2.7 would match the versions 1.2.7, 1.2.8, 2.5.3, and 1.3.9, but not the versions 1.2.6 or 1.1.0 408 parseO(&ver, "ver-1.2.7"); 409 ck_assert(satisfiesO(&ver, ">=1.2.7")); 410 parseO(&ver, "ver-1.2.8"); 411 ck_assert(satisfiesO(&ver, ">=1.2.7")); 412 parseO(&ver, "ver-2.5.3"); 413 ck_assert(satisfiesO(&ver, ">=1.2.7")); 414 parseO(&ver, "ver-1.3.9"); 415 ck_assert(satisfiesO(&ver, ">=1.2.7")); 416 parseO(&ver, "ver-1.2.6"); 417 ck_assert(!satisfiesO(&ver, ">=1.2.7")); 418 parseO(&ver, "ver-1.1.0"); 419 ck_assert(!satisfiesO(&ver, ">=1.2.7")); 420 parseO(&ver, "ver-1.2.7-pre"); 421 ck_assert(!satisfiesO(&ver, ">=1.2.7")); 422 423 // the comparator >1.2.7- would match 1.2.7 and 1.2.7-alpha.1 424 parseO(&ver, "ver-1.2.7"); 425 ck_assert(satisfiesO(&ver, ">=1.2.7-")); 426 parseO(&ver, "ver-1.2.7-alpha.1"); 427 ck_assert(satisfiesO(&ver, ">=1.2.7-")); 428 429 // the comparator >=1.2.7+ would match 1.2.7+arch64.build-1 and 1.2.7 but not and 1.2.7-alpha.1 430 parseO(&ver, "ver-1.2.7"); 431 ck_assert(satisfiesO(&ver, ">=1.2.7+")); 432 parseO(&ver, "ver-1.2.7+arch64.build-1"); 433 ck_assert(satisfiesO(&ver, ">=1.2.7+")); 434 parseO(&ver, "ver-1.2.7-alpha.1"); 435 ck_assert(!satisfiesO(&ver, ">=1.2.7+")); 436 437 // the range >=1.2.7 <1.3.0 would match the versions 1.2.7, 1.2.8, and 1.2.99, but not the versions 1.2.6, 1.3.0, or 1.1.0 438 parseO(&ver, "ver-1.2.7"); 439 ck_assert(satisfiesO(&ver, ">=1.2.7 <1.3.0")); 440 parseO(&ver, "ver-1.2.8"); 441 ck_assert(satisfiesO(&ver, ">=1.2.7 <1.3.0")); 442 parseO(&ver, "ver-1.2.99"); 443 ck_assert(satisfiesO(&ver, ">=1.2.7 <1.3.0")); 444 parseO(&ver, "ver-1.2.6"); 445 ck_assert(!satisfiesO(&ver, ">=1.2.7 <1.3.0")); 446 parseO(&ver, "ver-1.3.0"); 447 ck_assert(!satisfiesO(&ver, ">=1.2.7 <1.3.0")); 448 449 // the range 1.2.7 || >=1.2.9 <2.0.0 would match the versions 1.2.7, 1.2.9, and 1.4.6, but not the versions 1.2.8 or 2.0.0 450 parseO(&ver, "ver-1.2.7"); 451 ck_assert(satisfiesO(&ver, "1.2.7 || >=1.2.9 <2.0.0")); 452 parseO(&ver, "ver-1.2.9"); 453 ck_assert(satisfiesO(&ver, "1.2.7 || >=1.2.9 <2.0.0")); 454 parseO(&ver, "ver-1.4.6"); 455 ck_assert(satisfiesO(&ver, "1.2.7 || >=1.2.9 <2.0.0")); 456 parseO(&ver, "ver-1.2.8"); 457 ck_assert(!satisfiesO(&ver, "1.2.7 || >=1.2.9 <2.0.0")); 458 parseO(&ver, "ver-2.0.0"); 459 ck_assert(!satisfiesO(&ver, "1.2.7 || >=1.2.9 <2.0.0")); 460 461 // * := >= 0.0.0 (Any version) 462 parseO(&ver, "ver-1.2.7"); 463 ck_assert(satisfiesO(&ver, "*")); 464 ck_assert(satisfiesO(&ver, "x")); 465 ck_assert(satisfiesO(&ver, "X")); 466 467 // x.1.2 := =0.1.2 || =1.1.2 || 2.1.2... (Any release version with specified major.minor) 468 ck_assert(satisfiesO(&ver, "X.2.7")); 469 parseO(&ver, "ver-2.2.7"); 470 ck_assert(satisfiesO(&ver, "X.2.7")); 471 472 // 1.0.0.x.2 := 1.0.0.0.2 || 1.0.0.1.2 || 1.0.0.2.2... (Any patch version with Release.Major.minor equal to 1.0.0 and with other version equal to 2) 473 parseO(&ver, "ver-1.0.0.3.2"); 474 ck_assert(satisfiesO(&ver, "1.0.0.x.2")); 475 476 // 1.2.3 - 2.3.4 := >=1.2.3 <=2.3.4 477 parseO(&ver, "ver-1.2.3"); 478 ck_assert(satisfiesO(&ver, "1.2.3 - 2.3.4")); 479 parseO(&ver, "ver-2.3.4"); 480 ck_assert(satisfiesO(&ver, "1.2.3 - 2.3.4")); 481 parseO(&ver, "ver-1.2.2"); 482 ck_assert(!satisfiesO(&ver, "1.2.3 - 2.3.4")); 483 parseO(&ver, "ver-2.3.5"); 484 ck_assert(!satisfiesO(&ver, "1.2.3 - 2.3.4")); 485 486 // 1.2 - 2.3.4 := >=1.2.0 <=2.3.4 487 parseO(&ver, "ver-1.2.3"); 488 ck_assert(satisfiesO(&ver, "1.2.3 - 2.3.4")); 489 parseO(&ver, "ver-2.3.4"); 490 ck_assert(satisfiesO(&ver, "1.2.3 - 2.3.4")); 491 parseO(&ver, "ver-1.1.3"); 492 ck_assert(!satisfiesO(&ver, "1.2.3 - 2.3.4")); 493 parseO(&ver, "ver-2.3.5"); 494 ck_assert(!satisfiesO(&ver, "1.2.3 - 2.3.4")); 495 496 // 1.2.3 - 2.3 := >=1.2.3 <2.4.0 497 parseO(&ver, "ver-1.2.3"); 498 ck_assert(satisfiesO(&ver, "1.2.3 - 2.3")); 499 parseO(&ver, "ver-2.3.30"); 500 ck_assert(satisfiesO(&ver, "1.2.3 - 2.3")); 501 parseO(&ver, "ver-2.4"); 502 ck_assert(!satisfiesO(&ver, "1.2.3 - 2.3")); 503 parseO(&ver, "ver-1.2.2"); 504 ck_assert(!satisfiesO(&ver, "1.2.3 - 2.3")); 505 506 // 1.2.3 - 2 := >=1.2.3 <3.0.0 507 parseO(&ver, "ver-1.2.3"); 508 ck_assert(satisfiesO(&ver, "1.2.3 - 2")); 509 parseO(&ver, "ver-2.3.30"); 510 ck_assert(satisfiesO(&ver, "1.2.3 - 2")); 511 parseO(&ver, "ver-2.4"); 512 ck_assert(satisfiesO(&ver, "1.2.3 - 2")); 513 parseO(&ver, "ver-3.0.0"); 514 ck_assert(!satisfiesO(&ver, "1.2.3 - 2")); 515 parseO(&ver, "ver-1.2.2"); 516 ck_assert(!satisfiesO(&ver, "1.2.3 - 2")); 517 518 // 1.x := >=1.0.0- <2.0.0 (Matching major version) 519 parseO(&ver, "ver-1.2.3"); 520 ck_assert(satisfiesO(&ver, "1.x")); 521 parseO(&ver, "ver-1.0.0-pre"); 522 ck_assert(!satisfiesO(&ver, "1.x")); 523 parseO(&ver, "ver-2.0"); 524 ck_assert(!satisfiesO(&ver, "1.x")); 525 526 // 1.2.x := >=1.2.0- <1.3.0 (Matching major and minor versions) 527 parseO(&ver, "ver-1.2.3"); 528 ck_assert(satisfiesO(&ver, "1.2.x")); 529 parseO(&ver, "ver-1.2.3-pre"); 530 ck_assert(!satisfiesO(&ver, "1.2.x")); 531 parseO(&ver, "ver-1.3.0.1"); 532 ck_assert(!satisfiesO(&ver, "1.2.x")); 533 534 // 1.*- := >=1.0.0 <2.0.0 (Matching major version and prereleases) 535 parseO(&ver, "ver-1.0"); 536 ck_assert(satisfiesO(&ver, "1.*-")); 537 parseO(&ver, "ver-1.0-pre"); 538 ck_assert(satisfiesO(&ver, "1.*-")); 539 parseO(&ver, "ver-2.0-pre"); 540 ck_assert(!satisfiesO(&ver, "1.*-")); 541 542 // 1.X+ := >=1.0.0+ <2.0.0 (Matching major version and build version) 543 parseO(&ver, "ver-1.0+build1"); 544 ck_assert(satisfiesO(&ver, "1.X+")); 545 parseO(&ver, "ver-1.6"); 546 ck_assert(satisfiesO(&ver, "1.X+")); 547 parseO(&ver, "ver-1.6-pre"); 548 ck_assert(!satisfiesO(&ver, "1.X+")); 549 parseO(&ver, "ver-2.0-pre"); 550 ck_assert(!satisfiesO(&ver, "1.X+")); 551 552 // "" (empty string) := * := >=0.0.0 553 parseO(&ver, "ver-1.2.7"); 554 ck_assert(satisfiesO(&ver, "")); 555 556 // ~1.1.2.3 := >=1.1.2.3- <1.1.3.0 557 parseO(&ver, "ver-1.1.2.3"); 558 ck_assert(satisfiesO(&ver, "~1.1.2.3")); 559 parseO(&ver, "ver-1.1.2.3-pre"); 560 ck_assert(!satisfiesO(&ver, "~1.1.2.3")); 561 parseO(&ver, "ver-1.1.3"); 562 ck_assert(!satisfiesO(&ver, "~1.1.2.3")); 563 564 // ~1.1.2.3- := >=1.1.2.3 <1.1.3.0 (same as the line above, adds 1.1.2.3 prereleases) 565 parseO(&ver, "ver-1.1.2.3"); 566 ck_assert(satisfiesO(&ver, "~1.1.2.3-")); 567 parseO(&ver, "ver-1.1.2.3-pre"); 568 ck_assert(satisfiesO(&ver, "~1.1.2.3-")); 569 parseO(&ver, "ver-1.1.3"); 570 ck_assert(!satisfiesO(&ver, "~1.1.2.3-")); 571 572 // ~1.1.2 := >=1.1.2.0- <1.1.3.0 (Same as 1.1.2.x) 573 parseO(&ver, "ver-1.1.2.0"); 574 ck_assert(satisfiesO(&ver, "~1.1.2")); 575 parseO(&ver, "ver-1.1.2.0-pre"); 576 ck_assert(!satisfiesO(&ver, "~1.1.2")); 577 parseO(&ver, "ver-1.1.3"); 578 ck_assert(!satisfiesO(&ver, "~1.1.2")); 579 580 // ~1.1 := >=1.1.0.0- <1.2.0.0 (Same as 1.1.x) 581 parseO(&ver, "ver-1.1"); 582 ck_assert(satisfiesO(&ver, "~1.1")); 583 parseO(&ver, "ver-1.2"); 584 ck_assert(!satisfiesO(&ver, "~1.1")); 585 586 // ~1 := >=1.0.0- <2.0.0 (Same as 1.x) 587 parseO(&ver, "ver-1"); 588 ck_assert(satisfiesO(&ver, "~1")); 589 parseO(&ver, "ver-2.0"); 590 ck_assert(!satisfiesO(&ver, "~1")); 591 592 // ~0.2.3 >=0.2.3- <0.3.0 593 parseO(&ver, "ver-0.2.3"); 594 ck_assert(satisfiesO(&ver, "~0.2.3")); 595 parseO(&ver, "ver-0.3"); 596 ck_assert(!satisfiesO(&ver, "~0.2.3")); 597 598 // ~0.2 := >=0.2.0- <0.3.0 (Same as 0.2.x) 599 parseO(&ver, "ver-0.2"); 600 ck_assert(satisfiesO(&ver, "~0.2")); 601 parseO(&ver, "ver-0.3"); 602 ck_assert(!satisfiesO(&ver, "~0.2")); 603 604 // ~0 := >=0.0.0- <1.0.0 (same as 0.x) 605 parseO(&ver, "ver-0.0.1"); 606 ck_assert(satisfiesO(&ver, "~0")); 607 parseO(&ver, "ver-1.0"); 608 ck_assert(!satisfiesO(&ver, "~0")); 609 610 // ~0- := >=0.0.0 <1.0.0 (same as 0.x-, same as the line above, adds 0.0.0 prereleases) 611 parseO(&ver, "ver-0.0-pre"); 612 ck_assert(satisfiesO(&ver, "~0-")); 613 parseO(&ver, "ver-1.0"); 614 ck_assert(!satisfiesO(&ver, "~0-")); 615 616 // ~1.2.3-beta.2 := >=1.2.3-beta.2 <1.3.0 Note that prereleases in the 1.2.3 version will be allowed, if they are greater than or equal to beta.2. So, 1.2.3-beta.4 would be allowed, but 1.2.4-beta.2 would not, because it is a prerelease of a different [major, minor, patch] tuple. 617 parseO(&ver, "ver-1.2.3-beta.2"); 618 ck_assert(satisfiesO(&ver, "~1.2.3-beta.2")); 619 parseO(&ver, "ver-1.2.3-beta.3"); 620 ck_assert(satisfiesO(&ver, "~1.2.3-beta.2")); 621 parseO(&ver, "ver-1.2.3"); 622 ck_assert(satisfiesO(&ver, "~1.2.3-beta.2")); 623 parseO(&ver, "ver-1.2.3-beta.1"); 624 ck_assert(!satisfiesO(&ver, "~1.2.3-beta.2")); 625 parseO(&ver, "ver-1.3"); 626 ck_assert(!satisfiesO(&ver, "~1.2.3-beta.2")); 627 628 // ^1.1.2.3 := >=1.1.2.3- <1.2.0.0 629 parseO(&ver, "ver-1.1.2.3"); 630 ck_assert(satisfiesO(&ver, "^1.1.2.3")); 631 parseO(&ver, "ver-1.2.0"); 632 ck_assert(!satisfiesO(&ver, "^1.1.2.3")); 633 634 // ^0.0.2.3 := >=0.0.2.3- <0.1.0.0 635 parseO(&ver, "ver-0.0.2.3"); 636 ck_assert(satisfiesO(&ver, "^0.0.2.3")); 637 parseO(&ver, "ver-0.1"); 638 ck_assert(!satisfiesO(&ver, "^0.0.2.3")); 639 640 // ^0.0.0.3 := >=0.0.0.3- <0.1.0.0 641 parseO(&ver, "ver-0.0.2.3"); 642 ck_assert(satisfiesO(&ver, "^0.0.0.3")); 643 parseO(&ver, "ver-0.1"); 644 ck_assert(!satisfiesO(&ver, "^0.0.0.3")); 645 646 // ^1.2.3-beta.2 := >=1.2.3-beta.2 <1.3.0 Note that prereleases in the 1.2.3 version will be allowed, if they are greater than or equal to beta.2. So, 1.2.3-beta.4 would be allowed, but 1.2.4-beta.2 would not, because it is a prerelease of a different [major, minor, patch] tuple. 647 parseO(&ver, "ver-1.2.3-beta.2"); 648 ck_assert(satisfiesO(&ver, "^1.2.3-beta.2")); 649 parseO(&ver, "ver-1.2.3-beta.3"); 650 ck_assert(satisfiesO(&ver, "^1.2.3-beta.2")); 651 parseO(&ver, "ver-1.2.3-beta.1"); 652 ck_assert(!satisfiesO(&ver, "^1.2.3-beta.2")); 653 parseO(&ver, "ver-1.3"); 654 ck_assert(!satisfiesO(&ver, "^1.2.3-beta.2")); 655 656 // ^0.0.3-beta := >=0.0.3-beta <0.1.0 Note that prereleases in the 0.0.3 version only will be allowed, if they are greater than or equal to beta. So, 0.0.3-pr.2 would be allowed. 657 parseO(&ver, "ver-0.0.3-beta"); 658 ck_assert(satisfiesO(&ver, "^0.0.3-beta")); 659 parseO(&ver, "ver-0.1"); 660 ck_assert(!satisfiesO(&ver, "^0.0.3-beta")); 661 662 // ^1.1.2.x := >=1.1.2.0- <1.2.0.0 663 parseO(&ver, "ver-1.1.2"); 664 ck_assert(satisfiesO(&ver, "^1.1.2.x")); 665 parseO(&ver, "ver-1.2"); 666 ck_assert(!satisfiesO(&ver, "^1.1.2.x")); 667 668 // ^0.0.0.x := >=0.0.0- <0.1.0 669 parseO(&ver, "ver-0"); 670 ck_assert(satisfiesO(&ver, "^0.0.0.x")); 671 parseO(&ver, "ver-0-pre"); 672 ck_assert(!satisfiesO(&ver, "^0.0.0.x")); 673 parseO(&ver, "ver-0.1"); 674 ck_assert(!satisfiesO(&ver, "^0.0.0.x")); 675 676 // ^0.0 := >=0.0.0- <0.1.0 677 parseO(&ver, "ver-0"); 678 ck_assert(satisfiesO(&ver, "^0.0")); 679 parseO(&ver, "ver-0-pre"); 680 ck_assert(!satisfiesO(&ver, "^0.0")); 681 parseO(&ver, "ver-0.1"); 682 ck_assert(!satisfiesO(&ver, "^0.0")); 683 684 // ^1.1.x := >=1.1.0- <1.2.0 685 parseO(&ver, "ver-1.1.0"); 686 ck_assert(satisfiesO(&ver, "^1.1.x")); 687 parseO(&ver, "ver-1.2"); 688 ck_assert(!satisfiesO(&ver, "^1.1.x")); 689 690 // ^0.0.x := >=0.0.0- <0.1.0 691 parseO(&ver, "ver-0"); 692 ck_assert(satisfiesO(&ver, "^0.0.x")); 693 parseO(&ver, "ver-0-pre"); 694 ck_assert(!satisfiesO(&ver, "^0.0.x")); 695 parseO(&ver, "ver-0.1"); 696 ck_assert(!satisfiesO(&ver, "^0.0.x")); 697 698 freeO(&ver); 699 700 } 701 702 void toJsonT(void) { 703 704 createVersion(ver); 705 706 parseO(&ver, "1.0.0-pre+b012"); 707 708 smallJsont ref; 709 initiateG(&ref); 710 parseG(&ref, "{\"release\":1,\"major\":0,\"minor\":0,\"patch\":0,\"others\":[],\"prerelease\":[\"pre\"],\"build\":[\"b012\"]}"); 711 712 var j = toJsonO(&ver); 713 ck_assert(eqG(j, &ref)); 714 715 terminateG(j); 716 717 freeManyG(&ver, &ref); 718 719 } 720 721 void toJsonStrT(void) { 722 723 createVersion(ver); 724 725 parseO(&ver, "1.0.0-pre+b012"); 726 727 char *js = toJsonStrO(&ver); 728 ck_assert_str_eq(js, "{\"release\":1,\"major\":0,\"minor\":0,\"patch\":0,\"others\":[],\"prerelease\":[\"pre\"],\"build\":[\"b012\"]}"); 729 730 free(js); 731 freeO(&ver); 732 733 } 734 735 void fromJsonT(void) { 736 737 createVersion(ver); 738 739 smallJsont ref; 740 initiateG(&ref); 741 parseG(&ref, "{\"release\":1,\"major\":0,\"minor\":0,\"patch\":0,\"others\":[],\"prerelease\":[\"pre\"],\"build\":[\"b012\"]}"); 742 743 fromJsonO(&ver, &ref); 744 745 var j = toJsonO(&ver); 746 ck_assert(eqG(j, &ref)); 747 748 terminateG(j); 749 750 freeManyG(&ver, &ref); 751 752 } 753 754 void fromJsonStrT(void) { 755 756 createVersion(ver); 757 758 fromJsonStrO(&ver, "{\"release\":1,\"major\":0,\"minor\":0,\"patch\":0,\"others\":[],\"prerelease\":[\"pre\"],\"build\":[\"b012\"]}"); 759 760 char *js = toJsonStrO(&ver); 761 ck_assert_str_eq(js, "{\"release\":1,\"major\":0,\"minor\":0,\"patch\":0,\"others\":[],\"prerelease\":[\"pre\"],\"build\":[\"b012\"]}"); 762 763 free(js); 764 freeO(&ver); 765 766 } 767 768 769 int main(int n, char**v) { 770 771 initLibsheepy(v[0]); 772 setLogMode(LOG_FUNC); 773 774 basetT(); 775 validT(); 776 parseT(); 777 parseStrictT(); 778 cleanT(); 779 equalT(); 780 equalST(); 781 equalSST(); 782 cmpT(); 783 cmpST(); 784 cmpSST(); 785 incrT(); 786 sortT(); 787 satisfiesT(); 788 toJsonT(); 789 toJsonStrT(); 790 fromJsonT(); 791 fromJsonStrT(); 792 }