File: hashs.t

package info (click to toggle)
nqp 2016.12%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 7,960 kB
  • ctags: 3,884
  • sloc: java: 25,027; perl: 910; makefile: 12; sh: 2
file content (27 lines) | stat: -rw-r--r-- 607 bytes parent folder | download | duplicates (2)
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..11"
h = {'a' =>10,'b' => 18+2 , 'c' => 30}
h{'d'} = 100
puts "#{h{'a'} == 10? 'ok' : 'nok'} 1 - h{'a'}"
puts "#{h<b> == 20? 'ok' : 'nok'} 2 - h<b>"
h_idx = 'c'
puts "#{h{h_idx} == 30? 'ok' : 'nok'} 3 - h{c_idx}"
puts "#{h{'d'} == 100? 'ok' : 'nok'} 4 - h{'d'}"

delete(h, 'd')
t = 4

for kv in h do
    puts "ok #{t += 1} - hash key iteration"
end

h<d> = ['nok','ok']
puts "#{ h<d>[1] } 8 - HoA"

def test_hash_args(x, h_args)
    puts "ok #{ x } - fixed arg"
    for kv in h_args do
       puts "ok #{ value kv } - hash slurpy arg (#{key kv})"
    end
end

test_hash_args 9, 'z' => 10, 'y' => 11