llcppsigfetch:marco tokens & refine test
This commit is contained in:
28
chore/_xtool/llcppsigfetch/parse/cvt_test/cvt.go
Normal file
28
chore/_xtool/llcppsigfetch/parse/cvt_test/cvt.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package cvttest
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/chore/_xtool/llcppsigfetch/parse"
|
||||
)
|
||||
|
||||
func RunTest(testName string, testCases []string) {
|
||||
for i, content := range testCases {
|
||||
converter, err := parse.NewConverter(&parse.Config{
|
||||
File: content,
|
||||
Temp: true,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = converter.Convert()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
json := converter.MarshalASTFiles()
|
||||
c.Printf(c.Str("%s Case %d:\n%s\n\n"), c.AllocaCStr(testName), c.Int(i+1), json.Print())
|
||||
|
||||
converter.Dispose()
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/chore/_xtool/llcppsigfetch/parse"
|
||||
test "github.com/goplus/llgo/chore/_xtool/llcppsigfetch/parse/cvt_test"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -27,26 +26,7 @@ func TestFuncDecl() {
|
||||
`float* foo(char str[], double x);`,
|
||||
`float* foo(int arr[3][4]);`,
|
||||
}
|
||||
|
||||
for i, content := range testCases {
|
||||
converter, err := parse.NewConverter(&parse.Config{
|
||||
File: content,
|
||||
Temp: true,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = converter.Convert()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
json := converter.MarshalASTFiles()
|
||||
c.Printf(c.Str("TestFuncDecl Case %d:\n%s\n\n"), c.Int(i+1), json.Print())
|
||||
|
||||
converter.Dispose()
|
||||
}
|
||||
test.RunTest("TestFuncDecl", testCases)
|
||||
}
|
||||
|
||||
func TestScope() {
|
||||
@@ -69,26 +49,7 @@ func TestScope() {
|
||||
};
|
||||
}`,
|
||||
}
|
||||
|
||||
for i, content := range testCases {
|
||||
converter, err := parse.NewConverter(&parse.Config{
|
||||
File: content,
|
||||
Temp: true,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = converter.Convert()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
json := converter.MarshalASTFiles()
|
||||
c.Printf(c.Str("TestScope Case %d:\n%s\n\n"), c.Int(i+1), json.Print())
|
||||
|
||||
converter.Dispose()
|
||||
}
|
||||
test.RunTest("TestScope", testCases)
|
||||
}
|
||||
|
||||
func TestComment() {
|
||||
@@ -118,26 +79,7 @@ void foo();`,
|
||||
*/
|
||||
void foo();`,
|
||||
}
|
||||
|
||||
for i, content := range testCases {
|
||||
converter, err := parse.NewConverter(&parse.Config{
|
||||
File: content,
|
||||
Temp: true,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = converter.Convert()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
json := converter.MarshalASTFiles()
|
||||
c.Printf(c.Str("TestComment Case %d:\n%s\n\n"), c.Int(i+1), json.Print())
|
||||
|
||||
converter.Dispose()
|
||||
}
|
||||
test.RunTest("TestComment", testCases)
|
||||
}
|
||||
|
||||
func TestStructDecl() {
|
||||
@@ -155,26 +97,7 @@ func TestStructDecl() {
|
||||
float foo(int a,double b);;
|
||||
};`,
|
||||
}
|
||||
|
||||
for i, content := range testCases {
|
||||
converter, err := parse.NewConverter(&parse.Config{
|
||||
File: content,
|
||||
Temp: true,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = converter.Convert()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
json := converter.MarshalASTFiles()
|
||||
c.Printf(c.Str("TestStructDecl Case %d:\n%s\n\n"), c.Int(i+1), json.Print())
|
||||
|
||||
converter.Dispose()
|
||||
}
|
||||
test.RunTest("TestStructDecl", testCases)
|
||||
}
|
||||
|
||||
func TestClassDecl() {
|
||||
@@ -189,26 +112,7 @@ func TestClassDecl() {
|
||||
float foo(int a,double b);;
|
||||
};`,
|
||||
}
|
||||
|
||||
for i, content := range testCases {
|
||||
converter, err := parse.NewConverter(&parse.Config{
|
||||
File: content,
|
||||
Temp: true,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = converter.Convert()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
json := converter.MarshalASTFiles()
|
||||
c.Printf(c.Str("TestClassDecl Case %d:\n%s\n\n"), c.Int(i+1), json.Print())
|
||||
|
||||
converter.Dispose()
|
||||
}
|
||||
test.RunTest("TestClassDecl", testCases)
|
||||
}
|
||||
|
||||
func TestEnumDecl() {
|
||||
@@ -229,24 +133,5 @@ func TestEnumDecl() {
|
||||
c,
|
||||
};`,
|
||||
}
|
||||
|
||||
for i, content := range testCases {
|
||||
converter, err := parse.NewConverter(&parse.Config{
|
||||
File: content,
|
||||
Temp: 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()
|
||||
}
|
||||
test.RunTest("TestEnumDecl", testCases)
|
||||
}
|
||||
|
||||
@@ -6,13 +6,10 @@ TestDefine Case 1:
|
||||
"decls": [],
|
||||
"includes": [],
|
||||
"macros": [{
|
||||
"Name": {
|
||||
"Token": 2,
|
||||
"Lit": "OK"
|
||||
},
|
||||
"Body": [{
|
||||
"Name": "DEBUG",
|
||||
"Tokens": [{
|
||||
"Token": 3,
|
||||
"Lit": "1"
|
||||
"Lit": "DEBUG"
|
||||
}]
|
||||
}]
|
||||
}
|
||||
@@ -25,45 +22,64 @@ TestDefine Case 2:
|
||||
"decls": [],
|
||||
"includes": [],
|
||||
"macros": [{
|
||||
"Name": {
|
||||
"Token": 2,
|
||||
"Lit": "SQUARE"
|
||||
},
|
||||
"Body": [{
|
||||
"Token": 0,
|
||||
"Name": "OK",
|
||||
"Tokens": [{
|
||||
"Token": 3,
|
||||
"Lit": "OK"
|
||||
}, {
|
||||
"Token": 4,
|
||||
"Lit": "1"
|
||||
}]
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
TestDefine Case 3:
|
||||
{
|
||||
"temp.h": {
|
||||
"path": "temp.h",
|
||||
"decls": [],
|
||||
"includes": [],
|
||||
"macros": [{
|
||||
"Name": "SQUARE",
|
||||
"Tokens": [{
|
||||
"Token": 3,
|
||||
"Lit": "SQUARE"
|
||||
}, {
|
||||
"Token": 1,
|
||||
"Lit": "("
|
||||
}, {
|
||||
"Token": 2,
|
||||
"Token": 3,
|
||||
"Lit": "x"
|
||||
}, {
|
||||
"Token": 0,
|
||||
"Token": 1,
|
||||
"Lit": ")"
|
||||
}, {
|
||||
"Token": 0,
|
||||
"Token": 1,
|
||||
"Lit": "("
|
||||
}, {
|
||||
"Token": 0,
|
||||
"Token": 1,
|
||||
"Lit": "("
|
||||
}, {
|
||||
"Token": 2,
|
||||
"Token": 3,
|
||||
"Lit": "x"
|
||||
}, {
|
||||
"Token": 0,
|
||||
"Token": 1,
|
||||
"Lit": ")"
|
||||
}, {
|
||||
"Token": 0,
|
||||
"Token": 1,
|
||||
"Lit": "*"
|
||||
}, {
|
||||
"Token": 0,
|
||||
"Token": 1,
|
||||
"Lit": "("
|
||||
}, {
|
||||
"Token": 2,
|
||||
"Token": 3,
|
||||
"Lit": "x"
|
||||
}, {
|
||||
"Token": 0,
|
||||
"Token": 1,
|
||||
"Lit": ")"
|
||||
}, {
|
||||
"Token": 0,
|
||||
"Token": 1,
|
||||
"Lit": ")"
|
||||
}]
|
||||
}]
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/chore/_xtool/llcppsigfetch/parse"
|
||||
test "github.com/goplus/llgo/chore/_xtool/llcppsigfetch/parse/cvt_test"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -12,29 +11,11 @@ func main() {
|
||||
|
||||
func TestDefine() {
|
||||
testCases := []string{
|
||||
`#define DEBUG`,
|
||||
`#define OK 1`,
|
||||
`#define SQUARE(x) ((x) * (x))`,
|
||||
}
|
||||
|
||||
for i, content := range testCases {
|
||||
converter, err := parse.NewConverter(&parse.Config{
|
||||
File: content,
|
||||
Temp: true,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = converter.Convert()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
json := converter.MarshalASTFiles()
|
||||
c.Printf(c.Str("TestDefine Case %d:\n%s\n\n"), c.Int(i+1), json.Print())
|
||||
|
||||
converter.Dispose()
|
||||
}
|
||||
test.RunTest("TestDefine", testCases)
|
||||
}
|
||||
|
||||
func TestInclude() {
|
||||
@@ -42,24 +23,5 @@ func TestInclude() {
|
||||
`#include "foo.h"`,
|
||||
// `#include <limits.h>`, // Standard libraries are mostly platform-dependent
|
||||
}
|
||||
|
||||
for i, content := range testCases {
|
||||
converter, err := parse.NewConverter(&parse.Config{
|
||||
File: content,
|
||||
Temp: true,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = converter.Convert()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
json := converter.MarshalASTFiles()
|
||||
c.Printf(c.Str("TestInclude Case %d:\n%s\n\n"), c.Int(i+1), json.Print())
|
||||
|
||||
converter.Dispose()
|
||||
}
|
||||
test.RunTest("TestInclude", testCases)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user