-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Like with previous PR aiming to increase our test coverage (#1058), doing so this time revealed a few places where code was unused, or could be rewritten to be better optimized, removed, or made easier to read. One find that is yet to be addressed here is how we copy the whole `ast.found.refs` object into `ast.all_refs`, which surely comes with a cost that seems unnecessary, given we can use `ast.found.refs` directly instead. But since there are a few consumers, and they are not **exactly** identical (`all_refs` contains import refs too), I'll follow up on that in a later PR. I'm also adding the codecov badge to the README to make it easy to see when our coverage drops. But I'm not as convinced we should fail PRs when coverage isn't 100% as I was before, as it might make for a worse contributor experience. Fixes #918 Signed-off-by: Anders Eknert <[email protected]>
- Loading branch information
1 parent
0ae1823
commit 960265d
Showing
37 changed files
with
463 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package regal.ast_test | ||
|
||
import rego.v1 | ||
|
||
import data.regal.ast | ||
|
||
test_imports_keyword_rego_v1 if { | ||
module := ast.policy("import rego.v1") | ||
|
||
ast.imports_keyword(module.imports, "in") | ||
ast.imports_keyword(module.imports, "if") | ||
ast.imports_keyword(module.imports, "every") | ||
ast.imports_keyword(module.imports, "contains") | ||
} | ||
|
||
test_imports_keyword_future_keywords_all if { | ||
module := ast.policy("import future.keywords") | ||
|
||
ast.imports_keyword(module.imports, "in") | ||
ast.imports_keyword(module.imports, "if") | ||
ast.imports_keyword(module.imports, "every") | ||
ast.imports_keyword(module.imports, "contains") | ||
} | ||
|
||
test_imports_keyword_future_keywords_single if { | ||
module := ast.policy("import future.keywords.contains") | ||
|
||
ast.imports_keyword(module.imports, "contains") | ||
|
||
not ast.imports_keyword(module.imports, "in") | ||
not ast.imports_keyword(module.imports, "if") | ||
not ast.imports_keyword(module.imports, "every") | ||
} | ||
|
||
test_imports_keyword_future_keywords_every if { | ||
module := ast.policy("import future.keywords.every") | ||
|
||
ast.imports_keyword(module.imports, "every") | ||
ast.imports_keyword(module.imports, "in") | ||
|
||
not ast.imports_keyword(module.imports, "if") | ||
not ast.imports_keyword(module.imports, "contains") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package regal.lsp.completion.kind_test | ||
|
||
import rego.v1 | ||
|
||
import data.regal.lsp.completion.kind | ||
|
||
test_kind_for_coverage if { | ||
kind_values := [value | some value in kind] | ||
sort(kind_values) == numbers.range(1, 25) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package regal.lsp.completion_test | ||
|
||
import rego.v1 | ||
|
||
import data.regal.lsp.completion | ||
|
||
test_completion_entrypoint if { | ||
items := completion.items with completion.providers as {"test": {"items": {{"foo": "bar"}}}} | ||
|
||
items == {{"_regal": {"provider": "test"}, "foo": "bar"}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package regal.lsp.completion_test | ||
|
||
import rego.v1 | ||
|
||
import data.regal.ast | ||
import data.regal.capabilities | ||
|
||
import data.regal.lsp.completion | ||
|
||
test_ref_names if { | ||
module := ast.with_rego_v1(` | ||
import data.imp | ||
import data.foo.bar as bb | ||
x := 1 | ||
allow if { | ||
some x | ||
input.foo[x] == data.bar[x] | ||
startswith("hey", "h") | ||
imp.foo == data.x | ||
} | ||
`) | ||
|
||
ref_names := completion.ref_names with input as module | ||
with data.internal.combined_config as {"capabilities": capabilities.provided} | ||
|
||
ref_names == { | ||
"imp", | ||
"bb", | ||
"input.foo.$x", | ||
"data.bar.$x", | ||
"imp.foo", | ||
"data.x", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.