Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |