dte test coverage


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 50.0% high: ≥ 85.0%
Coverage Exec / Excl / Total
Lines: 100.0% 2 / 0 / 2
Functions: 100.0% 1 / 0 / 1
Branches: 75.0% 3 / 0 / 4

src/options.h
Line Branch Exec Source
1 #ifndef OPTIONS_H
2 #define OPTIONS_H
3
4 #include <stdbool.h>
5 #include <stddef.h>
6 #include <stdint.h>
7 #include "command/error.h"
8 #include "regexp.h"
9 #include "util/debug.h"
10 #include "util/macros.h"
11 #include "util/ptr-array.h"
12 #include "util/string.h"
13
14 enum {
15 INDENT_WIDTH_MAX = 8,
16 TAB_WIDTH_MAX = 8,
17 TEXT_WIDTH_MAX = 1000,
18 };
19
20 // Note: this must be kept in sync with ws_error_values[]
21 typedef enum {
22 WSE_SPACE_INDENT = 1 << 0, // Spaces in indent (except WSE_SPACE_ALIGN)
23 WSE_SPACE_ALIGN = 1 << 1, // Less than tab-width spaces at end of indent
24 WSE_TAB_INDENT = 1 << 2, // Tab in indent
25 WSE_TAB_AFTER_INDENT = 1 << 3, // Tab anywhere but indent
26 WSE_SPECIAL = 1 << 4, // Special whitespace characters
27 WSE_AUTO_INDENT = 1 << 5, // expand-tab ? WSE_TAB_AFTER_INDENT | WSE_TAB_INDENT : WSE_SPACE_INDENT
28 WSE_TRAILING = 1 << 6, // Trailing whitespace
29 WSE_ALL_TRAILING = 1 << 7, // Like WSE_TRAILING, but including around cursor
30 } WhitespaceErrorFlags;
31
32 // Note: this must be kept in sync with save_unmodified_enum[]
33 typedef enum {
34 SAVE_NONE,
35 SAVE_TOUCH,
36 SAVE_FULL,
37 } SaveUnmodifiedType;
38
39 #define COMMON_OPTIONS \
40 unsigned int detect_indent; \
41 unsigned int ws_error; \
42 unsigned int text_width; \
43 uint8_t indent_width; \
44 uint8_t tab_width; \
45 uint8_t save_unmodified; \
46 bool auto_indent; \
47 bool editorconfig; \
48 bool emulate_tab; \
49 bool expand_tab; \
50 bool file_history; \
51 bool fsync; \
52 bool overwrite; \
53 bool syntax
54
55 typedef struct {
56 COMMON_OPTIONS;
57 } CommonOptions;
58
59 // Note: all members should be initialized in buffer_new()
60 typedef struct {
61 COMMON_OPTIONS;
62 // Only local
63 bool brace_indent;
64 const char *filetype;
65 const InternedRegexp *indent_regex;
66 } LocalOptions;
67
68 typedef struct {
69 COMMON_OPTIONS;
70 // Only global
71 bool display_special;
72 bool lock_files;
73 bool optimize_true_color;
74 bool select_cursor_char;
75 bool set_window_title;
76 bool show_line_numbers;
77 bool tab_bar;
78 bool utf8_bom; // Default value for new files
79 uint8_t scroll_margin;
80 uint8_t crlf_newlines; // Default value for new files
81 uint8_t case_sensitive_search; // SearchCaseSensitivity
82 uint8_t window_separator; // WindowSeparatorType
83 uint8_t msg_compile; // Default EditorState::messages[] index for `compile`
84 uint8_t msg_tag; // Default EditorState::messages[] index for `tag`
85 unsigned int esc_timeout; // See term_read_input()
86 uint_least64_t filesize_limit; // Size limit imposed by load_buffer()
87 uint_least64_t syntax_line_limit; // Line length at which LocalOptions::syntax is disabled
88 const char *statusline_left;
89 const char *statusline_right;
90 } GlobalOptions;
91
92 #undef COMMON_OPTIONS
93
94 114 static inline bool use_spaces_for_indent(const LocalOptions *opt)
95 {
96
3/4
✓ Branch 2 → 3 taken 16 times.
✓ Branch 2 → 5 taken 98 times.
✓ Branch 3 → 4 taken 16 times.
✗ Branch 3 → 5 not taken.
114 return opt->expand_tab || opt->indent_width != opt->tab_width;
97 }
98
99 struct EditorState;
100
101 bool set_option(struct EditorState *e, const char *name, const char *value, bool local, bool global, bool quiet);
102 bool set_bool_option(struct EditorState *e, const char *name, bool local, bool global, bool quiet);
103 bool toggle_option(struct EditorState *e, const char *name, bool global, bool verbose);
104 bool toggle_option_values(struct EditorState *e, const char *name, bool global, bool verbose, char **values, size_t count);
105 bool validate_local_options(ErrorBuffer *ebuf, char **strs);
106 void collect_options(PointerArray *a, const char *prefix, bool local, bool global);
107 void collect_auto_options(PointerArray *a, const char *prefix);
108 void collect_toggleable_options(PointerArray *a, const char *prefix, bool global);
109 void collect_option_values(struct EditorState *e, PointerArray *a, const char *option, const char *prefix);
110 String dump_options(GlobalOptions *gopts, LocalOptions *lopts);
111 const char *get_option_value_string(struct EditorState *e, const char *name);
112
113 #if DEBUG_ASSERTIONS_ENABLED
114 void sanity_check_global_options(const GlobalOptions *opts);
115 void sanity_check_local_options(const LocalOptions *lopts);
116 #else
117 static inline void sanity_check_global_options(const GlobalOptions* UNUSED_ARG(gopts)) {}
118 static inline void sanity_check_local_options(const LocalOptions* UNUSED_ARG(lopts)) {}
119 #endif
120
121 #endif
122