1 module dud.semver.parsetest; 2 3 @safe private: 4 import std.exception : assertThrown, assertNotThrown; 5 import std.stdio; 6 import std.format : format; 7 8 import dud.semver.parse; 9 import dud.semver.semver; 10 import dud.semver.exception; 11 12 struct StrSV { 13 string str; 14 SemVer sv; 15 } 16 17 unittest { 18 StrSV[] tests = [ 19 StrSV("0.0.4", SemVer(0,0,4)), 20 StrSV("1.2.3", SemVer(1,2,3)), 21 StrSV("10.20.30", SemVer(10,20,30)), 22 StrSV("1.1.2-prerelease+meta", SemVer(1,1,2,["prerelease"], ["meta"])), 23 StrSV("1.1.2+meta", SemVer(1,1,2,[],["meta"])), 24 StrSV("1.0.0-alpha", SemVer(1,0,0,["alpha"],[])), 25 StrSV("1.0.0-beta", SemVer(1,0,0,["beta"],[])), 26 StrSV("1.0.0-alpha.beta", SemVer(1,0,0,["alpha", "beta"],[])), 27 StrSV("1.0.0-alpha.beta.1", SemVer(1,0,0,["alpha", "beta", "1"],[])), 28 StrSV("1.0.0-alpha.1", SemVer(1,0,0,["alpha", "1"],[])), 29 StrSV("1.0.0-alpha0.valid", SemVer(1,0,0,["alpha0", "valid"],[])), 30 StrSV("1.0.0-alpha.0valid", SemVer(1,0,0,["alpha", "0valid"],[])), 31 StrSV("1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay", 32 SemVer(1,0,0,["alpha-a", "b-c-somethinglong"], 33 ["build","1-aef","1-its-okay"])), 34 StrSV("1.0.0-rc.1+build.1", SemVer(1,0,0,["rc", "1"],["build","1"])), 35 StrSV("2.0.0-rc.1+build.123", SemVer(2,0,0,["rc", "1"],["build", "123"])), 36 StrSV("1.2.3-beta", SemVer(1,2,3,["beta"],[])), 37 StrSV("10.2.3-DEV-SNAPSHOT", SemVer(10,2,3,["DEV-SNAPSHOT"],[])), 38 StrSV("1.2.3-SNAPSHOT-123", SemVer(1,2,3,["SNAPSHOT-123"],[])), 39 StrSV("1.0.0", SemVer(1,0,0,[],[])), 40 StrSV("2.0.0", SemVer(2,0,0,[],[])), 41 StrSV("1.1.7", SemVer(1,1,7,[],[])), 42 StrSV("2.0.0+build.1848", SemVer(2,0,0,[],["build","1848"])), 43 StrSV("2.0.1-alpha.1227", SemVer(2,0,1,["alpha", "1227"],[])), 44 StrSV("1.0.0-alpha+beta", SemVer(1,0,0,["alpha"],["beta"])), 45 StrSV("1.0.0-0A.is.legal", SemVer(1,0,0,["0A", "is", "legal"],[])), 46 StrSV("1.1.2+meta-valid", SemVer(1,1,2, [], ["meta-valid"])) 47 ]; 48 49 foreach(test; tests) { 50 SemVer sv = assertNotThrown(parseSemVer(test.str), 51 format("An exception was thrown while parsing '%s'", test.str)); 52 assert(sv == test.sv, format("\ngot: %s\nexp: %s", sv, test.sv)); 53 } 54 } 55 56 unittest { 57 assertThrown!InvalidSeperator(parseSemVer("Hello World")); 58 assertThrown!OnlyDigitAllowed(parseSemVer("Hello World.")); 59 assertThrown!OnlyDigitAllowed(parseSemVer("1.2.332a")); 60 assertThrown!NonAsciiChar(parseSemVer("1.2.3+ßßßßääü")); 61 assertThrown!EmptyInput(parseSemVer("1.2.")); 62 assertThrown!EmptyInput(parseSemVer("1.")); 63 assertThrown!EmptyIdentifier(parseSemVer("2.0.1-alpha.1227..")); 64 assertThrown!EmptyIdentifier(parseSemVer("2.0.1+alpha.1227..")); 65 }