hy/tests/native_tests/language.hy

134 lines
2.5 KiB
Hy
Raw Normal View History

2013-03-06 04:08:53 +01:00
;
2013-03-10 03:14:30 +01:00
(import-from tests.resources kwtest)
2013-03-10 01:46:32 +01:00
(import-from os.path exists isdir isfile)
2013-03-10 03:14:30 +01:00
(import sys)
2013-03-10 01:46:32 +01:00
(defn test-sys-argv []
"NATIVE: test sys.argv"
(assert (isinstance sys.argv list)))
2013-03-07 00:57:21 +01:00
2013-03-10 03:01:59 +01:00
2013-03-10 00:58:47 +01:00
(defn test-lists []
2013-03-06 04:15:45 +01:00
"NATIVE: test lists work right"
2013-03-09 00:18:43 +01:00
(assert (= [1 2 3 4] (+ [1 2] [3 4]))))
2013-03-08 04:52:47 +01:00
2013-03-10 00:58:47 +01:00
(defn test-for-loop []
2013-03-08 04:52:47 +01:00
"NATIVE: test for loops?"
(def count 0)
(for [x [1 2 3 4 5]]
(def count (+ count x)))
2013-03-09 00:18:43 +01:00
(assert (= count 15)))
2013-03-09 02:45:19 +01:00
2013-03-10 00:58:47 +01:00
(defn test-in []
2013-03-09 02:45:19 +01:00
"NATIVE: test in"
(assert (in "a" ["a" "b" "c" "d"]))
(assert (not-in "f" ["a" "b" "c" "d"])))
2013-03-10 00:58:47 +01:00
(defn test-noteq []
2013-03-09 23:15:56 +01:00
"NATIVE: not eq"
(assert (!= 2 3)))
2013-03-10 00:58:47 +01:00
(defn test-numops []
2013-03-09 02:45:19 +01:00
"NATIVE: test numpos"
(assert (> 5 4 3 2 1))
(assert (< 1 2 3 4 5))
(assert (<= 5 5 5 5 ))
(assert (>= 5 5 5 5 )))
2013-03-10 00:58:47 +01:00
(defn test-is []
2013-03-09 06:01:43 +01:00
"NATIVE: test is can deal with None"
(def a null)
(assert (is a null))
(assert (is-not a "b")))
2013-03-10 00:58:47 +01:00
(defn test-branching []
2013-03-09 06:01:43 +01:00
"NATIVE: test if branching"
(if true
(assert (= 1 1))
(assert (= 2 1))))
2013-03-10 00:58:47 +01:00
(defn test-branching-with-do []
2013-03-09 06:01:43 +01:00
"NATIVE: test if branching (multiline)"
(if false
(assert (= 2 1))
(do
(assert (= 1 1))
(assert (= 1 1))
(assert (= 1 1)))))
2013-03-09 06:18:32 +01:00
2013-03-10 00:58:47 +01:00
(defn test-cond []
2013-03-09 06:18:32 +01:00
"NATIVE: test if cond sorta works."
(cond
(= 1 2) (assert (= true false))
(is null null) (assert (= true true))))
2013-03-09 06:55:27 +01:00
2013-03-10 00:58:47 +01:00
(defn test-index []
2013-03-09 06:55:27 +01:00
"NATIVE: Test that dict access works"
2013-03-09 06:56:13 +01:00
(assert (get {"one" "two"} "one") "two")
(assert (= (get [1 2 3 4 5] 1) 2)))
2013-03-09 21:57:13 +01:00
2013-03-10 00:58:47 +01:00
(defn test-lambda []
2013-03-09 21:57:13 +01:00
"NATIVE: test lambda operator"
(def square (lambda [x] (* x x)))
(assert (= 4 (square 2))))
2013-03-10 01:46:32 +01:00
(defn test-imported-bits []
"NATIVE: test the imports work"
(assert (is (exists ".") true))
(assert (is (isdir ".") true))
(assert (is (isfile ".") false)))
2013-03-10 03:01:59 +01:00
(defn foodec [func]
(lambda [] (+ 1 1)))
(decorate-with foodec
(defn tfunction []
(* 2 2)))
(defn test-decorators []
2013-03-10 03:16:28 +01:00
"NATIVE: test decorators."
2013-03-10 03:01:59 +01:00
(assert (= (tfunction) 2)))
2013-03-10 03:14:30 +01:00
(defn test-kwargs []
2013-03-10 03:16:28 +01:00
"NATIVE: test kwargs things."
2013-03-10 03:14:30 +01:00
(assert (= (kwapply (kwtest) {"one" "two"}) {"one" "two"})))
2013-03-10 04:04:38 +01:00
(defn test-dotted []
"NATIVE: test dotted invocation"
(assert (= (.join " " ["one" "two"]) "one two")))
(defn test-exceptions []
"NATIVE: test Exceptions"
(try
2013-03-12 01:17:27 +01:00
(throw (KeyError))
(catch IOError (assert (= 2 1)))
(catch KeyError (do
(+ 1 1)
(assert (= 1 1))))))
2013-03-12 20:46:20 +01:00
(defn test-earmuffs []
"NATIVE: Test earmuffs"
(def *foo* "2")
(def foo "3")
(assert (= *foo* FOO))
(assert (!= *foo* foo)))