Skip to content
Myr

Add edge case tests for large IDs and zero-size generation (#562)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- Test nanoid(1000) generates correct length with valid characters - Test non-secure nanoid(0) returns empty string - Test non-secure customAlphabet with 0 size returns empty string - Test urlAlphabet has exactly 64 symbols

authored by Mahmoud Hamdy · committed by GitHub · parent 96869c7 · Browse files · 2 files+21 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+21 added−0 removed

  • tests:+21 added−0 removed

2 files+21 added−0 removed

modified:test/index.test.js+12 added
46 unmodified lines
47 test(`changes ID length`, () => {48 equal(nanoid(10).length, 10)49 })5051 test(`generates large IDs`, () => {52 let id = nanoid(1000)53 equal(id.length, 1000)54 for (let char of id) {55 match(urlAlphabet, new RegExp(char, 'g'))56 }57 })5859 test(`accepts string`, () => {60 equal(nanoid('10').length, 10)61 })62
102 unmodified lines
165 test(`${type} / urlAlphabet / is string`, () => {166 equal(typeof urlAlphabet, 'string')167 })168169 test(`${type} / urlAlphabet / has 64 symbols`, () => {170 equal(urlAlphabet.length, 64)171 })172173 test(`${type} / urlAlphabet / has no duplicates`, () => {174 for (let i = 0; i < urlAlphabet.length; i++) {175 equal(urlAlphabet.lastIndexOf(urlAlphabet[i]), i)176 }
60 unmodified lines
modified:test/non-secure.test.js+9 added