from scripts.adapters.luac import parse_luac_output def test_parses_single_syntax_error(): stderr = "luac: ./src/game.lua:8: 'end' expected (to close 'function' at line 1) near ''" findings = parse_luac_output(stderr, repo_root="") assert len(findings) == 1 f = findings[0] assert f.tool == "luac" assert f.rule_id == "syntax-error" assert f.severity == "critical" assert f.line == 8 assert f.end_line == 8 assert "end" in f.message def test_parses_multiple_errors(): stderr = ( "luac: ./a.lua:3: unexpected symbol near '='\n" "luac: ./b.lua:17: 'end' expected near ''" ) findings = parse_luac_output(stderr, repo_root="") assert len(findings) == 2 files = {f.file for f in findings} assert "./a.lua" in files assert "./b.lua" in files def test_strips_repo_root_prefix(): stderr = "luac: /home/user/myrepo/src/game.lua:5: unexpected symbol near '+'" findings = parse_luac_output(stderr, repo_root="/home/user/myrepo") assert findings[0].file == "src/game.lua" def test_empty_stderr_returns_empty(): findings = parse_luac_output("", repo_root="") assert findings == [] def test_non_matching_lines_ignored(): stderr = "warning: something else\nnot a luac error" findings = parse_luac_output(stderr, repo_root="") assert findings == []