Skip to content

Commit

Permalink
add ruby unit tests for Engine#get_ast_as_json
Browse files Browse the repository at this point in the history
  • Loading branch information
thedavemarshall committed Jun 8, 2024
1 parent ef45c50 commit 595cb2e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions bindings/ruby/test/test_regorus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,22 @@ def test_gather_print_statements
assert_equal ["<query.rego>:1: Hello"], @engine.take_prints
end

def test_get_ast_as_json_source
ast_json = JSON.parse(@engine.get_ast_as_json).first

assert_equal "regorus_test.rego", ast_json["source"]["file"]
assert_match "is_manager {\n input.name == data.managers[_]\n}", ast_json["source"]["contents"]
end

def test_get_ast_as_json_ast
ast_json = JSON.parse(@engine.get_ast_as_json).first

assert_equal ["imports", "package", "rego_v1", "rules"], ast_json["ast"].keys.sort
assert_equal 6, ast_json["ast"]["rules"].count

assert_equal "is_manager", ast_json.dig("ast", "rules", 0, "Spec", "head", "Compr", "refr", "Var", -1)
end

def alice_results
{
result: [
Expand Down

0 comments on commit 595cb2e

Please sign in to comment.