/t/advanced/05attributes.t

http://github.com/NotFound/winxed · Raku · 57 lines · 44 code · 12 blank · 1 comment · 0 complexity · dcfdb44b9634bd5a24e9a9a16e9fb1f7 MD5 · raw file

  1. #! winxed
  2. // Test attribute access
  3. using extern Test.More plan, is;
  4. function main()
  5. {
  6. plan(6);
  7. int check;
  8. string s;
  9. string atname;
  10. var foo = new Foo;
  11. foo.set("bar");
  12. s = foo.bar;
  13. is(s, "bar", "get string");
  14. foo.bar = "world";
  15. is(foo.get(), "world", "set string");
  16. atname = "bar";
  17. foo.set("hello");
  18. is(foo.*atname, "hello", "indirect get string");
  19. foo.*atname = "hello";
  20. is(foo.bar, "hello", "indirect set string");
  21. check = 0;
  22. try {
  23. s = foo.thereisnothinghere;
  24. }
  25. catch() {
  26. check = 1;
  27. }
  28. is(check, 1, "get non existent throws");
  29. atname = "nosuchattribute";
  30. check = 0;
  31. try {
  32. s = foo.*atname;
  33. }
  34. catch() {
  35. check = 1;
  36. }
  37. is(check, 1, "indirect get non existent throws");
  38. }
  39. class Foo
  40. {
  41. var bar;
  42. function set(string s) { self.bar = s; }
  43. function get() { return self.bar; }
  44. }
  45. // End