-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
132ec1b
commit 48d6a6a
Showing
4 changed files
with
81 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Token } from "./token"; | ||
|
||
describe("Token", () => { | ||
|
||
'use strict'; | ||
|
||
it("constructor should set value", () => { | ||
const value = 'dGVzdA=='; | ||
let token = new Token(value); | ||
expect(token.value).toBe(value); | ||
}); | ||
|
||
it("constructor with null should default to empty string", () => { | ||
let token = new Token(null); | ||
expect(token.value).toBe(''); | ||
}); | ||
|
||
it("token with same value are equal", () => { | ||
let token1 = new Token('AA=='); | ||
let token2 = new Token('AA=='); | ||
expect(token1.equals(token2)).toBe(true); | ||
}); | ||
|
||
it("token with different value are not equal", () => { | ||
let token1 = new Token('AA=='); | ||
let token2 = new Token('ZZ=='); | ||
expect(token1.equals(token2)).toBe(false); | ||
}); | ||
|
||
it("token with null value equals to empty token", () => { | ||
let token1 = new Token(null); | ||
expect(token1.equals(Token.Empty)).toBe(true); | ||
}); | ||
|
||
it("token with blank value equals to empty token", () => { | ||
let token1 = new Token(''); | ||
expect(token1.equals(Token.Empty)).toBe(true); | ||
}); | ||
|
||
|
||
|
||
}); | ||
|
||
describe("Empty Token", () => { | ||
|
||
'use strict'; | ||
|
||
it("should have empty value", () => { | ||
expect(Token.Empty.value).toBe(''); | ||
}); | ||
|
||
}); |
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,21 @@ | ||
export class Token { | ||
|
||
private _value: string = null; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
public get value(): string { | ||
return this._value; | ||
} | ||
constructor(value: string) { | ||
this._value = value; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
if (this._value == null) this._value = ''; | ||
} | ||
|
||
public static get Empty(): Token { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
return new Token(''); | ||
} | ||
|
||
public equals(token: Token): boolean { | ||
if(token.value === this.value) return true; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
return false; | ||
} | ||
} |
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
don't assign it here.