|
1 | | -import { expect, test } from 'vitest'; |
| 1 | +import { describe, expect, test } from 'vitest'; |
2 | 2 |
|
3 | | -import { naturalSort } from '..'; |
| 3 | +import { naturalSort, naturalSortCaseSensitive } from '..'; |
4 | 4 |
|
5 | | -test('should sort normal things alphabetically', () => { |
6 | | - expect( |
7 | | - ['a', 'h', 'b', 'i', 'c', 'd', 'j', 'e', 'k', 'f', 'g'].sort((a, b) => |
8 | | - naturalSort(a, b), |
9 | | - ), |
10 | | - ).toEqual(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']); |
11 | | -}); |
| 5 | +describe('naturalSort', () => { |
| 6 | + test('should sort normal things alphabetically', () => { |
| 7 | + expect( |
| 8 | + ['a', 'h', 'b', 'i', 'c', 'd', 'j', 'e', 'k', 'f', 'g'].sort( |
| 9 | + (a, b) => naturalSort(a, b), |
| 10 | + ), |
| 11 | + ).toEqual(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']); |
| 12 | + }); |
| 13 | + |
| 14 | + test('should ignore capitalization differences', () => { |
| 15 | + expect( |
| 16 | + ['./ExampleComponent', './ExamplesList', './ExampleWidget'].sort( |
| 17 | + (a, b) => naturalSort(a, b), |
| 18 | + ), |
| 19 | + ).toEqual(['./ExampleComponent', './ExamplesList', './ExampleWidget']); |
| 20 | + }); |
12 | 21 |
|
13 | | -test('should ignore capitalization differences', () => { |
14 | | - // We have no option to cause case-sensitive sorting, so this is the "default" case! |
15 | | - expect( |
16 | | - ['./ExampleView', './ExamplesList'].sort((a, b) => naturalSort(a, b)), |
17 | | - ).toEqual(['./ExamplesList', './ExampleView']); |
| 22 | + test('should sort things numerically', () => { |
| 23 | + expect( |
| 24 | + [ |
| 25 | + 'a2', |
| 26 | + 'a3', |
| 27 | + 'a10', |
| 28 | + 'a1', |
| 29 | + 'a11', |
| 30 | + 'a9', |
| 31 | + 'a1b', |
| 32 | + 'file000b', |
| 33 | + 'file000a', |
| 34 | + 'file00a', |
| 35 | + 'file00z', |
| 36 | + ].sort(naturalSort), |
| 37 | + ).toEqual([ |
| 38 | + 'a1', |
| 39 | + 'a1b', |
| 40 | + 'a2', |
| 41 | + 'a3', |
| 42 | + 'a9', |
| 43 | + 'a10', |
| 44 | + 'a11', |
| 45 | + 'file000a', |
| 46 | + 'file00a', |
| 47 | + 'file000b', |
| 48 | + 'file00z', |
| 49 | + ]); |
| 50 | + }); |
18 | 51 | }); |
19 | 52 |
|
20 | | -test('should sort things numerically', () => { |
21 | | - expect( |
22 | | - ['a2', 'a3', 'a10', 'a1', 'a11', 'a9'].sort((a, b) => |
23 | | - naturalSort(a, b), |
24 | | - ), |
25 | | - ).toEqual(['a1', 'a2', 'a3', 'a9', 'a10', 'a11']); |
| 53 | +describe('naturalSortCaseSensitive', () => { |
| 54 | + test('should not ignore capitalization differences', () => { |
| 55 | + expect( |
| 56 | + ['./ExampleComponent', './ExamplesList', './ExampleWidget'].sort( |
| 57 | + (a, b) => naturalSortCaseSensitive(a, b), |
| 58 | + ), |
| 59 | + ).toEqual(['./ExampleComponent', './ExampleWidget', './ExamplesList']); |
| 60 | + }); |
| 61 | + |
| 62 | + test('should sort numerically and case-sensitively', () => { |
| 63 | + expect( |
| 64 | + [ |
| 65 | + 'file1', |
| 66 | + 'File10', |
| 67 | + 'AbA', |
| 68 | + 'file10', |
| 69 | + 'files10', |
| 70 | + 'file1z', |
| 71 | + 'file10ab', |
| 72 | + 'file2s', |
| 73 | + 'a', |
| 74 | + 'Ab', |
| 75 | + 'file20', |
| 76 | + 'file22', |
| 77 | + 'file11', |
| 78 | + 'file2', |
| 79 | + 'File20', |
| 80 | + 'file000b', |
| 81 | + 'file000a', |
| 82 | + 'file00a', |
| 83 | + 'file00z', |
| 84 | + 'aaa', |
| 85 | + 'AAA', |
| 86 | + 'bBb', |
| 87 | + 'BBB', |
| 88 | + ].sort(naturalSortCaseSensitive), |
| 89 | + ).toEqual([ |
| 90 | + 'AAA', |
| 91 | + 'Ab', |
| 92 | + 'AbA', |
| 93 | + 'BBB', |
| 94 | + 'File10', |
| 95 | + 'File20', |
| 96 | + 'a', |
| 97 | + 'aaa', |
| 98 | + 'bBb', |
| 99 | + 'file000a', |
| 100 | + 'file00a', |
| 101 | + 'file000b', |
| 102 | + 'file00z', |
| 103 | + 'file1', |
| 104 | + 'file1z', |
| 105 | + 'file2', |
| 106 | + 'file2s', |
| 107 | + 'file10', |
| 108 | + 'file10ab', |
| 109 | + 'file11', |
| 110 | + 'file20', |
| 111 | + 'file22', |
| 112 | + 'files10', |
| 113 | + ]); |
| 114 | + }); |
26 | 115 | }); |
0 commit comments