-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Dominik Wilkowski <[email protected]>
- Loading branch information
1 parent
3772d33
commit 5bfc387
Showing
9 changed files
with
1,070 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/*************************************************************************************************************************************************************** | ||
* | ||
* CleanInput unit tests | ||
* | ||
**************************************************************************************************************************************************************/ | ||
|
||
|
||
const CFonts = require('../src/lib.js') | ||
const CleanInput = CFonts.__test__.CleanInput; | ||
const CHARS = CFonts.CHARS; | ||
|
||
|
||
test(`CleanInput - Should white list characters`, () => { | ||
expect( CleanInput( 'abcd', ['A','B','C'] ) ).toEqual( 'abc' ); | ||
expect( CleanInput( 'abdc', ['A','B','C'] ) ).toEqual( 'abc' ); | ||
expect( CleanInput( 'ab c', ['A','B','C'] ) ).toEqual( 'abc' ); | ||
expect( CleanInput( 'abc', ['A','B','C'] ) ).toEqual( 'abc' ); | ||
expect( CleanInput( 'abc•', ['A','B','C'] ) ).toEqual( 'abc' ); | ||
expect( CleanInput( ' abc', ['A','B','C'] ) ).toEqual( 'abc' ); | ||
}); | ||
|
||
test(`CleanInput - Should keep all letters that are allowed`, () => { | ||
expect( CleanInput( CHARS.join(' ') ) ).toEqual( CHARS.join(' ') ); | ||
}); |
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,76 @@ | ||
/*************************************************************************************************************************************************************** | ||
* | ||
* Debugging unit tests | ||
* | ||
**************************************************************************************************************************************************************/ | ||
|
||
|
||
const CFonts = require('../src/lib.js') | ||
const Debugging = CFonts.Debugging; | ||
|
||
|
||
const StripColor = ( text ) => { | ||
const pattern = [ | ||
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)', | ||
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))' | ||
].join('|'); | ||
const ansi = new RegExp(pattern, 'g'); | ||
|
||
if( typeof text === 'string' ) { | ||
return text.replace( ansi, '' ); | ||
} | ||
else { | ||
return text; | ||
} | ||
}; | ||
|
||
|
||
test(`Debugging - Show headline message when debug is enabled`, () => { | ||
console.log = jest.fn(); | ||
|
||
Debugging.headline( 'text', 1, true, 1 ); | ||
|
||
expect( console.log.mock.calls[0][0] ).toBe( '\u001b[47m\u001b[49m\n\u001b[47m\u001b[1m ☑ \u001b[22m text\u001b[49m' ); | ||
}); | ||
|
||
|
||
test(`Debugging - Show report message when debug is enabled`, () => { | ||
console.log = jest.fn(); | ||
|
||
Debugging.report( 'text', 1, true, 1 ); | ||
|
||
expect( console.log.mock.calls[0][0] ) | ||
.toBe( '\u001b[47m\u001b[49m\n\u001b[47m\u001b[1m\u001b[32m ☑ \u001b[39m\u001b[22m \u001b[30mtext \u001b[39m\u001b[49m' ); | ||
}); | ||
|
||
|
||
test(`Debugging - Show error message when debug is enabled`, () => { | ||
console.error = jest.fn(); | ||
|
||
Debugging.error( 'text', 1, true, 1 ); | ||
|
||
expect( console.error.mock.calls[0][0] ) | ||
.toBe( '\u001b[47m\u001b[49m\n\u001b[47m\u001b[31m ☒ \u001b[39m \u001b[30mtext \u001b[39m\u001b[49m' ); | ||
}); | ||
|
||
|
||
test(`Debugging - Don’t show message when debug is disabled`, () => { | ||
console.log = jest.fn(); | ||
|
||
Debugging.headline( 'text', 1, false, 1 ); | ||
Debugging.report( 'text', 1, false, 1 ); | ||
Debugging.error( 'text', 1, false, 1 ); | ||
|
||
expect( console.log.mock.calls.length ).toBe( 0 ); | ||
}); | ||
|
||
|
||
test(`Debugging - Don’t show message when debuglevel is too high`, () => { | ||
console.log = jest.fn(); | ||
|
||
Debugging.headline( 'text', 1, true, 2 ); | ||
Debugging.report( 'text', 1, true, 2 ); | ||
Debugging.error( 'text', 1, true, 2 ); | ||
|
||
expect( console.log.mock.calls.length ).toBe( 0 ); | ||
}); |
Oops, something went wrong.