-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests for the escape and unescape functions in core/code b…
…lock
- Loading branch information
David Aguilera
committed
Apr 26, 2019
1 parent
d86123a
commit 1cb6ff8
Showing
1 changed file
with
62 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { escape, unescape } from '../utils'; | ||
|
||
describe( 'core/code', () => { | ||
describe( 'escape()', () => { | ||
it( 'should escape ampersands', () => { | ||
const text = escape( '&' ); | ||
expect( text ).toBe( '&' ); | ||
} ); | ||
|
||
it( 'should escape opening square brackets', () => { | ||
const text = escape( '[shortcode][/shortcode]' ); | ||
expect( text ).toBe( '[shortcode][/shortcode]' ); | ||
} ); | ||
|
||
it( 'should escape the protocol of an isolated url', () => { | ||
const text = escape( 'https://example.com/test/' ); | ||
expect( text ).toBe( 'https://example.com/test/' ); | ||
} ); | ||
|
||
it( 'should not escape the protocol of a non isolated url', () => { | ||
const text = escape( 'Text https://example.com/test/' ); | ||
expect( text ).toBe( 'Text https://example.com/test/' ); | ||
} ); | ||
|
||
it( 'should escape ampersands last', () => { | ||
const text = escape( '[shortcode][/shortcode]' ); | ||
expect( text ).toBe( '[shortcode][/shortcode]' ); | ||
expect( text ).not.toBe( '[shortcode][/shortcode]' ); | ||
} ); | ||
} ); | ||
|
||
describe( 'unescape()', () => { | ||
it( 'should unescape escaped ampersands', () => { | ||
const text = unescape( '&' ); | ||
expect( text ).toBe( '&' ); | ||
} ); | ||
|
||
it( 'should unescape escaped opening square brackets', () => { | ||
const text = unescape( '[shortcode][/shortcode]' ); | ||
expect( text ).toBe( '[shortcode][/shortcode]' ); | ||
} ); | ||
|
||
it( 'should unescape the escaped protocol of an isolated url', () => { | ||
const text = unescape( 'https://example.com/test/' ); | ||
expect( text ).toBe( 'https://example.com/test/' ); | ||
} ); | ||
|
||
it( 'should revert the result of escape()', () => { | ||
const ampersand = unescape( escape( '&' ) ); | ||
expect( ampersand ).toBe( '&' ); | ||
|
||
const squareBracket = unescape( escape( '[shortcode][/shortcode]' ) ); | ||
expect( squareBracket ).toBe( '[shortcode][/shortcode]' ); | ||
|
||
const url = unescape( escape( 'https://example.com/test/' ) ); | ||
expect( url ).toBe( 'https://example.com/test/' ); | ||
} ); | ||
} ); | ||
} ); |