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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
import os
import sys
from pathlib import Path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
from fortls.interface import cli # noqa: E402
parser = cli("fortls")
def test_command_line_general_options():
args = parser.parse_args(
"-c config_file.json -n 2 --notify_init --incremental_sync --sort_keywords"
" --disable_autoupdate --debug_log".split()
)
assert args.config == "config_file.json"
assert args.nthreads == 2
assert args.notify_init
assert args.incremental_sync
assert args.sort_keywords
assert args.disable_autoupdate
assert args.debug_log
def test_command_line_file_parsing_options():
args = parser.parse_args(
"--source_dirs tmp ./local /usr/include/** --incl_suffixes .FF .fpc .h f20"
" --excl_suffixes _tmp.f90 _h5hut_tests.F90 --excl_paths exclude tests".split()
)
assert args.source_dirs == {"tmp", "./local", "/usr/include/**"}
assert args.incl_suffixes == {".FF", ".fpc", ".h", "f20"}
assert args.excl_suffixes == {"_tmp.f90", "_h5hut_tests.F90"}
assert args.excl_paths == {"exclude", "tests"}
def test_command_line_autocomplete_options():
args = parser.parse_args(
"--autocomplete_no_prefix --autocomplete_no_snippets --autocomplete_name_only"
" --lowercase_intrinsics --use_signature_help".split()
)
assert args.autocomplete_no_prefix
assert args.autocomplete_no_snippets
assert args.autocomplete_name_only
assert args.lowercase_intrinsics
assert args.use_signature_help
def test_command_line_hover_options():
args = parser.parse_args(
"--hover_signature --hover_language FortranFreeForm".split()
)
assert args.hover_signature
assert args.hover_language == "FortranFreeForm"
def test_command_line_diagnostic_options():
args = parser.parse_args(
"--max_line_length 80 --max_comment_line_length 8 --disable_diagnostics".split()
)
assert args.max_line_length == 80
assert args.max_comment_line_length == 8
assert args.disable_diagnostics
def test_command_line_preprocessor_options():
args = parser.parse_args(
"--pp_suffixes .h .fh --include_dirs /usr/include/** ./local/incl --pp_defs"
' {"HAVE_PETSC":"","HAVE_ZOLTAN":"","Mat":"type(tMat)"}'.split()
)
assert args.pp_suffixes == [".h", ".fh"]
assert args.include_dirs == {"/usr/include/**", "./local/incl"}
assert args.pp_defs == {"HAVE_PETSC": "", "HAVE_ZOLTAN": "", "Mat": "type(tMat)"}
def test_command_line_symbol_options():
args = parser.parse_args("--symbol_skip_mem".split())
assert args.symbol_skip_mem
def test_command_line_code_actions_options():
args = parser.parse_args("--enable_code_actions".split())
assert args.enable_code_actions
def unittest_server_init(conn=None):
from fortls.langserver import LangServer
root = (Path(__file__).parent / "test_source").resolve()
parser = cli("fortls")
args = parser.parse_args("-c f90_config.json".split())
server = LangServer(conn, vars(args))
server.root_path = root
server._load_config_file()
return server, root
def test_config_file_general_options():
server, root = unittest_server_init()
assert server.nthreads == 8
assert server.notify_init
assert server.incremental_sync
assert server.sort_keywords
assert server.disable_autoupdate
assert server.recursion_limit == 1500
def test_config_file_dir_parsing_options():
server, r = unittest_server_init()
# File parsing
assert server.source_dirs == {"pp/**", "subdir"}
assert server.incl_suffixes == {".FF", ".fpc", ".h", "f20"}
assert server.excl_suffixes == {"_tmp.f90", "_h5hut_tests.F90"}
assert server.excl_paths == {"excldir", "hover/**"}
def test_config_file_autocomplete_options():
server, root = unittest_server_init()
# Autocomplete options
assert server.autocomplete_no_prefix
assert server.autocomplete_no_snippets
assert server.autocomplete_name_only
assert server.lowercase_intrinsics
assert server.use_signature_help
def test_config_file_hover_options():
server, root = unittest_server_init()
# Hover options
assert server.hover_signature
assert server.hover_language == "FortranFreeForm"
def test_config_file_diagnostic_options():
server, root = unittest_server_init()
# Diagnostic options
assert server.max_line_length == 80
assert server.max_comment_line_length == 80
assert server.disable_diagnostics
def test_config_file_preprocessor_options():
server, root = unittest_server_init()
# Preprocessor options
assert server.pp_suffixes == [".h", ".fh"]
assert server.include_dirs == {"./include/**"}
assert server.pp_defs == {
"HAVE_PETSC": "",
"HAVE_ZOLTAN": "",
"Mat": "type(tMat)",
}
def test_config_file_symbols_options():
server, root = unittest_server_init()
# Symbols options
assert server.symbol_skip_mem
def test_config_file_codeactions_options():
server, root = unittest_server_init()
# Code Actions options
assert server.enable_code_actions
|