nasl 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/bin/nasl-parse +1 -1
  2. data/lib/nasl.rb +1 -1
  3. data/lib/nasl/cli.rb +1 -1
  4. data/lib/nasl/command.rb +1 -1
  5. data/lib/nasl/commands/benchmark.rb +1 -1
  6. data/lib/nasl/commands/parse.rb +1 -1
  7. data/lib/nasl/commands/test.rb +1 -1
  8. data/lib/nasl/commands/tokenize.rb +2 -2
  9. data/lib/nasl/commands/xml.rb +1 -1
  10. data/lib/nasl/context.rb +1 -1
  11. data/lib/nasl/grammar.racc +23 -2
  12. data/lib/nasl/parser.rb +1 -1
  13. data/lib/nasl/parser/argument.rb +1 -1
  14. data/lib/nasl/parser/assigment.rb +1 -1
  15. data/lib/nasl/parser/block.rb +1 -1
  16. data/lib/nasl/parser/break.rb +1 -1
  17. data/lib/nasl/parser/call.rb +1 -1
  18. data/lib/nasl/parser/comment.rb +46 -0
  19. data/lib/nasl/parser/continue.rb +1 -1
  20. data/lib/nasl/parser/decrement.rb +1 -1
  21. data/lib/nasl/parser/empty.rb +1 -1
  22. data/lib/nasl/parser/export.rb +1 -1
  23. data/lib/nasl/parser/expression.rb +1 -1
  24. data/lib/nasl/parser/for.rb +1 -1
  25. data/lib/nasl/parser/foreach.rb +1 -1
  26. data/lib/nasl/parser/function.rb +1 -1
  27. data/lib/nasl/parser/global.rb +1 -1
  28. data/lib/nasl/parser/identifier.rb +1 -1
  29. data/lib/nasl/parser/if.rb +1 -1
  30. data/lib/nasl/parser/import.rb +1 -1
  31. data/lib/nasl/parser/include.rb +1 -1
  32. data/lib/nasl/parser/increment.rb +1 -1
  33. data/lib/nasl/parser/integer.rb +1 -1
  34. data/lib/nasl/parser/ip.rb +1 -1
  35. data/lib/nasl/parser/local.rb +1 -1
  36. data/lib/nasl/parser/lvalue.rb +1 -1
  37. data/lib/nasl/parser/node.rb +1 -1
  38. data/lib/nasl/parser/repeat.rb +1 -1
  39. data/lib/nasl/parser/repetition.rb +1 -1
  40. data/lib/nasl/parser/return.rb +1 -1
  41. data/lib/nasl/parser/string.rb +1 -1
  42. data/lib/nasl/parser/tree.rb +1 -1
  43. data/lib/nasl/parser/undefined.rb +1 -1
  44. data/lib/nasl/parser/while.rb +1 -1
  45. data/lib/nasl/test.rb +1 -1
  46. data/lib/nasl/token.rb +1 -1
  47. data/lib/nasl/tokenizer.rb +66 -5
  48. data/lib/nasl/version.rb +1 -1
  49. data/test/unit/parser/test_assignment.rb +1 -1
  50. data/test/unit/parser/test_blank.rb +1 -1
  51. data/test/unit/parser/test_block.rb +1 -1
  52. data/test/unit/parser/test_call.rb +1 -1
  53. data/test/unit/parser/test_comment.rb +140 -0
  54. data/test/unit/parser/test_constant.rb +1 -1
  55. data/test/unit/parser/test_empty.rb +1 -1
  56. data/test/unit/parser/test_expressions.rb +1 -1
  57. data/test/unit/parser/test_function.rb +1 -1
  58. data/test/unit/parser/test_if.rb +1 -1
  59. data/test/unit/parser/test_include.rb +1 -1
  60. data/test/unit/parser/test_incr_decr.rb +1 -1
  61. data/test/unit/parser/test_ip.rb +1 -1
  62. data/test/unit/parser/test_return.rb +1 -1
  63. data/test/unit/parser/test_string.rb +1 -1
  64. data/test/unit/parser/test_whitespace.rb +1 -1
  65. data/test/unit/test_context.rb +1 -1
  66. data/test/unit/tokenizer/test_comment.rb +218 -0
  67. data/test/unit/tokenizer/test_empty.rb +1 -9
  68. data/test/unit/tokenizer/test_integer.rb +1 -1
  69. data/test/unit/tokenizer/test_string.rb +1 -1
  70. metadata +34 -11
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
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, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
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, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
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, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -116,6 +116,12 @@ module Nasl
116
116
  ["}", :RBRACE]
117
117
  ]
118
118
 
119
+ @@annotated = [
120
+ :EXPORT,
121
+ :FUNCTION,
122
+ :GLOBAL
123
+ ]
124
+
119
125
  def initialize!
120
126
  return if @@initialized
121
127
 
@@ -155,6 +161,11 @@ module Nasl
155
161
  end
156
162
 
157
163
  def reset
164
+ # We need to remember the last token so we only emit comments significant
165
+ # to nasldoc.
166
+ @previous = nil
167
+ @deferred = nil
168
+
158
169
  # Set tokenizer to initial state, ready to tokenize the code from the
159
170
  # start.
160
171
  @point = 0
@@ -167,7 +178,7 @@ module Nasl
167
178
 
168
179
  def skip
169
180
  while true do
170
- whitespace = @line[/^(\s+|\s*#.*$)/]
181
+ whitespace = @line[/^\s+/]
171
182
  return if whitespace.nil?
172
183
  consume(whitespace.length)
173
184
  end
@@ -275,6 +286,25 @@ module Nasl
275
286
  return [type, contents]
276
287
  end
277
288
 
289
+ def get_comment
290
+ # Remember the column the comment begins in.
291
+ col = @ctx.col(@point)
292
+
293
+ # Consume all of the comments in the block.
294
+ block = []
295
+ begin
296
+ prev = @ctx.row(@point)
297
+ comment = @line[/^#.*$/]
298
+ break if comment.nil?
299
+ block << comment
300
+ consume(comment.length)
301
+ skip
302
+ cur = @ctx.row(@point)
303
+ end while @ctx.col(@point) == col && cur == prev + 1
304
+
305
+ return [:COMMENT, block.join("\n")]
306
+ end
307
+
278
308
  def get_operator
279
309
  # These are all of the operators defined in NASL. Their order is vitally
280
310
  # important.
@@ -288,6 +318,13 @@ module Nasl
288
318
  end
289
319
 
290
320
  def get_token
321
+ # If we deferred a token, emit it now.
322
+ unless @deferred.nil?
323
+ token = @deferred
324
+ @deferred = nil
325
+ return token
326
+ end
327
+
291
328
  # Make sure we're not at the end of the file.
292
329
  return [false, Token.new(:EOF, "$", @point...@point, @ctx)] if @eof
293
330
 
@@ -302,6 +339,8 @@ module Nasl
302
339
  get_string
303
340
  elsif @char =~ /[0-9]/
304
341
  get_integer
342
+ elsif @char == '#'
343
+ get_comment
305
344
  else
306
345
  get_operator
307
346
  end
@@ -309,17 +348,39 @@ module Nasl
309
348
  # Everything in the language is enumerated by the above functions, so if
310
349
  # we get here without a token parsed, the input file is invalid.
311
350
  die("Invalid character ('#@char')") if token.nil?
351
+
352
+ # Consume all whitespace after the token, and create an object with
353
+ # context.
312
354
  skip
355
+ token = [token.first, Token.new(*token, @mark...@point, @ctx)]
356
+
357
+ # If a comment is the first token in a file, or is followed by certain
358
+ # tokens, then it is considered significant. Such tokens will appear in
359
+ # the grammar so that it can be made visible to nasldoc.
360
+ if token.first == :COMMENT
361
+ if @previous.nil?
362
+ @previous = [:DUMMY, ""]
363
+ else
364
+ @previous = token
365
+ token = get_token
366
+ end
367
+ elsif !@previous.nil? && @previous.first == :COMMENT && @@annotated.include?(token.first)
368
+ @deferred = token
369
+ token = @previous
370
+ @previous = @deferred
371
+ else
372
+ @previous = token
373
+ end
313
374
 
314
- return [token.first, Token.new(*token, @mark...@point, @ctx)]
375
+ return token
315
376
  end
316
377
 
317
378
  def get_tokens
318
379
  tokens = []
319
380
 
320
- until @eof
381
+ begin
321
382
  tokens << get_token
322
- end
383
+ end while not tokens.last.last.type == :EOF
323
384
 
324
385
  return tokens
325
386
  end
@@ -1,3 +1,3 @@
1
1
  module Nasl
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
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, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
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, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
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, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -0,0 +1,140 @@
1
+ ################################################################################
2
+ # Copyright (c) 2011-2012, 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 TestComment < Test::Unit::TestCase
28
+ include Nasl::Test
29
+
30
+ def test_standalone
31
+ tree = parse(
32
+ <<-EOF
33
+ # Standalone
34
+ EOF
35
+ )
36
+ assert_not_nil(tree)
37
+
38
+ comms = tree.all(:Comment)
39
+ assert_not_nil(comms)
40
+ assert_equal(1, comms.length)
41
+
42
+ comm = comms.first
43
+ assert_equal("# Standalone", comm.text.body)
44
+ assert_nil(comm.next)
45
+ end
46
+
47
+ def test_unattached
48
+ tree = parse(
49
+ <<-EOF
50
+ # Unattached
51
+ ;
52
+ EOF
53
+ )
54
+ assert_not_nil(tree)
55
+
56
+ comms = tree.all(:Comment)
57
+ assert_not_nil(comms)
58
+ assert_equal(1, comms.length)
59
+
60
+ comm = comms.first
61
+ assert_equal("# Unattached", comm.text.body)
62
+ assert_nil(comm.next)
63
+
64
+ tree = parse(
65
+ <<-EOF
66
+ # Unattached
67
+ global_var foo;
68
+ EOF
69
+ )
70
+ assert_not_nil(tree)
71
+
72
+ comms = tree.all(:Comment)
73
+ assert_not_nil(comms)
74
+ assert_equal(1, comms.length)
75
+
76
+ comm = comms.first
77
+ assert_equal("# Unattached", comm.text.body)
78
+ assert_nil(comm.next)
79
+ end
80
+
81
+ def test_export
82
+ tree = parse(
83
+ <<-EOF
84
+ foo = TRUE;
85
+
86
+ # Export
87
+ export function foo() {}
88
+ EOF
89
+ )
90
+ assert_not_nil(tree)
91
+
92
+ comms = tree.all(:Comment)
93
+ assert_not_nil(comms)
94
+ assert_equal(1, comms.length)
95
+
96
+ comm = comms.first
97
+ assert_equal("# Export", comm.text.body)
98
+ assert_equal(Nasl::Export, comm.next.class)
99
+ end
100
+
101
+ def test_function
102
+ tree = parse(
103
+ <<-EOF
104
+ foo = TRUE;
105
+
106
+ # Function
107
+ function foo() {}
108
+ EOF
109
+ )
110
+ assert_not_nil(tree)
111
+
112
+ comms = tree.all(:Comment)
113
+ assert_not_nil(comms)
114
+ assert_equal(1, comms.length)
115
+
116
+ comm = comms.first
117
+ assert_equal("# Function", comm.text.body)
118
+ assert_equal(Nasl::Function, comm.next.class)
119
+ end
120
+
121
+ def test_global
122
+ tree = parse(
123
+ <<-EOF
124
+ foo = TRUE;
125
+
126
+ # Global
127
+ global_var bar;
128
+ EOF
129
+ )
130
+ assert_not_nil(tree)
131
+
132
+ comms = tree.all(:Comment)
133
+ assert_not_nil(comms)
134
+ assert_equal(1, comms.length)
135
+
136
+ comm = comms.first
137
+ assert_equal("# Global", comm.text.body)
138
+ assert_equal(Nasl::Global, comm.next.class)
139
+ end
140
+ end
@@ -1,5 +1,5 @@
1
1
  ################################################################################
2
- # Copyright (c) 2011, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
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, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
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, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
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, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
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, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
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, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
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, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
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, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
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, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
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, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
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, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
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, Mak Kolybabi
2
+ # Copyright (c) 2011-2012, Mak Kolybabi
3
3
  # All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
@@ -0,0 +1,218 @@
1
+ ################################################################################
2
+ # Copyright (c) 2011-2012, 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 TestTokenizerComment < Test::Unit::TestCase
28
+ include Nasl::Test
29
+
30
+ def verify(code, expected)
31
+ tkz = tokenize(code)
32
+ received = tkz.get_tokens
33
+
34
+ expected << [:EOF, "$"]
35
+
36
+ 0.upto(received.length - 1) do |i|
37
+ tok = received[i].last
38
+
39
+ # Handle more tokens than expected.
40
+ if expected[i].nil?
41
+ assert_equal([nil, nil], [tok.type, tok.body])
42
+ break
43
+ end
44
+
45
+ assert_equal(expected[i].first, tok.type, tok.context)
46
+ assert_equal(expected[i].last, tok.body, tok.context)
47
+ end
48
+
49
+ # Handle less tokens than expected.
50
+ if received.length < expected.length
51
+ assert_equal(expected[received.length], [nil, nil])
52
+ end
53
+
54
+ assert_equal(expected.length, received.length)
55
+ end
56
+
57
+ def test_empty
58
+ # Tokenize empty comment.
59
+ 0.upto(3).each do |i|
60
+ pad = ' ' * i
61
+ verify(pad + '#', [[:COMMENT, '#']])
62
+ end
63
+ end
64
+
65
+ def test_whitespace
66
+ # Tokenize whitespace comment.
67
+ 0.upto(3).each do |i|
68
+ pad = ' ' * i
69
+ verify('#' + pad, [[:COMMENT, '#' + pad]])
70
+ end
71
+ end
72
+
73
+ def test_block
74
+ code = <<-EOF
75
+ # Line 1
76
+ # Line 2
77
+ # Line 3
78
+ EOF
79
+
80
+ verify(code, [[:COMMENT, "# Line 1\n# Line 2\n# Line 3"]])
81
+ end
82
+
83
+ def test_unaligned
84
+ code = <<-EOF
85
+ # Comment 1
86
+ # Comment 2
87
+ EOF
88
+
89
+ verify(code, [[:COMMENT, "# Comment 1"]])
90
+ end
91
+
92
+ def test_disjoint
93
+ code = <<-EOF
94
+ # Comment 1
95
+
96
+ # Comment 2
97
+ EOF
98
+
99
+ verify(code, [[:COMMENT, "# Comment 1"]])
100
+ end
101
+
102
+ def test_hidden_before
103
+ code = <<-EOF
104
+ foo = TRUE;
105
+ # Comment
106
+ foo = TRUE;
107
+ EOF
108
+
109
+ assign = [
110
+ [:IDENT, "foo"],
111
+ [:ASS_EQ, "="],
112
+ [:TRUE, "TRUE"],
113
+ [:SEMICOLON, ";"],
114
+ ]
115
+
116
+ verify(code, assign + assign)
117
+ end
118
+
119
+ def test_hidden_aften
120
+ code = <<-EOF
121
+ foo = TRUE;
122
+
123
+ # Comment
124
+ EOF
125
+
126
+ verify(
127
+ code,
128
+ [
129
+ [:IDENT, "foo"],
130
+ [:ASS_EQ, "="],
131
+ [:TRUE, "TRUE"],
132
+ [:SEMICOLON, ";"],
133
+ ]
134
+ )
135
+ end
136
+
137
+ def test_export
138
+ code = <<-EOF
139
+ foo = TRUE;
140
+
141
+ # Export
142
+ export function bar() {}
143
+ EOF
144
+
145
+ verify(
146
+ code,
147
+ [
148
+ [:IDENT, "foo"],
149
+ [:ASS_EQ, "="],
150
+ [:TRUE, "TRUE"],
151
+ [:SEMICOLON, ";"],
152
+
153
+ [:COMMENT, "# Export"],
154
+
155
+ [:EXPORT, "export"],
156
+ [:FUNCTION, "function"],
157
+ [:IDENT, "bar"],
158
+ [:LPAREN, "("],
159
+ [:RPAREN, ")"],
160
+ [:LBRACE, "{"],
161
+ [:RBRACE, "}"]
162
+ ]
163
+ )
164
+ end
165
+
166
+ def test_function
167
+ code = <<-EOF
168
+ foo = TRUE;
169
+
170
+ # Function
171
+ function bar() {}
172
+ EOF
173
+
174
+ verify(
175
+ code,
176
+ [
177
+ [:IDENT, "foo"],
178
+ [:ASS_EQ, "="],
179
+ [:TRUE, "TRUE"],
180
+ [:SEMICOLON, ";"],
181
+
182
+ [:COMMENT, "# Function"],
183
+
184
+ [:FUNCTION, "function"],
185
+ [:IDENT, "bar"],
186
+ [:LPAREN, "("],
187
+ [:RPAREN, ")"],
188
+ [:LBRACE, "{"],
189
+ [:RBRACE, "}"]
190
+ ]
191
+ )
192
+ end
193
+
194
+ def test_global
195
+ code = <<-EOF
196
+ foo = TRUE;
197
+
198
+ # Global
199
+ global_var bar;
200
+ EOF
201
+
202
+ verify(
203
+ code,
204
+ [
205
+ [:IDENT, "foo"],
206
+ [:ASS_EQ, "="],
207
+ [:TRUE, "TRUE"],
208
+ [:SEMICOLON, ";"],
209
+
210
+ [:COMMENT, "# Global"],
211
+
212
+ [:GLOBAL, "global_var"],
213
+ [:IDENT, "bar"],
214
+ [:SEMICOLON, ";"]
215
+ ]
216
+ )
217
+ end
218
+ end