PageRenderTime 35ms CodeModel.GetById 8ms app.highlight 22ms RepoModel.GetById 2ms app.codeStats 0ms

/t/advanced/05attributes.t

http://github.com/NotFound/winxed
text | 57 lines | 45 code | 12 blank | 0 comment | 0 complexity | dcfdb44b9634bd5a24e9a9a16e9fb1f7 MD5 | raw file
 1#! winxed
 2
 3// Test attribute access
 4
 5using extern Test.More plan, is;
 6
 7function main()
 8{
 9    plan(6);
10
11    int check;
12    string s;
13    string atname;
14    var foo = new Foo;
15
16    foo.set("bar");
17    s = foo.bar;
18    is(s, "bar", "get string");
19
20    foo.bar = "world";
21    is(foo.get(), "world", "set string");
22
23    atname = "bar";
24    foo.set("hello");
25    is(foo.*atname, "hello", "indirect get string");
26
27    foo.*atname = "hello";
28    is(foo.bar, "hello", "indirect set string");
29
30    check = 0;
31    try {
32        s = foo.thereisnothinghere;
33    }
34    catch() {
35        check = 1;
36    }
37    is(check, 1, "get non existent throws");
38
39    atname = "nosuchattribute";
40    check = 0;
41    try {
42        s = foo.*atname;
43    }
44    catch() {
45        check = 1;
46    }
47    is(check, 1, "indirect get non existent throws");
48}
49
50class Foo
51{
52    var bar;
53    function set(string s) { self.bar = s; }
54    function get() { return self.bar; }
55}
56
57// End