adding in more tests.
This commit is contained in:
parent
05893569d7
commit
ce3e7a2d37
@ -86,15 +86,18 @@ class HyASTCompiler(object):
|
||||
def compile_do_expression(self, expr):
|
||||
return [self.compile(x) for x in expr[1:]]
|
||||
|
||||
def _code_branch(self, branch):
|
||||
if isinstance(branch, list):
|
||||
return self._mangle_branch(branch)
|
||||
return self._mangle_branch([branch])
|
||||
|
||||
@builds("if")
|
||||
def compile_if_expression(self, expr):
|
||||
expr.pop(0)
|
||||
lw = lambda w: (self._mangle_branch(w)
|
||||
if isinstance(w, list) else self._mangle_branch([w]))
|
||||
|
||||
return ast.If(test=self.compile(expr.pop(0)),
|
||||
body=lw(self.compile(expr.pop(0))),
|
||||
orelse=lw(self.compile(expr.pop(0))),
|
||||
body=self._code_branch(self.compile(expr.pop(0))),
|
||||
orelse=self._code_branch(self.compile(expr.pop(0))),
|
||||
lineno=expr.start_line,
|
||||
col_offset=expr.start_column)
|
||||
|
||||
@ -260,7 +263,7 @@ class HyASTCompiler(object):
|
||||
kwonlyargs=[],
|
||||
kw_defaults=[],
|
||||
defaults=[]),
|
||||
body=self._mangle_branch([
|
||||
body=self._code_branch([
|
||||
self.compile(x) for x in expression]),
|
||||
decorator_list=[])
|
||||
|
||||
|
@ -28,9 +28,25 @@
|
||||
(assert (>= 5 5 5 5 )))
|
||||
|
||||
|
||||
; implement null
|
||||
;(defn test_is []
|
||||
; "NATIVE: test is"
|
||||
; (def a null)
|
||||
; (assert (is a null))
|
||||
; (assert (is-not a "b")))
|
||||
(defn test_is []
|
||||
"NATIVE: test is can deal with None"
|
||||
(def a null)
|
||||
(assert (is a null))
|
||||
(assert (is-not a "b")))
|
||||
|
||||
|
||||
(defn test_branching []
|
||||
"NATIVE: test if branching"
|
||||
(if true
|
||||
(assert (= 1 1))
|
||||
(assert (= 2 1))))
|
||||
|
||||
|
||||
(defn test_branching_with_do []
|
||||
"NATIVE: test if branching (multiline)"
|
||||
(if false
|
||||
(assert (= 2 1))
|
||||
(do
|
||||
(assert (= 1 1))
|
||||
(assert (= 1 1))
|
||||
(assert (= 1 1)))))
|
||||
|
Loading…
x
Reference in New Issue
Block a user