Coverage for tests / unit / parsers / shellcheck_parser / test_edge_cases.py: 100%
46 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
1"""Tests for shellcheck parser edge cases."""
3from __future__ import annotations
5import json
7from assertpy import assert_that
9from lintro.parsers.shellcheck.shellcheck_parser import parse_shellcheck_output
11from .conftest import make_issue, make_shellcheck_output
14def test_parse_unicode_in_message() -> None:
15 """Handle Unicode characters in error messages."""
16 output = make_shellcheck_output(
17 [
18 make_issue(message="Mensagem com acentos: café"),
19 ],
20 )
21 result = parse_shellcheck_output(output=output)
23 assert_that(result).is_length(1)
24 assert_that(result[0].message).contains("café")
27def test_parse_file_with_path() -> None:
28 """Parse file with directory path."""
29 output = make_shellcheck_output(
30 [
31 make_issue(file="scripts/deploy/prod.sh"),
32 ],
33 )
34 result = parse_shellcheck_output(output=output)
36 assert_that(result).is_length(1)
37 assert_that(result[0].file).is_equal_to("scripts/deploy/prod.sh")
40def test_parse_very_long_message() -> None:
41 """Handle extremely long error messages."""
42 long_text = "x" * 5000
43 output = make_shellcheck_output([make_issue(message=long_text)])
44 result = parse_shellcheck_output(output=output)
46 assert_that(result).is_length(1)
47 assert_that(len(result[0].message)).is_equal_to(5000)
50def test_parse_very_large_line_number() -> None:
51 """Handle very large line numbers."""
52 output = make_shellcheck_output([make_issue(line=999999)])
53 result = parse_shellcheck_output(output=output)
55 assert_that(result).is_length(1)
56 assert_that(result[0].line).is_equal_to(999999)
59def test_parse_special_chars_in_message() -> None:
60 """Handle special characters in error messages."""
61 output = make_shellcheck_output(
62 [
63 make_issue(message='Use "$var" instead of $var for safety.'),
64 ],
65 )
66 result = parse_shellcheck_output(output=output)
68 assert_that(result).is_length(1)
69 assert_that(result[0].message).contains('"$var"')
72def test_parse_deeply_nested_path() -> None:
73 """Handle deeply nested file paths."""
74 deep_path = "a/b/c/d/e/f/g/h/i/j/script.sh"
75 output = make_shellcheck_output([make_issue(file=deep_path)])
76 result = parse_shellcheck_output(output=output)
78 assert_that(result).is_length(1)
79 assert_that(result[0].file).is_equal_to(deep_path)
82def test_parse_missing_required_fields_uses_defaults() -> None:
83 """Parse handles missing fields with defaults."""
84 data = [
85 {
86 "level": "warning",
87 "code": 2086,
88 },
89 ]
90 output = json.dumps(data)
91 result = parse_shellcheck_output(output=output)
93 assert_that(result).is_length(1)
94 assert_that(result[0].file).is_equal_to("")
95 assert_that(result[0].line).is_equal_to(0)
96 assert_that(result[0].column).is_equal_to(0)
97 assert_that(result[0].message).is_equal_to("")