@@ -2,55 +2,52 @@ import { describe, it, expect } from 'vitest';
22import { sanitizeProjectName } from '../../shared/sanitize-project-name.js' ;
33
44describe ( 'sanitizeProjectName' , ( ) => {
5- it ( 'passes through simple ASCII names' , ( ) => {
5+ it ( 'passes through simple ASCII letter names' , ( ) => {
66 expect ( sanitizeProjectName ( 'myproject' ) ) . toBe ( 'myproject' ) ;
7- expect ( sanitizeProjectName ( 'my-project' ) ) . toBe ( 'my-project' ) ;
8- expect ( sanitizeProjectName ( 'my_project' ) ) . toBe ( 'my_project' ) ;
9- } ) ;
10-
11- it ( 'lowercases ASCII' , ( ) => {
127 expect ( sanitizeProjectName ( 'MyProject' ) ) . toBe ( 'myproject' ) ;
8+ expect ( sanitizeProjectName ( 'my_project' ) ) . toBe ( 'my_project' ) ;
139 } ) ;
1410
15- it ( 'converts spaces to underscores' , ( ) => {
11+ it ( 'replaces dots, hyphens, spaces, and digits with underscores' , ( ) => {
12+ expect ( sanitizeProjectName ( 'im.codes' ) ) . toBe ( 'im_codes' ) ;
13+ expect ( sanitizeProjectName ( 'my-project' ) ) . toBe ( 'my_project' ) ;
1614 expect ( sanitizeProjectName ( 'my project' ) ) . toBe ( 'my_project' ) ;
15+ expect ( sanitizeProjectName ( 'v1.0' ) ) . toBe ( 'v' ) ;
16+ expect ( sanitizeProjectName ( 'abc123def' ) ) . toBe ( 'abc_def' ) ;
1717 } ) ;
1818
19- it ( 'converts Chinese characters to hex codepoints ' , ( ) => {
19+ it ( 'falls back to a generated slug when input has no letters ' , ( ) => {
2020 const result = sanitizeProjectName ( '测试' ) ;
21- expect ( result ) . toBe ( '6d4b-8bd5' ) ;
22- // Verify it's deterministic
23- expect ( sanitizeProjectName ( '测试' ) ) . toBe ( result ) ;
21+ expect ( result ) . toMatch ( / ^ p r o j _ [ a - z ] + $ / ) ;
22+ expect ( sanitizeProjectName ( '测试' ) ) . not . toBe ( '' ) ;
2423 } ) ;
2524
26- it ( 'handles mixed ASCII and Chinese ' , ( ) => {
27- const result = sanitizeProjectName ( 'my测试project' ) ;
28- expect ( result ) . toMatch ( / ^ m y - ? 6 d 4 b - 8 b d 5 - ? p r o j e c t $ / ) ;
25+ it ( 'handles mixed ASCII and non-ASCII by normalizing separators ' , ( ) => {
26+ expect ( sanitizeProjectName ( 'my测试project' ) ) . toBe ( 'my_project ') ;
27+ expect ( sanitizeProjectName ( 'café' ) ) . toBe ( 'caf' ) ;
2928 } ) ;
3029
31- it ( 'trims leading/trailing underscores and hyphens ' , ( ) => {
30+ it ( 'trims leading and trailing underscores ' , ( ) => {
3231 expect ( sanitizeProjectName ( '_test_' ) ) . toBe ( 'test' ) ;
3332 expect ( sanitizeProjectName ( '-test-' ) ) . toBe ( 'test' ) ;
33+ expect ( sanitizeProjectName ( '123test456' ) ) . toBe ( 'test' ) ;
3434 } ) ;
3535
36- it ( 'generates fallback for empty input' , ( ) => {
37- const result = sanitizeProjectName ( ' ' ) ;
38- expect ( result ) . toMatch ( / ^ p r o j _ / ) ;
39- } ) ;
40-
41- it ( 'collapses consecutive underscores' , ( ) => {
36+ it ( 'collapses repeated separators into one underscore' , ( ) => {
4237 expect ( sanitizeProjectName ( 'a b' ) ) . toBe ( 'a_b' ) ;
38+ expect ( sanitizeProjectName ( 'a---...999b' ) ) . toBe ( 'a_b' ) ;
4339 } ) ;
4440
45- it ( 'preserves dots' , ( ) => {
46- expect ( sanitizeProjectName ( 'v1.0' ) ) . toBe ( 'v1.0' ) ;
41+ it ( 'generates fallback for empty input' , ( ) => {
42+ const result = sanitizeProjectName ( ' ' ) ;
43+ expect ( result ) . toMatch ( / ^ p r o j _ [ a - z ] + $ / ) ;
4744 } ) ;
4845
49- it ( 'produces tmux-safe output (no special chars) ' , ( ) => {
50- const names = [ '测试' , '我的项目' , 'café' , 'über cool' , '日本語テスト' ] ;
46+ it ( 'produces strictly tmux-safe output using only lowercase letters and underscores ' , ( ) => {
47+ const names = [ '测试' , '我的项目' , 'café' , 'über cool' , '日本語テスト' , 'im.codes' , 'abc123' ] ;
5148 for ( const name of names ) {
5249 const slug = sanitizeProjectName ( name ) ;
53- expect ( slug ) . toMatch ( / ^ [ a - z 0 - 9 . _ - ] + $ / ) ;
50+ expect ( slug ) . toMatch ( / ^ [ a - z _ ] + $ / ) ;
5451 }
5552 } ) ;
5653} ) ;
0 commit comments