This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from Microsoft/users/jpricket/0130
Adding CLC version checks as well as localizing
- Loading branch information
Showing
8 changed files
with
193 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
"use strict"; | ||
|
||
/** | ||
* This class represents the Version of the TF command line. | ||
*/ | ||
export class TfvcVersion { | ||
private static separator: string = "."; | ||
|
||
private _major: number; | ||
private _minor: number; | ||
private _revision: number; | ||
private _build: string; | ||
|
||
public static FromString(version: string): TfvcVersion { | ||
const parts: string[] = version ? version.split(TfvcVersion.separator) : []; | ||
let major = parts.length >= 1 ? Number(parts[0]) : 0; | ||
let minor = parts.length >= 2 ? Number(parts[1]) : 0; | ||
let revision = parts.length >= 3 ? Number(parts[2]) : 0; | ||
let build = parts.length >= 4 ? parts.slice(3).join(TfvcVersion.separator) : ""; | ||
return new TfvcVersion(major, minor, revision, build); | ||
} | ||
|
||
public static Compare(version1: TfvcVersion, version2: TfvcVersion): number { | ||
if (version1._major !== version2._major) { | ||
return version1._major - version2._major; | ||
} | ||
if (version1._minor !== version2._minor) { | ||
return version1._minor - version2._minor; | ||
} | ||
if (version1._revision !== version2._revision) { | ||
return version1._revision - version2._revision; | ||
} | ||
return 0; | ||
} | ||
|
||
public constructor(major: number, minor: number, revision: number, build: string) { | ||
this._major = major; | ||
this._minor = minor; | ||
this._revision = revision; | ||
this._build = build; | ||
} | ||
|
||
public get Major(): number { return this._major; } | ||
public get Minor(): number { return this._minor; } | ||
public get Revision(): number { return this._revision; } | ||
public get Build(): string { return this._build; } | ||
|
||
public ToString(): string { | ||
return this._major + TfvcVersion.separator + this._minor + TfvcVersion.separator + this._revision + | ||
(this._build ? TfvcVersion.separator + this._build : ""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
"use strict"; | ||
|
||
import { assert } from "chai"; | ||
|
||
import { TfvcVersion } from "../../src/tfvc/tfvcversion"; | ||
|
||
describe("Tfvc-Version", function() { | ||
beforeEach(function() { | ||
// | ||
}); | ||
|
||
it("should verify constructor", function() { | ||
let version: TfvcVersion = new TfvcVersion(12, 11, 10, ""); | ||
assert.equal(version.ToString(), "12.11.10"); | ||
}); | ||
|
||
it("should verify constructor - with build", function() { | ||
let version: TfvcVersion = new TfvcVersion(12, 11, 10, "buildpart"); | ||
assert.equal(version.ToString(), "12.11.10.buildpart"); | ||
}); | ||
|
||
it("should verify constructor - with dotted build", function() { | ||
let version: TfvcVersion = new TfvcVersion(12, 11, 10, "build.part."); | ||
assert.equal(version.ToString(), "12.11.10.build.part."); | ||
}); | ||
|
||
it("should verify FromString", function() { | ||
let version: TfvcVersion = TfvcVersion.FromString("12.11.10.build.part."); | ||
assert.equal(version.ToString(), "12.11.10.build.part."); | ||
}); | ||
|
||
it("should verify FromString - missing build", function() { | ||
let version: TfvcVersion = TfvcVersion.FromString("12.11.10"); | ||
assert.equal(version.ToString(), "12.11.10"); | ||
}); | ||
|
||
it("should verify FromString - missing revision", function() { | ||
let version: TfvcVersion = TfvcVersion.FromString("12.11"); | ||
assert.equal(version.ToString(), "12.11.0"); | ||
}); | ||
|
||
it("should verify Compare", function() { | ||
let version1: TfvcVersion = TfvcVersion.FromString("12.11"); | ||
let version2: TfvcVersion = TfvcVersion.FromString("12.11.10"); | ||
assert.isTrue(TfvcVersion.Compare(version1, version2) < 0); | ||
assert.isTrue(TfvcVersion.Compare(version2, version1) > 0); | ||
}); | ||
|
||
it("should verify Compare - equals", function() { | ||
let version1: TfvcVersion = TfvcVersion.FromString("12.11.10"); | ||
let version2: TfvcVersion = TfvcVersion.FromString("12.11.10"); | ||
assert.isTrue(TfvcVersion.Compare(version1, version2) === 0); | ||
assert.isTrue(TfvcVersion.Compare(version2, version1) === 0); | ||
}); | ||
|
||
}); |