def testGetFormsLambdaList2(self): st = """def foo(a,) {}""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual(forms, [(FORM_TYPE, [(ATOM_TYPE, "defun"), (ATOM_TYPE, "foo"), (FORM_TYPE, [(ATOM_TYPE, "a")])])])
def testGetFormsClass1(self): st = """class foo {}""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual(forms, [(FORM_TYPE, [(ATOM_TYPE, "defclass"), (ATOM_TYPE, "foo"), (FORM_TYPE, []), (FORM_TYPE, [])])])
def testGetFormsBodyBlock5(self): st = """x=foo{}""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo(), True) self.assertEqual(forms, [(COMMENT_TYPE, "; source line # 1"), (FORM_TYPE, [(ATOM_TYPE, "setf"), (ATOM_TYPE, "x"), (FORM_TYPE, [(ATOM_TYPE, "foo")])])])
def testGetFormsImplicitLexscope9(self): st = """progn{ foo(x) x=0 lexscope explicit global z z=1 lexscope implicit y=2 foo(x)}""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo(implScope=True, explScopeWarn=True)) self.assertEqual(forms, [(FORM_TYPE, [ (ATOM_TYPE, "progn"), (FORM_TYPE, [(ATOM_TYPE, "foo"), (ATOM_TYPE, "x")]), (FORM_TYPE, [(ATOM_TYPE, "let"), (FORM_TYPE, [(ATOM_TYPE, "x")]), (FORM_TYPE, [(ATOM_TYPE, "setf"), (ATOM_TYPE, "x"), (ATOM_TYPE, "0")]), (FORM_TYPE, [(ATOM_TYPE, "setf"), (ATOM_TYPE, "z"), (ATOM_TYPE, "1")]), (FORM_TYPE, [(ATOM_TYPE, "let"), (FORM_TYPE, [(ATOM_TYPE, "y")]), (FORM_TYPE, [(ATOM_TYPE, "setf"), (ATOM_TYPE, "y"), (ATOM_TYPE, "2")]), (FORM_TYPE, [(ATOM_TYPE, "foo"), (ATOM_TYPE, "x")])])]) ])])
def testGetFormsFletAndReturn1(self): st = """flet foo {return} boo (a) {return a} pr (b) {return} {foo(1,2)-boo(3,4)}""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual(forms, [(FORM_TYPE, [ (ATOM_TYPE, "flet"), (FORM_TYPE, [(FORM_TYPE, [(ATOM_TYPE, "foo"), (FORM_TYPE, []), (FORM_TYPE, [(ATOM_TYPE, "return-from"), (ATOM_TYPE, "foo"), (FORM_TYPE, [])])]), (FORM_TYPE, [(ATOM_TYPE, "boo"), (FORM_TYPE, [(ATOM_TYPE, "a")]), (FORM_TYPE, [(ATOM_TYPE, "return-from"), (ATOM_TYPE, "boo"), (ATOM_TYPE, "a")])]), (FORM_TYPE, [(ATOM_TYPE, "pr"), (FORM_TYPE, [(ATOM_TYPE, "b")]), (FORM_TYPE, [(ATOM_TYPE, "return-from"), (ATOM_TYPE, "pr"), (FORM_TYPE, [])])])]), (FORM_TYPE, [(ATOM_TYPE, "_-_"), (FORM_TYPE, [(ATOM_TYPE, "foo"), (ATOM_TYPE, "1"), (ATOM_TYPE, "2")]), (FORM_TYPE, [(ATOM_TYPE, "boo"), (ATOM_TYPE, "3"), (ATOM_TYPE, "4")])]) ])])
def testGetFormsObjMeth3(self): st = """x=y.foo()""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual(forms, [(FORM_TYPE, [(ATOM_TYPE, "setf"), (ATOM_TYPE, "x"), (FORM_TYPE, [(ATOM_TYPE, "foo"), (ATOM_TYPE, "y")])])])
def testGetFormsColumn7(self): st = """x='foo:a""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual(forms, [(FORM_TYPE, [(ATOM_TYPE, "setf"), (ATOM_TYPE, "x"), (SHORTCUT_TYPE, "'", (ATOM_TYPE, "foo:a"))])])
def testGetFormsBlockForm8(self): st = """def $foo {}""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual(forms, [(FORM_TYPE, [(ATOM_TYPE, "defun"), (SHORTCUT_TYPE, ",", (ATOM_TYPE, "foo")), (FORM_TYPE, [])])])
def testGetFormsOperForm8(self): st = """x+'y""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual(forms, [(FORM_TYPE, [(ATOM_TYPE, "_+_"), (ATOM_TYPE, "x"), (SHORTCUT_TYPE, "'", (ATOM_TYPE, "y"))])])
def testGetFormsMeth1(self): st = """meth foo (a){}""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual(forms, [(FORM_TYPE, [(ATOM_TYPE, "defmethod"), (ATOM_TYPE, "foo"), (FORM_TYPE, [(ATOM_TYPE, "a")])])])
def testGetFormsBlockName4(self): st = """block $foo {a}""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual(forms, [(FORM_TYPE, [(ATOM_TYPE, "block"), (SHORTCUT_TYPE, ",", (ATOM_TYPE, "foo")), (ATOM_TYPE, "a")])])
def testGetFormsDoLists2(self): st = """do () () {a}""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual(forms, [(FORM_TYPE, [(ATOM_TYPE, "do"), (FORM_TYPE, []), (FORM_TYPE, [(ATOM_TYPE, LISP_NIL)]), (ATOM_TYPE, "a")])])
def testGetFormsArray2(self): st = """x=[]""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual( forms, [(FORM_TYPE, [(ATOM_TYPE, "setf"), (ATOM_TYPE, "x"), (FORM_TYPE, [(ATOM_TYPE, "_make-vector_")])])])
def testGetFormsLetList3(self): st = """let (x,y) {a}""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual(forms, [(FORM_TYPE, [(ATOM_TYPE, "let"), (FORM_TYPE, [(ATOM_TYPE, "x"), (ATOM_TYPE, "y")]), (ATOM_TYPE, "a")])])
def testGetFormsFlet2(self): st = """flet foo (a,b) {a+b} boo (a,b) {a*b} pr {} {foo(1,2)-boo(3,4)}""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual(forms, [(FORM_TYPE, [ (ATOM_TYPE, "flet"), (FORM_TYPE, [(FORM_TYPE, [(ATOM_TYPE, "foo"), (FORM_TYPE, [(ATOM_TYPE, "a"), (ATOM_TYPE, "b")]), (FORM_TYPE, [(ATOM_TYPE, "_+_"), (ATOM_TYPE, "a"), (ATOM_TYPE, "b")])]), (FORM_TYPE, [(ATOM_TYPE, "boo"), (FORM_TYPE, [(ATOM_TYPE, "a"), (ATOM_TYPE, "b")]), (FORM_TYPE, [(ATOM_TYPE, "_*_"), (ATOM_TYPE, "a"), (ATOM_TYPE, "b")])]), (FORM_TYPE, [(ATOM_TYPE, "pr"), (FORM_TYPE, [])])]), (FORM_TYPE, [(ATOM_TYPE, "_-_"), (FORM_TYPE, [(ATOM_TYPE, "foo"), (ATOM_TYPE, "1"), (ATOM_TYPE, "2")]), (FORM_TYPE, [(ATOM_TYPE, "boo"), (ATOM_TYPE, "3"), (ATOM_TYPE, "4")])]) ])])
def testGetFormsOperForm22(self): st = """x+-y""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual(forms, [(FORM_TYPE, [(ATOM_TYPE, "_+_"), (ATOM_TYPE, "x"), (FORM_TYPE, [(ATOM_TYPE, "_unary-_"), (ATOM_TYPE, "y")])])])
def testGetFormDict1(self): st = """x={}""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual( forms, [(FORM_TYPE, [(ATOM_TYPE, "setf"), (ATOM_TYPE, "x"), (FORM_TYPE, [(ATOM_TYPE, "_make-hash-table_")])])])
def testGetFormsString2(self): st = """x="Hello, "+"World!" """ forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual( forms, [(FORM_TYPE, [(ATOM_TYPE, "setf"), (ATOM_TYPE, "x"), (FORM_TYPE, [(ATOM_TYPE, "_+_"), (ATOM_TYPE, "\"Hello, \""), (ATOM_TYPE, "\"World!\"")])])])
def testGetFormsBlockForm10(self): st = """def setter foo {}""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual(forms, [(FORM_TYPE, [(ATOM_TYPE, "defun"), (FORM_TYPE, [(ATOM_TYPE, "setf"), (ATOM_TYPE, "foo")]), (FORM_TYPE, [])])])
def testGetFormsCLisp1(self): st = """x=cl{{(- 1 2)}}-3\n""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual(forms, [(FORM_TYPE, [(ATOM_TYPE, "setf"), (ATOM_TYPE, "x"), (FORM_TYPE, [(ATOM_TYPE, "_-_"), (ATOM_TYPE, "(- 1 2)\n"), (ATOM_TYPE, "3")])])])
def testGetFormsFunc4(self): st = """x=foo(a,b)""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual(forms, [(FORM_TYPE, [(ATOM_TYPE, "setf"), (ATOM_TYPE, "x"), (FORM_TYPE, [(ATOM_TYPE, "foo"), (ATOM_TYPE, "a"), (ATOM_TYPE, "b")])])])
def testGetFormsBracketForm4(self): st = """~() ; comment here ~() ~()""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual(forms, [(FORM_TYPE, []), (COMMENT_TYPE, "; comment here"), (FORM_TYPE, []), (FORM_TYPE, [])])
def testGetFormsComplexNum2(self): st = """x=#c(3.4e-10,23/45)""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual(forms, [(FORM_TYPE, [(ATOM_TYPE, "setf"), (ATOM_TYPE, "x"), (FORM_TYPE, [(ATOM_TYPE, "complex"), (ATOM_TYPE, "3.4e-10"), (ATOM_TYPE, "23/45")])])])
def testGetFormsUse5(self): st = """use {x=a,y=b} a(1) b(2)""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual(forms, [(FORM_TYPE, [(ATOM_TYPE, "x"), (ATOM_TYPE, "1")]), (FORM_TYPE, [(ATOM_TYPE, "y"), (ATOM_TYPE, "2")])])
def testGetFormsLambdaList9(self): st = """def foo(a,b=?bPresent) {}""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual(forms, [(FORM_TYPE, [ (ATOM_TYPE, "defun"), (ATOM_TYPE, "foo"), (FORM_TYPE, [(ATOM_TYPE, "a"), (ATOM_TYPE, "&optional"), (FORM_TYPE, [(ATOM_TYPE, "b"), (ATOM_TYPE, "nil"), (ATOM_TYPE, "bPresent")])]) ])])
def testGetFormGetitem10(self): st = """a[->9,2]""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual( forms, [(FORM_TYPE, [(ATOM_TYPE, "_getitem_"), (ATOM_TYPE, "a"), (FORM_TYPE, [(ATOM_TYPE, "_make-slice_"), (ATOM_TYPE, "nil"), (ATOM_TYPE, "9"), (ATOM_TYPE, "2")])])])
def testGetFormsStruct2(self): st = """struct foo {a b c}""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual(forms, [(FORM_TYPE, [(ATOM_TYPE, "defstruct"), (FORM_TYPE, [(ATOM_TYPE, "foo")]), (ATOM_TYPE, "a"), (ATOM_TYPE, "b"), (ATOM_TYPE, "c")])])
def testGetFormsBreak3(self): st = """break from blockName x=3""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual(forms, [(FORM_TYPE, [(ATOM_TYPE, "return-from"), (ATOM_TYPE, "blockName"), (FORM_TYPE, [(ATOM_TYPE, "setf"), (ATOM_TYPE, "x"), (ATOM_TYPE, "3")])])])
def testGetFormsReturn2(self): st = """def foo {return a}""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual(forms, [(FORM_TYPE, [(ATOM_TYPE, "defun"), (ATOM_TYPE, "foo"), (FORM_TYPE, []), (FORM_TYPE, [(ATOM_TYPE, "return-from"), (ATOM_TYPE, "foo"), (ATOM_TYPE, "a")])])])
def testGetFormsBlockForm4(self): st = """def foo () {~() ~()}""" forms = getForms(GrowingList(StringIO.StringIO(st)), LevelInfo()) self.assertEqual(forms, [(FORM_TYPE, [(ATOM_TYPE, "defun"), (ATOM_TYPE, "foo"), (FORM_TYPE, []), (FORM_TYPE, []), (FORM_TYPE, [])])])