Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 101 lines (70 sloc) 1.811 kb
6095227 improve syntax stuff and add more tests
Stevan Little authored
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 use mop;
9
10 class Point {
9ad04b0 convert the tests to take advantage of the new standard traits
Stevan Little authored
11 has $x is ro = 0;
12 has $y is ro = 0;
6095227 improve syntax stuff and add more tests
Stevan Little authored
13
14 method set_x ($new_x) {
15 $x = $new_x;
16 }
17
18 method set_y ($new_y) {
19 $y = $new_y;
20 }
21
22 method clear {
23 ($x, $y) = (0, 0);
24 }
25
357277b rename this to avoid possible conflict (hint: see next commit)
Stevan Little authored
26 method pack {
6095227 improve syntax stuff and add more tests
Stevan Little authored
27 +{ x => $self->x, y => $self->y }
28 }
29 }
30
31 # ... subclass it ...
32
8b98ce2 parse the extends declaration outside of a class proto
Stevan Little authored
33 class Point3D extends Point {
9ad04b0 convert the tests to take advantage of the new standard traits
Stevan Little authored
34 has $z is ro = 0;
6095227 improve syntax stuff and add more tests
Stevan Little authored
35
36 method set_z ($new_z) {
37 $z = $new_z;
38 }
39
357277b rename this to avoid possible conflict (hint: see next commit)
Stevan Little authored
40 method pack {
058bfb2 hijack next::method in the bootstrap
Stevan Little authored
41 my $data = $self->next::method;
10fa452 move point test
Stevan Little authored
42 $data->{z} = $z;
43 $data;
6095227 improve syntax stuff and add more tests
Stevan Little authored
44 }
45 }
355b16e Jesse Luehrs fix end of line whitespace
doy authored
46
6095227 improve syntax stuff and add more tests
Stevan Little authored
47 ## Test an instance
fe6bf0a fuck it, one big commit, i don't care right now
Stevan Little authored
48 {
49 my $p = Point->new;
50 isa_ok($p, 'Point');
6095227 improve syntax stuff and add more tests
Stevan Little authored
51
fd28337 more refactoring and some tests
Stevan Little authored
52 is_deeply(
53 mop::mro::get_linear_isa('Point'),
54 [ 'Point', 'mop::object' ],
55 '... got the expected linear isa'
56 );
57
fe6bf0a fuck it, one big commit, i don't care right now
Stevan Little authored
58 is $p->x, 0, '... got the default value for x';
59 is $p->y, 0, '... got the default value for y';
6095227 improve syntax stuff and add more tests
Stevan Little authored
60
fe6bf0a fuck it, one big commit, i don't care right now
Stevan Little authored
61 $p->set_x(10);
62 is $p->x, 10, '... got the right value for x';
6095227 improve syntax stuff and add more tests
Stevan Little authored
63
fe6bf0a fuck it, one big commit, i don't care right now
Stevan Little authored
64 $p->set_y(320);
65 is $p->y, 320, '... got the right value for y';
6095227 improve syntax stuff and add more tests
Stevan Little authored
66
357277b rename this to avoid possible conflict (hint: see next commit)
Stevan Little authored
67 is_deeply $p->pack, { x => 10, y => 320 }, '... got the right value from pack';
fe6bf0a fuck it, one big commit, i don't care right now
Stevan Little authored
68 }
6095227 improve syntax stuff and add more tests
Stevan Little authored
69
70 ## Test the instance
fe6bf0a fuck it, one big commit, i don't care right now
Stevan Little authored
71 {
72 my $p3d = Point3D->new();
73 isa_ok($p3d, 'Point3D');
46a74a3 few test additions
Stevan Little authored
74 isa_ok($p3d, 'Point');
6095227 improve syntax stuff and add more tests
Stevan Little authored
75
fd28337 more refactoring and some tests
Stevan Little authored
76 is_deeply(
77 mop::mro::get_linear_isa('Point3D'),
78 [ 'Point3D', 'Point', 'mop::object' ],
79 '... got the expected linear isa'
80 );
81
fe6bf0a fuck it, one big commit, i don't care right now
Stevan Little authored
82 is $p3d->z, 0, '... got the default value for z';
6095227 improve syntax stuff and add more tests
Stevan Little authored
83
fe6bf0a fuck it, one big commit, i don't care right now
Stevan Little authored
84 $p3d->set_x(10);
85 is $p3d->x, 10, '... got the right value for x';
6095227 improve syntax stuff and add more tests
Stevan Little authored
86
fe6bf0a fuck it, one big commit, i don't care right now
Stevan Little authored
87 $p3d->set_y(320);
88 is $p3d->y, 320, '... got the right value for y';
6095227 improve syntax stuff and add more tests
Stevan Little authored
89
fe6bf0a fuck it, one big commit, i don't care right now
Stevan Little authored
90 $p3d->set_z(30);
91 is $p3d->z, 30, '... got the right value for z';
6095227 improve syntax stuff and add more tests
Stevan Little authored
92
357277b rename this to avoid possible conflict (hint: see next commit)
Stevan Little authored
93 is_deeply $p3d->pack, { x => 10, y => 320, z => 30 }, '... got the right value from pack';
fe6bf0a fuck it, one big commit, i don't care right now
Stevan Little authored
94 }
6095227 improve syntax stuff and add more tests
Stevan Little authored
95
fd28337 more refactoring and some tests
Stevan Little authored
96
6095227 improve syntax stuff and add more tests
Stevan Little authored
97 done_testing;
98
99
100
Something went wrong with that request. Please try again.