Remove apply from tests

This commit is contained in:
Kodi Arfer 2017-07-15 16:54:43 -07:00
parent 75e4ad8304
commit 97ecb0b553
6 changed files with 19 additions and 50 deletions

View File

@ -95,9 +95,9 @@
([&optional [a "nop"] [b "p"]] (+ a b)))
(assert (= (fun 1) 1))
(assert (= (apply fun [] {"a" "t"}) "t"))
(assert (= (apply fun ["hello "] {"b" "world"}) "hello world"))
(assert (= (apply fun [] {"a" "hello " "b" "world"}) "hello world")))
(assert (= (fun :a "t") "t"))
(assert (= (fun "hello " :b "world") "hello world"))
(assert (= (fun :a "hello " :b "world") "hello world")))
(defn test-docs []

View File

@ -383,36 +383,12 @@
(defn test-kwargs []
"NATIVE: test kwargs things."
(assert (= (apply kwtest [] {"one" "two"}) {"one" "two"}))
(assert (= (kwtest :one "two") {"one" "two"}))
(setv mydict {"one" "three"})
(assert (= (apply kwtest [] mydict) mydict))
(assert (= (apply kwtest [] ((fn [] {"one" "two"}))) {"one" "two"})))
(assert (= (kwtest #** mydict) mydict))
(assert (= (kwtest #** ((fn [] {"one" "two"}))) {"one" "two"})))
(defn test-apply []
"NATIVE: test working with args and functions"
(defn sumit [a b c] (+ a b c))
(assert (= (apply sumit [1] {"b" 2 "c" 3}) 6))
(assert (= (apply sumit [1 2 2]) 5))
(assert (= (apply sumit [] {"a" 1 "b" 1 "c" 2}) 4))
(assert (= (apply sumit ((fn [] [1 1])) {"c" 1}) 3))
(defn noargs [] [1 2 3])
(assert (= (apply noargs) [1 2 3]))
(defn sumit-mangle [an-a a-b a-c a-d] (+ an-a a-b a-c a-d))
(def Z "a_d")
(assert (= (apply sumit-mangle [] {"an-a" 1 :a-b 2 'a-c 3 Z 4}) 10)))
(defn test-apply-with-methods []
"NATIVE: test apply to call a method"
(setv str "foo {bar}")
(assert (= (apply .format [str] {"bar" "baz"})
(apply .format ["foo {0}" "baz"])
"foo baz"))
(setv lst ["a {0} {1} {foo} {bar}" "b" "c"])
(assert (= (apply .format lst {"foo" "d" "bar" "e"})
"a b c d e")))
(defn test-dotted []
"NATIVE: test dotted invocation"
@ -430,20 +406,20 @@
(assert (= (.meth m) "meth"))
(assert (= (.meth m "foo" "bar") "meth foo bar"))
(assert (= (.meth :b "1" :a "2" m "foo" "bar") "meth foo bar 2 1"))
(assert (= (apply .meth [m "foo" "bar"]) "meth foo bar"))
(assert (= (.meth m #* ["foo" "bar"]) "meth foo bar"))
(setv x.p m)
(assert (= (.p.meth x) "meth"))
(assert (= (.p.meth x "foo" "bar") "meth foo bar"))
(assert (= (.p.meth :b "1" :a "2" x "foo" "bar") "meth foo bar 2 1"))
(assert (= (apply .p.meth [x "foo" "bar"]) "meth foo bar"))
(assert (= (.p.meth x #* ["foo" "bar"]) "meth foo bar"))
(setv x.a (X))
(setv x.a.b m)
(assert (= (.a.b.meth x) "meth"))
(assert (= (.a.b.meth x "foo" "bar") "meth foo bar"))
(assert (= (.a.b.meth :b "1" :a "2" x "foo" "bar") "meth foo bar 2 1"))
(assert (= (apply .a.b.meth [x "foo" "bar"]) "meth foo bar"))
(assert (= (.a.b.meth x #* ["foo" "bar"]) "meth foo bar"))
(assert (is (.isdigit :foo) False)))
@ -1185,8 +1161,8 @@
"NATIVE: test &key function arguments"
(defn foo [&key {"a" None "b" 1}] [a b])
(assert (= (foo) [None 1]))
(assert (= (apply foo [] {"a" 2}) [2 1]))
(assert (= (apply foo [] {"b" 42}) [None 42])))
(assert (= (foo :a 2) [2 1]))
(assert (= (foo :b 42) [None 42])))
(defn test-optional-arguments []

View File

@ -84,12 +84,12 @@
"NATIVE: test macro calling a plain function"
(assert (= 3 (bar 1 2))))
(defn test-optional-and-apply-in-macro []
(defn test-optional-and-unpacking-in-macro []
; https://github.com/hylang/hy/issues/1154
(defn f [&rest args]
(+ "f:" (repr args)))
(defmacro mac [&optional x]
`(apply f [~x]))
`(f #* [~x]))
(assert (= (mac) "f:(None,)")))
(defn test-midtree-yield []

View File

@ -288,8 +288,3 @@
(assert (is (f 3 [1 2]) (!= f-name "in")))
(assert (is (f 2 [1 2]) (= f-name "in")))
(forbid (f 2 [1 2] [3 4])))
#@(pytest.mark.xfail
(defn test-apply-op []
; https://github.com/hylang/hy/issues/647
(assert (= (eval '(apply + ["a" "b" "c"])) "abc"))))

View File

@ -16,15 +16,15 @@
"NATIVE: test keyword-only arguments"
;; keyword-only with default works
(defn kwonly-foo-default-false [&kwonly [foo False]] foo)
(assert (= (apply kwonly-foo-default-false) False))
(assert (= (apply kwonly-foo-default-false [] {"foo" True}) True))
(assert (= (kwonly-foo-default-false) False))
(assert (= (kwonly-foo-default-false :foo True) True))
;; keyword-only without default ...
(defn kwonly-foo-no-default [&kwonly foo] foo)
(setv attempt-to-omit-default (try
(kwonly-foo-no-default)
(except [e [Exception]] e)))
;; works
(assert (= (apply kwonly-foo-no-default [] {"foo" "quux"}) "quux"))
(assert (= (kwonly-foo-no-default :foo "quux") "quux"))
;; raises TypeError with appropriate message if not supplied
(assert (isinstance attempt-to-omit-default TypeError))
(assert (in "missing 1 required keyword-only argument: 'foo'"
@ -32,8 +32,7 @@
;; keyword-only with other arg types works
(defn function-of-various-args [a b &rest args &kwonly foo &kwargs kwargs]
(, a b args foo kwargs))
(assert (= (apply function-of-various-args
[1 2 3 4] {"foo" 5 "bar" 6 "quux" 7})
(assert (= (function-of-various-args 1 2 3 4 :foo 5 :bar 6 :quux 7)
(, 1 2 (, 3 4) 5 {"bar" 6 "quux" 7}))))

View File

@ -100,9 +100,8 @@
"Increments each argument passed to the decorated function."
((wraps func)
(fn [&rest args &kwargs kwargs]
(apply func
(map inc args)
(dict-comp k (inc v) [[k v] (.items kwargs)])))))
(func #* (map inc args)
#** (dict-comp k (inc v) [[k v] (.items kwargs)])))))
#@(increment-arguments
(defn foo [&rest args &kwargs kwargs]