forked from mdx-js/mdx
-
Notifications
You must be signed in to change notification settings - Fork 0
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
389b5a5
commit 135aa2d
Showing
2 changed files
with
46 additions
and
1 deletion.
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,45 @@ | ||
import {test} from 'uvu' | ||
import * as assert from 'uvu/assert' | ||
import {toValidIdentifierName} from '../lib/util/to-valid-identifier-name.js' | ||
|
||
/** @param {string} invalidChar */ | ||
function toTestFailureMessage(invalidChar) { | ||
return `Invalid characters like "${invalidChar}" should be converted to underscores "_"` | ||
} | ||
|
||
test('toValidIdentifierName', () => { | ||
// Valid strings left untouched | ||
assert.equal(toValidIdentifierName('test'), 'test') | ||
assert.equal(toValidIdentifierName('camelCase'), 'camelCase') | ||
// Invalid cont character -> underscore | ||
assert.equal( | ||
toValidIdentifierName('custom-element'), | ||
'custom_element', | ||
toTestFailureMessage('-') | ||
) | ||
assert.equal( | ||
toValidIdentifierName('custom element'), | ||
'custom_element', | ||
toTestFailureMessage(' ') | ||
) | ||
// Invalid starting character -> underscore | ||
assert.equal( | ||
toValidIdentifierName('-badStarting'), | ||
'_badStarting', | ||
toTestFailureMessage('-') | ||
) | ||
assert.equal( | ||
toValidIdentifierName('1badStarting'), | ||
'_badStarting', | ||
toTestFailureMessage('1') | ||
) | ||
assert.equal( | ||
toValidIdentifierName(' badStarting'), | ||
'_badStarting', | ||
toTestFailureMessage(' ') | ||
) | ||
// Empty string -> underscore | ||
assert.equal('_', toValidIdentifierName('')) | ||
}) | ||
|
||
test.run() |