AST tweaks and new tests.

This commit is contained in:
Greg 2019-05-31 10:21:04 -04:00
parent 96edbba641
commit 5a5a4f9406
32 changed files with 658 additions and 91 deletions

1
.gitignore vendored
View File

@ -5,7 +5,6 @@ examples/app/app
examples/app/ns
examples/bluetooth/bluetooth
examples/bluetooth/ns
examples/bluetooth/old
examples/foundation/foundation
examples/foundation/ns
examples/simple/simple

View File

@ -193,8 +193,6 @@ func Parse(fullline string) Node {
return parseNotTailCalledAttr(line)
case "ObjCCategoryDecl":
return parseObjCCategoryDecl(line)
case "ObjCImplementation":
return parseObjCImplementation(line)
case "ObjCInterface":
return parseObjCInterface(line,false)
case "super ObjCInterface":

View File

@ -9,6 +9,10 @@ import (
"git.wow.st/gmp/nswrap/util"
)
func init() {
TrackPositions = true
}
func formatMultiLine(o interface{}) string {
s := fmt.Sprintf("%#v", o)
s = strings.Replace(s, "{", "{\n", -1)
@ -17,23 +21,26 @@ func formatMultiLine(o interface{}) string {
return s
}
func runNodeTest(t *testing.T, actual, expected Node, i int) {
testName := fmt.Sprintf("Example%d", i)
t.Run(testName, func(t *testing.T) {
if !reflect.DeepEqual(expected, actual) {
t.Errorf("%s", util.ShowDiff(formatMultiLine(expected),
formatMultiLine(actual)))
}
})
}
func runNodeTests(t *testing.T, tests map[string]Node) {
i := 1
for line, expected := range tests {
testName := fmt.Sprintf("Example%d", i)
// Append the name of the struct onto the front. This would
// make the complete line it would normally be parsing.
name := reflect.TypeOf(expected).Elem().Name()
actual := Parse(name + " " + line)
runNodeTest(t,actual,expected,i)
i++
t.Run(testName, func(t *testing.T) {
// Append the name of the struct onto the front. This would make the
// complete line it would normally be parsing.
name := reflect.TypeOf(expected).Elem().Name()
actual := Parse(name + " " + line)
if !reflect.DeepEqual(expected, actual) {
t.Errorf("%s", util.ShowDiff(formatMultiLine(expected),
formatMultiLine(actual)))
}
})
}
}

View File

@ -0,0 +1,62 @@
package ast
import (
"testing"
)
func TestAttributedType(t *testing.T) {
nodes := map[string]Node{
`0x10c0d6770 'CVDisplayLinkRef _Nonnull' sugar`:
&AttributedType{
Addr: 0x10c0d6770,
Type: `CVDisplayLinkRef _Nonnull`,
Sugar: true,
ChildNodes: []Node{},
},
`0x10c0d68b0 'const CVTimeStamp * _Nonnull' sugar`:
&AttributedType{
Addr: 0x10c0d68b0,
Type: `const CVTimeStamp * _Nonnull`,
Sugar: true,
ChildNodes: []Node{},
},
`0x10c0d6ab0 'CVOptionFlags * _Nonnull' sugar`:
&AttributedType{
Addr: 0x10c0d6ab0,
Type: `CVOptionFlags * _Nonnull`,
Sugar: true,
ChildNodes: []Node{},
},
`0x10c0fc7d0 'CVPixelBufferRef _Nonnull' sugar`:
&AttributedType{
Addr: 0x10c0fc7d0,
Type: `CVPixelBufferRef _Nonnull`,
Sugar: true,
ChildNodes: []Node{},
},
`0x7faa1906d680 'NSError * _Nullable' sugar`:
&AttributedType{
Addr: 0x7faa1906d680,
Type: `NSError * _Nullable`,
Sugar: true,
ChildNodes: []Node{},
},
`0x7faa19085760 'id<NSSecureCoding> _Nullable' sugar`:
&AttributedType{
Addr: 0x7faa19085760,
Type: `id<NSSecureCoding> _Nullable`,
Sugar: true,
ChildNodes: []Node{},
},
`0x7faa19085840 'NSError * _Null_unspecified' sugar`:
&AttributedType{
Addr: 0x7faa19085840,
Type: `NSError * _Null_unspecified`,
Sugar: true,
ChildNodes: []Node{},
},
}
runNodeTests(t, nodes)
}

View File

@ -11,8 +11,8 @@ func TestAvailabilityAttr(t *testing.T) {
Pos: NewPositionFromString("/usr/include/AvailabilityInternal.h:21697:88, col:124"),
OS: "macos",
Version: "10.10",
Unknown1: 0,
Unknown2: 0,
Unknown1: "0",
Unknown2: "0",
IsUnavailable: false,
Message1: "",
Message2: "",
@ -24,8 +24,8 @@ func TestAvailabilityAttr(t *testing.T) {
Pos: NewPositionFromString("/usr/include/Availability.h:215:81, col:115"),
OS: "watchos",
Version: "3.0",
Unknown1: 0,
Unknown2: 0,
Unknown1: "0",
Unknown2: "0",
IsUnavailable: false,
Message1: "",
Message2: "",
@ -37,8 +37,8 @@ func TestAvailabilityAttr(t *testing.T) {
Pos: NewPositionFromString("col:81, col:115"),
OS: "tvos",
Version: "10.0",
Unknown1: 0,
Unknown2: 0,
Unknown1: "0",
Unknown2: "0",
IsUnavailable: false,
Message1: "",
Message2: "",
@ -50,8 +50,8 @@ func TestAvailabilityAttr(t *testing.T) {
Pos: NewPositionFromString("col:81, col:115"),
OS: "ios",
Version: "10.0",
Unknown1: 0,
Unknown2: 0,
Unknown1: "0",
Unknown2: "0",
IsUnavailable: false,
Message1: "",
Message2: "",
@ -63,8 +63,8 @@ func TestAvailabilityAttr(t *testing.T) {
Pos: NewPositionFromString("/usr/include/sys/cdefs.h:275:50, col:99"),
OS: "swift",
Version: "0",
Unknown1: 0,
Unknown2: 0,
Unknown1: "0",
Unknown2: "0",
IsUnavailable: true,
Message1: "Use snprintf instead.",
Message2: "",
@ -76,8 +76,8 @@ func TestAvailabilityAttr(t *testing.T) {
Pos: NewPositionFromString("line:275:50, col:99"),
OS: "swift",
Version: "0",
Unknown1: 0,
Unknown2: 0,
Unknown1: "0",
Unknown2: "0",
IsUnavailable: true,
Message1: "Use mkstemp(3) instead.",
Message2: "",
@ -89,8 +89,8 @@ func TestAvailabilityAttr(t *testing.T) {
Pos: NewPositionFromString("/usr/include/AvailabilityInternal.h:14571:88, col:124"),
OS: "macosx",
Version: "10.10",
Unknown1: 0,
Unknown2: 0,
Unknown1: "0",
Unknown2: "0",
IsUnavailable: false,
Message1: "",
Message2: "",
@ -102,8 +102,8 @@ func TestAvailabilityAttr(t *testing.T) {
Pos: NewPositionFromString("/usr/include/gethostuuid.h:39:65, col:100"),
OS: "macos",
Version: "10.5",
Unknown1: 0,
Unknown2: 0,
Unknown1: "0",
Unknown2: "0",
IsUnavailable: false,
Message1: "",
Message2: "",

View File

@ -17,7 +17,7 @@ func TestBinaryOperator(t *testing.T) {
Addr: 0x1ff95b8,
Pos: NewPositionFromString("line:78:2, col:7"),
Type: "T_ENUM",
Type2: "T_ENUM",
Type2: "",
Operator: "=",
ChildNodes: []Node{},
},

View File

@ -0,0 +1,24 @@
package ast
import (
"testing"
)
func TestBlockPointerType(t *testing.T) {
nodes := map[string]Node{
`0x7fa3b88bbb30 'void (^)(void)'`:
&BlockPointerType{
Addr: 0x7fa3b88bbb30,
Type: `void (^)(void)`,
ChildNodes: []Node{},
},
`0x7fa3b88bbb30 'NSComparisonResult (^)(id _Nonnull, id _Nonnull)'`:
&BlockPointerType{
Addr: 0x7fa3b88bbb30,
Type: `NSComparisonResult (^)(id _Nonnull, id _Nonnull)`,
ChildNodes: []Node{},
},
}
runNodeTests(t, nodes)
}

View File

@ -17,7 +17,7 @@ func TestCStyleCastExpr(t *testing.T) {
Addr: 0x2781518,
Pos: NewPositionFromString("col:7, col:17"),
Type: "T_ENUM",
Type2: "T_ENUM",
Type2: "",
Kind: "IntegralCast",
ChildNodes: []Node{},
},

View File

@ -35,7 +35,7 @@ func parseEnumConstantDecl(line string) *EnumConstantDecl {
return &EnumConstantDecl{
Addr: ParseAddress(groups["address"]),
Pos: NewPositionFromString(groups["position"]),
//Position2: groups["position2"],
Position2: groups["position2"],
Referenced: len(groups["referenced"]) > 0,
Name: strings.TrimSpace(groups["name"]),
Type: removeQuotes(groups["type"]),

View File

@ -34,7 +34,7 @@ func parseEnumDecl(line string) *EnumDecl {
return &EnumDecl{
Addr: ParseAddress(groups["address"]),
Pos: NewPositionFromString(groups["position"]),
//Position2: groups["position2"],
Position2: groups["position2"],
Name: strings.TrimSpace(groups["name"]),
Type: removeQuotes(groups["type"]),
//Type2: type2,

View File

@ -0,0 +1,20 @@
package ast
import (
"testing"
)
func TestObjCCategoryDecl(t *testing.T) {
nodes := map[string]Node{
`0x7fdef0862430 <line:120:1, col:16> col:16 NSObject`:
&ObjCCategoryDecl{
Addr: 0x7fdef0862430,
Pos: NewPositionFromString("line:120:1, col:16"),
Position2: "",
Name: "NSObject",
ChildNodes: []Node{},
},
}
runNodeTests(t, nodes)
}

View File

@ -1,44 +0,0 @@
package ast
// ObjCImplementation is an Objective-C implementation
type ObjCImplementation struct {
Addr Address
Name string
ChildNodes []Node
}
func parseObjCImplementation(line string) *ObjCImplementation {
groups := groupsFromRegex(
"'(?P<name>.*)'",
line,
)
return &ObjCImplementation{
Addr: ParseAddress(groups["address"]),
Name: groups["name"],
ChildNodes: []Node{},
}
}
// AddChild adds a new child node. Child nodes can then be accessed with the
// Children attribute.
func (n *ObjCImplementation) AddChild(node Node) {
n.ChildNodes = append(n.ChildNodes, node)
}
// Address returns the numeric address of the node. See the documentation for
// the Address type for more information.
func (n *ObjCImplementation) Address() Address {
return n.Addr
}
// Children returns the child nodes. If this node does not have any children or
// this node does not support children it will always return an empty slice.
func (n *ObjCImplementation) Children() []Node {
return n.ChildNodes
}
// Position returns the position in the original source code.
func (n *ObjCImplementation) Position() Position {
return Position{}
}

View File

@ -0,0 +1,39 @@
package ast
import (
"testing"
)
func TestObjCInterfaceDecl(t *testing.T) {
nodes := map[string]Node{
`0x7fdef0862430 <line:120:1, col:16> col:16 NSObject`:
&ObjCInterfaceDecl{
Addr: 0x7fdef0862430,
Pos: NewPositionFromString("line:120:1, col:16"),
Position2: "",
Name: "NSObject",
Implicit: false,
ChildNodes: []Node{},
},
`0x7fdef0862430 prev 0x7fca43341430 <line:120:1, col:16> col:16 NSObject`:
&ObjCInterfaceDecl{
Addr: 0x7fdef0862430,
Pos: NewPositionFromString("line:120:1, col:16"),
Position2: "",
Name: "NSObject",
Implicit: false,
ChildNodes: []Node{},
},
`0x7fdef0862430 <<invalid sloc>> <invalid sloc> implicit Protocol`:
&ObjCInterfaceDecl{
Addr: 0x7fdef0862430,
Pos: Position{},
Position2: "",
Name: "Protocol",
Implicit: true,
ChildNodes: []Node{},
},
}
runNodeTests(t, nodes)
}

View File

@ -0,0 +1,28 @@
package ast
import (
"testing"
)
func TestObjCInterface(t *testing.T) {
runNodeTest(t,
Parse(`ObjCInterface 0x7f84d10dc1d0 'NSObject'`),
&ObjCInterface{
Addr: 0x7f84d10dc1d0,
Name: `NSObject`,
Super: false,
ChildNodes: []Node{},
},
1,
)
runNodeTest(t,
Parse(`super ObjCInterface 0x7f84d10dc1d0 'NSObject'`),
&ObjCInterface{
Addr: 0x7f84d10dc1d0,
Name: `NSObject`,
Super: true,
ChildNodes: []Node{},
},
2,
)
}

View File

@ -0,0 +1,18 @@
package ast
import (
"testing"
)
func TestObjCInterfaceType(t *testing.T) {
nodes := map[string]Node{
`0x7fdef0862430 'NSObject'`:
&ObjCInterfaceType{
Addr: 0x7fdef0862430,
Type: "NSObject",
ChildNodes: []Node{},
},
}
runNodeTests(t, nodes)
}

View File

@ -3,19 +3,19 @@ package ast
// ObjCMethod is an Objective-C method
type ObjCMethod struct {
Addr Address
Type string
Name string
ChildNodes []Node
}
func parseObjCMethod(line string) *ObjCMethod {
groups := groupsFromRegex(
"'(?P<type>.*)'",
"'(?P<name>.*)'",
line,
)
return &ObjCMethod{
Addr: ParseAddress(groups["address"]),
Type: groups["type"],
Name: groups["name"],
ChildNodes: []Node{},
}
}

View File

@ -0,0 +1,90 @@
package ast
import (
"testing"
)
func TestObjCMethodDecl(t *testing.T) {
nodes := map[string]Node{
`0x7f92a58a7570 <line:17:1, col:27> col:1 - isEqual: 'BOOL':'signed char'`:
&ObjCMethodDecl{
Addr: 0x7f92a58a7570,
Pos: NewPositionFromString("line:17:1, col:27"),
Position2: "",
Name: "isEqual",
Type: "BOOL",
Type2: "",
ClassMethod: false,
Parameters: []string{"isEqual"},
Implicit: false,
ChildNodes: []Node{},
},
`0x7f92a58a7978 </usr/include/objc/NSObject.h:22:1, col:21> col:1 - self 'instancetype':'id'`:
&ObjCMethodDecl{
Addr: 0x7f92a58a7978,
Pos: NewPositionFromString("/usr/include/objc/NSObject.h:22:1, col:21"),
Position2: "",
Name: "self",
Type: "instancetype",
Type2: "",
ClassMethod: false,
Parameters: []string{},
Implicit: false,
ChildNodes: []Node{},
},
`0x7f92a58a82b0 <line:34:1, col:42> col:1 - respondsToSelector: 'BOOL':'signed char'`:
&ObjCMethodDecl{
Addr: 0x7f92a58a82b0,
Pos: NewPositionFromString("line:34:1, col:42"),
Position2: "",
Name: "respondsToSelector",
Type: "BOOL",
Type2: "",
ClassMethod: false,
Parameters: []string{"respondsToSelector"},
Implicit: false,
ChildNodes: []Node{},
},
`0x7f92a58a82b0 <line:34:1, col:42> col:1 + instancesRespondToSelector: 'BOOL':'signed char'`:
&ObjCMethodDecl{
Addr: 0x7f92a58a82b0,
Pos: NewPositionFromString("line:34:1, col:42"),
Position2: "",
Name: "instancesRespondToSelector",
Type: "BOOL",
Type2: "",
ClassMethod: true,
Parameters: []string{"instancesRespondToSelector"},
Implicit: false,
ChildNodes: []Node{},
},
`0x7f92a58a7cd8 <line:26:1, col:83> col:1 - performSelector:withObject:withObject: 'id':'id'`:
&ObjCMethodDecl{
Addr: 0x7f92a58a7cd8,
Pos: NewPositionFromString("line:26:1, col:83"),
Position2: "",
Name: "performSelector",
Type: "id",
Type2: "",
ClassMethod: false,
Parameters: []string{"performSelector","withObject","withObject"},
Implicit: false,
ChildNodes: []Node{},
},
`0x7f92a4459318 <line:41:71> col:71 implicit - writableTypeIdentifiersForItemProvider 'NSArray<NSString *> * _Nonnull':'NSArray<NSString *> *'`:
&ObjCMethodDecl{
Addr: 0x7f92a4459318,
Pos: NewPositionFromString("line:41:71"),
Position2: "",
Name: "writableTypeIdentifiersForItemProvider",
Type: `NSArray<NSString *> * _Nonnull`,
Type2: "",
ClassMethod: false,
Parameters: []string{},
Implicit: true,
ChildNodes: []Node{},
},
}
runNodeTests(t, nodes)
}

26
ast/objc_method_test.go Normal file
View File

@ -0,0 +1,26 @@
package ast
import (
"testing"
)
func TestObjCMethod(t *testing.T) {
runNodeTest(t,
Parse(`ObjCMethod 0x7f84d10dc1d0 'isValid'`),
&ObjCMethod{
Addr: 0x7f84d10dc1d0,
Name: `isValid`,
ChildNodes: []Node{},
},
1,
)
runNodeTest(t,
Parse(`getter ObjCMethod 0x7f84d10dc1d0 'isValid'`),
&ObjCMethod{
Addr: 0x7f84d10dc1d0,
Name: `isValid`,
ChildNodes: []Node{},
},
2,
)
}

View File

@ -0,0 +1,30 @@
package ast
import (
"testing"
)
func TestObjCObjectPointerType(t *testing.T) {
nodes := map[string]Node{
`0x10c101ab0 'NSObject<OS_xpc_object> *'`:
&ObjCObjectPointerType{
Addr: 0x10c101ab0,
Type: `NSObject<OS_xpc_object> *`,
ChildNodes: []Node{},
},
`0x7faa18805fc0 'id'`:
&ObjCObjectPointerType{
Addr: 0x7faa18805fc0,
Type: `id`,
ChildNodes: []Node{},
},
`0x7fca45a08a60 'NSAppleEventDescriptor *'`:
&ObjCObjectPointerType{
Addr: 0x7fca45a08a60,
Type: `NSAppleEventDescriptor *`,
ChildNodes: []Node{},
},
}
runNodeTests(t, nodes)
}

View File

@ -0,0 +1,24 @@
package ast
import (
"testing"
)
func TestObjCObjectType(t *testing.T) {
nodes := map[string]Node{
`0x10c101ab0 'NSObject<OS_xpc_object>'`:
&ObjCObjectType{
Addr: 0x10c101ab0,
Type: `NSObject<OS_xpc_object>`,
ChildNodes: []Node{},
},
`0x7faa18805fc0 'id'`:
&ObjCObjectType{
Addr: 0x7faa18805fc0,
Type: `id`,
ChildNodes: []Node{},
},
}
runNodeTests(t, nodes)
}

View File

@ -0,0 +1,34 @@
package ast
import (
"testing"
)
func TestObjCPropertyDecl(t *testing.T) {
nodes := map[string]Node{
`0x10a9be000 <line:157:1, col:46> col:46 blueColor 'NSColor * _Nonnull':'NSColor *' readonly atomic strong class`:
&ObjCPropertyDecl{
Addr: 0x10a9be000,
Pos: NewPositionFromString("line:157:1, col:46"),
Position2: "col:46",
Name: "blueColor",
Type: `NSColor * _Nonnull`,
Type2: "",
Attr: "readonly atomic strong class",
ChildNodes: []Node{},
},
`0x7fca44e4a180 <line:50:1, col:61> col:61 undoRegistrationEnabled 'BOOL':'signed char' readonly atomic getter<col:29>`:
&ObjCPropertyDecl{
Addr: 0x7fca44e4a180,
Pos: NewPositionFromString("line:50:1, col:61"),
Position2: "col:61",
Name: "undoRegistrationEnabled",
Type: "BOOL",
Type2: "",
Attr: "readonly atomic getter<col:29>",
ChildNodes: []Node{},
},
}
runNodeTests(t, nodes)
}

View File

@ -4,7 +4,6 @@ package ast
type ObjCProtocol struct {
Addr Address
Name string
Content string
ChildNodes []Node
}
@ -17,7 +16,6 @@ func parseObjCProtocol(line string) *ObjCProtocol {
return &ObjCProtocol{
Addr: ParseAddress(groups["address"]),
Name: groups["name"],
Content: groups["content"],
ChildNodes: []Node{},
}
}

View File

@ -0,0 +1,28 @@
package ast
import (
"testing"
)
func TestObjCProtocolDecl(t *testing.T) {
nodes := map[string]Node{
`0x10a9da630 <line:22:1, col:11> col:11 NSBrowserDelegate`:
&ObjCProtocolDecl{
Addr: 0x10a9da630,
Pos: NewPositionFromString("line:22:1, col:11"),
Position2: "",
Name: "NSBrowserDelegate",
ChildNodes: []Node{},
},
`0x10c37fc70 </System/Library/Frameworks/AppKit.framework/Headers/NSPrintPanel.h:58:1, line:70:2> line:58:11 NSPrintPanelAccessorizing`:
&ObjCProtocolDecl{
Addr: 0x10c37fc70,
Pos: NewPositionFromString("/System/Library/Frameworks/AppKit.framework/Headers/NSPrintPanel.h:58:1, line:70:2"),
Position2: "",
Name: "NSPrintPanelAccessorizing",
ChildNodes: []Node{},
},
}
runNodeTests(t, nodes)
}

18
ast/objc_protocol_test.go Normal file
View File

@ -0,0 +1,18 @@
package ast
import (
"testing"
)
func TestObjCProtocol(t *testing.T) {
nodes := map[string]Node{
`0x10c26d630 'NSColorPickingDefault'`:
&ObjCProtocol{
Addr: 0x10c26d630,
Name: "NSColorPickingDefault",
ChildNodes: []Node{},
},
}
runNodeTests(t, nodes)
}

View File

@ -0,0 +1,77 @@
package ast
import (
"testing"
)
func TestObjCTypeParamDecl(t *testing.T) {
nodes := map[string]Node{
`0x10c2d1a78 <col:27> col:27 AnchorType 'id':'id'`:
&ObjCTypeParamDecl{
Addr: 0x10c2d1a78,
Pos: NewPositionFromString("col:27"),
Position2: "",
Name: "AnchorType",
Type: "id",
Type2: "",
IsReferenced: false,
IsCovariant: false,
IsBounded: false,
ChildNodes: []Node{},
},
`0x7faa181df328 <col:16> col:16 ObjectType covariant 'id':'id'`:
&ObjCTypeParamDecl{
Addr: 0x7faa181df328,
Pos: NewPositionFromString("col:16"),
Position2: "",
Name: "ObjectType",
Type: "id",
Type2: "",
IsReferenced: false,
IsCovariant: true,
IsBounded: false,
ChildNodes: []Node{},
},
`0x7faa18216cf0 <col:26, col:43> col:26 referenced UnitType bounded 'NSUnit *'`:
&ObjCTypeParamDecl{
Addr: 0x7faa18216cf0,
Pos: NewPositionFromString("col:26, col:43"),
Position2: "",
Name: "UnitType",
Type: "NSUnit *",
Type2: "",
IsReferenced: true,
IsCovariant: false,
IsBounded: true,
ChildNodes: []Node{},
},
`0x7faa18ba2ba8 <col:25> col:25 referenced K covariant 'id':'id'`:
&ObjCTypeParamDecl{
Addr: 0x7faa18ba2ba8,
Pos: NewPositionFromString("col:25"),
Position2: "",
Name: "K",
Type: "id",
Type2: "",
IsReferenced: true,
IsCovariant: true,
IsBounded: false,
ChildNodes: []Node{},
},
`0x7faa18ba2c18 <col:28> col:28 V covariant 'id':'id'`:
&ObjCTypeParamDecl{
Addr: 0x7faa18ba2c18,
Pos: NewPositionFromString("col:28"),
Position2: "",
Name: "V",
Type: "id",
Type2: "",
IsReferenced: false,
IsCovariant: true,
IsBounded: false,
ChildNodes: []Node{},
},
}
runNodeTests(t, nodes)
}

View File

@ -37,15 +37,15 @@ func parseParmVarDecl(line string) *ParmVarDecl {
type2 = type2[2 : len(type2)-1]
}*/
/*if strings.Index(groups["position"], "<invalid sloc>") > -1 {
if strings.Index(groups["position"], "<invalid sloc>") > -1 {
groups["position"] = "<invalid sloc>"
groups["position2"] = "<invalid sloc>"
}*/
}
return &ParmVarDecl{
Addr: ParseAddress(groups["address"]),
Pos: NewPositionFromString(groups["position"]),
//Position2: strings.TrimSpace(groups["position2"]),
Position2: strings.TrimSpace(groups["position2"]),
Name: strings.TrimSpace(groups["name"]),
Type: groups["type"],
//Type2: type2,

View File

@ -59,7 +59,7 @@ func TestParmVarDecl(t *testing.T) {
Position2: "col:47",
Type: "size_t",
Name: "__size",
Type2: "unsigned long",
Type2: "",
IsUsed: false,
IsReferenced: false,
IsRegister: false,
@ -71,7 +71,7 @@ func TestParmVarDecl(t *testing.T) {
Position2: "col:34",
Type: "int (* _Nullable)(void *, char *, int)",
Name: "",
Type2: "int (*)(void *, char *, int)",
Type2: "",
IsUsed: false,
IsReferenced: false,
IsRegister: false,
@ -95,7 +95,7 @@ func TestParmVarDecl(t *testing.T) {
Position2: "col:16",
Type: "char *",
Name: "foo",
Type2: "char *",
Type2: "",
IsUsed: false,
IsReferenced: true,
IsRegister: false,

View File

@ -0,0 +1,28 @@
package ast
import (
"testing"
)
func TestUnavailableAttr(t *testing.T) {
nodes := map[string]Node{
`0x7faa18a445d8 <line:66:45> "" IR_None`:
&UnavailableAttr{
Addr: 0x7faa18a445d8,
Pos: NewPositionFromString("line:66:45"),
Position2: "",
Content: `"" IR_None`,
ChildNodes: []Node{},
},
`0x7faa18a289f8 <line:150:54, col:70> "use a (__bridge id) cast instead" IR_None`:
&UnavailableAttr{
Addr: 0x7faa18a289f8,
Pos: NewPositionFromString("line:150:54, col:70"),
Position2: "",
Content: `"use a (__bridge id) cast instead" IR_None`,
ChildNodes: []Node{},
},
}
runNodeTests(t, nodes)
}

21
ast/unknown_test.go Normal file
View File

@ -0,0 +1,21 @@
package ast
import (
"testing"
)
func TestUnknown(t *testing.T) {
nodes := map[string]Node{
`0x7faa18a445d8 <line:66:45> "asdf" aoeu`:
&Unknown{
Addr: 0x7faa18a445d8,
Name: "Unknown",
Pos: NewPositionFromString("line:66:45"),
Position2: "",
Content: ` "asdf" aoeu`,
ChildNodes: []Node{},
},
}
runNodeTests(t, nodes)
}

15
ast/variadic_test.go Normal file
View File

@ -0,0 +1,15 @@
package ast
import (
"testing"
)
func TestVariadic(t *testing.T) {
runNodeTest(t,
Parse(`...`),
&Variadic{
ChildNodes: []Node{},
},
1,
)
}

26
ast/vector_type_test.go Normal file
View File

@ -0,0 +1,26 @@
package ast
import (
"testing"
)
func TestVectorType(t *testing.T) {
nodes := map[string]Node{
`0x7faa18f2d520 '__attribute__((__vector_size__(1 * sizeof(long long)))) long long' 1`:
&VectorType{
Addr: 0x7faa18f2d520,
Type: `__attribute__((__vector_size__(1 * sizeof(long long)))) long long`,
Length: 1,
ChildNodes: []Node{},
},
`0x7fca42b88f30 '__attribute__((__vector_size__(16 * sizeof(signed char)))) signed char' 16`:
&VectorType{
Addr: 0x7fca42b88f30,
Type: `__attribute__((__vector_size__(16 * sizeof(signed char)))) signed char`,
Length: 16,
ChildNodes: []Node{},
},
}
runNodeTests(t, nodes)
}

View File

@ -120,6 +120,7 @@ func main() {
hrm_uuid = ns.CBUUIDWithGoString("180D")
hrv_uuid = ns.CBUUIDWithGoString("2A37")
//We defined our own queue because this won't work on the main queue.
cm = ns.CBCentralManagerAlloc().InitWithDelegateQueue(cd,queue)
select { }