💾 Archived View for gmi.noulin.net › gitRepositories › version › file › testVersion.c.gmi captured on 2023-07-10 at 15:39:35. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-01-29)

-=-=-=-=-=-=-

version

Log

Files

Refs

README

LICENSE

testVersion.c (23267B)

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