nasl 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/nasl/parser/call.rb +1 -1
- data/lib/nasl/test.rb +9 -17
- data/lib/nasl/version.rb +1 -1
- data/nasl.gemspec +0 -1
- data/test/unit/parser/test_call.rb +131 -0
- metadata +10 -9
data/lib/nasl/parser/call.rb
CHANGED
data/lib/nasl/test.rb
CHANGED
@@ -44,15 +44,7 @@ module Nasl
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def parse(code)
|
47
|
-
|
48
|
-
tree = Nasl::Parser.new.parse(code)
|
49
|
-
msg = ''
|
50
|
-
rescue Racc::ParseError => e
|
51
|
-
tree = nil
|
52
|
-
msg = e
|
53
|
-
end
|
54
|
-
|
55
|
-
return tree, msg
|
47
|
+
Nasl::Parser.new.parse(code, "(test)")
|
56
48
|
end
|
57
49
|
|
58
50
|
def tokenize(code)
|
@@ -64,9 +56,9 @@ module Nasl
|
|
64
56
|
end
|
65
57
|
|
66
58
|
def fail(code)
|
67
|
-
tree
|
59
|
+
tree = parse(code)
|
68
60
|
|
69
|
-
assert_nil(tree
|
61
|
+
assert_nil(tree)
|
70
62
|
end
|
71
63
|
|
72
64
|
def fail_parse(code)
|
@@ -78,20 +70,20 @@ module Nasl
|
|
78
70
|
end
|
79
71
|
|
80
72
|
def pass(code)
|
81
|
-
tree
|
73
|
+
tree = parse(code)
|
82
74
|
|
83
|
-
assert_not_nil(tree
|
75
|
+
assert_not_nil(tree)
|
84
76
|
end
|
85
77
|
|
86
78
|
def diff(code, kg_tree)
|
87
|
-
tree
|
88
|
-
assert_not_nil(tree
|
79
|
+
tree = parse(code)
|
80
|
+
assert_not_nil(tree)
|
89
81
|
assert_not_equal(flatten(kg_tree), flatten(tree.to_s)) if !tree.nil?
|
90
82
|
end
|
91
83
|
|
92
84
|
def same(code, kg_tree)
|
93
|
-
tree
|
94
|
-
assert_not_nil(tree
|
85
|
+
tree = parse(code)
|
86
|
+
assert_not_nil(tree)
|
95
87
|
assert_equal(flatten(kg_tree), flatten(tree.to_s)) if !tree.nil?
|
96
88
|
end
|
97
89
|
end
|
data/lib/nasl/version.rb
CHANGED
data/nasl.gemspec
CHANGED
@@ -13,7 +13,6 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.rubyforge_project = 'nasl'
|
14
14
|
|
15
15
|
s.files = `git ls-files`.split("\n") + ['lib/nasl/grammar.tab.rb']
|
16
|
-
|
17
16
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
17
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
18
|
s.require_paths = ['lib']
|
@@ -0,0 +1,131 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright (c) 2011, Mak Kolybabi
|
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 TestCall < Test::Unit::TestCase
|
28
|
+
include Nasl::Test
|
29
|
+
|
30
|
+
def test_no_args
|
31
|
+
tree = parse("foo();")
|
32
|
+
assert_not_nil(tree)
|
33
|
+
|
34
|
+
calls = tree.all(:Call)
|
35
|
+
assert_not_nil(calls)
|
36
|
+
assert_equal(1, calls.length)
|
37
|
+
|
38
|
+
call = calls.first
|
39
|
+
assert_not_nil(call)
|
40
|
+
assert_equal(0, call.args.length)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_anonymous_args
|
44
|
+
tree = parse("foo(1, '2', three);")
|
45
|
+
assert_not_nil(tree)
|
46
|
+
|
47
|
+
calls = tree.all(:Call)
|
48
|
+
assert_not_nil(calls)
|
49
|
+
assert_equal(1, calls.length)
|
50
|
+
|
51
|
+
call = calls.first
|
52
|
+
assert_not_nil(call)
|
53
|
+
assert_equal(3, call.args.length)
|
54
|
+
|
55
|
+
arg = call.args[0]
|
56
|
+
assert_equal(:anonymous, arg.type)
|
57
|
+
assert(arg.expr.is_a? Nasl::Integer)
|
58
|
+
|
59
|
+
arg = call.args[1]
|
60
|
+
assert_equal(:anonymous, arg.type)
|
61
|
+
assert(arg.expr.is_a? Nasl::String)
|
62
|
+
|
63
|
+
arg = call.args[2]
|
64
|
+
assert_equal(:anonymous, arg.type)
|
65
|
+
assert(arg.expr.is_a? Nasl::Lvalue)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_named_args
|
69
|
+
tree = parse("foo(a:1, b:'2', c:three);")
|
70
|
+
assert_not_nil(tree)
|
71
|
+
|
72
|
+
calls = tree.all(:Call)
|
73
|
+
assert_not_nil(calls)
|
74
|
+
assert_equal(1, calls.length)
|
75
|
+
|
76
|
+
call = calls.first
|
77
|
+
assert_not_nil(call)
|
78
|
+
assert_equal(3, call.args.length)
|
79
|
+
|
80
|
+
arg = call.args[0]
|
81
|
+
assert_equal(:named, arg.type)
|
82
|
+
assert(arg.name.is_a? Nasl::Identifier)
|
83
|
+
assert(arg.expr.is_a? Nasl::Integer)
|
84
|
+
assert_equal(arg.expr, call.arg['a'])
|
85
|
+
|
86
|
+
arg = call.args[1]
|
87
|
+
assert_equal(:named, arg.type)
|
88
|
+
assert(arg.name.is_a? Nasl::Identifier)
|
89
|
+
assert(arg.expr.is_a? Nasl::String)
|
90
|
+
assert_equal(arg.expr, call.arg['b'])
|
91
|
+
|
92
|
+
arg = call.args[2]
|
93
|
+
assert_equal(:named, arg.type)
|
94
|
+
assert(arg.name.is_a? Nasl::Identifier)
|
95
|
+
assert(arg.expr.is_a? Nasl::Lvalue)
|
96
|
+
assert_equal(arg.expr, call.arg['c'])
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_mixed_args
|
100
|
+
tree = parse("foo(a:1, '2', c:three, bar());")
|
101
|
+
assert_not_nil(tree)
|
102
|
+
|
103
|
+
calls = tree.all(:Call)
|
104
|
+
assert_not_nil(calls)
|
105
|
+
assert_equal(2, calls.length)
|
106
|
+
|
107
|
+
call = calls[1]
|
108
|
+
assert_not_nil(call)
|
109
|
+
assert_equal(4, call.args.length)
|
110
|
+
|
111
|
+
arg = call.args[0]
|
112
|
+
assert_equal(:named, arg.type)
|
113
|
+
assert(arg.name.is_a? Nasl::Identifier)
|
114
|
+
assert(arg.expr.is_a? Nasl::Integer)
|
115
|
+
assert_equal(arg.expr, call.arg['a'])
|
116
|
+
|
117
|
+
arg = call.args[1]
|
118
|
+
assert_equal(:anonymous, arg.type)
|
119
|
+
assert(arg.expr.is_a? Nasl::String)
|
120
|
+
|
121
|
+
arg = call.args[2]
|
122
|
+
assert_equal(:named, arg.type)
|
123
|
+
assert(arg.name.is_a? Nasl::Identifier)
|
124
|
+
assert(arg.expr.is_a? Nasl::Lvalue)
|
125
|
+
assert_equal(arg.expr, call.arg['c'])
|
126
|
+
|
127
|
+
arg = call.args[3]
|
128
|
+
assert_equal(:anonymous, arg.type)
|
129
|
+
assert(arg.expr.is_a? Nasl::Call)
|
130
|
+
end
|
131
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nasl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-12-25 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &17198404300 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *17198404300
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: builder
|
27
|
-
requirement: &
|
27
|
+
requirement: &17198403880 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *17198403880
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: racc
|
38
|
-
requirement: &
|
38
|
+
requirement: &17198403460 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *17198403460
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rainbow
|
49
|
-
requirement: &
|
49
|
+
requirement: &17198403040 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *17198403040
|
58
58
|
description:
|
59
59
|
email:
|
60
60
|
- mak@kolybabi.com
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- test/unit/parser/test_assignment.rb
|
119
119
|
- test/unit/parser/test_blank.rb
|
120
120
|
- test/unit/parser/test_block.rb
|
121
|
+
- test/unit/parser/test_call.rb
|
121
122
|
- test/unit/parser/test_constant.rb
|
122
123
|
- test/unit/parser/test_empty.rb
|
123
124
|
- test/unit/parser/test_expressions.rb
|