Coverage for tests / test_halstead / test_typescript.py: 100%

23 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-08 15:04 -0800

1"""Halstead integration tests for TypeScript.""" 

2 

3from analyzers.typescript import analyze_source 

4 

5 

6def test_halstead_basic(): 

7 """Basic TypeScript function produces Halstead metrics.""" 

8 code = """ 

9function add(a, b) { 

10 return a + b; 

11} 

12""" 

13 result = analyze_source(code) 

14 h = result.functions[0].halstead 

15 assert h is not None 

16 assert h.N1 > 0 

17 assert h.N2 > 0 

18 assert h.volume > 0 

19 

20 

21def test_halstead_strict_equality(): 

22 """=== and !== are counted as operators.""" 

23 code = """ 

24function f() { 

25 const x = a === b; 

26 const y = c !== d; 

27} 

28""" 

29 result = analyze_source(code) 

30 h = result.functions[0].halstead 

31 assert h.n1 >= 2 # at least === and !== 

32 

33 

34def test_halstead_optional_chaining_and_nullish(): 

35 """?. and ?? are counted as operators.""" 

36 code = """ 

37function f() { 

38 const x = a?.b ?? c; 

39} 

40""" 

41 result = analyze_source(code) 

42 h = result.functions[0].halstead 

43 assert h.N1 > 0 

44 assert h.volume > 0 

45 

46 

47def test_halstead_empty_source(): 

48 """Empty TypeScript source has no functions.""" 

49 result = analyze_source("") 

50 assert len(result.functions) == 0