File: contextual.t

package info (click to toggle)
nqp 2014.07-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 23,596 kB
  • ctags: 7,993
  • sloc: ansic: 22,689; java: 20,240; cpp: 4,956; asm: 3,976; perl: 950; python: 267; sh: 245; makefile: 14
file content (27 lines) | stat: -rwxr-xr-x 670 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
puts"1..9"
# These tests explore context sensitive parsing of variables vs methods
def xx(n=-7) ; 2 - n; end
def three ; 3; end

def zz(m)
    three = 3
    xx = 1
    puts  "ok #{xx + m +3} - nested symbols"
    puts  "ok #{three +m +2} - nested symbols"
    8
end

# in particular, `xx +1` is parsed as a method call, `yy -1` as an expression

puts "ok #{xx +1} - method parse"

yy = 3
puts "ok #{yy -1} - arithmetic parse"

puts "ok #{three} - parameterless method"
puts "ok #{three + 1} - parameterless method arithmetic"
puts "ok #{three() +2} - parameterless method + paren arithmetic"

puts "ok #{zz 2} - method with args"
puts "ok #{xx} - parameter defaulting"