File: test_preproc_parser.py

package info (click to toggle)
fortran-language-server 3.2.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,268 kB
  • sloc: python: 9,688; f90: 1,195; fortran: 30; makefile: 28; ansic: 20
file content (38 lines) | stat: -rw-r--r-- 1,164 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from __future__ import annotations

from fortls.parsers.internal.parser import preprocess_file


def test_pp_leading_spaces():
    lines = [
        " #define LEADING_SPACES_INDENT 1",
        "  #   define LEADING_SPACES_INDENT2",
        "    #    define FILE_ENCODING ,encoding='UTF-8'",
        "program pp_intentation",
        "  implicit none",
        "  print*, LEADING_SPACES_INDENT",
        "  open(unit=1,file='somefile.txt' FILE_ENCODING)",
        "end program pp_intentation",
    ]
    _, _, _, defs = preprocess_file(lines)
    ref = {
        "LEADING_SPACES_INDENT": "1",
        "LEADING_SPACES_INDENT2": "True",
        "FILE_ENCODING": ",encoding='UTF-8'",
    }
    assert defs == ref


def test_pp_macro_expansion():
    lines = [
        "# define WRAP(PROCEDURE) PROCEDURE , wrap_/**/PROCEDURE",
        "generic, public :: set => WRAP(abc)",
        "procedure :: WRAP(abc)",
    ]
    ref = [
        "# define WRAP(PROCEDURE) PROCEDURE , wrap_/**/PROCEDURE",
        "generic, public :: set => abc , wrap_/**/abc",
        "procedure :: abc , wrap_/**/abc",
    ]
    output, _, _, _ = preprocess_file(lines)
    assert output == ref