|
| 1 | +import pytest |
1 | 2 | from setup_tests import test_dir
|
2 | 3 |
|
3 | 4 | from fortls.parsers.internal.parser import FortranFile
|
@@ -57,3 +58,41 @@ def test_weird_parser_bug():
|
57 | 58 | ast = file.parse()
|
58 | 59 | assert err_str is None
|
59 | 60 | assert not ast.end_errors
|
| 61 | + |
| 62 | + |
| 63 | +@pytest.mark.parametrize( |
| 64 | + "ln_no, pp_defs, reference", |
| 65 | + [ |
| 66 | + (6, {}, 6), |
| 67 | + (7, {}, 6), |
| 68 | + (8, {}, 6), |
| 69 | + (11, {"TEST": True}, 60), # not entirely correct ref vals |
| 70 | + (23, {"MULT": True}, 90), # not entirely correct ref vals |
| 71 | + (32, {"TEST": True, "MULT": True}, 130), # not entirely correct ref vals |
| 72 | + (39, {"TEST": True, "MULT": True}, 2400), # not entirely correct ref vals |
| 73 | + ], |
| 74 | +) |
| 75 | +def test_get_code_line_multilines(ln_no: int, pp_defs: dict, reference: int): |
| 76 | + """Tests how the get_code_line performs with multi-line and preprocessor |
| 77 | +
|
| 78 | + Not all the results are correct, since get_code_line is not aware of the |
| 79 | + preprocessor skips. Instead what it does is it evaluates all the line |
| 80 | + continuations and appends them in post. |
| 81 | + """ |
| 82 | + |
| 83 | + def calc_result(res: tuple): |
| 84 | + pre, cur, post = res |
| 85 | + res = "".join(pre + [cur] + post).replace(" ", "") |
| 86 | + assert "result" in res, "Fortran variable `result` not found in results" |
| 87 | + loc = {} |
| 88 | + exec(res, None, loc) |
| 89 | + return loc["result"] |
| 90 | + |
| 91 | + file_path = test_dir / "parse" / "mixed" / "multilines.F90" |
| 92 | + file = FortranFile(str(file_path)) |
| 93 | + file.load_from_disk() |
| 94 | + file.preprocess(pp_defs=pp_defs) |
| 95 | + pp = bool(pp_defs) |
| 96 | + res = file.get_code_line(line_no=ln_no, pp_content=pp) |
| 97 | + result = calc_result(res) |
| 98 | + assert result == reference |
0 commit comments