Merge branch 'master' into pr/884
Conflicts: tests/compilers/test_ast.py
This commit is contained in:
commit
80b2386c35
@ -459,8 +459,9 @@ class HyASTCompiler(object):
|
|||||||
try:
|
try:
|
||||||
value = next(exprs_iter)
|
value = next(exprs_iter)
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
msg = "Keyword argument {kw} needs a value"
|
raise HyTypeError(expr,
|
||||||
raise HyCompileError(msg.format(kw=str(expr)))
|
"Keyword argument {kw} needs "
|
||||||
|
"a value.".format(kw=str(expr[1:])))
|
||||||
|
|
||||||
compiled_value = self.compile(value)
|
compiled_value = self.compile(value)
|
||||||
ret += compiled_value
|
ret += compiled_value
|
||||||
|
@ -308,6 +308,9 @@ def t_identifier(p):
|
|||||||
if p.endswith("?") and p != "?":
|
if p.endswith("?") and p != "?":
|
||||||
p = "is_%s" % (p[:-1])
|
p = "is_%s" % (p[:-1])
|
||||||
|
|
||||||
|
if p.endswith("!") and p != "!":
|
||||||
|
p = "%s_bang" % (p[:-1])
|
||||||
|
|
||||||
return p
|
return p
|
||||||
|
|
||||||
obj = ".".join([mangle(part) for part in obj.split(".")])
|
obj = ".".join([mangle(part) for part in obj.split(".")])
|
||||||
|
@ -439,6 +439,16 @@ def test_lambda_list_keywords_mixed():
|
|||||||
" (list x xs kwxs kwoxs))")
|
" (list x xs kwxs kwoxs))")
|
||||||
|
|
||||||
|
|
||||||
|
def test_missing_keyword_argument_value():
|
||||||
|
"""Ensure the compiler chokes on missing keyword argument values."""
|
||||||
|
try:
|
||||||
|
can_compile("((fn [x] x) :x)")
|
||||||
|
except HyTypeError as e:
|
||||||
|
assert(e.message == "Keyword argument :x needs a value.")
|
||||||
|
else:
|
||||||
|
assert(False)
|
||||||
|
|
||||||
|
|
||||||
def test_ast_unicode_strings():
|
def test_ast_unicode_strings():
|
||||||
"""Ensure we handle unicode strings correctly"""
|
"""Ensure we handle unicode strings correctly"""
|
||||||
|
|
||||||
@ -521,7 +531,16 @@ def test_cons_correct():
|
|||||||
can_compile("(cons a b)")
|
can_compile("(cons a b)")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_bad_setv():
|
def test_bad_setv():
|
||||||
"""Ensure setv handles error cases"""
|
"""Ensure setv handles error cases"""
|
||||||
cant_compile("(setv if 1)")
|
cant_compile("(setv if 1)")
|
||||||
cant_compile("(setv (a b) [1 2])")
|
cant_compile("(setv (a b) [1 2])")
|
||||||
|
|
||||||
|
|
||||||
|
def test_defn():
|
||||||
|
"""Ensure that defn works correctly in various corner cases"""
|
||||||
|
cant_compile("(defn if [] 1)")
|
||||||
|
cant_compile("(defn \"hy\" [] 1)")
|
||||||
|
cant_compile("(defn :hy [] 1)")
|
||||||
|
can_compile("(defn &hy [] 1)")
|
||||||
|
@ -326,6 +326,24 @@ def test_lex_mangling_qmark():
|
|||||||
assert entry == [HySymbol(".is_foo.bar.is_baz")]
|
assert entry == [HySymbol(".is_foo.bar.is_baz")]
|
||||||
|
|
||||||
|
|
||||||
|
def test_lex_mangling_bang():
|
||||||
|
"""Ensure that identifiers ending with a bang get mangled ok"""
|
||||||
|
entry = tokenize("foo!")
|
||||||
|
assert entry == [HySymbol("foo_bang")]
|
||||||
|
entry = tokenize("!")
|
||||||
|
assert entry == [HySymbol("!")]
|
||||||
|
entry = tokenize("im!foo")
|
||||||
|
assert entry == [HySymbol("im!foo")]
|
||||||
|
entry = tokenize(".foo!")
|
||||||
|
assert entry == [HySymbol(".foo_bang")]
|
||||||
|
entry = tokenize("foo.bar!")
|
||||||
|
assert entry == [HySymbol("foo.bar_bang")]
|
||||||
|
entry = tokenize("foo!.bar")
|
||||||
|
assert entry == [HySymbol("foo_bang.bar")]
|
||||||
|
entry = tokenize(".foo!.bar.baz!")
|
||||||
|
assert entry == [HySymbol(".foo_bang.bar.baz_bang")]
|
||||||
|
|
||||||
|
|
||||||
def test_simple_cons():
|
def test_simple_cons():
|
||||||
"""Check that cons gets tokenized correctly"""
|
"""Check that cons gets tokenized correctly"""
|
||||||
entry = tokenize("(a . b)")[0]
|
entry = tokenize("(a . b)")[0]
|
||||||
|
@ -673,6 +673,12 @@
|
|||||||
(assert (= 43 (my-fun 42))))
|
(assert (= 43 (my-fun 42))))
|
||||||
|
|
||||||
|
|
||||||
|
(defn test-defn-lambdakey []
|
||||||
|
"NATIVE: test defn with a &symbol function name"
|
||||||
|
(defn &hy [] 1)
|
||||||
|
(assert (= (&hy) 1)))
|
||||||
|
|
||||||
|
|
||||||
(defn test-defn-do []
|
(defn test-defn-do []
|
||||||
"NATIVE: test defn evaluation order with do"
|
"NATIVE: test defn evaluation order with do"
|
||||||
(setv acc [])
|
(setv acc [])
|
||||||
|
Loading…
Reference in New Issue
Block a user