/src/test/run-pass/expr-fn.rs

http://github.com/jruderman/rust · Rust · 58 lines · 46 code · 11 blank · 1 comment · 11 complexity · 3a81be66acd1425a4cb40b78824cfaaa MD5 · raw file

  1. fn test_int() {
  2. fn f() -> int { 10 }
  3. assert (f() == 10);
  4. }
  5. fn test_vec() {
  6. fn f() -> ~[int] { ~[10, 11] }
  7. assert (f()[1] == 11);
  8. }
  9. fn test_generic() {
  10. fn f<T: copy>(t: T) -> T { t }
  11. assert (f(10) == 10);
  12. }
  13. fn test_alt() {
  14. fn f() -> int { match true { false => { 10 } true => { 20 } } }
  15. assert (f() == 20);
  16. }
  17. fn test_if() {
  18. fn f() -> int { if true { 10 } else { 20 } }
  19. assert (f() == 10);
  20. }
  21. fn test_block() {
  22. fn f() -> int { { 10 } }
  23. assert (f() == 10);
  24. }
  25. fn test_ret() {
  26. fn f() -> int {
  27. return 10 // no semi
  28. }
  29. assert (f() == 10);
  30. }
  31. // From issue #372
  32. fn test_372() {
  33. fn f() -> int { let x = { 3 }; x }
  34. assert (f() == 3);
  35. }
  36. fn test_nil() { () }
  37. fn main() {
  38. test_int();
  39. test_vec();
  40. test_generic();
  41. test_alt();
  42. test_if();
  43. test_block();
  44. test_ret();
  45. test_372();
  46. test_nil();
  47. }