@@ -1072,35 +1072,16 @@ describe('PackageURL', () => {
10721072 // Test error formatting edge cases using imports
10731073 const { PurlError } = require ( '../src/error' )
10741074
1075- it ( 'should handle error messages with no period at end' , ( ) => {
1075+ it . each ( [
1076+ [ 'Error without period' , 'Invalid purl: error without period' ] ,
1077+ [ 'Error with double period..' , 'Invalid purl: error with double period..' ] ,
1078+ [ 'already lowercase' , 'Invalid purl: already lowercase' ] ,
1079+ [ '' , 'Invalid purl: ' ]
1080+ ] ) ( 'should format error message "%s" correctly' , ( input , expected ) => {
10761081 try {
1077- throw new PurlError ( 'Error without period' )
1082+ throw new PurlError ( input )
10781083 } catch ( e ) {
1079- expect ( e . message ) . toBe ( 'Invalid purl: error without period' )
1080- }
1081- } )
1082-
1083- it ( 'should handle error messages with double period at end' , ( ) => {
1084- try {
1085- throw new PurlError ( 'Error with double period..' )
1086- } catch ( e ) {
1087- expect ( e . message ) . toBe ( 'Invalid purl: error with double period..' )
1088- }
1089- } )
1090-
1091- it ( 'should handle error messages starting with lowercase' , ( ) => {
1092- try {
1093- throw new PurlError ( 'already lowercase' )
1094- } catch ( e ) {
1095- expect ( e . message ) . toBe ( 'Invalid purl: already lowercase' )
1096- }
1097- } )
1098-
1099- it ( 'should handle empty error messages' , ( ) => {
1100- try {
1101- throw new PurlError ( '' )
1102- } catch ( e ) {
1103- expect ( e . message ) . toBe ( 'Invalid purl: ' )
1084+ expect ( e . message ) . toBe ( expected )
11041085 }
11051086 } )
11061087
@@ -1117,25 +1098,16 @@ describe('PackageURL', () => {
11171098 } )
11181099
11191100 // Test objects module - recursiveFreeze edge cases
1120- it ( 'should handle recursive freeze with already frozen objects' , ( ) => {
1121- const frozen = Object . freeze ( { a : 1 } )
1122- const purl = new PackageURL ( 'type' , null , 'name' , null , {
1123- key : 'value' ,
1124- } )
1125- // Just test that it doesn't throw
1126- expect ( purl . qualifiers ) . toHaveProperty ( 'key' , 'value' )
1127- } )
1128-
1129- it ( 'should handle recursive freeze with nested objects' , ( ) => {
1130- const nested = { inner : { deep : 'value' } }
1131- const purl = new PackageURL ( 'type' , null , 'name' , null , nested )
1132- // Just test that nested values are preserved
1133- expect ( purl . qualifiers ) . toHaveProperty ( 'inner' )
1134- } )
1135-
1136- it ( 'should detect and throw on infinite loop in recursiveFreeze' , ( ) => {
1137- // This would require modifying internal constants to test properly
1138- // Skipping as it requires changing LOOP_SENTINEL
1101+ it . each ( [
1102+ [ 'already frozen objects' , { key : 'value' } ] ,
1103+ [ 'nested objects' , { inner : { deep : 'value' } } ] ,
1104+ [ 'arrays' , { arr : [ 1 , 2 , { nested : true } ] } ] ,
1105+ [ 'mixed types' , { str : 'test' , num : 123 , obj : { nested : true } } ]
1106+ ] ) ( 'should handle recursiveFreeze with %s' , ( description , qualifiers ) => {
1107+ const purl = new PackageURL ( 'type' , null , 'name' , null , qualifiers )
1108+ expect ( purl . qualifiers ) . toBeDefined ( )
1109+ // Just verify the purl was created successfully and qualifiers exist
1110+ expect ( typeof purl . qualifiers ) . toBe ( 'object' )
11391111 } )
11401112
11411113 // Test validation edge cases
@@ -1253,21 +1225,6 @@ describe('PackageURL', () => {
12531225 } )
12541226
12551227 // Test error formatting
1256- it ( 'should format error messages correctly' , ( ) => {
1257- const { PurlError } = require ( '../src/error' )
1258-
1259- const err1 = new PurlError ( 'Error without period' )
1260- expect ( err1 . message ) . toBe ( 'Invalid purl: error without period' )
1261-
1262- const err2 = new PurlError ( 'error already lowercase' )
1263- expect ( err2 . message ) . toBe ( 'Invalid purl: error already lowercase' )
1264-
1265- const err3 = new PurlError ( '.' )
1266- expect ( err3 . message ) . toBe ( 'Invalid purl: .' )
1267-
1268- const err4 = new PurlError ( '' )
1269- expect ( err4 . message ) . toBe ( 'Invalid purl: ' )
1270- } )
12711228
12721229 // Test recursiveFreeze edge cases
12731230 it ( 'should handle recursiveFreeze with various inputs' , ( ) => {
@@ -1605,15 +1562,6 @@ describe('PackageURL', () => {
16051562 } )
16061563
16071564 // Test error.js line 12 - uppercase to lowercase
1608- it ( 'should format error messages with uppercase start' , ( ) => {
1609- const { PurlError } = require ( '../src/error' )
1610-
1611- try {
1612- throw new PurlError ( 'Error Message With Uppercase' )
1613- } catch ( e ) {
1614- expect ( e . message ) . toBe ( 'Invalid purl: error Message With Uppercase' )
1615- }
1616- } )
16171565
16181566 // Test objects.js line 33 - infinite loop branch
16191567 it ( 'should handle massive arrays in recursiveFreeze' , ( ) => {
@@ -1912,41 +1860,8 @@ describe('PackageURL', () => {
19121860 } )
19131861
19141862 // Test objects.js line 33 - check for recursiveFreeze edge case
1915- it ( 'should test recursiveFreeze with property descriptor edge cases' , ( ) => {
1916- const { recursiveFreeze } = require ( '../src/objects' )
1917-
1918- // Test with object that has non-configurable properties
1919- const obj = { }
1920- Object . defineProperty ( obj , 'nonConfig' , {
1921- value : { nested : 'value' } ,
1922- writable : true ,
1923- enumerable : true ,
1924- configurable : false ,
1925- } )
1926-
1927- const frozen = recursiveFreeze ( obj )
1928- expect ( Object . isFrozen ( frozen ) ) . toBe ( true )
1929- expect ( Object . isFrozen ( frozen . nonConfig ) ) . toBe ( true )
1930- } )
19311863
19321864 // Test error.js line 12 - lowercase conversion edge case
1933- it ( 'should test error message formatting with various cases' , ( ) => {
1934- const { PurlError } = require ( '../src/error' )
1935-
1936- // Test line 12 - lowercase conversion only for first letter if uppercase
1937- try {
1938- throw new PurlError ( 'Error message' )
1939- } catch ( e ) {
1940- expect ( e . message ) . toBe ( 'Invalid purl: error message' )
1941- }
1942-
1943- // Test with number start
1944- try {
1945- throw new PurlError ( '123 error' )
1946- } catch ( e ) {
1947- expect ( e . message ) . toBe ( 'Invalid purl: 123 error' )
1948- }
1949- } )
19501865
19511866 // Additional tests for 100% coverage
19521867 // Test normalize.js lines 7, 13 - namespaceFilter
@@ -2089,17 +2004,6 @@ describe('PackageURL', () => {
20892004 } )
20902005
20912006 // Test error.js line 12 - check for uppercase A-Z range
2092- it ( 'should test error formatting uppercase check' , ( ) => {
2093- const { formatPurlErrorMessage } = require ( '../src/error' )
2094-
2095- // Test with Z (edge of A-Z range)
2096- const result1 = formatPurlErrorMessage ( 'Zebra error' )
2097- expect ( result1 ) . toBe ( 'Invalid purl: zebra error' )
2098-
2099- // Test with A (start of A-Z range)
2100- const result2 = formatPurlErrorMessage ( 'Apple error' )
2101- expect ( result2 ) . toBe ( 'Invalid purl: apple error' )
2102- } )
21032007
21042008 // Test objects.js line 33 - else branch (non-array)
21052009 it ( 'should test recursiveFreeze with objects that have getters' , ( ) => {
@@ -2150,17 +2054,6 @@ describe('PackageURL', () => {
21502054 } )
21512055
21522056 // Test error.js line 12 - conditional branch
2153- it ( 'should test error message with non-uppercase start' , ( ) => {
2154- const { formatPurlErrorMessage } = require ( '../src/error' )
2155-
2156- // Test when first char is not A-Z
2157- const result = formatPurlErrorMessage ( 'lowercase start' )
2158- expect ( result ) . toBe ( 'Invalid purl: lowercase start' )
2159-
2160- // Test empty message
2161- const result2 = formatPurlErrorMessage ( '' )
2162- expect ( result2 ) . toBe ( 'Invalid purl: ' )
2163- } )
21642057
21652058 // Test objects.js line 33 - property descriptor iteration
21662059 it ( 'should test recursiveFreeze with symbols and non-enumerable props' , ( ) => {
@@ -2324,16 +2217,6 @@ describe('PackageURL', () => {
23242217 } )
23252218
23262219 // Test error.js line 12 - OR condition in uppercase check
2327- it ( 'should test error message formatting OR condition' , ( ) => {
2328- const { formatPurlErrorMessage } = require ( '../src/error' )
2329-
2330- // Test the OR condition (should be && not ||)
2331- const result = formatPurlErrorMessage ( 'Z' )
2332- expect ( result ) . toBe ( 'Invalid purl: z' )
2333-
2334- const result2 = formatPurlErrorMessage ( '@' )
2335- expect ( result2 ) . toBe ( 'Invalid purl: @' )
2336- } )
23372220
23382221 // Test objects.js line 33 - Object.values path
23392222 it ( 'should test recursiveFreeze with Object.values path' , ( ) => {
0 commit comments