Version

Version struct

Data struct to store version with MAJOR.MINOR.PATCH format.

Constructors

this
this(M major, N minor, P patch)

Default constructor

this
this(string str)

Construct from string Use common version strings and convert to MAJOR.MINOR.PATCH version scheme if its possible

Members

Functions

opCmp
int opCmp(Version v)
Undocumented in source. Be warned that the author may not have intended to support it.
opCmp
int opCmp(Version v)
Undocumented in source. Be warned that the author may not have intended to support it.
opIndex
uint[] opIndex()
Undocumented in source. Be warned that the author may not have intended to support it.
opIndex
uint opIndex(size_t idx)
Undocumented in source. Be warned that the author may not have intended to support it.
opIndexAssign
uint opIndexAssign(uint val, size_t idx)
Undocumented in source. Be warned that the author may not have intended to support it.
toString
string toString()
Undocumented in source. Be warned that the author may not have intended to support it.

Variables

major
uint major;

Major version

minor
uint minor;

Minor version

patch
uint patch;

Patch version

Examples

Version foo = Version(3, 1);
assert(foo.to!string == "3.1.0");
Version ver = Version();
assertEquals(0, ver.major);
assertEquals(0, ver.minor);
assertEquals(0, ver.patch);

ver = Version(1);
assertEquals(1, ver.major);
assertEquals(0, ver.minor);
assertEquals(0, ver.patch);

ver = Version(2, 1);
assertEquals(2, ver.major);
assertEquals(1, ver.minor);
assertEquals(0, ver.patch);

ver = Version(1, 2, 4);
assertEquals(1, ver.major);
assertEquals(2, ver.minor);
assertEquals(4, ver.patch);
Version ver = Version(1, 4, 5);
assertEquals(1, ver[0]);
assertEquals(4, ver[1]);
assertEquals(5, ver[2]);

ver[2] = 2;
assertEquals(Version(1, 4, 2), ver);

expectThrows(ver[3] = 0);
expectThrows(ver[3]);
Version ver = Version("");
assertEquals(Version(), ver);

// supress minor and patch
ver = Version("1");
assertEquals(Version(1), ver);

// supress patch
ver = Version("2.1");
assertEquals(Version(2, 1, 0), ver);

ver = Version("1.2.4");
assertEquals(Version(1, 2, 4), ver);

ver = Version("v1.2.4");
assertEquals(Version(1, 2, 4), ver);

ver = Version("1.2.4-alpha.1");
assertEquals(Version(1, 2, 4), ver);

ver = Version("1.2-1");
assertEquals(Version(1, 2, 1), ver);

ver = Version("1.2.4-1");
assertEquals(Version(1, 2, 4), ver);

ver = Version("2-1");
assertEquals(Version(2, 0, 1), ver);

ver = Version("1.2+543");
assertEquals(Version(1, 2), ver);

ver = Version("1.2.1+543");
assertEquals(Version(1, 2, 1), ver);

expectThrows(Version("-alpha.1"));
expectThrows(Version(".-rc.1"));
expectThrows(Version("1.."));
expectThrows(Version("vv1.1"));
expectThrows(Version("1.1-"));
expectThrows(Version("-1"));
expectThrows(Version("-"));
expectThrows(Version("alpha"));
expectThrows(Version("."));
Version ver = Version(1, 3, 4);
assertEquals("1.3.4", ver.to!string);

ver = Version(1, 3);
assertEquals("1.3.0", ver.to!string);
assertGreaterThan(Version(2), Version(1));
assertGreaterThan(Version(2), Version(1, 2, 3));
assertLessThan(Version(2), Version(3));

assertFalse(Version(1) < Version(1) || Version(1) > Version(1));
assertTrue(Version(1) >= Version(1) && Version(1) <= Version(1));

assertEquals(Version(2), Version(2));
assertGreaterThan(Version(1, 0, 1), Version(1, 0, 0));
assertLessThan(Version(1, 0, 32), Version(1, 1, 0));

Meta