Coverage for tests / test_halstead / test_go.py: 100%
24 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-08 15:04 -0800
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-08 15:04 -0800
1"""Halstead integration tests for Go."""
3from analyzers.go import analyze_source
6def test_halstead_basic():
7 """Basic Go function produces Halstead metrics."""
8 code = """
9package main
11func 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
23def test_halstead_short_var_declaration():
24 """:= is counted as an operator."""
25 code = """
26package main
28func 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
39def test_halstead_channel_operator():
40 """<- is counted as an operator."""
41 code = """
42package main
44func 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
55def test_halstead_empty_source():
56 """Empty Go source has no functions."""
57 result = analyze_source("")
58 assert len(result.functions) == 0