nasl 0.0.8 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/README.md +11 -16
  4. data/Rakefile +38 -0
  5. data/bin/nasl-parse +1 -1
  6. data/lib/nasl.rb +1 -1
  7. data/lib/nasl/cli.rb +1 -1
  8. data/lib/nasl/command.rb +1 -1
  9. data/lib/nasl/commands/benchmark.rb +1 -1
  10. data/lib/nasl/commands/parse.rb +1 -1
  11. data/lib/nasl/commands/test.rb +1 -1
  12. data/lib/nasl/commands/tokenize.rb +1 -1
  13. data/lib/nasl/commands/xml.rb +1 -1
  14. data/lib/nasl/context.rb +5 -5
  15. data/lib/nasl/grammar.racc +104 -16
  16. data/lib/nasl/parser.rb +1 -1
  17. data/lib/nasl/parser/argument.rb +1 -1
  18. data/lib/nasl/parser/array.rb +51 -0
  19. data/lib/nasl/parser/assigment.rb +1 -1
  20. data/lib/nasl/parser/block.rb +7 -1
  21. data/lib/nasl/parser/break.rb +2 -2
  22. data/lib/nasl/parser/call.rb +3 -2
  23. data/lib/nasl/parser/comment.rb +2 -2
  24. data/lib/nasl/parser/continue.rb +2 -2
  25. data/lib/nasl/parser/decrement.rb +1 -1
  26. data/lib/nasl/parser/empty.rb +2 -2
  27. data/lib/nasl/parser/export.rb +1 -1
  28. data/lib/nasl/parser/expression.rb +1 -1
  29. data/lib/nasl/parser/for.rb +2 -2
  30. data/lib/nasl/parser/foreach.rb +4 -4
  31. data/lib/nasl/parser/function.rb +1 -1
  32. data/lib/nasl/parser/global.rb +1 -1
  33. data/lib/nasl/parser/identifier.rb +7 -2
  34. data/lib/nasl/parser/if.rb +2 -2
  35. data/lib/nasl/parser/import.rb +1 -1
  36. data/lib/nasl/parser/include.rb +2 -2
  37. data/lib/nasl/parser/increment.rb +1 -1
  38. data/lib/nasl/parser/integer.rb +7 -2
  39. data/lib/nasl/parser/ip.rb +2 -2
  40. data/lib/nasl/parser/key_value_pair.rb +43 -0
  41. data/lib/nasl/parser/list.rb +41 -0
  42. data/lib/nasl/parser/local.rb +1 -1
  43. data/lib/nasl/parser/lvalue.rb +1 -1
  44. data/lib/nasl/parser/node.rb +2 -2
  45. data/lib/nasl/parser/parameter.rb +43 -0
  46. data/lib/nasl/parser/reference.rb +41 -0
  47. data/lib/nasl/parser/repeat.rb +1 -1
  48. data/lib/nasl/parser/repetition.rb +1 -1
  49. data/lib/nasl/parser/return.rb +2 -2
  50. data/lib/nasl/parser/string.rb +7 -2
  51. data/lib/nasl/parser/tree.rb +2 -2
  52. data/lib/nasl/parser/undefined.rb +2 -2
  53. data/lib/nasl/parser/while.rb +1 -1
  54. data/lib/nasl/test.rb +1 -1
  55. data/lib/nasl/token.rb +2 -2
  56. data/lib/nasl/tokenizer.rb +7 -4
  57. data/lib/nasl/version.rb +27 -1
  58. data/nasl.gemspec +35 -8
  59. data/test/unit/parser/test_array.rb +174 -0
  60. data/test/unit/parser/test_assignment.rb +75 -4
  61. data/test/unit/parser/test_blank.rb +1 -1
  62. data/test/unit/parser/test_block.rb +29 -1
  63. data/test/unit/parser/test_call.rb +57 -5
  64. data/test/unit/parser/test_comment.rb +1 -1
  65. data/test/unit/parser/test_constant.rb +1 -1
  66. data/test/unit/parser/test_empty.rb +1 -1
  67. data/test/unit/parser/test_expressions.rb +8 -1
  68. data/test/unit/parser/test_foreach.rb +43 -0
  69. data/test/unit/parser/test_function.rb +147 -51
  70. data/test/unit/parser/test_global.rb +49 -0
  71. data/test/unit/parser/test_if.rb +3 -3
  72. data/test/unit/parser/test_include.rb +1 -1
  73. data/test/unit/parser/test_incr_decr.rb +1 -1
  74. data/test/unit/parser/test_ip.rb +1 -1
  75. data/test/unit/parser/test_list.rb +42 -0
  76. data/test/unit/parser/test_local.rb +49 -0
  77. data/test/unit/parser/test_return.rb +7 -3
  78. data/test/unit/parser/test_string.rb +1 -1
  79. data/test/unit/parser/test_whitespace.rb +1 -1
  80. data/test/unit/test_context.rb +1 -1
  81. data/test/unit/tokenizer/test_comment.rb +1 -1
  82. data/test/unit/tokenizer/test_empty.rb +1 -1
  83. data/test/unit/tokenizer/test_integer.rb +1 -1
  84. data/test/unit/tokenizer/test_references.rb +41 -0
  85. data/test/unit/tokenizer/test_string.rb +2 -1
  86. metadata +49 -86
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011-2012, Mak Kolybabi
2
+ # Copyright (c) 2011-2014, Tenable Network Security
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -56,7 +56,14 @@ class TestAssignment < Test::Unit::TestCase
56
56
  def test_function
57
57
  same(
58
58
  "q = foo();",
59
- '<tree><assignment><op>=</op><lvalue><identifier name="q"/></lvalue><call><identifier name="foo"/></call></assignment></tree>'
59
+ '<tree><assignment><op>=</op><lvalue><identifier name="q"/></lvalue><call><lvalue><identifier name="foo"/></lvalue></call></assignment></tree>'
60
+ )
61
+ end
62
+
63
+ def test_reference
64
+ same(
65
+ "q = @foo;",
66
+ '<tree><assignment><op>=</op><lvalue><identifier name="q"/></lvalue><reference><identifier name="foo"/></reference></assignment></tree>'
60
67
  )
61
68
  end
62
69
 
@@ -101,11 +108,75 @@ class TestAssignment < Test::Unit::TestCase
101
108
  def test_conditional
102
109
  same(
103
110
  "if (q = foo());",
104
- '<tree><if><assignment><op>=</op><lvalue><identifier name="q"/></lvalue><call><identifier name="foo"/></call></assignment><empty/></if></tree>'
111
+ '<tree><if><assignment><op>=</op><lvalue><identifier name="q"/></lvalue><call><lvalue><identifier name="foo"/></lvalue></call></assignment><empty/></if></tree>'
105
112
  )
106
113
  same(
107
114
  "while (q = foo());",
108
- '<tree><while><assignment><op>=</op><lvalue><identifier name="q"/></lvalue><call><identifier name="foo"/></call></assignment><empty/></while></tree>'
115
+ '<tree><while><assignment><op>=</op><lvalue><identifier name="q"/></lvalue><call><lvalue><identifier name="foo"/></lvalue></call></assignment><empty/></while></tree>'
116
+ )
117
+ end
118
+
119
+ def test_list
120
+ same(
121
+ "q = [];",
122
+ '<tree><assignment><op>=</op><lvalue><identifier name="q"/></lvalue><list></list></assignment></tree>'
123
+ )
124
+
125
+ same(
126
+ "q = [[[]], [[]], [[]]];",
127
+ '<tree><assignment><op>=</op><lvalue><identifier name="q"/></lvalue><list><list><list></list></list><list><list></list></list><list><list></list></list></list></assignment></tree>'
128
+ )
129
+
130
+ same(
131
+ "q = [1];",
132
+ '<tree><assignment><op>=</op><lvalue><identifier name="q"/></lvalue><list><integer value="1"/></list></assignment></tree>'
133
+ )
134
+
135
+ same(
136
+ "q = [1, 'b', foo()];",
137
+ '<tree><assignment><op>=</op><lvalue><identifier name="q"/></lvalue><list><integer value="1"/><data>b</data><call><lvalue><identifier name="foo"/></lvalue></call></list></assignment></tree>'
138
+ )
139
+
140
+ same(
141
+ "foo(arg:[1]);",
142
+ '<tree><call><lvalue><identifier name="foo"/></lvalue><argument type="named"><identifier name="arg"/><list><integer value="1"/></list></argument></call></tree>'
143
+ )
144
+
145
+ same(
146
+ "q = [] + [];",
147
+ '<tree><assignment><op>=</op><lvalue><identifier name="q"/></lvalue><expression><op>+</op><list></list><list></list></expression></assignment></tree>'
148
+ )
149
+ end
150
+
151
+ def test_array
152
+ same(
153
+ "q = {};",
154
+ '<tree><assignment><op>=</op><lvalue><identifier name="q"/></lvalue><array></array></assignment></tree>'
155
+ )
156
+
157
+ same(
158
+ "q = {'a':{'b':{}}, 'c':{'d':{}}, 'e':{'f':{}}};",
159
+ '<tree><assignment><op>=</op><lvalue><identifier name="q"/></lvalue><array><key_value_pair><data>a</data><array><key_value_pair><data>b</data><array></array></key_value_pair></array></key_value_pair><key_value_pair><data>c</data><array><key_value_pair><data>d</data><array></array></key_value_pair></array></key_value_pair><key_value_pair><data>e</data><array><key_value_pair><data>f</data><array></array></key_value_pair></array></key_value_pair></array></assignment></tree>'
160
+ )
161
+
162
+ same(
163
+ 'q = {"a":1};',
164
+ '<tree><assignment><op>=</op><lvalue><identifier name="q"/></lvalue><array><key_value_pair><string>a</string><integer value="1"/></key_value_pair></array></assignment></tree>'
165
+ )
166
+
167
+ same(
168
+ "q = {1:1, 2:'b', 3:foo()};",
169
+ '<tree><assignment><op>=</op><lvalue><identifier name="q"/></lvalue><array><key_value_pair><integer value="1"/><integer value="1"/></key_value_pair><key_value_pair><integer value="2"/><data>b</data></key_value_pair><key_value_pair><integer value="3"/><call><lvalue><identifier name="foo"/></lvalue></call></key_value_pair></array></assignment></tree>'
170
+ )
171
+
172
+ same(
173
+ "foo(arg:{1:1});",
174
+ '<tree><call><lvalue><identifier name="foo"/></lvalue><argument type="named"><identifier name="arg"/><array><key_value_pair><integer value="1"/><integer value="1"/></key_value_pair></array></argument></call></tree>'
175
+ )
176
+
177
+ same(
178
+ "q = {} + {};",
179
+ '<tree><assignment><op>=</op><lvalue><identifier name="q"/></lvalue><expression><op>+</op><array></array><array></array></expression></assignment></tree>'
109
180
  )
110
181
  end
111
182
  end
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011-2012, Mak Kolybabi
2
+ # Copyright (c) 2011-2014, Tenable Network Security
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011-2012, Mak Kolybabi
2
+ # Copyright (c) 2011-2014, Tenable Network Security
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -27,6 +27,34 @@
27
27
  class TestBlock < Test::Unit::TestCase
28
28
  include Nasl::Test
29
29
 
30
+ def test_each
31
+ tree = parse(
32
+ <<-EOF
33
+ {
34
+ a = 1;
35
+ break;
36
+ fn();
37
+ ;
38
+ }
39
+ EOF
40
+ )
41
+ assert_not_nil(tree)
42
+
43
+ blks = tree.all(:Block)
44
+ assert_not_nil(blks)
45
+ assert_equal(1, blks.length)
46
+
47
+ clss = [:Assignment, :Break, :Call, :Empty]
48
+
49
+ i = 0
50
+ blks.first.each do |stmt|
51
+ assert_not_nil(stmt)
52
+ assert_equal(Nasl.const_get(clss[i]), stmt.class)
53
+
54
+ i += 1
55
+ end
56
+ end
57
+
30
58
  def test_empty
31
59
  same("{}", "<tree><block></block></tree>")
32
60
  same("{;}", "<tree><block><empty/></block></tree>")
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011-2012, Mak Kolybabi
2
+ # Copyright (c) 2011-2014, Tenable Network Security
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -27,8 +27,60 @@
27
27
  class TestCall < Test::Unit::TestCase
28
28
  include Nasl::Test
29
29
 
30
+ def test_keyword_prefix
31
+ # We never want to have a function with the same name as a keyword.
32
+ fail_parse("break();")
33
+ fail_parse("continue();")
34
+ fail_parse("else();")
35
+ fail_parse("export();")
36
+ fail_parse("for();")
37
+ fail_parse("foreach();")
38
+ fail_parse("function();")
39
+ fail_parse("global_var();")
40
+ fail_parse("if();")
41
+ fail_parse("import();")
42
+ fail_parse("include();")
43
+ fail_parse("local_var();")
44
+ fail_parse("repeat();")
45
+ fail_parse("return();")
46
+ fail_parse("until();")
47
+ fail_parse("while();")
48
+
49
+ # We never want to have a function with the same name as a constant.
50
+ fail_parse("FALSE();")
51
+ fail_parse("NULL();")
52
+ fail_parse("TRUE();")
53
+
54
+ # 'in' and 'x' are exceptions. They are valid function names, despite being a keywords.
55
+ pass("in();")
56
+ pass("x();")
57
+
58
+ # Having a keyword at the start of a function name is perfectly valid.
59
+ pass("break_();")
60
+ pass("continue_();")
61
+ pass("else_();")
62
+ pass("export_();")
63
+ pass("for_();")
64
+ pass("foreach_();")
65
+ pass("function_();")
66
+ pass("global_var_();")
67
+ pass("if_();")
68
+ pass("import_();")
69
+ pass("include_();")
70
+ pass("local_var_();")
71
+ pass("repeat_();")
72
+ pass("return_();")
73
+ pass("until_();")
74
+ pass("while_();")
75
+
76
+ # Having a constant at the start of a function name is perfectly valid.
77
+ pass("FALSE_();")
78
+ pass("NULL_();")
79
+ pass("TRUE_();")
80
+ end
81
+
30
82
  def test_no_args
31
- tree = parse("foo();")
83
+ tree = parse("foo[a][1]['b'][c+d].e.f.g();")
32
84
  assert_not_nil(tree)
33
85
 
34
86
  calls = tree.all(:Call)
@@ -41,7 +93,7 @@ class TestCall < Test::Unit::TestCase
41
93
  end
42
94
 
43
95
  def test_anonymous_args
44
- tree = parse("foo(1, '2', three);")
96
+ tree = parse("foo[a][1]['b'][c+d].e.f.g(1, '2', three);")
45
97
  assert_not_nil(tree)
46
98
 
47
99
  calls = tree.all(:Call)
@@ -66,7 +118,7 @@ class TestCall < Test::Unit::TestCase
66
118
  end
67
119
 
68
120
  def test_named_args
69
- tree = parse("foo(a:1, b:'2', c:three);")
121
+ tree = parse("foo[a][1]['b'][c+d].e.f.g(a:1, b:'2', c:three);")
70
122
  assert_not_nil(tree)
71
123
 
72
124
  calls = tree.all(:Call)
@@ -97,7 +149,7 @@ class TestCall < Test::Unit::TestCase
97
149
  end
98
150
 
99
151
  def test_mixed_args
100
- tree = parse("foo(a:1, '2', c:three, bar());")
152
+ tree = parse("foo[a][1]['b'][c+d].e.f.g(a:1, '2', c:three, bar());")
101
153
  assert_not_nil(tree)
102
154
 
103
155
  calls = tree.all(:Call)
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011-2012, Mak Kolybabi
2
+ # Copyright (c) 2011-2014, Tenable Network Security
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011-2012, Mak Kolybabi
2
+ # Copyright (c) 2011-2014, Tenable Network Security
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011-2012, Mak Kolybabi
2
+ # Copyright (c) 2011-2014, Tenable Network Security
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011-2012, Mak Kolybabi
2
+ # Copyright (c) 2011-2014, Tenable Network Security
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -46,6 +46,13 @@ class TestExpressions < Test::Unit::TestCase
46
46
 
47
47
  def test_bitwise
48
48
  pass("q = 0 | 1;")
49
+ pass("q = 0 & 1;")
50
+ end
51
+
52
+ def test_period
53
+ pass("q = a.b;")
54
+ pass("q = a._;")
55
+ fail_parse("q = a.1");
49
56
  end
50
57
 
51
58
  def test_precedence
@@ -0,0 +1,43 @@
1
+ ################################################################################
2
+ # Copyright (c) 2011-2014, Tenable Network Security
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # 1. Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+ ################################################################################
26
+
27
+ class TestForeach < Test::Unit::TestCase
28
+ include Nasl::Test
29
+
30
+ def test_old
31
+ same(
32
+ %q|foreach foo (bar);|,
33
+ '<tree><foreach><identifier name="foo"/><lvalue><identifier name="bar"/></lvalue><empty/></foreach></tree>'
34
+ )
35
+ end
36
+
37
+ def test_new
38
+ same(
39
+ %q|foreach (foo in bar);|,
40
+ '<tree><foreach><identifier name="foo"/><lvalue><identifier name="bar"/></lvalue><empty/></foreach></tree>'
41
+ )
42
+ end
43
+ end
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011-2012, Mak Kolybabi
2
+ # Copyright (c) 2011-2014, Tenable Network Security
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -28,55 +28,151 @@ class TestFunction < Test::Unit::TestCase
28
28
  include Nasl::Test
29
29
 
30
30
  def test_keyword_prefix
31
- # While we never want to have a function with the same name as a keyword,
32
- # having a keyword at the start of a function name is perfectly valid.
33
- fail_parse("if();")
34
- fail_parse("break();")
35
- fail_parse("continue();")
36
- fail_parse("else();")
37
- fail_parse("export();")
38
- fail_parse("for();")
39
- fail_parse("foreach();")
40
- fail_parse("function();")
41
- fail_parse("global_var();")
42
- fail_parse("if();")
43
- fail_parse("import();")
44
- fail_parse("include();")
45
- fail_parse("local_var();")
46
- fail_parse("repeat();")
47
- fail_parse("return();")
48
- fail_parse("until();")
49
- fail_parse("while();")
50
-
51
- # While we never want to have a function with the same name as a constant,
52
- # having a constant at the start of a function name is perfectly valid.
53
- fail_parse("FALSE();")
54
- fail_parse("NULL();")
55
- fail_parse("TRUE();")
56
-
57
- # X is an exception. It is a valid function name, despite being a keyword.
58
- pass("x();")
59
-
60
- pass("if_();")
61
- pass("break_();")
62
- pass("continue_();")
63
- pass("else_();")
64
- pass("export_();")
65
- pass("for_();")
66
- pass("foreach_();")
67
- pass("function_();")
68
- pass("global_var_();")
69
- pass("if_();")
70
- pass("import_();")
71
- pass("include_();")
72
- pass("local_var_();")
73
- pass("repeat_();")
74
- pass("return_();")
75
- pass("until_();")
76
- pass("while_();")
77
-
78
- pass("FALSE_();")
79
- pass("NULL_();")
80
- pass("TRUE_();")
31
+ # We never want to have a function with the same name as a keyword.
32
+ fail_parse("function break() {}")
33
+ fail_parse("function continue() {}")
34
+ fail_parse("function else() {}")
35
+ fail_parse("function export() {}")
36
+ fail_parse("function for() {}")
37
+ fail_parse("function foreach() {}")
38
+ fail_parse("function function() {}")
39
+ fail_parse("function global_var() {}")
40
+ fail_parse("function if() {}")
41
+ fail_parse("function import() {}")
42
+ fail_parse("function include() {}")
43
+ fail_parse("function local_var() {}")
44
+ fail_parse("function repeat() {}")
45
+ fail_parse("function return() {}")
46
+ fail_parse("function until() {}")
47
+ fail_parse("function while() {}")
48
+
49
+ # We never want to have a function with the same name as a constant.
50
+ fail_parse("function FALSE() {}")
51
+ fail_parse("function NULL() {}")
52
+ fail_parse("function TRUE() {}")
53
+
54
+ # 'in' and 'x' are exceptions. They are valid function names, despite being a keywords.
55
+ pass("function in() {}")
56
+ pass("function x() {}")
57
+
58
+ # Having a keyword at the start of a function name is perfectly valid.
59
+ pass("function break_() {}")
60
+ pass("function continue_() {}")
61
+ pass("function else_() {}")
62
+ pass("function export_() {}")
63
+ pass("function for_() {}")
64
+ pass("function foreach_() {}")
65
+ pass("function function_() {}")
66
+ pass("function global_var_() {}")
67
+ pass("function if_() {}")
68
+ pass("function import_() {}")
69
+ pass("function include_() {}")
70
+ pass("function local_var_() {}")
71
+ pass("function repeat_() {}")
72
+ pass("function return_() {}")
73
+ pass("function until_() {}")
74
+ pass("function while_() {}")
75
+
76
+ # Having a constant at the start of a function name is perfectly valid.
77
+ pass("function FALSE_() {}")
78
+ pass("function NULL_() {}")
79
+ pass("function TRUE_() {}")
80
+ end
81
+
82
+ def test_no_args
83
+ tree = parse("function foo() {}")
84
+ assert_not_nil(tree)
85
+
86
+ funcs = tree.all(:Function)
87
+ assert_not_nil(funcs)
88
+ assert_equal(1, funcs.length)
89
+
90
+ func = funcs.first
91
+ assert_not_nil(func)
92
+ assert_equal(0, func.params.length)
93
+ end
94
+
95
+ def test_named_args
96
+ tree = parse("function foo(a, b, c) {}")
97
+ assert_not_nil(tree)
98
+
99
+ funcs = tree.all(:Function)
100
+ assert_not_nil(funcs)
101
+ assert_equal(1, funcs.length)
102
+
103
+ func = funcs.first
104
+ assert_not_nil(func)
105
+ assert_equal(3, func.params.length)
106
+
107
+ param = func.params[0]
108
+ assert(param.is_a? Nasl::Parameter)
109
+ assert_equal(param.name.name, 'a')
110
+ assert_equal(param.pass_by, 'value')
111
+
112
+ param = func.params[1]
113
+ assert(param.is_a? Nasl::Parameter)
114
+ assert_equal(param.name.name, 'b')
115
+ assert_equal(param.pass_by, 'value')
116
+
117
+ param = func.params[2]
118
+ assert(param.is_a? Nasl::Parameter)
119
+ assert_equal(param.name.name, 'c')
120
+ assert_equal(param.pass_by, 'value')
121
+ end
122
+
123
+ def test_reference_args
124
+ tree = parse("function foo(&a, &b, &c) {}")
125
+ assert_not_nil(tree)
126
+
127
+ funcs = tree.all(:Function)
128
+ assert_not_nil(funcs)
129
+ assert_equal(1, funcs.length)
130
+
131
+ func = funcs.first
132
+ assert_not_nil(func)
133
+ assert_equal(3, func.params.length)
134
+
135
+ param = func.params[0]
136
+ assert(param.is_a? Nasl::Parameter)
137
+ assert_equal(param.name.name, 'a')
138
+ assert_equal(param.pass_by, 'reference')
139
+
140
+ param = func.params[1]
141
+ assert(param.is_a? Nasl::Parameter)
142
+ assert_equal(param.name.name, 'b')
143
+ assert_equal(param.pass_by, 'reference')
144
+
145
+ param = func.params[2]
146
+ assert(param.is_a? Nasl::Parameter)
147
+ assert_equal(param.name.name, 'c')
148
+ assert_equal(param.pass_by, 'reference')
149
+ end
150
+
151
+ def test_mixed_args
152
+ tree = parse("function foo(a, &b, c) {}")
153
+ assert_not_nil(tree)
154
+
155
+ funcs = tree.all(:Function)
156
+ assert_not_nil(funcs)
157
+ assert_equal(1, funcs.length)
158
+
159
+ func = funcs.first
160
+ assert_not_nil(func)
161
+ assert_equal(3, func.params.length)
162
+
163
+ param = func.params[0]
164
+ assert(param.is_a? Nasl::Parameter)
165
+ assert_equal(param.name.name, 'a')
166
+ assert_equal(param.pass_by, 'value')
167
+
168
+ param = func.params[1]
169
+ assert(param.is_a? Nasl::Parameter)
170
+ assert_equal(param.name.name, 'b')
171
+ assert_equal(param.pass_by, 'reference')
172
+
173
+ param = func.params[2]
174
+ assert(param.is_a? Nasl::Parameter)
175
+ assert_equal(param.name.name, 'c')
176
+ assert_equal(param.pass_by, 'value')
81
177
  end
82
178
  end