From fbc1c5e8c0902fbfea7da19e2293cd084b07c315 Mon Sep 17 00:00:00 2001 From: Nick Rolfe Date: Fri, 29 Jan 2021 16:31:22 +0000 Subject: [PATCH] Add test for Module --- .../ast/modules/modules.expected | 43 ++++++++++++++ ql/test/library-tests/ast/modules/modules.ql | 17 ++++++ ql/test/library-tests/ast/modules/modules.rb | 57 +++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 ql/test/library-tests/ast/modules/modules.expected create mode 100644 ql/test/library-tests/ast/modules/modules.ql create mode 100644 ql/test/library-tests/ast/modules/modules.rb diff --git a/ql/test/library-tests/ast/modules/modules.expected b/ql/test/library-tests/ast/modules/modules.expected new file mode 100644 index 00000000000..af9eeb84b3f --- /dev/null +++ b/ql/test/library-tests/ast/modules/modules.expected @@ -0,0 +1,43 @@ +modules +| modules.rb:1:1:2:3 | Empty | Module | Empty | +| modules.rb:4:1:24:3 | Foo | Module | Foo | +| modules.rb:5:3:14:5 | Bar | Module | Bar | +| modules.rb:26:1:35:3 | Foo | Module | Foo | +| modules.rb:37:1:46:3 | Bar | Module | Bar | +| modules.rb:48:1:57:3 | Bar | Module | Bar | +modulesWithScopeResolutionNames +| modules.rb:48:1:57:3 | Bar | modules.rb:48:8:48:15 | ...::Bar | +exprsInModules +| modules.rb:4:1:24:3 | Foo | 0 | modules.rb:5:3:14:5 | Bar | Module | +| modules.rb:4:1:24:3 | Foo | 1 | modules.rb:16:3:17:5 | method_in_foo | Method | +| modules.rb:4:1:24:3 | Foo | 2 | modules.rb:19:3:20:5 | ClassInFoo | Class | +| modules.rb:4:1:24:3 | Foo | 3 | modules.rb:22:3:22:19 | call to puts | Call | +| modules.rb:4:1:24:3 | Foo | 4 | modules.rb:23:3:23:17 | ... = ... | AssignExpr | +| modules.rb:5:3:14:5 | Bar | 0 | modules.rb:6:5:7:7 | ClassInFooBar | Class | +| modules.rb:5:3:14:5 | Bar | 1 | modules.rb:9:5:10:7 | method_in_foo_bar | Method | +| modules.rb:5:3:14:5 | Bar | 2 | modules.rb:12:5:12:26 | call to puts | Call | +| modules.rb:5:3:14:5 | Bar | 3 | modules.rb:13:5:13:19 | ... = ... | AssignExpr | +| modules.rb:26:1:35:3 | Foo | 0 | modules.rb:27:3:28:5 | method_in_another_definition_of_foo | Method | +| modules.rb:26:1:35:3 | Foo | 1 | modules.rb:30:3:31:5 | ClassInAnotherDefinitionOfFoo | Class | +| modules.rb:26:1:35:3 | Foo | 2 | modules.rb:33:3:33:25 | call to puts | Call | +| modules.rb:26:1:35:3 | Foo | 3 | modules.rb:34:3:34:17 | ... = ... | AssignExpr | +| modules.rb:37:1:46:3 | Bar | 0 | modules.rb:38:3:39:5 | method_a | Method | +| modules.rb:37:1:46:3 | Bar | 1 | modules.rb:41:3:42:5 | method_b | Method | +| modules.rb:37:1:46:3 | Bar | 2 | modules.rb:44:3:44:19 | call to puts | Call | +| modules.rb:37:1:46:3 | Bar | 3 | modules.rb:45:3:45:17 | ... = ... | AssignExpr | +| modules.rb:48:1:57:3 | Bar | 0 | modules.rb:49:3:50:5 | ClassInAnotherDefinitionOfFooBar | Class | +| modules.rb:48:1:57:3 | Bar | 1 | modules.rb:52:3:53:5 | method_in_another_definition_of_foo_bar | Method | +| modules.rb:48:1:57:3 | Bar | 2 | modules.rb:55:3:55:30 | call to puts | Call | +| modules.rb:48:1:57:3 | Bar | 3 | modules.rb:56:3:56:17 | ... = ... | AssignExpr | +methodsInModules +| modules.rb:4:1:24:3 | Foo | modules.rb:16:3:17:5 | method_in_foo | +| modules.rb:5:3:14:5 | Bar | modules.rb:9:5:10:7 | method_in_foo_bar | +| modules.rb:26:1:35:3 | Foo | modules.rb:27:3:28:5 | method_in_another_definition_of_foo | +| modules.rb:37:1:46:3 | Bar | modules.rb:38:3:39:5 | method_a | +| modules.rb:37:1:46:3 | Bar | modules.rb:41:3:42:5 | method_b | +| modules.rb:48:1:57:3 | Bar | modules.rb:52:3:53:5 | method_in_another_definition_of_foo_bar | +classesInModules +| modules.rb:4:1:24:3 | Foo | modules.rb:19:3:20:5 | ClassInFoo | +| modules.rb:5:3:14:5 | Bar | modules.rb:6:5:7:7 | ClassInFooBar | +| modules.rb:26:1:35:3 | Foo | modules.rb:30:3:31:5 | ClassInAnotherDefinitionOfFoo | +| modules.rb:48:1:57:3 | Bar | modules.rb:49:3:50:5 | ClassInAnotherDefinitionOfFooBar | diff --git a/ql/test/library-tests/ast/modules/modules.ql b/ql/test/library-tests/ast/modules/modules.ql new file mode 100644 index 00000000000..900a6d68e6c --- /dev/null +++ b/ql/test/library-tests/ast/modules/modules.ql @@ -0,0 +1,17 @@ +import ruby + +query predicate modules(Module m, string pClass, string name) { + pClass = m.getAPrimaryQlClass() and name = m.getName() +} + +query predicate modulesWithScopeResolutionNames(Module m, ScopeResolution name) { + name = m.getNameScopeResolution() +} + +query predicate exprsInModules(Module m, int i, Expr e, string eClass) { + e = m.getExpr(i) and eClass = e.getAPrimaryQlClass() +} + +query predicate methodsInModules(Module mod, Method method) { method = mod.getAMethod() } + +query predicate classesInModules(Module m, Class c) { c = m.getAClass() } diff --git a/ql/test/library-tests/ast/modules/modules.rb b/ql/test/library-tests/ast/modules/modules.rb new file mode 100644 index 00000000000..f34ddcec27a --- /dev/null +++ b/ql/test/library-tests/ast/modules/modules.rb @@ -0,0 +1,57 @@ +module Empty +end + +module Foo + module Bar + class ClassInFooBar + end + + def method_in_foo_bar + end + + puts 'module Foo::Bar' + $global_var = 0 + end + + def method_in_foo + end + + class ClassInFoo + end + + puts 'module Foo' + $global_var = 1 +end + +module Foo + def method_in_another_definition_of_foo + end + + class ClassInAnotherDefinitionOfFoo + end + + puts 'module Foo again' + $global_var = 2 +end + +module Bar + def method_a + end + + def method_b + end + + puts 'module Bar' + $global_var = 3 +end + +module Foo::Bar + class ClassInAnotherDefinitionOfFooBar + end + + def method_in_another_definition_of_foo_bar + end + + puts 'module Foo::Bar again' + $global_var = 4 +end \ No newline at end of file