def parse(self, src): if src not in self.cache: src = tools.unindent(src) node = ast.parse(src) lenatu.augment(node) self.cache[src] = node else: node = self.cache[src] return node
def testOneLineNoIndent(self): self.assertEqual("x=1", tools.unindent("x=1"))
def testEmptyString(self): self.assertEqual("", tools.unindent(""))
def testPartiallyIndendedComment(self): self.assertEqual("#comment\nx=1", tools.unindent(" #comment\n x=1"))
def testIgnoreComments(self): self.assertEqual("#comment\nx=1", tools.unindent("#comment\n x=1"))
def testIgnoreEmtptyLines(self): self.assertEqual("\nx=1", tools.unindent("\n x=1"))
def testStructurePreservedTabs(self): self.assertEqual("def foo():\n x=1", tools.unindent("\tdef foo():\n\t x=1"))
def testStructurePreservedSpaces(self): self.assertEqual("def foo():\n x=1", tools.unindent(" def foo():\n x=1"))
def testTwoLinesMixed(self): self.assertEqual("x=1\ny=2", tools.unindent("\tx=1\n y=2"))
def testTwoLinesTabs(self): self.assertEqual("x=1\ny=2", tools.unindent("\tx=1\n\ty=2"))
def testTwoLinesSpaces(self): self.assertEqual("x=1\ny=2", tools.unindent(" x=1\n y=2"))
def testOneLineMix(self): self.assertEqual("x=1", tools.unindent(" \t \t x=1"))