/t/advanced/05mreturn.t

http://github.com/NotFound/winxed · Raku · 42 lines · 30 code · 11 blank · 1 comment · 4 complexity · 36087cb7dc39ae3564ba627bb26e5253 MD5 · raw file

  1. #! winxed
  2. // Test return with multiple values
  3. using extern Test.More plan, is, ok;
  4. function main()
  5. {
  6. plan(6);
  7. :(int i, int j) = ret2();
  8. is(i, 42, "first value of 2");
  9. is(j, 24, "second value of 2");
  10. :(i, j[optional], int has2[opt_flag]) = ret1();
  11. is(i, 7, "first value of 1");
  12. is(has2, 0, "optional not used");
  13. :(i, j[optional], has2[opt_flag]) = ret2();
  14. is(has2, 1, "optional used");
  15. :(var v1, var v2, var v3) = retvars();
  16. ok(v1 == null && v2 != null && v3 == null, "null/non null vars");
  17. }
  18. function ret1()
  19. {
  20. return 7;
  21. }
  22. function ret2()
  23. {
  24. return 42, 24;
  25. }
  26. function retvars()
  27. {
  28. var v = 1;
  29. return null, v, null;
  30. }
  31. // End