tests.l 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. (def import (fn path (eval (read (recv (open path))))))
  2. (import "/sd/os/lib.l")
  3. (def foo (fn "foo"))
  4. (foo)
  5. (cons 1 2)
  6. (cons "foo" 1)
  7. (cons 1 "foo")
  8. (cons "a" (cons "b" "c"))
  9. (def test (fn tn tx (print (list "test " tn (if tx "OK" "FAIL")))))
  10. (def = eq)
  11. (def not (fn a (if a 0 1)))
  12. (test 1 (= 1 1))
  13. (test 2 (= 2 2))
  14. (test 3 (not (= 1 0)))
  15. (test 4 (not (= 0 1)))
  16. (test 6 (= + +))
  17. (test 7 (= (+ 1 2) (+ 2 1)))
  18. (test 8 (def a 1))
  19. (test 9 (not (= a (def b (+ a 1)))))
  20. (test 10 (= a a))
  21. (test 11 (= b 2))
  22. (test 12 (= 4 (do 1 2 "foo" 4)))
  23. (test 13 (= 3 (size (do 1 2 "foo"))))
  24. (def fib (fn n 0))
  25. (def fib (fn n (if (lt n 3) 1 (+ (fib (- n 1)) (fib (- n 2))) )))
  26. (test 14 (= (fib 10) 55))
  27. (def foo (fn a b (+ a b)))
  28. (test 15 (do (def a 5) (def b 6) (= (foo (+ a 1) (- b 2)) 10)))
  29. (test 17 (= (get [65] 0) (get "beef" 1)))
  30. (test 18 (= (get [66] 0) (get "beef" 3)))
  31. (test 19 (lt 4 500))
  32. (test 20 (gt -2 -4))
  33. (test 21 (eq 666 (* -1 -666)))
  34. (test 22 (= (get (substr "hellaz" 1 3) 0) 101))
  35. (def fun1 (fn a b c (list a b c)))
  36. (def fun2 (fn a b c (fun1 c a b)))
  37. (print (fun2 2 3 1))
  38. (test 23 (= 5 (+ (+ (+ 1 1) 1) (+ 1 1))))
  39. (test 24 (= 4 (+ (+ 1 1) (+ 1 1))))
  40. (test 25 (= 3 (+ (+ 1 1) 1)))
  41. (def func-a (fn xx yy (* (+ xx 1) (+ yy 1))))
  42. (def func-b (fn x y (func-a x y)))
  43. (test 26 (= (func-b 5 5) 36))
  44. (test 16 (= 12 (strlen (concat "hello" "worlden"))))
  45. (def lett (fn g (do
  46. (let a 23)
  47. (let b 46)
  48. (let c 66)
  49. (let d 72)
  50. (let e "foo")
  51. (list g a b c d e g)
  52. )))
  53. (print (lett 6))
  54. (def spillover (fn a b c d e f (do
  55. (print (list a b c d e f))
  56. (print (list f e d c b a))
  57. )))
  58. (spillover 1 2 3 4 5 6)
  59. (def fa (fn x y z w (do
  60. (let a 8)
  61. (let b 9)
  62. (print a)
  63. (print b)
  64. (print x) ; gives 2, should give 1
  65. (print y)
  66. (print z)
  67. (print (list "fa: " a b x y z w))
  68. )))
  69. (def fb (fn a b (do
  70. (print a)
  71. (print b)
  72. (fa a b "3" "4")
  73. )))
  74. (fb 1 2)