1 module dud.semver.comparisontest; 2 3 @safe pure private: 4 import std.format : format; 5 6 import dud.semver.parse; 7 import dud.semver.semver; 8 import dud.semver.comparision; 9 10 unittest { 11 auto s1 = SemVer(0,0,1); 12 auto s2 = SemVer(0,0,2); 13 auto s3 = SemVer(0,1,0); 14 auto s4 = SemVer(0,1,1); 15 auto s5 = SemVer(0,1,2); 16 auto s6 = SemVer(1,0,0); 17 auto s7 = SemVer(1,0,1); 18 auto s8 = SemVer(1,0,2); 19 auto s9 = SemVer(1,1,0); 20 auto s10 = SemVer(1,1,1); 21 auto s11 = SemVer(1,1,2); 22 23 auto all = [ s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11 ]; 24 25 foreach(idx, it; all) { 26 foreach(jdx, jt; all) { 27 int cmp = compare(it, jt); 28 if(idx < jdx) { 29 assert(cmp == -1, format("%s %s %s", it, cmp, jt)); 30 } else if(idx == jdx) { 31 assert(cmp == 0, format("%s %s %s", it, cmp, jt)); 32 } else if(idx > jdx) { 33 assert(cmp == 1, format("%s %s %s", it, cmp, jt)); 34 } 35 } 36 } 37 } 38 39 unittest { 40 auto s1 = SemVer(1,0,0,["foo", "bar"], []); 41 auto s2 = SemVer(1,0,0,["foo", "bar", "args"], []); 42 43 assert(compare(s1, s1) == 0); 44 assert(compare(s2, s2) == 0); 45 assert(compare(s1, s2) == -1); 46 assert(compare(s2, s1) == 1); 47 48 assert(s1 == s1); 49 assert(s1 < s2); 50 assert(s2 > s1); 51 } 52 53 unittest { 54 auto s1 = SemVer(1,0,0,["12", "34"], []); 55 auto s2 = SemVer(1,0,0,["12", "35"], []); 56 57 assert(compare(s1, s1) == 0); 58 assert(compare(s2, s2) == 0); 59 assert(compare(s1, s2) == -1); 60 assert(compare(s2, s1) == 1); 61 } 62 63 unittest { 64 auto s1 = SemVer(1,0,0,["12", "foo", "34"], []); 65 auto s2 = SemVer(1,0,0,["12", "foo", "35"], []); 66 67 assert(compare(s1, s1) == 0); 68 assert(compare(s2, s2) == 0); 69 assert(compare(s1, s2) == -1); 70 assert(compare(s2, s1) == 1); 71 } 72 73 unittest { 74 auto s1 = SemVer(1,0,0,[], []); 75 auto s2 = SemVer(1,0,0,["12", "foo", "35"], []); 76 77 assert(compare(s1, s1) == 0); 78 assert(compare(s2, s2) == 0); 79 assert(compare(s1, s2) == 1); 80 assert(compare(s2, s1) == -1); 81 } 82 83 unittest { 84 auto s1 = SemVer(1,0,0,["foo", "baz"], []); 85 auto s2 = SemVer(1,0,0,["foo", "bar"], []); 86 87 assert(compare(s1, s1) == 0); 88 assert(compare(s2, s2) == 0); 89 assert(compare(s1, s2) == 1); 90 assert(compare(s2, s1) == -1); 91 } 92 93 unittest { 94 auto s1 = SemVer(1,0,0,["rc", "1"], []); 95 auto s2 = SemVer(1,0,0,["rc", "2"], []); 96 auto s3 = SemVer(1,0,0,[], []); 97 98 assert(compare(s1, s1) == 0); 99 assert(compare(s2, s2) == 0); 100 assert(compare(s3, s3) == 0); 101 102 assert(compare(s1, s2) == -1); 103 assert(compare(s1, s3) == -1); 104 assert(compare(s2, s3) == -1); 105 106 assert(compare(s3, s1) == 1); 107 assert(compare(s3, s2) == 1); 108 } 109 110 unittest { 111 auto s1 = SemVer(1,0,0,["beta", "0"], []); 112 auto s2 = SemVer(1,0,0,["beta", "1"], []); 113 auto s3 = SemVer(1,0,0,["rc", "1"], []); 114 auto s4 = SemVer(1,0,0,["rc", "2"], []); 115 auto s5 = SemVer(1,0,0,[], []); 116 117 assert(compare(s1, s2) == -1); 118 assert(compare(s2, s3) == -1); 119 assert(compare(s3, s4) == -1); 120 assert(compare(s4, s5) == -1); 121 122 assert(compare(s1, s5) == -1); 123 assert(compare(s2, s5) == -1); 124 assert(compare(s3, s5) == -1); 125 assert(compare(s4, s5) == -1); 126 } 127 128 unittest { 129 string[][] prs = [ 130 [], ["foo"], ["1", "2"], ["1", "foo"], ["1", "baz"], ["1", "3"] 131 ]; 132 133 string[][] bs = [ 134 [], ["somehash"], ["somehash", "morehash", "dmd"] 135 ]; 136 137 SemVer[] semvers; 138 foreach(mj; 0 .. 3) { 139 foreach(mi; 0 .. 3) { 140 foreach(p; 0 .. 3) { 141 foreach(pr; prs) { 142 foreach(b; bs) { 143 semvers ~= SemVer(mj, mi, p, pr, b); 144 } 145 } 146 } 147 } 148 } 149 150 foreach(idx, sv1; semvers) { 151 foreach(jdx, sv2; semvers) { 152 int c = sv1 < sv2; 153 bool e = sv1 == sv2; 154 bool ne = sv1 != sv2; 155 156 if(idx == jdx) { 157 assert(c == 0); 158 assert(e); 159 assert(!ne); 160 } 161 } 162 } 163 }