File: contextual.t

package info (click to toggle)
nqp 2024.09%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,972 kB
  • sloc: java: 28,087; perl: 3,479; ansic: 451; makefile: 202; javascript: 68; sh: 1
file content (27 lines) | stat: -rw-r--r-- 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"