-
-
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
Showing
5 changed files
with
36 additions
and
18 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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
export default function fakeLetter(options) { | ||
export default function letter(options) { | ||
options = options || {}; | ||
let keyspace = { | ||
"en_US": "abcdefghijklmnopqrstuvwxyz", | ||
"ru_RU": "абвгдеёжзийклмнопрстуфхцчшщъыьэюя" | ||
}; | ||
let locale = ((options.locale === undefined) ? 'en_US' : options.locale); | ||
let locale = options.locale || 'en_US'; | ||
let letter = keyspace[locale].charAt(Math.floor(Math.random() * keyspace[locale].length)); | ||
return (options.casing === 'upper' ? letter.toUpperCase() : letter); | ||
}; |
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 |
---|---|---|
@@ -1,18 +1,28 @@ | ||
import fakeLetter from './index.js'; | ||
import letter from './index.js'; | ||
import test from 'ava'; | ||
|
||
test('fakeLetter return type to be string', t => { | ||
t.is(typeof fakeLetter(), 'string'); | ||
test('letter return type to be string', t => { | ||
t.is(typeof letter(), 'string'); | ||
}); | ||
|
||
test('fakeLetter length casing eq 1', t => { | ||
t.is(fakeLetter().length, 1); | ||
t.is(fakeLetter({ casing: 'upper' }).length, 1); | ||
t.is(fakeLetter({ casing: 'lower' }).length, 1); | ||
test('letter length casing eq 1', t => { | ||
t.is(letter().length, 1); | ||
t.is(letter({ casing: 'upper' }).length, 1); | ||
t.is(letter({ casing: 'lower' }).length, 1); | ||
}); | ||
|
||
test('fakeLetter with casing and locale ru_RU length eq 1', t => { | ||
t.is(fakeLetter().length, 1); | ||
t.is(fakeLetter({ casing: 'upper', locale: 'ru_RU' }).length, 1); | ||
t.is(fakeLetter({ casing: 'lower', locale: 'ru_RU' }).length, 1); | ||
test('letter with locale ru_RU includes', t => { | ||
t.true('абвгдеёжзийклмнопрстуфхцчшщъыьэюя'.includes(letter({ locale: 'ru_RU' }))); | ||
t.false('абвгдеёжзийклмнопрстуфхцчшщъыьэюя'.includes('z')); | ||
}); | ||
|
||
test('letter with locale en_US includes', t => { | ||
t.true('abcdefghijklmnopqrstuvwxyz'.includes(letter({ locale: 'en_US' }))); | ||
t.false('abcdefghijklmnopqrstuvwxyz'.includes('я')); | ||
}); | ||
|
||
test('letter with casing and locale ru_RU length eq 1', t => { | ||
t.is(letter().length, 1); | ||
t.is(letter({ casing: 'upper', locale: 'ru_RU' }).length, 1); | ||
t.is(letter({ casing: 'lower', locale: 'ru_RU' }).length, 1); | ||
}); |