Test the use of and
in shadowed chained comparisons
This commit is contained in:
parent
b89d142e95
commit
1abf293793
@ -50,6 +50,7 @@
|
|||||||
|
|
||||||
(defn test-shadow-compare []
|
(defn test-shadow-compare []
|
||||||
"NATIVE: test shadow compare"
|
"NATIVE: test shadow compare"
|
||||||
|
|
||||||
(for [x [< <= = != >= >]]
|
(for [x [< <= = != >= >]]
|
||||||
(assert (try
|
(assert (try
|
||||||
(x)
|
(x)
|
||||||
@ -59,6 +60,7 @@
|
|||||||
(x 1)
|
(x 1)
|
||||||
(except [TypeError] True)
|
(except [TypeError] True)
|
||||||
(else (raise AssertionError)))))
|
(else (raise AssertionError)))))
|
||||||
|
|
||||||
(for [(, x y) [[< >=]
|
(for [(, x y) [[< >=]
|
||||||
[<= >]
|
[<= >]
|
||||||
[= !=]]]
|
[= !=]]]
|
||||||
@ -67,6 +69,7 @@
|
|||||||
[1 1]
|
[1 1]
|
||||||
[2 2]]]
|
[2 2]]]
|
||||||
(assert (= (apply x args) (not (apply y args))))))
|
(assert (= (apply x args) (not (apply y args))))))
|
||||||
|
|
||||||
(let [s-lt <
|
(let [s-lt <
|
||||||
s-gt >
|
s-gt >
|
||||||
s-le <=
|
s-le <=
|
||||||
@ -84,4 +87,15 @@
|
|||||||
(assert (apply s-eq [1 1 1 1 1]))
|
(assert (apply s-eq [1 1 1 1 1]))
|
||||||
(assert (not (apply s-eq [1 1 2 1 1])))
|
(assert (not (apply s-eq [1 1 2 1 1])))
|
||||||
(assert (apply s-ne [1 2 3 4 5]))
|
(assert (apply s-ne [1 2 3 4 5]))
|
||||||
(assert (not (apply s-ne [1 1 2 3 4])))))
|
(assert (not (apply s-ne [1 1 2 3 4]))))
|
||||||
|
|
||||||
|
; Make sure chained comparisons use `and`, not `&`.
|
||||||
|
; https://github.com/hylang/hy/issues/1191
|
||||||
|
(defclass C [object] [
|
||||||
|
__init__ (fn [self x]
|
||||||
|
(setv self.x x))
|
||||||
|
__lt__ (fn [self other]
|
||||||
|
self.x)])
|
||||||
|
(assert (= (< (C "a") (C "b") (C "c")) "b"))
|
||||||
|
(setv f <)
|
||||||
|
(assert (= (f (C "a") (C "b") (C "c")) "b")))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user