diff options
author | Minteck <contact@minteck.org> | 2021-12-21 16:52:28 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2021-12-21 16:52:28 +0100 |
commit | 46e43f4bde4a35785b4997b81e86cd19f046b69b (patch) | |
tree | c53c2f826f777f9d6b2d249dab556feb72a6c3a6 /src/node_modules/chance/test/test.file.js | |
download | langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.gz langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.bz2 langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.zip |
Commit
Diffstat (limited to 'src/node_modules/chance/test/test.file.js')
-rw-r--r-- | src/node_modules/chance/test/test.file.js | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/src/node_modules/chance/test/test.file.js b/src/node_modules/chance/test/test.file.js new file mode 100644 index 0000000..4b0bf61 --- /dev/null +++ b/src/node_modules/chance/test/test.file.js @@ -0,0 +1,116 @@ +import test from 'ava' +import Chance from '../chance.js' +import _ from 'lodash' + +const chance = new Chance() + +const fileExtensions = { + "raster": [ "bmp", "gif", "gpl", "ico", "jpeg", "psd", "png", "psp", "raw", + "tiff" ], + "vector": [ "3dv", "amf", "awg", "ai", "cgm", "cdr", "cmx", "dxf", "e2d", + "egt", "eps", "fs", "odg", "svg", "xar" ], + "3d": [ "3dmf", "3dm", "3mf", "3ds", "an8", "aoi", "blend", "cal3d", "cob", + "ctm", "iob", "jas", "max", "mb", "mdx", "obj", "x", "x3d" ], + "document": [ "doc", "docx", "dot", "html", "xml", "odt", "odm", "ott", "csv", + "rtf", "tex", "xhtml", "xps" ] +} + +// chance.file() +test('file() returns random file length with random extension', t => { + _.times(1000, () => { + let file = chance.file() + t.true(_.isString(file)) + t.is(file.split('.').length, 2) + }) +}) + +test('file() returns error if wrong fileType provided', t => { + _.times(1000, () => { + const fn = () => chance.file({ fileType: 'not_specified' }) + t.throws(fn, 'Chance: Expect file type value to be \'raster\', \'vector\', \'3d\' or \'document\'') + }) +}) + +test('file() does not return error if legit fileType provided', t => { + _.times(1000, () => { + const fn = () => chance.file({ fileType: 'raster' }) + t.notThrows(fn) + }) +}) + +test('file() returns filename with specific extension type', t => { + _.times(1000, () => { + let file = chance.file({ fileType: 'raster' }) + t.true(_.isString(file)) + let extension = file.split('.')[1] + t.true(fileExtensions['raster'].indexOf(extension) !== -1) + }) +}) + +test('file() returns filename with specific extension', t => { + _.times(1000, () => { + let file = chance.file({ extension: 'doc' }) + let extension = file.split('.')[1] + t.is(extension, 'doc') + }) +}) + +test('file() can take a length and obey it', t => { + _.times(1000, () => { + let length = chance.d10() + let file = chance.file({ length: length }) + let filename = file.split('.')[0] + t.is(filename.length, length) + }) +}) + +test('file() can take a pool of extensions and obey them', t => { + _.times(1000, () => { + let extensions = [ 'bmp', '3dv', '3dmf', 'doc' ] + let file = chance.file({ extensions: extensions }) + let extension = file.split('.')[1] + t.true(extensions.indexOf(extension) !== -1) + }) +}) + +test('file() can take pool of extensions by object collection and obey them', t => { + const objectExtensionCollection = { + "one": [ "extension_one_1", "extension_one_2", "extension_one_3" ], + "two": [ "extension_two_1", "extension_two_2", "extension_two_3" ], + "three": [ "extension_three_1", "extension_three_2", "extension_three_3" ] + } + + _.times(1000, () => { + let file = chance.file({ extensions: objectExtensionCollection }) + let extension = file.split('.')[1] + let extensionCount = 0 + for (let key in objectExtensionCollection) { + let collection = objectExtensionCollection[key] + collection.map((ext) => { + if (ext === extension) { + extensionCount++ + } + }) + } + t.is(extensionCount, 1) + }) +}) + +test('file() throws if bad extensions option provided', t => { + const fn = () => chance.file({ extensions: 10 }) + t.throws(fn, 'Chance: Extensions must be an Array or Object') +}) + +test('file() does not throw if good extensions option provided as array', t => { + _.times(1000, () => { + const fn = () => chance.file({ extensions: fileExtensions.document }) + t.notThrows(fn) + }) +}) + +test('file() does not throw if good extensions option provided as object', t => { + _.times(1000, () => { + const fn = () => chance.file({ extensions: fileExtensions }) + t.notThrows(fn) + }) +}) |