Skip to content

Commit

Permalink
some tests for attribute access
Browse files Browse the repository at this point in the history
  • Loading branch information
NotFound committed Jul 9, 2011
1 parent 1d88fd0 commit 55d883f
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions t/advanced/05attributes.t
@@ -0,0 +1,57 @@
#! winxed

// Test attribute access

using extern Test.More plan, is;

function main()
{
plan(6);

int check;
string s;
string atname;
var foo = new Foo;

foo.set("bar");
s = foo.bar;
is(s, "bar", "get string");

foo.bar = "world";
is(foo.get(), "world", "set string");

atname = "bar";
foo.set("hello");
is(foo.*atname, "hello", "indirect get string");

foo.*atname = "hello";
is(foo.bar, "hello", "indirect set string");

check = 0;
try {
s = foo.thereisnothinghere;
}
catch() {
check = 1;
}
is(check, 1, "get non existent throws");

atname = "nosuchattribute";
check = 0;
try {
s = foo.*atname;
}
catch() {
check = 1;
}
is(check, 1, "indirect get non existent throws");
}

class Foo
{
var bar;
function set(string s) { self.bar = s; }
function get() { return self.bar; }
}

// End

0 comments on commit 55d883f

Please sign in to comment.