Skip to content

Commit fb26c49

Browse files
authored
Nicer formatting of with test sequences (#1969)
At last! Not comprehensive but a good start.. Signed-off-by: Anders Eknert <anders.eknert@apple.com>
1 parent 0c826eb commit fb26c49

51 files changed

Lines changed: 774 additions & 541 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bundle/regal/config/exclusion_test.rego

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,24 @@ rules_config_ignore_delta := {"rules": {"test": {"test-case": {"ignore": {"files
6666

6767
config_ignore := {"ignore": {"files": ["p.rego"]}}
6868

69-
test_excluded_file_default if {
70-
not config.excluded_file("test", "test-case", "p.rego") with data.eval.params as params({})
71-
with config.merged_config as rules_config_error
72-
}
69+
test_excluded_file_default if not config.excluded_file("test", "test-case", "p.rego")
70+
with data.eval.params as params({})
71+
with config.merged_config as rules_config_error
7372

7473
test_excluded_file_with_ignore if {
7574
compiled := config.patterns_compiler(config_ignore.ignore.files) with config.merged_config as object.union(
7675
rules_config_error,
7776
rules_config_ignore_delta,
7877
)
7978

80-
config.excluded_file("test", "test-case", "p.rego") with data.regal.util as "obnoxious formatter"
79+
config.excluded_file("test", "test-case", "p.rego")
80+
with data.regal.util as "obnoxious formatter"
8181
with data.internal.prepared.ignore_patterns.files.test["test-case"] as compiled
8282
}
8383

84-
test_excluded_file_cli_overrides_config if {
85-
not config.excluded_file("test", "test-case", "p.rego") with config.merged_config as config_ignore
86-
with data.eval.params as params({"ignore_files": [""]})
87-
}
84+
test_excluded_file_cli_overrides_config if not config.excluded_file("test", "test-case", "p.rego")
85+
with config.merged_config as config_ignore
86+
with data.eval.params as params({"ignore_files": [""]})
8887

8988
test_trailing_slash[pattern] if {
9089
some [pattern, want] in [

bundle/regal/lsp/codelens/codelens_test.rego

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@ test_code_lenses_for_module if {
1414
rule2 if 1 + rule1 == 2
1515
`
1616
module := regal.parse_module("policy.rego", policy)
17-
lenses := codelens.lenses with input as {
18-
"params": {"textDocument": {"uri": "file://policy.rego"}},
19-
# Ugh, why did we make enableDebugCodelens camel case 😭
20-
"regal": {
21-
"client": {"init_options": {"enableDebugCodelens": true}},
22-
"server": {"feature_flags": {"debug_provider": true}},
23-
"file": {
24-
"name": "policy.rego",
25-
"lines": split(policy, "\n"),
17+
lenses := codelens.lenses
18+
with input as {
19+
"params": {"textDocument": {"uri": "file://policy.rego"}},
20+
# Ugh, why did we make enableDebugCodelens camel case 😭
21+
"regal": {
22+
"client": {"init_options": {"enableDebugCodelens": true}},
23+
"server": {"feature_flags": {"debug_provider": true}},
24+
"file": {
25+
"name": "policy.rego",
26+
"lines": split(policy, "\n"),
27+
},
2628
},
27-
},
28-
}
29+
}
2930
with data.workspace.parsed as {"file://policy.rego": module}
3031

3132
lenses == [

bundle/regal/lsp/completion/main_test.rego

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,22 @@ test_completion_entrypoint if {
88
items == {{"_regal": {"provider": "test"}, "foo": "bar"}}
99
}
1010

11-
test_inside_comment if {
12-
_data := {"file:///p.rego": {"comments": [
11+
test_inside_comment if completion.inside_comment
12+
with input as {"params": {
13+
"textDocument": {"uri": "file:///p.rego"},
14+
"position": {"line": 3, "character": 4},
15+
}}
16+
with data.workspace.parsed as {"file:///p.rego": {"comments": [
1317
{"location": "2:1:2:10"},
1418
{"location": "4:1:4:10"},
1519
]}}
16-
_input := {"params": {
20+
21+
test_not_inside_comment if not completion.inside_comment
22+
with input as {"params": {
1723
"textDocument": {"uri": "file:///p.rego"},
1824
"position": {"line": 3, "character": 4},
1925
}}
20-
21-
completion.inside_comment with input as _input with data.workspace.parsed as _data
22-
}
23-
24-
test_not_inside_comment if {
25-
_data := {"file:///p.rego": {"comments": [
26+
with data.workspace.parsed as {"file:///p.rego": {"comments": [
2627
{"location": "2:1:2:10"},
2728
{"location": "4:8:4:10"},
2829
]}}
29-
_input := {"params": {
30-
"textDocument": {"uri": "file:///p.rego"},
31-
"position": {"line": 3, "character": 4},
32-
}}
33-
34-
not completion.inside_comment with input as _input with data.workspace.parsed as _data
35-
}

bundle/regal/lsp/completion/providers/booleans/booleans_test.rego

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ allow := f`}
1616
"regal": {"file": {"lines": split(workspace["file:///p.rego"], "\n")}},
1717
}
1818

19-
items := provider.items with input as regal_module with data.workspace.parsed as utils.parsed_modules(workspace)
19+
items := provider.items
20+
with input as regal_module
21+
with data.workspace.parsed as utils.parsed_modules(workspace)
2022

2123
count(items) == 1
2224

@@ -40,7 +42,9 @@ allow if {
4042
"regal": {"file": {"lines": split(workspace["file:///p.rego"], "\n")}},
4143
}
4244

43-
items := provider.items with input as regal_module with data.workspace.parsed as utils.parsed_modules(workspace)
45+
items := provider.items
46+
with input as regal_module
47+
with data.workspace.parsed as utils.parsed_modules(workspace)
4448

4549
count(items) == 1
4650

@@ -64,7 +68,9 @@ allow if {
6468
"regal": {"file": {"lines": split(workspace["file:///p.rego"], "\n")}},
6569
}
6670

67-
items := provider.items with input as regal_module with data.workspace.parsed as utils.parsed_modules(workspace)
71+
items := provider.items
72+
with input as regal_module
73+
with data.workspace.parsed as utils.parsed_modules(workspace)
6874

6975
count(items) == 1
7076

@@ -88,7 +94,9 @@ allow if {
8894
"regal": {"file": {"lines": split(workspace["file:///p.rego"], "\n")}},
8995
}
9096

91-
items := provider.items with input as regal_module with data.workspace.parsed as utils.parsed_modules(workspace)
97+
items := provider.items
98+
with input as regal_module
99+
with data.workspace.parsed as utils.parsed_modules(workspace)
92100

93101
count(items) == 0
94102
}

bundle/regal/lsp/completion/providers/builtins/builtins_test.rego

Lines changed: 84 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@ package regal.lsp.completion.providers.builtins_test
33
import data.regal.lsp.completion.providers.builtins
44

55
test_simple_builtin_completion if {
6-
items := builtins.items with input as {
7-
"params": {
8-
"textDocument": {"uri": "file:///p.rego"},
9-
"position": {"line": 3, "character": 10},
10-
},
11-
"regal": {"file": {"lines": [
12-
"package p",
13-
"",
14-
"allow if {",
15-
" b := c",
16-
"}",
17-
]}},
18-
}
6+
items := builtins.items
7+
with input as {
8+
"params": {
9+
"textDocument": {"uri": "file:///p.rego"},
10+
"position": {"line": 3, "character": 10},
11+
},
12+
"regal": {"file": {"lines": [
13+
"package p",
14+
"",
15+
"allow if {",
16+
" b := c",
17+
"}",
18+
]}},
19+
}
1920
with data.workspace.builtins as _builtins
2021

2122
items == {
@@ -49,19 +50,20 @@ test_simple_builtin_completion if {
4950
}
5051

5152
test_simple_builtin_completion_single_match if {
52-
items := builtins.items with input as {
53-
"params": {
54-
"textDocument": {"uri": "file:///p.rego"},
55-
"position": {"line": 3, "character": 11},
56-
},
57-
"regal": {"file": {"lines": [
58-
"package p",
59-
"",
60-
"allow if {",
61-
" b := co",
62-
"}",
63-
]}},
64-
}
53+
items := builtins.items
54+
with input as {
55+
"params": {
56+
"textDocument": {"uri": "file:///p.rego"},
57+
"position": {"line": 3, "character": 11},
58+
},
59+
"regal": {"file": {"lines": [
60+
"package p",
61+
"",
62+
"allow if {",
63+
" b := co",
64+
"}",
65+
]}},
66+
}
6567
with data.workspace.builtins as _builtins
6668

6769
items == {{
@@ -80,19 +82,20 @@ test_simple_builtin_completion_single_match if {
8082
}
8183

8284
test_simple_builtin_completion_single_match_longer_ref if {
83-
items := builtins.items with input as {
84-
"params": {
85-
"textDocument": {"uri": "file:///p.rego"},
86-
"position": {"line": 3, "character": 17},
87-
},
88-
"regal": {"file": {"lines": [
89-
"package p",
90-
"",
91-
"allow if {",
92-
" b := crypto.h",
93-
"}",
94-
]}},
95-
}
85+
items := builtins.items
86+
with input as {
87+
"params": {
88+
"textDocument": {"uri": "file:///p.rego"},
89+
"position": {"line": 3, "character": 17},
90+
},
91+
"regal": {"file": {"lines": [
92+
"package p",
93+
"",
94+
"allow if {",
95+
" b := crypto.h",
96+
"}",
97+
]}},
98+
}
9699
with data.workspace.builtins as _builtins
97100

98101
items == {{
@@ -112,54 +115,59 @@ test_simple_builtin_completion_single_match_longer_ref if {
112115

113116
test_no_completion_of_deprecated_builtin if {
114117
builtins_deprecated := [object.union(_builtins[0], {"deprecated": true})]
115-
items := builtins.items with data.workspace.builtins as builtins_deprecated with input as {
116-
"params": {
117-
"textDocument": {"uri": "file:///p.rego"},
118-
"position": {"line": 3, "character": 10},
119-
},
120-
"regal": {"file": {"lines": [
121-
"package p",
122-
"",
123-
"allow if {",
124-
" b := c",
125-
"}",
126-
]}},
127-
}
118+
items := builtins.items
119+
with data.workspace.builtins as builtins_deprecated
120+
with input as {
121+
"params": {
122+
"textDocument": {"uri": "file:///p.rego"},
123+
"position": {"line": 3, "character": 10},
124+
},
125+
"regal": {"file": {"lines": [
126+
"package p",
127+
"",
128+
"allow if {",
129+
" b := c",
130+
"}",
131+
]}},
132+
}
128133

129134
count(items) == 0
130135
}
131136

132137
test_no_completion_of_infix_builtin if {
133138
builtins_deprecated := [object.union(_builtins[0], {"infix": "🔄"})]
134-
items := builtins.items with data.workspace.builtins as builtins_deprecated with input as {
135-
"params": {
136-
"textDocument": {"uri": "file:///p.rego"},
137-
"position": {"line": 3, "character": 10},
138-
},
139-
"regal": {"file": {"lines": [
140-
"package p",
141-
"",
142-
"allow if {",
143-
" b := c",
144-
"}",
145-
]}},
146-
}
139+
items := builtins.items
140+
with data.workspace.builtins as builtins_deprecated
141+
with input as {
142+
"params": {
143+
"textDocument": {"uri": "file:///p.rego"},
144+
"position": {"line": 3, "character": 10},
145+
},
146+
"regal": {"file": {"lines": [
147+
"package p",
148+
"",
149+
"allow if {",
150+
" b := c",
151+
"}",
152+
]}},
153+
}
147154

148155
count(items) == 0
149156
}
150157

151158
test_no_completion_in_default_rule if {
152-
items := builtins.items with input as {
153-
"params": {
154-
"textDocument": {"uri": "file:///p.rego"},
155-
"position": {"line": 2, "character": 16},
156-
},
157-
"regal": {"file": {"lines": [
158-
"package p",
159-
"",
160-
"default foo := c",
161-
]}},
162-
}
159+
items := builtins.items
160+
with input as {
161+
"params": {
162+
"textDocument": {"uri": "file:///p.rego"},
163+
"position": {"line": 2, "character": 16},
164+
},
165+
"regal": {"file": {"lines": [
166+
"package p",
167+
"",
168+
"default foo := c",
169+
]}},
170+
}
163171
with data.workspace.builtins as _builtins
164172

165173
count(items) == 0

0 commit comments

Comments
 (0)