@@ -5,6 +5,7 @@ import type { OptionDef } from '../src/command';
55const OPTIONS : OptionDef [ ] = [
66 { flag : '--timeout <seconds>' , description : 'Request timeout' , type : 'number' } ,
77 { flag : '--message <text>' , description : 'Message text' , type : 'array' } ,
8+ { flag : '--verbose' , description : 'Verbose output' } ,
89] ;
910
1011describe ( 'parseFlags' , ( ) => {
@@ -25,4 +26,30 @@ describe('parseFlags', () => {
2526
2627 expect ( flags . timeout ) . toBe ( 1.5 ) ;
2728 } ) ;
29+
30+ it ( 'treats a bare boolean flag as true' , ( ) => {
31+ expect ( parseFlags ( [ '--verbose' ] , OPTIONS ) . verbose ) . toBe ( true ) ;
32+ } ) ;
33+
34+ it ( 'honours explicit false-like values on a boolean flag' , ( ) => {
35+ // Regression: `--flag=false` / `--flag=0` were silently set to true.
36+ for ( const v of [ 'false' , '0' , 'no' , 'off' , ' OFF ' , 'False' ] ) {
37+ expect ( parseFlags ( [ `--verbose=${ v } ` ] , OPTIONS ) . verbose ) . toBe ( false ) ;
38+ }
39+ } ) ;
40+
41+ it ( 'honours explicit true-like values on a boolean flag' , ( ) => {
42+ for ( const v of [ 'true' , '1' , 'yes' , 'on' , 'TRUE' ] ) {
43+ expect ( parseFlags ( [ `--verbose=${ v } ` ] , OPTIONS ) . verbose ) . toBe ( true ) ;
44+ }
45+ } ) ;
46+
47+ it ( 'rejects an unrecognised explicit boolean value' , ( ) => {
48+ expect ( ( ) => parseFlags ( [ '--verbose=maybe' ] , OPTIONS ) ) . toThrow (
49+ 'Flag --verbose requires a boolean value' ,
50+ ) ;
51+ expect ( ( ) => parseFlags ( [ '--verbose=' ] , OPTIONS ) ) . toThrow (
52+ 'Flag --verbose requires a boolean value' ,
53+ ) ;
54+ } ) ;
2855} ) ;
0 commit comments