llcppsigfetch:basic enum

This commit is contained in:
luoliwoshang
2024-08-19 12:07:30 +08:00
parent 9d16df5f25
commit 090e689689
4 changed files with 235 additions and 4 deletions

View File

@@ -11,6 +11,7 @@ func main() {
TestComment()
TestStructDecl()
TestClassDecl()
TestEnumDecl()
}
func TestFuncDecl() {
@@ -194,3 +195,40 @@ func TestClassDecl() {
converter.Dispose()
}
}
func TestEnumDecl() {
testCases := []string{
`enum Foo {
a,
b,
c,
};`,
`enum Foo {
a = 1,
b = 2,
c = 4,
};`,
`enum Foo {
a = 1,
b,
c,
};`,
}
for i, content := range testCases {
converter, err := parse.NewConverter(content, true)
if err != nil {
panic(err)
}
_, err = converter.Convert()
if err != nil {
panic(err)
}
json := converter.MarshalASTFiles()
c.Printf(c.Str("TestEnumDecl Case %d:\n%s\n\n"), c.Int(i+1), json.Print())
converter.Dispose()
}
}

View File

@@ -1296,6 +1296,144 @@ TestClassDecl Case 2:
}
}
TestEnumDecl Case 1:
{
"temp.h": {
"path": "temp.h",
"decls": [{
"Loc": {
"File": "temp.h"
},
"Doc": {
"List": []
},
"Parent": null,
"Name": {
"Name": "Foo"
},
"Items": [{
"Name": {
"Name": "a"
},
"Value": {
"Kind": 0,
"Value": "0"
}
}, {
"Name": {
"Name": "b"
},
"Value": {
"Kind": 0,
"Value": "1"
}
}, {
"Name": {
"Name": "c"
},
"Value": {
"Kind": 0,
"Value": "2"
}
}]
}],
"includes": [],
"macros": []
}
}
TestEnumDecl Case 2:
{
"temp.h": {
"path": "temp.h",
"decls": [{
"Loc": {
"File": "temp.h"
},
"Doc": {
"List": []
},
"Parent": null,
"Name": {
"Name": "Foo"
},
"Items": [{
"Name": {
"Name": "a"
},
"Value": {
"Kind": 0,
"Value": "1"
}
}, {
"Name": {
"Name": "b"
},
"Value": {
"Kind": 0,
"Value": "2"
}
}, {
"Name": {
"Name": "c"
},
"Value": {
"Kind": 0,
"Value": "4"
}
}]
}],
"includes": [],
"macros": []
}
}
TestEnumDecl Case 3:
{
"temp.h": {
"path": "temp.h",
"decls": [{
"Loc": {
"File": "temp.h"
},
"Doc": {
"List": []
},
"Parent": null,
"Name": {
"Name": "Foo"
},
"Items": [{
"Name": {
"Name": "a"
},
"Value": {
"Kind": 0,
"Value": "1"
}
}, {
"Name": {
"Name": "b"
},
"Value": {
"Kind": 0,
"Value": "2"
}
}, {
"Name": {
"Name": "c"
},
"Value": {
"Kind": 0,
"Value": "3"
}
}]
}],
"includes": [],
"macros": []
}
}
#stderr