@@ -31,5 +31,49 @@ describe('main', () => {
3131 const normalizedId = normalizeCweId ( 'abc' )
3232 expect ( normalizedId ) . toBeNull ( )
3333 } )
34+
35+ it ( 'should return null for empty strings' , ( ) => {
36+ // Test that empty strings return null
37+ const normalizedId = normalizeCweId ( '' )
38+ expect ( normalizedId ) . toBeNull ( )
39+ } )
40+
41+ it ( 'should return null for strings with only spaces' , ( ) => {
42+ // Test that strings with only spaces return null
43+ const normalizedId = normalizeCweId ( ' ' )
44+ expect ( normalizedId ) . toBeNull ( )
45+ } )
46+
47+ it ( 'should handle strings with leading/trailing spaces' , ( ) => {
48+ // Test that strings with spaces are parsed correctly
49+ const normalizedId = normalizeCweId ( ' 99 ' )
50+ expect ( normalizedId ) . toBe ( '99' )
51+ } )
52+
53+ it ( 'should return null for negative numbers' , ( ) => {
54+ // Test that negative numbers return null (CWE IDs should be positive)
55+ const normalizedId = normalizeCweId ( '-99' )
56+ expect ( normalizedId ) . toBeNull ( )
57+ } )
58+
59+ it ( 'should handle strings with mixed alphanumeric characters (parseInt is lenient)' , ( ) => {
60+ // Test that mixed alphanumeric strings are parsed leniently
61+ // parseInt stops at first non-numeric character, so '99abc' becomes 99
62+ // This is acceptable for our use case as malformed tags would be rare
63+ const normalizedId = normalizeCweId ( '99abc' )
64+ expect ( normalizedId ) . toBe ( '99' )
65+ } )
66+
67+ it ( 'should handle zero' , ( ) => {
68+ // Test that zero is handled correctly
69+ const normalizedId = normalizeCweId ( '0' )
70+ expect ( normalizedId ) . toBe ( '0' )
71+ } )
72+
73+ it ( 'should handle zero with leading zeros' , ( ) => {
74+ // Test that zero with leading zeros is handled correctly
75+ const normalizedId = normalizeCweId ( '000' )
76+ expect ( normalizedId ) . toBe ( '0' )
77+ } )
3478 } )
3579} )
0 commit comments