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

1"""Halstead integration tests for Go."""

2

3 from analyzers.go import analyze_source

4

5

6 def test_halstead_basic():

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

8 code = """

9 package main

10

11 func add(a, b int) int {

12 return a + b

13}

14"""

15 result = analyze_source(code)

16 h = result.functions[0].halstead

17 assert h is not None

18 assert h.N1 > 0

19 assert h.N2 > 0

20 assert h.volume > 0

21

22

23 def test_halstead_short_var_declaration():

24 """:= is counted as an operator."""

25 code = """

26 package main

27

28 func f() {

29 x := 1

30 y := x + 2

31}

32"""

33 result = analyze_source(code)

34 h = result.functions[0].halstead

35 assert h.N1 > 0

36 assert h.volume > 0

37

38

39 def test_halstead_channel_operator():

40 """<- is counted as an operator."""

41 code = """

42 package main

43

44 func f(ch chan int) {

45 ch <- 42

46 x := <-ch

47}

48"""

49 result = analyze_source(code)

50 h = result.functions[0].halstead

51 assert h.N1 > 0

52 assert h.volume > 0

53

54

55 def test_halstead_empty_source():

56 """Empty Go source has no functions."""

57 result = analyze_source("")

58 assert len(result.functions) == 0