[cage] Fix pgegrep, which was merely an innocent bystander in the Great Namespace...
[parrot.git] / t / oo / attributes.t
blob4020d06b7c4a85ebd9ba17b5189f8c52d06b1645
1 #! parrot
2 # Copyright (C) 2008, Parrot Foundation.
3 # $Id$
5 =head1 NAME
7 t/oo/attributes.t - Test OO attributes
9 =head1 SYNOPSIS
11     % prove t/oo/attributes.t
13 =head1 DESCRIPTION
15 Tests OO features related to adding and removing attributes.
17 =cut
19 .sub main :main
20     .include 'test_more.pir'
22     plan(3)
24     remove_1()
25 .end
27 .sub remove_1
28     .local pmc class, object, init_hash
29     .local pmc exception, message
31     init_hash = new 'Hash'
32     $P1 = new 'String'
33     $P1 = 'data for Foo'
34     init_hash['data'] = $P1
36     # First pass, adding an attribute.
37     class = newclass "Foo"
38     addattribute class, 'data'
39     object = new class, init_hash
40     $P2 = getattribute object, 'data'
41     is($P2, 'data for Foo', 'class attribute retrieved via the instance')
43     # Second pass, removing the attribute after adding it.
44     class = newclass "Bar"
45     addattribute class, 'data'
46     removeattribute class, 'data'
47     push_eh catch_bad_attr_init
48     object = new class, init_hash
49     pop_eh
50     ok(0)
52   try_access:
53     object = new class
54     push_eh catch_bad_attr_access
55     $P2 = getattribute object, 'data'
56     pop_eh
57     ok(0)
59     end
61   catch_bad_attr_init:
62     .get_results (exception)
63     message = exception
64     is(message, "No such attribute 'data'", 'class attribute deleted')
65     pop_eh
66     goto try_access
68   catch_bad_attr_access:
69     .get_results (exception)
70     message = exception
71     is(message, "No such attribute 'data'", 'class attribute deleted')
73 .end