Mercurial > lcfOS
diff test/testc3.py @ 389:2ec730e45ea1
Added check for recursive struct
author | Windel Bouwman |
---|---|
date | Fri, 16 May 2014 12:29:31 +0200 |
parents | c2ddc8a36f5e |
children | 6ae782a085e0 |
line wrap: on
line diff
--- a/test/testc3.py Fri May 02 14:51:46 2014 +0200 +++ b/test/testc3.py Fri May 16 12:29:31 2014 +0200 @@ -64,7 +64,7 @@ def expectErrors(self, snippet, rows): """ Helper to test for expected errors on rows """ - ircode = list(self.builder.build([io.StringIO(snippet)])) + list(self.builder.build([io.StringIO(snippet)])) actualErrors = [err.row for err in self.diag.diags] if rows != actualErrors: self.diag.printErrors() @@ -106,7 +106,7 @@ snip = """module C; const int a = 2; """ - i = self.expectOK(snip) + self.expectOK(snip) @unittest.skip('Not checked yet') def testConstantMutual(self): @@ -118,7 +118,7 @@ return b; } """ - i = self.expectOK(snip) + self.expectOK(snip) def testPackageNotExists(self): p1 = """module p1; @@ -506,6 +506,63 @@ """ self.expectErrors(snippet, [7]) + def testLinkedList(self): + """ + Test if a struct can contain a field with a pointer to itself + """ + snippet = """ + module testlinkedlist; + + type struct { + int x; + list_t* next; + } list_t; + + function void t() + { + var list_t* a; + a = a->next; + } + """ + self.expectOK(snippet) + + def testInfiniteStruct(self): + """ + Test if a struct can contain a field with itself as type? + This should not be possible! + """ + snippet = """ + module testnestedstruct; + + type struct { + int x; + list_t inner; + } list_t; + + """ + self.expectErrors(snippet, [0]) + + def testMutualStructs(self): + """ + Test if two structs can contain each other! + This should not be possible! + """ + snippet = """ + module testnestedstruct; + + type struct { + int x; + B other; + } A; + + type struct { + int x; + A other; + } B; + + """ + self.expectErrors(snippet, [0]) + def testComplexType(self): snippet = """ module testpointer;