|
| 1 | +import {normalizeCweId} from '../src/utils' |
| 2 | + |
1 | 3 | describe('main', () => { |
2 | 4 | it('placeholder test', () => { |
3 | 5 | // This is a placeholder test to prevent Jest from failing |
4 | 6 | // TODO: Add proper unit tests for the main module |
5 | 7 | expect(true).toBe(true) |
6 | 8 | }) |
| 9 | + |
| 10 | + describe('CWE ID normalization', () => { |
| 11 | + it('should handle CWE IDs with leading zeros', () => { |
| 12 | + // Test that 099 maps to 99 |
| 13 | + const normalizedId = normalizeCweId('099') |
| 14 | + expect(normalizedId).toBe('99') |
| 15 | + }) |
| 16 | + |
| 17 | + it('should handle CWE IDs without leading zeros', () => { |
| 18 | + // Test that 89 maps to 89 |
| 19 | + const normalizedId = normalizeCweId('89') |
| 20 | + expect(normalizedId).toBe('89') |
| 21 | + }) |
| 22 | + |
| 23 | + it('should handle CWE IDs with multiple leading zeros', () => { |
| 24 | + // Test that 020 maps to 20 |
| 25 | + const normalizedId = normalizeCweId('020') |
| 26 | + expect(normalizedId).toBe('20') |
| 27 | + }) |
| 28 | + |
| 29 | + it('should return null for non-numeric CWE IDs', () => { |
| 30 | + // Test that invalid CWE IDs return null |
| 31 | + const normalizedId = normalizeCweId('abc') |
| 32 | + expect(normalizedId).toBeNull() |
| 33 | + }) |
| 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 | + }) |
| 78 | + }) |
7 | 79 | }) |
0 commit comments