nasl 0.0.8 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/README.md +11 -16
- data/Rakefile +38 -0
- data/bin/nasl-parse +1 -1
- data/lib/nasl.rb +1 -1
- data/lib/nasl/cli.rb +1 -1
- data/lib/nasl/command.rb +1 -1
- data/lib/nasl/commands/benchmark.rb +1 -1
- data/lib/nasl/commands/parse.rb +1 -1
- data/lib/nasl/commands/test.rb +1 -1
- data/lib/nasl/commands/tokenize.rb +1 -1
- data/lib/nasl/commands/xml.rb +1 -1
- data/lib/nasl/context.rb +5 -5
- data/lib/nasl/grammar.racc +104 -16
- data/lib/nasl/parser.rb +1 -1
- data/lib/nasl/parser/argument.rb +1 -1
- data/lib/nasl/parser/array.rb +51 -0
- data/lib/nasl/parser/assigment.rb +1 -1
- data/lib/nasl/parser/block.rb +7 -1
- data/lib/nasl/parser/break.rb +2 -2
- data/lib/nasl/parser/call.rb +3 -2
- data/lib/nasl/parser/comment.rb +2 -2
- data/lib/nasl/parser/continue.rb +2 -2
- data/lib/nasl/parser/decrement.rb +1 -1
- data/lib/nasl/parser/empty.rb +2 -2
- data/lib/nasl/parser/export.rb +1 -1
- data/lib/nasl/parser/expression.rb +1 -1
- data/lib/nasl/parser/for.rb +2 -2
- data/lib/nasl/parser/foreach.rb +4 -4
- data/lib/nasl/parser/function.rb +1 -1
- data/lib/nasl/parser/global.rb +1 -1
- data/lib/nasl/parser/identifier.rb +7 -2
- data/lib/nasl/parser/if.rb +2 -2
- data/lib/nasl/parser/import.rb +1 -1
- data/lib/nasl/parser/include.rb +2 -2
- data/lib/nasl/parser/increment.rb +1 -1
- data/lib/nasl/parser/integer.rb +7 -2
- data/lib/nasl/parser/ip.rb +2 -2
- data/lib/nasl/parser/key_value_pair.rb +43 -0
- data/lib/nasl/parser/list.rb +41 -0
- data/lib/nasl/parser/local.rb +1 -1
- data/lib/nasl/parser/lvalue.rb +1 -1
- data/lib/nasl/parser/node.rb +2 -2
- data/lib/nasl/parser/parameter.rb +43 -0
- data/lib/nasl/parser/reference.rb +41 -0
- data/lib/nasl/parser/repeat.rb +1 -1
- data/lib/nasl/parser/repetition.rb +1 -1
- data/lib/nasl/parser/return.rb +2 -2
- data/lib/nasl/parser/string.rb +7 -2
- data/lib/nasl/parser/tree.rb +2 -2
- data/lib/nasl/parser/undefined.rb +2 -2
- data/lib/nasl/parser/while.rb +1 -1
- data/lib/nasl/test.rb +1 -1
- data/lib/nasl/token.rb +2 -2
- data/lib/nasl/tokenizer.rb +7 -4
- data/lib/nasl/version.rb +27 -1
- data/nasl.gemspec +35 -8
- data/test/unit/parser/test_array.rb +174 -0
- data/test/unit/parser/test_assignment.rb +75 -4
- data/test/unit/parser/test_blank.rb +1 -1
- data/test/unit/parser/test_block.rb +29 -1
- data/test/unit/parser/test_call.rb +57 -5
- data/test/unit/parser/test_comment.rb +1 -1
- data/test/unit/parser/test_constant.rb +1 -1
- data/test/unit/parser/test_empty.rb +1 -1
- data/test/unit/parser/test_expressions.rb +8 -1
- data/test/unit/parser/test_foreach.rb +43 -0
- data/test/unit/parser/test_function.rb +147 -51
- data/test/unit/parser/test_global.rb +49 -0
- data/test/unit/parser/test_if.rb +3 -3
- data/test/unit/parser/test_include.rb +1 -1
- data/test/unit/parser/test_incr_decr.rb +1 -1
- data/test/unit/parser/test_ip.rb +1 -1
- data/test/unit/parser/test_list.rb +42 -0
- data/test/unit/parser/test_local.rb +49 -0
- data/test/unit/parser/test_return.rb +7 -3
- data/test/unit/parser/test_string.rb +1 -1
- data/test/unit/parser/test_whitespace.rb +1 -1
- data/test/unit/test_context.rb +1 -1
- data/test/unit/tokenizer/test_comment.rb +1 -1
- data/test/unit/tokenizer/test_empty.rb +1 -1
- data/test/unit/tokenizer/test_integer.rb +1 -1
- data/test/unit/tokenizer/test_references.rb +41 -0
- data/test/unit/tokenizer/test_string.rb +2 -1
- metadata +49 -86
@@ -0,0 +1,41 @@
|
|
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
|
+
require 'nasl/parser/node'
|
28
|
+
|
29
|
+
module Nasl
|
30
|
+
class Reference < Node
|
31
|
+
attr_reader :name
|
32
|
+
|
33
|
+
def initialize(tree, *tokens)
|
34
|
+
super
|
35
|
+
|
36
|
+
@name = @tokens[0]
|
37
|
+
|
38
|
+
@children << :name
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/nasl/parser/repeat.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
################################################################################
|
2
|
-
# Copyright (c) 2011-
|
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-
|
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
|
data/lib/nasl/parser/return.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
################################################################################
|
2
|
-
# Copyright (c) 2011-
|
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
|
@@ -22,7 +22,7 @@
|
|
22
22
|
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
23
23
|
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
24
24
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
-
|
25
|
+
###############################################################################
|
26
26
|
|
27
27
|
require 'nasl/parser/node'
|
28
28
|
|
data/lib/nasl/parser/string.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
# Copyright (c) 2011-
|
1
|
+
################################################################################
|
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,6 +28,7 @@ require 'nasl/parser/node'
|
|
28
28
|
|
29
29
|
module Nasl
|
30
30
|
class String < Node
|
31
|
+
include Comparable
|
31
32
|
attr_reader :text, :type
|
32
33
|
|
33
34
|
def initialize(tree, *tokens)
|
@@ -37,6 +38,10 @@ module Nasl
|
|
37
38
|
@type = @tokens.first.type
|
38
39
|
end
|
39
40
|
|
41
|
+
def <=>(other)
|
42
|
+
self.text <=> other.text
|
43
|
+
end
|
44
|
+
|
40
45
|
def to_xml(xml)
|
41
46
|
xml.method_missing(@type.downcase, @text)
|
42
47
|
end
|
data/lib/nasl/parser/tree.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
################################################################################
|
2
|
-
# Copyright (c) 2011-
|
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,7 +27,7 @@
|
|
27
27
|
require 'builder'
|
28
28
|
|
29
29
|
module Nasl
|
30
|
-
class Tree < Array
|
30
|
+
class Tree < ::Array
|
31
31
|
def all(cls)
|
32
32
|
(@all[Nasl.const_get(cls).to_s] ||= [])
|
33
33
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
# Copyright (c) 2011-
|
1
|
+
################################################################################
|
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
|
data/lib/nasl/parser/while.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
################################################################################
|
2
|
-
# Copyright (c) 2011-
|
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
|
data/lib/nasl/test.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
################################################################################
|
2
|
-
# Copyright (c) 2011-
|
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
|
data/lib/nasl/token.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
# Copyright (c) 2011-
|
1
|
+
################################################################################
|
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
|
data/lib/nasl/tokenizer.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
# Copyright (c) 2011-
|
1
|
+
################################################################################
|
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
|
@@ -42,6 +42,7 @@ module Nasl
|
|
42
42
|
'global_var' => :GLOBAL,
|
43
43
|
'if' => :IF,
|
44
44
|
'import' => :IMPORT,
|
45
|
+
'in' => :IN,
|
45
46
|
'include' => :INCLUDE,
|
46
47
|
'local_var' => :LOCAL,
|
47
48
|
'repeat' => :REPEAT,
|
@@ -83,7 +84,6 @@ module Nasl
|
|
83
84
|
|
84
85
|
["|", :BIT_OR],
|
85
86
|
["^", :BIT_XOR],
|
86
|
-
["&", :BIT_AND],
|
87
87
|
[">>>", :BIT_SRA],
|
88
88
|
[">>", :BIT_SRL],
|
89
89
|
["<<", :BIT_SLL],
|
@@ -113,7 +113,10 @@ module Nasl
|
|
113
113
|
["[", :LBRACK],
|
114
114
|
["]", :RBRACK],
|
115
115
|
["{", :LBRACE],
|
116
|
-
["}", :RBRACE]
|
116
|
+
["}", :RBRACE],
|
117
|
+
|
118
|
+
["&", :AMPERSAND],
|
119
|
+
["@", :AT_SIGN]
|
117
120
|
]
|
118
121
|
|
119
122
|
@@annotated = [
|
data/lib/nasl/version.rb
CHANGED
@@ -1,3 +1,29 @@
|
|
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
|
+
|
1
27
|
module Nasl
|
2
|
-
VERSION = '0.
|
28
|
+
VERSION = '0.1.1'
|
3
29
|
end
|
data/nasl.gemspec
CHANGED
@@ -1,4 +1,31 @@
|
|
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
|
+
|
1
27
|
# -*- encoding: utf-8 -*-
|
28
|
+
|
2
29
|
$:.push File.expand_path('../lib', __FILE__)
|
3
30
|
|
4
31
|
require 'nasl/version'
|
@@ -8,11 +35,11 @@ Gem::Specification.new do |s|
|
|
8
35
|
s.version = Nasl::VERSION
|
9
36
|
s.license = 'BSD'
|
10
37
|
s.homepage = 'http://github.com/tenable/nasl'
|
11
|
-
s.summary = 'A parser for the Nessus Attack Scripting Language.'
|
12
|
-
s.description =
|
38
|
+
s.summary = 'A language parser for the Nessus Attack Scripting Language.'
|
39
|
+
s.description = 'A language parser for the Nessus Attack Scripting Language. Supporting NASL v5.2.'
|
13
40
|
|
14
|
-
s.authors = ['Mak Kolybabi']
|
15
|
-
s.email = ['mak@kolybabi.com']
|
41
|
+
s.authors = ['Mak Kolybabi', 'Alex Weber', 'Jacob Hammack']
|
42
|
+
s.email = ['mak@kolybabi.com', 'aweber@tenble.com', 'jhammack@tenable.com']
|
16
43
|
|
17
44
|
s.rubyforge_project = 'nasl'
|
18
45
|
|
@@ -21,9 +48,9 @@ Gem::Specification.new do |s|
|
|
21
48
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
49
|
s.require_paths = ['lib']
|
23
50
|
|
24
|
-
s.add_development_dependency 'racc'
|
25
|
-
s.add_development_dependency 'rake'
|
51
|
+
s.add_development_dependency 'racc', '~>1.4'
|
52
|
+
s.add_development_dependency 'rake', '~>10.1'
|
26
53
|
|
27
|
-
s.add_runtime_dependency 'builder', '
|
28
|
-
s.add_runtime_dependency 'rainbow'
|
54
|
+
s.add_runtime_dependency 'builder', '~> 3.1'
|
55
|
+
s.add_runtime_dependency 'rainbow', '~> 2.0'
|
29
56
|
end
|
@@ -0,0 +1,174 @@
|
|
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 TestArray < Test::Unit::TestCase
|
28
|
+
include Nasl::Test
|
29
|
+
|
30
|
+
def test_empty
|
31
|
+
tree = parse("foo = {};")
|
32
|
+
assert_not_nil(tree)
|
33
|
+
|
34
|
+
arrays = tree.all(:Array)
|
35
|
+
assert_not_nil(arrays)
|
36
|
+
assert_equal(1, arrays.length)
|
37
|
+
|
38
|
+
array = arrays.first
|
39
|
+
assert_not_nil(array)
|
40
|
+
assert_equal(0, array.pairs.length)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_integers
|
44
|
+
tree = parse("foo = {1:02, 3:4, 5:0x6};")
|
45
|
+
assert_not_nil(tree)
|
46
|
+
|
47
|
+
arrays = tree.all(:Array)
|
48
|
+
assert_not_nil(arrays)
|
49
|
+
assert_equal(1, arrays.length)
|
50
|
+
|
51
|
+
array = arrays.first
|
52
|
+
assert_not_nil(array)
|
53
|
+
assert_equal(3, array.pairs.length)
|
54
|
+
|
55
|
+
assert_equal(1, array.pairs[0].key.value)
|
56
|
+
assert_equal(array.keys[1], array.pairs[0].value)
|
57
|
+
pair = array.pairs[0]
|
58
|
+
assert(pair.key.is_a? Nasl::Integer)
|
59
|
+
assert(pair.value.is_a? Nasl::Integer)
|
60
|
+
assert_equal(2, pair.value.value)
|
61
|
+
|
62
|
+
assert_equal(3, array.pairs[1].key.value)
|
63
|
+
assert_equal(array.keys[3], array.pairs[1].value)
|
64
|
+
pair = array.pairs[1]
|
65
|
+
assert(pair.key.is_a? Nasl::Integer)
|
66
|
+
assert(pair.value.is_a? Nasl::Integer)
|
67
|
+
assert_equal(4, pair.value.value)
|
68
|
+
|
69
|
+
assert_equal(5, array.pairs[2].key.value)
|
70
|
+
assert_equal(array.keys[5], array.pairs[2].value)
|
71
|
+
pair = array.pairs[2]
|
72
|
+
assert(pair.key.is_a? Nasl::Integer)
|
73
|
+
assert(pair.value.is_a? Nasl::Integer)
|
74
|
+
assert_equal(6, pair.value.value)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_string
|
78
|
+
tree = parse(%q|foo = {'a':"b", "c":'d'};|)
|
79
|
+
assert_not_nil(tree)
|
80
|
+
|
81
|
+
arrays = tree.all(:Array)
|
82
|
+
assert_not_nil(arrays)
|
83
|
+
assert_equal(1, arrays.length)
|
84
|
+
|
85
|
+
array = arrays.first
|
86
|
+
assert_not_nil(array)
|
87
|
+
assert_equal(2, array.pairs.length)
|
88
|
+
|
89
|
+
pair = array.pairs[0]
|
90
|
+
assert(pair.key.is_a? Nasl::String)
|
91
|
+
assert_equal(:DATA, pair.key.type)
|
92
|
+
assert_equal('a', pair.key.text)
|
93
|
+
assert(pair.value.is_a? Nasl::String)
|
94
|
+
assert_equal(:STRING, pair.value.type)
|
95
|
+
assert_equal('b', pair.value.text)
|
96
|
+
assert_equal(pair.value, array.keys['a'])
|
97
|
+
|
98
|
+
pair = array.pairs[1]
|
99
|
+
assert(pair.key.is_a? Nasl::String)
|
100
|
+
assert_equal(:STRING, pair.key.type)
|
101
|
+
assert_equal('c', pair.key.text)
|
102
|
+
assert(pair.value.is_a? Nasl::String)
|
103
|
+
assert_equal(:DATA, pair.value.type)
|
104
|
+
assert_equal('d', pair.value.text)
|
105
|
+
assert_equal(pair.value, array.keys['c'])
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_mixed
|
109
|
+
tree = parse(%q|foo = {'a':1, 2:"b"};|)
|
110
|
+
assert_not_nil(tree)
|
111
|
+
|
112
|
+
arrays = tree.all(:Array)
|
113
|
+
assert_not_nil(arrays)
|
114
|
+
assert_equal(1, arrays.length)
|
115
|
+
|
116
|
+
array = arrays.first
|
117
|
+
assert_not_nil(array)
|
118
|
+
assert_equal(2, array.pairs.length)
|
119
|
+
|
120
|
+
pair = array.pairs[0]
|
121
|
+
assert(pair.key.is_a? Nasl::String)
|
122
|
+
assert_equal(:DATA, pair.key.type)
|
123
|
+
assert_equal('a', pair.key.text)
|
124
|
+
assert(pair.value.is_a? Nasl::Integer)
|
125
|
+
assert_equal(1, pair.value.value)
|
126
|
+
assert_equal(pair.value, array.keys['a'])
|
127
|
+
|
128
|
+
pair = array.pairs[1]
|
129
|
+
assert(pair.key.is_a? Nasl::Integer)
|
130
|
+
assert_equal(2, pair.key.value)
|
131
|
+
assert(pair.value.is_a? Nasl::String)
|
132
|
+
assert_equal(:STRING, pair.value.type)
|
133
|
+
assert_equal('b', pair.value.text)
|
134
|
+
assert_equal(pair.value, array.keys[2])
|
135
|
+
end
|
136
|
+
|
137
|
+
# A single trailing comma in an array literal is valid, but multiple is not.
|
138
|
+
def test_single_trailing_comma
|
139
|
+
tree = parse(%q|foo = {'a':1, 2:"b",};|)
|
140
|
+
assert_not_nil(tree)
|
141
|
+
|
142
|
+
arrays = tree.all(:Array)
|
143
|
+
assert_not_nil(arrays)
|
144
|
+
assert_equal(1, arrays.length)
|
145
|
+
|
146
|
+
array = arrays.first
|
147
|
+
assert_not_nil(array)
|
148
|
+
assert_equal(2, array.pairs.length)
|
149
|
+
|
150
|
+
pair = array.pairs[0]
|
151
|
+
assert(pair.key.is_a? Nasl::String)
|
152
|
+
assert_equal(:DATA, pair.key.type)
|
153
|
+
assert_equal('a', pair.key.text)
|
154
|
+
assert(pair.value.is_a? Nasl::Integer)
|
155
|
+
assert_equal(1, pair.value.value)
|
156
|
+
assert_equal(pair.value, array.keys['a'])
|
157
|
+
|
158
|
+
pair = array.pairs[1]
|
159
|
+
assert(pair.key.is_a? Nasl::Integer)
|
160
|
+
assert_equal(2, pair.key.value)
|
161
|
+
assert(pair.value.is_a? Nasl::String)
|
162
|
+
assert_equal(:STRING, pair.value.type)
|
163
|
+
assert_equal('b', pair.value.text)
|
164
|
+
assert_equal(pair.value, array.keys[2])
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_multiple_trailing_comma
|
168
|
+
fail_parse(%q|foo = {'a':1, 2:"b",,};|)
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_empty_array_with_comma
|
172
|
+
fail_parse(%q|return {,};|)
|
173
|
+
end
|
174
|
+
end
|