-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.test.ts
More file actions
79 lines (67 loc) · 2.69 KB
/
main.test.ts
File metadata and controls
79 lines (67 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import {normalizeCweId} from '../src/utils.js'
describe('main', () => {
it('placeholder test', () => {
// This is a placeholder test to prevent Jest from failing
// TODO: Add proper unit tests for the main module
expect(true).toBe(true)
})
describe('CWE ID normalization', () => {
it('should handle CWE IDs with leading zeros', () => {
// Test that 099 maps to 99
const normalizedId = normalizeCweId('099')
expect(normalizedId).toBe('99')
})
it('should handle CWE IDs without leading zeros', () => {
// Test that 89 maps to 89
const normalizedId = normalizeCweId('89')
expect(normalizedId).toBe('89')
})
it('should handle CWE IDs with multiple leading zeros', () => {
// Test that 020 maps to 20
const normalizedId = normalizeCweId('020')
expect(normalizedId).toBe('20')
})
it('should return null for non-numeric CWE IDs', () => {
// Test that invalid CWE IDs return null
const normalizedId = normalizeCweId('abc')
expect(normalizedId).toBeNull()
})
it('should return null for empty strings', () => {
// Test that empty strings return null
const normalizedId = normalizeCweId('')
expect(normalizedId).toBeNull()
})
it('should return null for strings with only spaces', () => {
// Test that strings with only spaces return null
const normalizedId = normalizeCweId(' ')
expect(normalizedId).toBeNull()
})
it('should handle strings with leading/trailing spaces', () => {
// Test that strings with spaces are parsed correctly
const normalizedId = normalizeCweId(' 99 ')
expect(normalizedId).toBe('99')
})
it('should return null for negative numbers', () => {
// Test that negative numbers return null (CWE IDs should be positive)
const normalizedId = normalizeCweId('-99')
expect(normalizedId).toBeNull()
})
it('should handle strings with mixed alphanumeric characters (parseInt is lenient)', () => {
// Test that mixed alphanumeric strings are parsed leniently
// parseInt stops at first non-numeric character, so '99abc' becomes 99
// This is acceptable for our use case as malformed tags would be rare
const normalizedId = normalizeCweId('99abc')
expect(normalizedId).toBe('99')
})
it('should handle zero', () => {
// Test that zero is handled correctly
const normalizedId = normalizeCweId('0')
expect(normalizedId).toBe('0')
})
it('should handle zero with leading zeros', () => {
// Test that zero with leading zeros is handled correctly
const normalizedId = normalizeCweId('000')
expect(normalizedId).toBe('0')
})
})
})