2 # Copyright (C) 2001-2010, Parrot Foundation.
7 t/pmc/oplib.t - OpLib PMC
15 # Hardcoded assumptions for tests:
16 # * We have an op called end
17 # * It has no arguments
18 # * Is the only member of its familiy
19 .const string TESTED_OP = 'end'
20 .const int TESTED_OP_ELEMS = 0
21 .const int TESTED_OP_FAMILIY_ELEMS = 1
22 # Never have an op with this name:
23 .const string TESTED_NOSUCHOP = 'hopeweneverhaveopcodesnamedlikethis'
25 .include 'except_types.pasm'
28 .include 'test_more.pir'
41 $P1 = new ['OpLib'], $P0
47 .local pmc oplib, op, eh
50 oplib = new ['OpLib'], $P0
55 is(i, 0, 'last opcode exists')
56 eh = new ['ExceptionHandler']
57 eh.'handle_types'(.EXCEPTION_OUT_OF_BOUNDS)
61 nok(1, 'out of bounds opcode number should throw')
66 ok(1, 'out of bounds opcode number throws')
72 $P0 = new ['OpLib'], $P0
75 ok($I0, "got end opcode")
80 $P0 = new ['OpLib'], $P0
81 $I1 = $P0[TESTED_NOSUCHOP]
83 ok($I0, "get non existent opcode fails")
87 .local pmc oplib, op, op2, name
89 oplib = new ['OpLib'], $P0
91 # Using a string constant
94 is($I0, 0, "got end opcode data")
97 is($I0, TESTED_OP_ELEMS, "the opcode tested has the expected lenght")
100 name = new ['String']
104 is($I0, 0, "got end opcode data keyed pmc")
107 $S0 = "Implement cacheing, Opcode.is_same, or change comparison"
108 todo($I0, "got same result from both ways", $S0)
111 $I0 = oplib[TESTED_OP]
112 is($I0, $I1, 'opcode number from Opcode and from OpLib is the same')
115 is($S0, TESTED_OP, 'name from Opcode matches name searched for')
120 $P0 = new ['OpLib'], $P0
121 $P1 = $P0.'op_family'(TESTED_OP)
127 is($I0, TESTED_OP_FAMILIY_ELEMS, "'end' family is not null and has 1 element")
130 .sub family_no_opcode
132 $P0 = new ['OpLib'], $P0
133 $P1 = $P0.'op_family'(TESTED_NOSUCHOP)
135 ok($I0, "non existent opcode family is null")
142 # vim: expandtab shiftwidth=4 ft=pir: