Remove tests of cons cells
This commit is contained in:
parent
736426fc12
commit
097647bf6f
@ -569,11 +569,6 @@ def test_attribute_empty():
|
||||
cant_compile('[2].foo')
|
||||
|
||||
|
||||
def test_cons_correct():
|
||||
"""Ensure cons gets compiled correctly"""
|
||||
can_compile("(cons a b)")
|
||||
|
||||
|
||||
def test_invalid_list_comprehension():
|
||||
"""Ensure that invalid list comprehensions do not break the compiler"""
|
||||
cant_compile("(genexpr x [])")
|
||||
|
@ -1,71 +0,0 @@
|
||||
;; Copyright 2018 the authors.
|
||||
;; This file is part of Hy, which is free software licensed under the Expat
|
||||
;; license. See the LICENSE.
|
||||
|
||||
(defmacro car [x] `(get ~x 0))
|
||||
(defmacro cdr [x] `(cut ~x 1))
|
||||
|
||||
|
||||
(defn test-cons-mutability []
|
||||
"Test the mutability of conses"
|
||||
(setv tree (cons (cons 1 2) (cons 2 3)))
|
||||
(setv (car tree) "foo")
|
||||
(assert (= tree (cons "foo" (cons 2 3))))
|
||||
(setv (cdr tree) "bar")
|
||||
(assert (= tree (cons "foo" "bar"))))
|
||||
|
||||
|
||||
(defn test-cons-quoting []
|
||||
"Test quoting of conses"
|
||||
(assert (= (cons 1 2) (quote (1 . 2))))
|
||||
(assert (= (quote foo) (car (quote (foo . bar)))))
|
||||
(assert (= (quote bar) (cdr (quote (foo . bar))))))
|
||||
|
||||
|
||||
(defn test-cons-behavior []
|
||||
"NATIVE: test the behavior of cons is consistent"
|
||||
(defn t= [a b]
|
||||
(and (= a b) (= (type a) (type b))))
|
||||
(assert (t= (cons 1 2) '(1 . 2)))
|
||||
(assert (t= (cons 1 None) '(1)))
|
||||
(assert (t= (cons None 2) '(None . 2)))
|
||||
(assert (t= (cons 1 []) [1]))
|
||||
(setv tree (cons (cons 1 2) (cons 2 3)))
|
||||
(assert (t= (car tree) (cons 1 2)))
|
||||
(assert (t= (cdr tree) (cons 2 3))))
|
||||
|
||||
|
||||
(defn test-cons-iteration []
|
||||
"NATIVE: test the iteration behavior of cons"
|
||||
(setv x '(0 1 2 3 4 . 5))
|
||||
(setv it (iter x))
|
||||
(for* [i (range 6)]
|
||||
(assert (= i (next it))))
|
||||
(assert
|
||||
(= 'success
|
||||
(try
|
||||
(do
|
||||
(next it)
|
||||
'failurenext)
|
||||
(except [e TypeError] (if (= e.args (, "Iteration on malformed cons"))
|
||||
'success
|
||||
'failureexc))
|
||||
(except [e Exception] 'failureexc2)))))
|
||||
|
||||
|
||||
(defn test-cons? []
|
||||
"NATIVE: test behavior of cons?"
|
||||
(assert (cons? (cons 1 2)))
|
||||
(assert (cons? '(1 . 2)))
|
||||
(assert (cons? '(1 2 3 . 4)))
|
||||
(assert (cons? (list* 1 2 3)))
|
||||
(assert (not (cons? (cons 1 [2]))))
|
||||
(assert (not (cons? (list* 1 None)))))
|
||||
|
||||
|
||||
(defn test-list* []
|
||||
"NATIVE: test behavior of list*"
|
||||
(assert (= 1 (list* 1)))
|
||||
(assert (= (cons 1 2) (list* 1 2)))
|
||||
(assert (= (cons 1 (cons 2 3)) (list* 1 2 3)))
|
||||
(assert (= '(1 2 3 4 . 5) (list* 1 2 3 4 5))))
|
@ -10,7 +10,6 @@
|
||||
(setv walk-form '(print {"foo" "bar"
|
||||
"array" [1 2 3 [4]]
|
||||
"something" (+ 1 2 3 4)
|
||||
"cons!" (cons 1 2)
|
||||
"quoted?" '(foo)}))
|
||||
|
||||
(defn collector [acc x]
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
from math import isnan
|
||||
from hy.models import (HyExpression, HyInteger, HyFloat, HyComplex, HySymbol,
|
||||
HyString, HyDict, HyList, HySet, HyCons, HyKeyword)
|
||||
HyString, HyDict, HyList, HySet, HyKeyword)
|
||||
from hy.lex import LexException, PrematureEndOfInput, tokenize
|
||||
import pytest
|
||||
|
||||
@ -350,34 +350,6 @@ def test_lex_comment_382():
|
||||
assert entry == [HySymbol("foo")]
|
||||
|
||||
|
||||
def test_simple_cons():
|
||||
"""Check that cons gets tokenized correctly"""
|
||||
entry = tokenize("(a . b)")[0]
|
||||
assert entry == HyCons(HySymbol("a"), HySymbol("b"))
|
||||
|
||||
|
||||
def test_dotted_list():
|
||||
"""Check that dotted lists get tokenized correctly"""
|
||||
entry = tokenize("(a b c . (d . e))")[0]
|
||||
assert entry == HyCons(HySymbol("a"),
|
||||
HyCons(HySymbol("b"),
|
||||
HyCons(HySymbol("c"),
|
||||
HyCons(HySymbol("d"),
|
||||
HySymbol("e")))))
|
||||
|
||||
|
||||
def test_cons_list():
|
||||
"""Check that cons of something and a list gets tokenized as a list"""
|
||||
entry = tokenize("(a . [])")[0]
|
||||
assert entry == HyList([HySymbol("a")])
|
||||
assert type(entry) == HyList
|
||||
entry = tokenize("(a . ())")[0]
|
||||
assert entry == HyExpression([HySymbol("a")])
|
||||
assert type(entry) == HyExpression
|
||||
entry = tokenize("(a b . {})")[0]
|
||||
assert entry == HyDict([HySymbol("a"), HySymbol("b")])
|
||||
assert type(entry) == HyDict
|
||||
|
||||
def test_discard():
|
||||
"""Check that discarded terms are removed properly."""
|
||||
# empty
|
||||
|
@ -7,8 +7,7 @@ import hy
|
||||
from clint.textui.colored import clean
|
||||
from hy._compat import long_type, str_type
|
||||
from hy.models import (wrap_value, replace_hy_obj, HyString, HyInteger, HyList,
|
||||
HyDict, HySet, HyExpression, HyCons, HyComplex, HyFloat,
|
||||
pretty)
|
||||
HyDict, HySet, HyExpression, HyComplex, HyFloat, pretty)
|
||||
|
||||
|
||||
def test_wrap_long_type():
|
||||
@ -96,41 +95,6 @@ def test_set():
|
||||
assert hyset == [3, 1, 2, 2]
|
||||
|
||||
|
||||
def test_cons_slicing():
|
||||
"""Check that cons slicing works as expected"""
|
||||
cons = HyCons("car", "cdr")
|
||||
assert cons[0] == "car"
|
||||
assert cons[1:] == "cdr"
|
||||
try:
|
||||
cons[:]
|
||||
assert True is False
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
try:
|
||||
cons[1]
|
||||
assert True is False
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
|
||||
def test_cons_replacing():
|
||||
"""Check that assigning to a cons works as expected"""
|
||||
cons = HyCons("foo", "bar")
|
||||
cons[0] = "car"
|
||||
|
||||
assert cons == HyCons("car", "bar")
|
||||
|
||||
cons[1:] = "cdr"
|
||||
assert cons == HyCons("car", "cdr")
|
||||
|
||||
try:
|
||||
cons[:] = "foo"
|
||||
assert True is False
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
|
||||
def test_number_model_copy():
|
||||
i = HyInteger(42)
|
||||
assert (i == copy.copy(i))
|
||||
@ -146,7 +110,7 @@ def test_number_model_copy():
|
||||
|
||||
|
||||
PRETTY_STRINGS = {
|
||||
k % ('[1.0] {1.0} (1.0) #{1.0} (0.0 1.0 . 2.0)',):
|
||||
k % ('[1.0] {1.0} (1.0) #{1.0}',):
|
||||
v.format("""
|
||||
HyList([
|
||||
HyFloat(1.0)]),
|
||||
@ -156,16 +120,12 @@ PRETTY_STRINGS = {
|
||||
HyExpression([
|
||||
HyFloat(1.0)]),
|
||||
HySet([
|
||||
HyFloat(1.0)]),
|
||||
<HyCons (
|
||||
HyFloat(0.0)
|
||||
HyFloat(1.0)
|
||||
. HyFloat(2.0))>""")
|
||||
HyFloat(1.0)])""")
|
||||
for k, v in {'[%s]': 'HyList([{}])',
|
||||
'#{%s}': 'HySet([{}])'}.items()}
|
||||
|
||||
PRETTY_STRINGS.update({
|
||||
'{[1.0] {1.0} (1.0) #{1.0} (0.0 1.0 . 2.0)}':
|
||||
'{[1.0] {1.0} (1.0) #{1.0}}':
|
||||
"""HyDict([
|
||||
HyList([
|
||||
HyFloat(1.0)]),
|
||||
@ -177,29 +137,7 @@ PRETTY_STRINGS.update({
|
||||
HyFloat(1.0)]),
|
||||
HySet([
|
||||
HyFloat(1.0)])
|
||||
,
|
||||
<HyCons (
|
||||
HyFloat(0.0)
|
||||
HyFloat(1.0)
|
||||
. HyFloat(2.0))> # odd
|
||||
])"""
|
||||
,
|
||||
'([1.0] {1.0} (1.0) #{1.0} (0.0 1.0 . 2.0) . 3.0)':
|
||||
"""<HyCons (
|
||||
HyList([
|
||||
HyFloat(1.0)])
|
||||
HyDict([
|
||||
HyFloat(1.0) # odd
|
||||
])
|
||||
HyExpression([
|
||||
HyFloat(1.0)])
|
||||
HySet([
|
||||
HyFloat(1.0)])
|
||||
<HyCons (
|
||||
HyFloat(0.0)
|
||||
HyFloat(1.0)
|
||||
. HyFloat(2.0))>
|
||||
. HyFloat(3.0))>"""
|
||||
,
|
||||
'[1.0 1j [] {} () #{}]':
|
||||
"""HyList([
|
||||
@ -239,8 +177,6 @@ PRETTY_STRINGS.update({
|
||||
def test_compound_model_repr():
|
||||
HY_LIST_MODELS = (HyExpression, HyDict, HySet, HyList)
|
||||
with pretty(False):
|
||||
assert eval(repr(HyCons(1, 2))).__class__ is HyCons
|
||||
assert eval(repr(HyCons(1, 2))) == HyCons(1, 2)
|
||||
for model in HY_LIST_MODELS:
|
||||
assert eval(repr(model())).__class__ is model
|
||||
assert eval(repr(model([1, 2]))) == model([1, 2])
|
||||
|
Loading…
Reference in New Issue
Block a user