diff --git a/t/advanced/05attributes.t b/t/advanced/05attributes.t new file mode 100644 index 0000000..f788efe --- /dev/null +++ b/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