|
| 1 | +import assert from 'assert'; |
| 2 | +import { normalizePackageName } from '../../../managers/builtin/utils'; |
| 3 | + |
| 4 | +suite('normalizePackageName', () => { |
| 5 | + test('should lowercase names', () => { |
| 6 | + assert.strictEqual(normalizePackageName('Requests'), 'requests'); |
| 7 | + assert.strictEqual(normalizePackageName('NUMPY'), 'numpy'); |
| 8 | + }); |
| 9 | + |
| 10 | + test('should replace underscores with hyphens', () => { |
| 11 | + assert.strictEqual(normalizePackageName('my_package'), 'my-package'); |
| 12 | + }); |
| 13 | + |
| 14 | + test('should replace dots with hyphens', () => { |
| 15 | + assert.strictEqual(normalizePackageName('zope.interface'), 'zope-interface'); |
| 16 | + }); |
| 17 | + |
| 18 | + test('should collapse consecutive separators into a single hyphen', () => { |
| 19 | + assert.strictEqual(normalizePackageName('my__package'), 'my-package'); |
| 20 | + assert.strictEqual(normalizePackageName('my_-package'), 'my-package'); |
| 21 | + assert.strictEqual(normalizePackageName('my_.package'), 'my-package'); |
| 22 | + }); |
| 23 | + |
| 24 | + test('should handle mixed separators and casing', () => { |
| 25 | + assert.strictEqual(normalizePackageName('My_Package.Name'), 'my-package-name'); |
| 26 | + assert.strictEqual(normalizePackageName('Foo-Bar_Baz'), 'foo-bar-baz'); |
| 27 | + }); |
| 28 | + |
| 29 | + test('should return already-normalized names unchanged', () => { |
| 30 | + assert.strictEqual(normalizePackageName('requests'), 'requests'); |
| 31 | + assert.strictEqual(normalizePackageName('my-package'), 'my-package'); |
| 32 | + }); |
| 33 | + |
| 34 | + test('should handle single-word names', () => { |
| 35 | + assert.strictEqual(normalizePackageName('pip'), 'pip'); |
| 36 | + }); |
| 37 | + |
| 38 | + test('should produce equal results for equivalent package names', () => { |
| 39 | + const variants = ['My_Package', 'my-package', 'my.package', 'My.Package', 'MY_PACKAGE', 'my_package']; |
| 40 | + const normalized = variants.map(normalizePackageName); |
| 41 | + assert.ok( |
| 42 | + normalized.every((n) => n === normalized[0]), |
| 43 | + `All variants should normalize to the same value, got: ${JSON.stringify(normalized)}`, |
| 44 | + ); |
| 45 | + }); |
| 46 | +}); |
0 commit comments