You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
932 B

4 years ago
  1. 'sue strict'
  2. var t = require('tap')
  3. var uniqueFilename = require('../index.js')
  4. t.plan(6)
  5. var randomTmpfile = uniqueFilename('tmp')
  6. t.like(randomTmpfile, /^tmp.[a-f0-9]{8}$/, 'random tmp file')
  7. var randomAgain = uniqueFilename('tmp')
  8. t.notEqual(randomAgain, randomTmpfile, 'random tmp files are not the same')
  9. var randomPrefixedTmpfile = uniqueFilename('tmp', 'my-test')
  10. t.like(randomPrefixedTmpfile, /^tmp.my-test-[a-f0-9]{8}$/, 'random prefixed tmp file')
  11. var randomPrefixedAgain = uniqueFilename('tmp', 'my-test')
  12. t.notEqual(randomPrefixedAgain, randomPrefixedTmpfile, 'random prefixed tmp files are not the same')
  13. var uniqueTmpfile = uniqueFilename('tmp', 'testing', '/my/thing/to/uniq/on')
  14. t.like(uniqueTmpfile, /^tmp.testing-7ddd44c0$/, 'unique filename')
  15. var uniqueAgain = uniqueFilename('tmp', 'testing', '/my/thing/to/uniq/on')
  16. t.is(uniqueTmpfile, uniqueAgain, 'same unique string component produces same filename')