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):
|
def compile_do_expression(self, expr):
|
||||||
return [self.compile(x) for x in expr[1:]]
|
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")
|
@builds("if")
|
||||||
def compile_if_expression(self, expr):
|
def compile_if_expression(self, expr):
|
||||||
expr.pop(0)
|
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)),
|
return ast.If(test=self.compile(expr.pop(0)),
|
||||||
body=lw(self.compile(expr.pop(0))),
|
body=self._code_branch(self.compile(expr.pop(0))),
|
||||||
orelse=lw(self.compile(expr.pop(0))),
|
orelse=self._code_branch(self.compile(expr.pop(0))),
|
||||||
lineno=expr.start_line,
|
lineno=expr.start_line,
|
||||||
col_offset=expr.start_column)
|
col_offset=expr.start_column)
|
||||||
|
|
||||||
@ -260,7 +263,7 @@ class HyASTCompiler(object):
|
|||||||
kwonlyargs=[],
|
kwonlyargs=[],
|
||||||
kw_defaults=[],
|
kw_defaults=[],
|
||||||
defaults=[]),
|
defaults=[]),
|
||||||
body=self._mangle_branch([
|
body=self._code_branch([
|
||||||
self.compile(x) for x in expression]),
|
self.compile(x) for x in expression]),
|
||||||
decorator_list=[])
|
decorator_list=[])
|
||||||
|
|
||||||
|
@ -28,9 +28,25 @@
|
|||||||
(assert (>= 5 5 5 5 )))
|
(assert (>= 5 5 5 5 )))
|
||||||
|
|
||||||
|
|
||||||
; implement null
|
(defn test_is []
|
||||||
;(defn test_is []
|
"NATIVE: test is can deal with None"
|
||||||
; "NATIVE: test is"
|
(def a null)
|
||||||
; (def a null)
|
(assert (is a null))
|
||||||
; (assert (is a null))
|
(assert (is-not a "b")))
|
||||||
; (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