From a251e7382e9eeaddc72449a59b8f90c1432cfe15 Mon Sep 17 00:00:00 2001 From: Greg Date: Tue, 4 Jun 2019 00:14:04 -0400 Subject: [PATCH] Improve test coverage. --- ast/aligned_attr_test.go | 16 +- ast/alloc_size_attr_test.go | 37 +- ast/always_inline_attr_test.go | 9 +- ast/arc_weakref_unavailable_attr_test.go | 22 + ast/array_filler_test.go | 17 +- ast/array_subscript_expr_test.go | 23 +- ast/asm_label_attr_test.go | 16 +- ast/ast.go | 9 +- ast/ast_test.go | 50 +- ast/attributed_type_test.go | 45 +- ast/availability_attr_test.go | 58 +- ast/binary_operator_test.go | 16 +- ast/block_command_comment_test.go | 9 +- ast/block_pointer_type_test.go | 14 +- ast/break_stmt_test.go | 9 +- ast/builtin_type_test.go | 16 +- ast/c_style_cast_expr_test.go | 16 +- ast/call_expr_test.go | 16 +- ast/case_stmt_test.go | 9 +- ast/cf_audited_transfer_attr_test.go | 23 + ast/cf_consumed_attr_test.go | 23 + ast/cf_returns_not_retained_attr_test.go | 22 + ast/cf_returns_retained_attr_test.go | 22 + ast/character_literal_test.go | 9 +- ast/compound_assign_operator_test.go | 9 +- ast/compound_literal_expr_test.go | 9 +- ast/compound_stmt_test.go | 16 +- ast/conditional_operator_test.go | 9 +- ast/const_attr.go | 3 - ast/const_attr_test.go | 9 +- ast/constant_array_type_test.go | 16 +- ast/continue_stmt_test.go | 9 +- ast/convert_vector_expr_test.go | 36 + ast/decayed_type_test.go | 9 +- ast/decl_ref_expr_test.go | 37 +- ast/decl_stmt_test.go | 9 +- ast/default_stmt_test.go | 9 +- ast/deprecated_attr_test.go | 23 +- ast/disable_tail_calls_attr_test.go | 9 +- ast/do_stmt_test.go | 9 +- ast/elaborated_type_test.go | 9 +- ast/empty_decl.go | 2 +- ast/empty_decl_test.go | 9 +- ast/enum_constant_decl_test.go | 16 +- ast/enum_decl_test.go | 16 +- ast/enum_extensibility_attr.go | 6 +- ast/enum_extensibility_attr_test.go | 23 + ast/enum_test.go | 9 +- ast/enum_type_test.go | 9 +- ast/field_decl_test.go | 72 +- ast/field_test.go | 9 +- ast/flag_enum_attr.go | 36 +- ast/flag_enum_attr_test.go | 23 + ast/floating_literal_test.go | 16 +- ast/for_stmt_test.go | 9 +- ast/format_arg_attr_test.go | 9 +- ast/format_attr_test.go | 23 +- ast/full_comment_test.go | 9 +- ast/function_decl_test.go | 93 ++- ast/function_proto_type_test.go | 9 +- ast/gcc_asm_stmt_test.go | 9 +- ast/go_stmt_test.go | 9 +- ast/html_end_tag_comment_test.go | 9 +- ast/html_start_tag_comment_test.go | 9 +- ast/ib_action_attr_test.go | 22 + ast/ib_outlet_attr_test.go | 22 + ast/if_stmt_test.go | 9 +- ast/implicit_cast_expr_test.go | 30 +- ast/implicit_value_init_expr_test.go | 16 +- ast/incomplete_array_type_test.go | 9 +- ast/indirect_field_decl_test.go | 9 +- ast/init_list_expr_test.go | 23 +- ast/inline_command_comment_test.go | 9 +- ast/integer_literal_test.go | 9 +- ast/label_stmt_test.go | 9 +- ast/malloc_attr_test.go | 9 +- ast/max_field_alignment_attr_test.go | 16 +- ast/may_alias_attr_test.go | 22 + ast/member_expr.go | 2 + ast/member_expr_test.go | 51 +- ast/min_vector_width_attr.go | 36 +- ast/min_vector_width_attr_test.go | 23 + ast/mode_attr_test.go | 9 +- ast/no_debug_attr_test.go | 22 + ast/no_escape_attr_test.go | 22 + ast/no_inline_attr_test.go | 9 +- ast/no_throw_attr_test.go | 30 +- ast/non_null_attr_test.go | 51 +- ast/not_tail_called_attr_test.go | 9 +- ast/ns_consumed_attr_test.go | 23 + ast/ns_consumes_self_attr_test.go | 22 + ast/ns_error_domain_attr_test.go | 23 + ast/ns_returns_retained_attr_test.go | 22 + ast/objc_bool_literal_expr_test.go | 38 + ast/objc_boxable_attr_test.go | 22 + ast/objc_bridge_attr_test.go | 23 + ast/objc_bridge_mutable_attr_test.go | 23 + ast/objc_bridge_related_attr_test.go | 23 + ast/objc_category_decl_test.go | 8 +- ast/objc_designated_initializer_attr_test.go | 22 + ast/objc_exception_attr_test.go | 22 + ast/objc_explicit_protocol_impl_attr_test.go | 22 + ast/objc_independent_class_attr_test.go | 22 + ast/objc_interface_decl_test.go | 20 +- ast/objc_interface_test.go | 17 +- ast/objc_interface_type_test.go | 8 +- ast/objc_ivar_decl_test.go | 27 + ast/objc_message_expr_test.go | 23 + ast/objc_method_decl_test.go | 38 +- ast/objc_method_test.go | 17 +- ast/objc_object_pointer_type_test.go | 20 +- ast/objc_object_type_test.go | 14 +- ast/objc_property_decl_test.go | 14 +- ast/objc_protocol_decl_test.go | 14 +- ast/objc_protocol_test.go | 8 +- ast/objc_requires_super_attr_test.go | 22 + ast/objc_returns_inner_pointer_attr_test.go | 23 + ast/objc_root_class_attr_test.go | 22 + ast/objc_type_param_decl.go | 5 - ast/objc_type_param_decl_test.go | 32 +- ast/offset_of_expr_test.go | 9 +- ast/packed_attr_test.go | 9 +- ast/paragraph_comment_test.go | 9 +- ast/param_command_comment_test.go | 9 +- ast/paren_expr_test.go | 23 +- ast/paren_type_test.go | 9 +- ast/parm_var_decl_test.go | 65 +- ast/pointer_type_test.go | 9 +- ast/position.go | 10 +- ast/position_test.go | 20 + ast/predefined_expr_test.go | 9 +- ast/pure_attr_test.go | 16 +- ast/qual_type_test.go | 9 +- ast/record_decl_test.go | 37 +- ast/record_test.go | 9 +- ast/record_type_test.go | 9 +- ast/restrict_attr_test.go | 9 +- ast/return_stmt_test.go | 9 +- ast/returns_twice_attr_test.go | 16 +- ast/sentinel_attr_test.go | 9 +- ast/shuffle_vector_expr_test.go | 36 + ast/stmt_expr_test.go | 9 +- ast/string_literal_test.go | 16 +- ast/swift_bridged_typedef_attr_test.go | 22 + ast/swift_error_attr_test.go | 23 + ast/swift_name_attr_test.go | 23 + ast/swift_newtype_attr_test.go | 23 + ast/swift_private_attr_test.go | 22 + ast/switch_stmt_test.go | 9 +- ast/target_attr_test.go | 23 + ast/text_comment_test.go | 9 +- ast/translation_unit_decl_test.go | 9 +- ast/transparent_union_attr_test.go | 9 +- ast/traverse.go | 4 +- ast/typedef_decl_test.go | 58 +- ast/typedef_test.go | 9 +- ast/typedef_type_test.go | 9 +- ast/unary_expr_or_type_trait_expr_test.go | 30 +- ast/unary_operator_test.go | 30 +- ast/unavailable_attr_test.go | 14 +- ast/unknown_test.go | 826 ++++++++++++++++++- ast/unused_attr_test.go | 16 +- ast/used_attr_test.go | 22 + ast/util.go | 2 +- ast/util_test.go | 24 + ast/va_arg_expr_test.go | 9 +- ast/var_decl_test.go | 72 +- ast/variadic_test.go | 9 +- ast/vector_type_test.go | 14 +- ast/verbatim_block_comment_test.go | 9 +- ast/verbatim_block_line_comment_test.go | 9 +- ast/verbatim_line_comment_test.go | 9 +- ast/visibility_attr_test.go | 16 +- ast/warn_unused_result_attr_test.go | 16 +- ast/weak_attr_test.go | 9 +- ast/weak_import_attr_test.go | 22 + ast/while_stmt_test.go | 9 +- main.go | 1 + types/cparser.go | 14 +- types/main_test.go | 599 ++++++++++++++ types/node.go | 3 +- 181 files changed, 4211 insertions(+), 477 deletions(-) create mode 100644 ast/arc_weakref_unavailable_attr_test.go create mode 100644 ast/cf_audited_transfer_attr_test.go create mode 100644 ast/cf_consumed_attr_test.go create mode 100644 ast/cf_returns_not_retained_attr_test.go create mode 100644 ast/cf_returns_retained_attr_test.go create mode 100644 ast/convert_vector_expr_test.go create mode 100644 ast/enum_extensibility_attr_test.go create mode 100644 ast/flag_enum_attr_test.go create mode 100644 ast/ib_action_attr_test.go create mode 100644 ast/ib_outlet_attr_test.go create mode 100644 ast/may_alias_attr_test.go create mode 100644 ast/min_vector_width_attr_test.go create mode 100644 ast/no_debug_attr_test.go create mode 100644 ast/no_escape_attr_test.go create mode 100644 ast/ns_consumed_attr_test.go create mode 100644 ast/ns_consumes_self_attr_test.go create mode 100644 ast/ns_error_domain_attr_test.go create mode 100644 ast/ns_returns_retained_attr_test.go create mode 100644 ast/objc_bool_literal_expr_test.go create mode 100644 ast/objc_boxable_attr_test.go create mode 100644 ast/objc_bridge_attr_test.go create mode 100644 ast/objc_bridge_mutable_attr_test.go create mode 100644 ast/objc_bridge_related_attr_test.go create mode 100644 ast/objc_designated_initializer_attr_test.go create mode 100644 ast/objc_exception_attr_test.go create mode 100644 ast/objc_explicit_protocol_impl_attr_test.go create mode 100644 ast/objc_independent_class_attr_test.go create mode 100644 ast/objc_ivar_decl_test.go create mode 100644 ast/objc_message_expr_test.go create mode 100644 ast/objc_requires_super_attr_test.go create mode 100644 ast/objc_returns_inner_pointer_attr_test.go create mode 100644 ast/objc_root_class_attr_test.go create mode 100644 ast/shuffle_vector_expr_test.go create mode 100644 ast/swift_bridged_typedef_attr_test.go create mode 100644 ast/swift_error_attr_test.go create mode 100644 ast/swift_name_attr_test.go create mode 100644 ast/swift_newtype_attr_test.go create mode 100644 ast/swift_private_attr_test.go create mode 100644 ast/target_attr_test.go create mode 100644 ast/used_attr_test.go create mode 100644 ast/util_test.go create mode 100644 ast/weak_import_attr_test.go create mode 100644 types/main_test.go diff --git a/ast/aligned_attr_test.go b/ast/aligned_attr_test.go index 17647c0..f610337 100644 --- a/ast/aligned_attr_test.go +++ b/ast/aligned_attr_test.go @@ -5,20 +5,30 @@ import ( ) func TestAlignedAttr(t *testing.T) { - nodes := map[string]Node{ - `0x7f8a1d8ccfd0 aligned`: &AlignedAttr{ + nodes := map[string]testNode{ + `0x7f8a1d8ccfd0 aligned`: + testNode{&AlignedAttr{ Addr: 0x7f8a1d8ccfd0, Pos: NewPositionFromString("col:47, col:57"), IsAligned: true, ChildNodes: []Node{}, + }, + 0x7f8a1d8ccfd0, + NewPositionFromString("col:47, col:57"), + []Node{}, }, - `0x2c8ba10 `: &AlignedAttr{ + `0x2c8ba10 `: testNode{ &AlignedAttr{ Addr: 0x2c8ba10, Pos: NewPositionFromString("col:42"), IsAligned: false, ChildNodes: []Node{}, + }, + 0x2c8ba10, + NewPositionFromString("col:42"), + []Node{}, }, } runNodeTests(t, nodes) } + diff --git a/ast/alloc_size_attr_test.go b/ast/alloc_size_attr_test.go index fa59835..1ec155d 100644 --- a/ast/alloc_size_attr_test.go +++ b/ast/alloc_size_attr_test.go @@ -5,22 +5,45 @@ import ( ) func TestAllocSizeAttr(t *testing.T) { - nodes := map[string]Node{ - `0x7f8e390a5d38 1 2`: &AllocSizeAttr{ + nodes := map[string]testNode{ + `0x7f8e390a5d38 1 2`: + testNode{&AllocSizeAttr{ Addr: 0x7f8e390a5d38, Pos: NewPositionFromString("col:100, col:114"), - A: 1, - B: 2, + A: "1", + B: "2", ChildNodes: []Node{}, }, - `0x7fbd1a167f48 Inherited 1 0`: &AllocSizeAttr{ + 0x7f8e390a5d38, + NewPositionFromString("col:100, col:114"), + []Node{}, + }, + `0x7fbd1a167f48 Inherited 1 0`: + testNode{&AllocSizeAttr{ Addr: 0x7fbd1a167f48, Pos: NewPositionFromString("/usr/include/stdlib.h:342:37"), Inherited: true, - A: 1, - B: 0, + A: "1", + B: "0", ChildNodes: []Node{}, }, + 0x7fbd1a167f48, + NewPositionFromString("/usr/include/stdlib.h:342:37"), + []Node{}, + }, + `0x7fbd1a167f48 Inherited 1`: + testNode{&AllocSizeAttr{ + Addr: 0x7fbd1a167f48, + Pos: NewPositionFromString("/usr/include/stdlib.h:342:37"), + Inherited: true, + A: "1", + B: "", + ChildNodes: []Node{}, + }, + 0x7fbd1a167f48, + NewPositionFromString("/usr/include/stdlib.h:342:37"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/always_inline_attr_test.go b/ast/always_inline_attr_test.go index 5c0bd91..325b073 100644 --- a/ast/always_inline_attr_test.go +++ b/ast/always_inline_attr_test.go @@ -5,12 +5,17 @@ import ( ) func TestAlwaysInlineAttr(t *testing.T) { - nodes := map[string]Node{ - `0x7fce780f5018 always_inline`: &AlwaysInlineAttr{ + nodes := map[string]testNode{ + `0x7fce780f5018 always_inline`: + testNode{&AlwaysInlineAttr{ Addr: 0x7fce780f5018, Pos: NewPositionFromString("/usr/include/sys/cdefs.h:313:68"), ChildNodes: []Node{}, }, + 0x7fce780f5018, + NewPositionFromString("/usr/include/sys/cdefs.h:313:68"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/arc_weakref_unavailable_attr_test.go b/ast/arc_weakref_unavailable_attr_test.go new file mode 100644 index 0000000..dc91b36 --- /dev/null +++ b/ast/arc_weakref_unavailable_attr_test.go @@ -0,0 +1,22 @@ +package ast + +import ( + "testing" +) + +func TestArcWeakrefUnavailableAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 `: + testNode{&ArcWeakrefUnavailableAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/array_filler_test.go b/ast/array_filler_test.go index adec204..f8639b1 100644 --- a/ast/array_filler_test.go +++ b/ast/array_filler_test.go @@ -1,20 +1,13 @@ package ast import ( - "reflect" "testing" - - "git.wow.st/gmp/nswrap/util" ) func TestArrayFiller(t *testing.T) { - expected := &ArrayFiller{ - ChildNodes: []Node{}, - } - actual := Parse(`array filler`) - - if !reflect.DeepEqual(expected, actual) { - t.Errorf("%s", util.ShowDiff(formatMultiLine(expected), - formatMultiLine(actual))) - } + i := 0 + runNodeTest(t, Parse(`array filler`), + testNode{ &ArrayFiller{ ChildNodes: []Node{} }, + 0,NewPositionFromString(""),[]Node{}}, + &i) } diff --git a/ast/array_subscript_expr_test.go b/ast/array_subscript_expr_test.go index 5f44020..b29f733 100644 --- a/ast/array_subscript_expr_test.go +++ b/ast/array_subscript_expr_test.go @@ -5,8 +5,9 @@ import ( ) func TestArraySubscriptExpr(t *testing.T) { - nodes := map[string]Node{ - `0x7fe35b85d180 'char *' lvalue`: &ArraySubscriptExpr{ + nodes := map[string]testNode{ + `0x7fe35b85d180 'char *' lvalue`: + testNode{&ArraySubscriptExpr{ Addr: 0x7fe35b85d180, Pos: NewPositionFromString("col:63, col:69"), Type: "char *", @@ -14,7 +15,12 @@ func TestArraySubscriptExpr(t *testing.T) { IsLvalue: true, ChildNodes: []Node{}, }, - `0x2416660 'u32':'unsigned int' lvalue`: &ArraySubscriptExpr{ + 0x7fe35b85d180, + NewPositionFromString("col:63, col:69"), + []Node{}, + }, + `0x2416660 'u32':'unsigned int' lvalue`: + testNode{&ArraySubscriptExpr{ Addr: 0x2416660, Pos: NewPositionFromString("col:2, col:5"), Type: "u32", @@ -22,7 +28,12 @@ func TestArraySubscriptExpr(t *testing.T) { IsLvalue: true, ChildNodes: []Node{}, }, - `0x3f147c0 'extCoord':'extCoord' lvalue`: &ArraySubscriptExpr{ + 0x2416660, + NewPositionFromString("col:2, col:5"), + []Node{}, + }, + `0x3f147c0 'extCoord':'extCoord' lvalue`: + testNode{&ArraySubscriptExpr{ Addr: 0x3f147c0, Pos: NewPositionFromString("col:39, col:55"), Type: "extCoord", @@ -30,6 +41,10 @@ func TestArraySubscriptExpr(t *testing.T) { IsLvalue: true, ChildNodes: []Node{}, }, + 0x3f147c0, + NewPositionFromString("col:39, col:55"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/asm_label_attr_test.go b/ast/asm_label_attr_test.go index 83775c9..40a0fe9 100644 --- a/ast/asm_label_attr_test.go +++ b/ast/asm_label_attr_test.go @@ -5,21 +5,31 @@ import ( ) func TestAsmLabelAttr(t *testing.T) { - nodes := map[string]Node{ - `0x7ff26d8224e8 "_fopen"`: &AsmLabelAttr{ + nodes := map[string]testNode{ + `0x7ff26d8224e8 "_fopen"`: + testNode{&AsmLabelAttr{ Addr: 0x7ff26d8224e8, Pos: NewPositionFromString("/usr/include/sys/cdefs.h:569:36"), Inherited: false, FunctionName: "_fopen", ChildNodes: []Node{}, }, - `0x7fd55a169318 Inherited "_popen"`: &AsmLabelAttr{ + 0x7ff26d8224e8, + NewPositionFromString("/usr/include/sys/cdefs.h:569:36"), + []Node{}, + }, + `0x7fd55a169318 Inherited "_popen"`: + testNode{&AsmLabelAttr{ Addr: 0x7fd55a169318, Pos: NewPositionFromString("/usr/include/stdio.h:325:47"), Inherited: true, FunctionName: "_popen", ChildNodes: []Node{}, }, + 0x7fd55a169318, + NewPositionFromString("/usr/include/stdio.h:325:47"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/ast.go b/ast/ast.go index e2fc139..a9b7f4e 100644 --- a/ast/ast.go +++ b/ast/ast.go @@ -9,7 +9,10 @@ import ( "git.wow.st/gmp/nswrap/util" ) -var TrackPositions bool = false +var ( + TrackPositions bool = false + Debug = false +) // Node represents any node in the AST. type Node interface { @@ -406,7 +409,9 @@ func groupsFromRegex(rx, line string) map[string]string { re := util.GetRegex(rx) match := re.FindStringSubmatch(line) if len(match) == 0 { - fmt.Printf("AST parser: could not match regexp with string. Regexp:\n" + rx + "\nOriginal line:\n" + line + "\n\n") + if Debug { + fmt.Printf("AST parser: could not match regexp with string. Regexp:\n" + rx + "\nOriginal line:\n" + line + "\n\n") + } return nil } diff --git a/ast/ast_test.go b/ast/ast_test.go index 6b5e07c..0b23f53 100644 --- a/ast/ast_test.go +++ b/ast/ast_test.go @@ -9,6 +9,13 @@ import ( "git.wow.st/gmp/nswrap/util" ) +type testNode struct { + n Node + addr Address + pos Position + children []Node +} + func init() { TrackPositions = true } @@ -21,26 +28,50 @@ 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), +func runNodeTest(t *testing.T, actual Node, expected testNode, i *int) { + testName := fmt.Sprintf("Example%d", *i) + t.Run(testName + "a", func(t *testing.T) { + if !reflect.DeepEqual(expected.n, actual) { + t.Errorf("%s", util.ShowDiff(formatMultiLine(expected.n), formatMultiLine(actual))) } }) + t.Run(testName+"b", func(t *testing.T) { + if !reflect.DeepEqual(actual.Address(),expected.addr) { + t.Errorf("Address mismatch") + } + }) + t.Run(testName+"c", func(t *testing.T) { + if !reflect.DeepEqual(actual.Position(),expected.pos) { + t.Errorf("Position mismatch") + } + }) + t.Run(testName+"d", func(t *testing.T) { + if !reflect.DeepEqual(actual.Children(),expected.children) { + t.Errorf("Children mismatch") + } + }) + t.Run(testName+"e", func(t *testing.T) { + cs := expected.children + node := &Unknown{} + actual.AddChild(node) + cs = append(cs,node) + if !reflect.DeepEqual(actual.Children(),cs) { + t.Errorf("Children mismatch") + } + }) + (*i)++ } -func runNodeTests(t *testing.T, tests map[string]Node) { +func runNodeTests(t *testing.T, tests map[string]testNode) { i := 1 for line, expected := range tests { // 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() + name := reflect.TypeOf(expected.n).Elem().Name() actual := Parse(name + " " + line) - runNodeTest(t,actual,expected,i) - i++ + runNodeTest(t,actual,expected,&i) } } @@ -75,3 +106,4 @@ func BenchmarkParse(b *testing.B) { } } } + diff --git a/ast/attributed_type_test.go b/ast/attributed_type_test.go index 94af40f..510a58a 100644 --- a/ast/attributed_type_test.go +++ b/ast/attributed_type_test.go @@ -5,58 +5,85 @@ import ( ) func TestAttributedType(t *testing.T) { - nodes := map[string]Node{ + nodes := map[string]testNode{ `0x10c0d6770 'CVDisplayLinkRef _Nonnull' sugar`: - &AttributedType{ + testNode{&AttributedType{ Addr: 0x10c0d6770, Type: `CVDisplayLinkRef _Nonnull`, Sugar: true, ChildNodes: []Node{}, }, + 0x10c0d6770, + NewPositionFromString(""), + []Node{}, + }, `0x10c0d68b0 'const CVTimeStamp * _Nonnull' sugar`: - &AttributedType{ + testNode{&AttributedType{ Addr: 0x10c0d68b0, Type: `const CVTimeStamp * _Nonnull`, Sugar: true, ChildNodes: []Node{}, }, + 0x10c0d68b0, + NewPositionFromString(""), + []Node{}, + }, `0x10c0d6ab0 'CVOptionFlags * _Nonnull' sugar`: - &AttributedType{ + testNode{&AttributedType{ Addr: 0x10c0d6ab0, Type: `CVOptionFlags * _Nonnull`, Sugar: true, ChildNodes: []Node{}, }, + 0x10c0d6ab0, + NewPositionFromString(""), + []Node{}, + }, `0x10c0fc7d0 'CVPixelBufferRef _Nonnull' sugar`: - &AttributedType{ + testNode{&AttributedType{ Addr: 0x10c0fc7d0, Type: `CVPixelBufferRef _Nonnull`, Sugar: true, ChildNodes: []Node{}, }, + 0x10c0fc7d0, + NewPositionFromString(""), + []Node{}, + }, `0x7faa1906d680 'NSError * _Nullable' sugar`: - &AttributedType{ + testNode{&AttributedType{ Addr: 0x7faa1906d680, Type: `NSError * _Nullable`, Sugar: true, ChildNodes: []Node{}, }, + 0x7faa1906d680, + NewPositionFromString(""), + []Node{}, + }, `0x7faa19085760 'id _Nullable' sugar`: - &AttributedType{ + testNode{&AttributedType{ Addr: 0x7faa19085760, Type: `id _Nullable`, Sugar: true, ChildNodes: []Node{}, }, + 0x7faa19085760, + NewPositionFromString(""), + []Node{}, + }, `0x7faa19085840 'NSError * _Null_unspecified' sugar`: - &AttributedType{ + testNode{&AttributedType{ Addr: 0x7faa19085840, Type: `NSError * _Null_unspecified`, Sugar: true, ChildNodes: []Node{}, }, + 0x7faa19085840, + NewPositionFromString(""), + []Node{}, + }, } - runNodeTests(t, nodes) } diff --git a/ast/availability_attr_test.go b/ast/availability_attr_test.go index a548c41..e85e285 100644 --- a/ast/availability_attr_test.go +++ b/ast/availability_attr_test.go @@ -5,8 +5,9 @@ import ( ) func TestAvailabilityAttr(t *testing.T) { - nodes := map[string]Node{ - `0x7fc5ff8e5d18 macos 10.10 0 0 "" ""`: &AvailabilityAttr{ + nodes := map[string]testNode{ + `0x7fc5ff8e5d18 macos 10.10 0 0 "" ""`: + testNode{&AvailabilityAttr{ Addr: 0x7fc5ff8e5d18, Pos: NewPositionFromString("/usr/include/AvailabilityInternal.h:21697:88, col:124"), OS: "macos", @@ -19,7 +20,12 @@ func TestAvailabilityAttr(t *testing.T) { IsInherited: false, ChildNodes: []Node{}, }, - `0x7fc5ff8e60d0 watchos 3.0 0 0 "" ""`: &AvailabilityAttr{ + 0x7fc5ff8e5d18, + NewPositionFromString("/usr/include/AvailabilityInternal.h:21697:88, col:124"), + []Node{}, + }, + `0x7fc5ff8e60d0 watchos 3.0 0 0 "" ""`: + testNode{&AvailabilityAttr{ Addr: 0x7fc5ff8e60d0, Pos: NewPositionFromString("/usr/include/Availability.h:215:81, col:115"), OS: "watchos", @@ -32,7 +38,12 @@ func TestAvailabilityAttr(t *testing.T) { IsInherited: false, ChildNodes: []Node{}, }, - `0x7fc5ff8e6170 tvos 10.0 0 0 "" ""`: &AvailabilityAttr{ + 0x7fc5ff8e60d0, + NewPositionFromString("/usr/include/Availability.h:215:81, col:115"), + []Node{}, + }, + `0x7fc5ff8e6170 tvos 10.0 0 0 "" ""`: + testNode{&AvailabilityAttr{ Addr: 0x7fc5ff8e6170, Pos: NewPositionFromString("col:81, col:115"), OS: "tvos", @@ -45,7 +56,12 @@ func TestAvailabilityAttr(t *testing.T) { IsInherited: false, ChildNodes: []Node{}, }, - `0x7fc5ff8e61d8 ios 10.0 0 0 "" ""`: &AvailabilityAttr{ + 0x7fc5ff8e6170, + NewPositionFromString("col:81, col:115"), + []Node{}, + }, + `0x7fc5ff8e61d8 ios 10.0 0 0 "" ""`: + testNode{&AvailabilityAttr{ Addr: 0x7fc5ff8e61d8, Pos: NewPositionFromString("col:81, col:115"), OS: "ios", @@ -58,7 +74,12 @@ func TestAvailabilityAttr(t *testing.T) { IsInherited: false, ChildNodes: []Node{}, }, - `0x7fc5ff8f0e18 swift 0 0 0 Unavailable "Use snprintf instead." ""`: &AvailabilityAttr{ + 0x7fc5ff8e61d8, + NewPositionFromString("col:81, col:115"), + []Node{}, + }, + `0x7fc5ff8f0e18 swift 0 0 0 Unavailable "Use snprintf instead." ""`: + testNode{&AvailabilityAttr{ Addr: 0x7fc5ff8f0e18, Pos: NewPositionFromString("/usr/include/sys/cdefs.h:275:50, col:99"), OS: "swift", @@ -71,7 +92,12 @@ func TestAvailabilityAttr(t *testing.T) { IsInherited: false, ChildNodes: []Node{}, }, - `0x7fc5ff8f1988 swift 0 0 0 Unavailable "Use mkstemp(3) instead." ""`: &AvailabilityAttr{ + 0x7fc5ff8f0e18, + NewPositionFromString("/usr/include/sys/cdefs.h:275:50, col:99"), + []Node{}, + }, + `0x7fc5ff8f1988 swift 0 0 0 Unavailable "Use mkstemp(3) instead." ""`: + testNode{&AvailabilityAttr{ Addr: 0x7fc5ff8f1988, Pos: NewPositionFromString("line:275:50, col:99"), OS: "swift", @@ -84,7 +110,12 @@ func TestAvailabilityAttr(t *testing.T) { IsInherited: false, ChildNodes: []Node{}, }, - `0x104035438 macosx 10.10 0 0 ""`: &AvailabilityAttr{ + 0x7fc5ff8f1988, + NewPositionFromString("line:275:50, col:99"), + []Node{}, + }, + `0x104035438 macosx 10.10 0 0 ""`: + testNode{&AvailabilityAttr{ Addr: 0x104035438, Pos: NewPositionFromString("/usr/include/AvailabilityInternal.h:14571:88, col:124"), OS: "macosx", @@ -97,7 +128,12 @@ func TestAvailabilityAttr(t *testing.T) { IsInherited: false, ChildNodes: []Node{}, }, - `0x7f9bd588b1a8 Inherited macos 10.5 0 0 "" ""`: &AvailabilityAttr{ + 0x104035438, + NewPositionFromString("/usr/include/AvailabilityInternal.h:14571:88, col:124"), + []Node{}, + }, + `0x7f9bd588b1a8 Inherited macos 10.5 0 0 "" ""`: + testNode{&AvailabilityAttr{ Addr: 0x7f9bd588b1a8, Pos: NewPositionFromString("/usr/include/gethostuuid.h:39:65, col:100"), OS: "macos", @@ -110,6 +146,10 @@ func TestAvailabilityAttr(t *testing.T) { IsInherited: true, ChildNodes: []Node{}, }, + 0x7f9bd588b1a8, + NewPositionFromString("/usr/include/gethostuuid.h:39:65, col:100"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/binary_operator_test.go b/ast/binary_operator_test.go index bdbc24f..d62fc6f 100644 --- a/ast/binary_operator_test.go +++ b/ast/binary_operator_test.go @@ -5,15 +5,21 @@ import ( ) func TestBinaryOperator(t *testing.T) { - nodes := map[string]Node{ - `0x7fca2d8070e0 'unsigned char' '='`: &BinaryOperator{ + nodes := map[string]testNode{ + `0x7fca2d8070e0 'unsigned char' '='`: + testNode{&BinaryOperator{ Addr: 0x7fca2d8070e0, Pos: NewPositionFromString("col:11, col:23"), Type: "unsigned char", Operator: "=", ChildNodes: []Node{}, }, - `0x1ff95b8 'T_ENUM':'T_ENUM' '='`: &BinaryOperator{ + 0x7fca2d8070e0, + NewPositionFromString("col:11, col:23"), + []Node{}, + }, + `0x1ff95b8 'T_ENUM':'T_ENUM' '='`: + testNode{&BinaryOperator{ Addr: 0x1ff95b8, Pos: NewPositionFromString("line:78:2, col:7"), Type: "T_ENUM", @@ -21,6 +27,10 @@ func TestBinaryOperator(t *testing.T) { Operator: "=", ChildNodes: []Node{}, }, + 0x1ff95b8, + NewPositionFromString("line:78:2, col:7"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/block_command_comment_test.go b/ast/block_command_comment_test.go index cb86ba8..d172df1 100644 --- a/ast/block_command_comment_test.go +++ b/ast/block_command_comment_test.go @@ -5,13 +5,18 @@ import ( ) func TestBlockCommandComment(t *testing.T) { - nodes := map[string]Node{ - `0x1069fae60 Name="abstract"`: &BlockCommandComment{ + nodes := map[string]testNode{ + `0x1069fae60 Name="abstract"`: + testNode{&BlockCommandComment{ Addr: 0x1069fae60, Pos: NewPositionFromString("col:4, line:163:57"), Name: "abstract", ChildNodes: []Node{}, }, + 0x1069fae60, + NewPositionFromString("col:4, line:163:57"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/block_pointer_type_test.go b/ast/block_pointer_type_test.go index 870825f..98605ec 100644 --- a/ast/block_pointer_type_test.go +++ b/ast/block_pointer_type_test.go @@ -5,19 +5,27 @@ import ( ) func TestBlockPointerType(t *testing.T) { - nodes := map[string]Node{ + nodes := map[string]testNode{ `0x7fa3b88bbb30 'void (^)(void)'`: - &BlockPointerType{ + testNode{&BlockPointerType{ Addr: 0x7fa3b88bbb30, Type: `void (^)(void)`, ChildNodes: []Node{}, }, + 0x7fa3b88bbb30, + NewPositionFromString(""), + []Node{}, + }, `0x7fa3b88bbb30 'NSComparisonResult (^)(id _Nonnull, id _Nonnull)'`: - &BlockPointerType{ + testNode{&BlockPointerType{ Addr: 0x7fa3b88bbb30, Type: `NSComparisonResult (^)(id _Nonnull, id _Nonnull)`, ChildNodes: []Node{}, }, + 0x7fa3b88bbb30, + NewPositionFromString(""), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/break_stmt_test.go b/ast/break_stmt_test.go index 3c2cace..a4136fd 100644 --- a/ast/break_stmt_test.go +++ b/ast/break_stmt_test.go @@ -5,12 +5,17 @@ import ( ) func TestBreakStmt(t *testing.T) { - nodes := map[string]Node{ - `0x7fca2d8070e0 `: &BreakStmt{ + nodes := map[string]testNode{ + `0x7fca2d8070e0 `: + testNode{&BreakStmt{ Addr: 0x7fca2d8070e0, Pos: NewPositionFromString("col:11, col:23"), ChildNodes: []Node{}, }, + 0x7fca2d8070e0, + NewPositionFromString("col:11, col:23"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/builtin_type_test.go b/ast/builtin_type_test.go index 60768fd..865c059 100644 --- a/ast/builtin_type_test.go +++ b/ast/builtin_type_test.go @@ -5,17 +5,27 @@ import ( ) func TestBuiltinType(t *testing.T) { - nodes := map[string]Node{ - `0x7f8a43023f40 '__int128'`: &BuiltinType{ + nodes := map[string]testNode{ + `0x7f8a43023f40 '__int128'`: + testNode{&BuiltinType{ Addr: 0x7f8a43023f40, Type: "__int128", ChildNodes: []Node{}, }, - `0x7f8a43023ea0 'unsigned long long'`: &BuiltinType{ + 0x7f8a43023f40, + NewPositionFromString(""), + []Node{}, + }, + `0x7f8a43023ea0 'unsigned long long'`: + testNode{&BuiltinType{ Addr: 0x7f8a43023ea0, Type: "unsigned long long", ChildNodes: []Node{}, }, + 0x7f8a43023ea0, + NewPositionFromString(""), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/c_style_cast_expr_test.go b/ast/c_style_cast_expr_test.go index 2e5ec6f..3c35c73 100644 --- a/ast/c_style_cast_expr_test.go +++ b/ast/c_style_cast_expr_test.go @@ -5,15 +5,21 @@ import ( ) func TestCStyleCastExpr(t *testing.T) { - nodes := map[string]Node{ - `0x7fddc18fb2e0 'char' `: &CStyleCastExpr{ + nodes := map[string]testNode{ + `0x7fddc18fb2e0 'char' `: + testNode{&CStyleCastExpr{ Addr: 0x7fddc18fb2e0, Pos: NewPositionFromString("col:50, col:56"), Type: "char", Kind: "IntegralCast", ChildNodes: []Node{}, }, - `0x2781518 'T_ENUM':'T_ENUM' `: &CStyleCastExpr{ + 0x7fddc18fb2e0, + NewPositionFromString("col:50, col:56"), + []Node{}, + }, + `0x2781518 'T_ENUM':'T_ENUM' `: + testNode{&CStyleCastExpr{ Addr: 0x2781518, Pos: NewPositionFromString("col:7, col:17"), Type: "T_ENUM", @@ -21,6 +27,10 @@ func TestCStyleCastExpr(t *testing.T) { Kind: "IntegralCast", ChildNodes: []Node{}, }, + 0x2781518, + NewPositionFromString("col:7, col:17"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/call_expr_test.go b/ast/call_expr_test.go index b8aeae1..58acbc0 100644 --- a/ast/call_expr_test.go +++ b/ast/call_expr_test.go @@ -5,19 +5,29 @@ import ( ) func TestCallExpr(t *testing.T) { - nodes := map[string]Node{ - `0x7f9bf3033240 'int'`: &CallExpr{ + nodes := map[string]testNode{ + `0x7f9bf3033240 'int'`: + testNode{&CallExpr{ Addr: 0x7f9bf3033240, Pos: NewPositionFromString("col:11, col:25"), Type: "int", ChildNodes: []Node{}, }, - `0x7f9bf3035c20 'int'`: &CallExpr{ + 0x7f9bf3033240, + NewPositionFromString("col:11, col:25"), + []Node{}, + }, + `0x7f9bf3035c20 'int'`: + testNode{&CallExpr{ Addr: 0x7f9bf3035c20, Pos: NewPositionFromString("line:7:4, col:64"), Type: "int", ChildNodes: []Node{}, }, + 0x7f9bf3035c20, + NewPositionFromString("line:7:4, col:64"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/case_stmt_test.go b/ast/case_stmt_test.go index ea24a74..0668763 100644 --- a/ast/case_stmt_test.go +++ b/ast/case_stmt_test.go @@ -5,12 +5,17 @@ import ( ) func TestCaseStmt(t *testing.T) { - nodes := map[string]Node{ - `0x7fc8b5094688 `: &CaseStmt{ + nodes := map[string]testNode{ + `0x7fc8b5094688 `: + testNode{&CaseStmt{ Addr: 0x7fc8b5094688, Pos: NewPositionFromString("line:11:5, line:12:21"), ChildNodes: []Node{}, }, + 0x7fc8b5094688, + NewPositionFromString("line:11:5, line:12:21"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/cf_audited_transfer_attr_test.go b/ast/cf_audited_transfer_attr_test.go new file mode 100644 index 0000000..ac49f1c --- /dev/null +++ b/ast/cf_audited_transfer_attr_test.go @@ -0,0 +1,23 @@ +package ast + +import ( + "testing" +) + +func TestCFAuditedTransferAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 content`: + testNode{&CFAuditedTransferAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + Content: " content", + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/cf_consumed_attr_test.go b/ast/cf_consumed_attr_test.go new file mode 100644 index 0000000..428c16f --- /dev/null +++ b/ast/cf_consumed_attr_test.go @@ -0,0 +1,23 @@ +package ast + +import ( + "testing" +) + +func TestCFConsumedAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 content`: + testNode{&CFConsumedAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + Content: " content", + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/cf_returns_not_retained_attr_test.go b/ast/cf_returns_not_retained_attr_test.go new file mode 100644 index 0000000..575603c --- /dev/null +++ b/ast/cf_returns_not_retained_attr_test.go @@ -0,0 +1,22 @@ +package ast + +import ( + "testing" +) + +func TestCFReturnsNotRetainedAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 `: + testNode{&CFReturnsNotRetainedAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/cf_returns_retained_attr_test.go b/ast/cf_returns_retained_attr_test.go new file mode 100644 index 0000000..2763ad8 --- /dev/null +++ b/ast/cf_returns_retained_attr_test.go @@ -0,0 +1,22 @@ +package ast + +import ( + "testing" +) + +func TestCFReturnsRetainedAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 `: + testNode{&CFReturnsRetainedAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/character_literal_test.go b/ast/character_literal_test.go index 00badcc..baa4c89 100644 --- a/ast/character_literal_test.go +++ b/ast/character_literal_test.go @@ -5,14 +5,19 @@ import ( ) func TestCharacterLiteral(t *testing.T) { - nodes := map[string]Node{ - `0x7f980b858308 'int' 10`: &CharacterLiteral{ + nodes := map[string]testNode{ + `0x7f980b858308 'int' 10`: + testNode{&CharacterLiteral{ Addr: 0x7f980b858308, Pos: NewPositionFromString("col:62"), Type: "int", Value: 10, ChildNodes: []Node{}, }, + 0x7f980b858308, + NewPositionFromString("col:62"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/compound_assign_operator_test.go b/ast/compound_assign_operator_test.go index b7bed1a..bfacc66 100644 --- a/ast/compound_assign_operator_test.go +++ b/ast/compound_assign_operator_test.go @@ -5,8 +5,9 @@ import ( ) func TestCompoundAssignOperator(t *testing.T) { - nodes := map[string]Node{ - `0x2dc5758 'int' '+=' ComputeLHSTy='int' ComputeResultTy='int'`: &CompoundAssignOperator{ + nodes := map[string]testNode{ + `0x2dc5758 'int' '+=' ComputeLHSTy='int' ComputeResultTy='int'`: + testNode{&CompoundAssignOperator{ Addr: 0x2dc5758, Pos: NewPositionFromString("line:5:2, col:7"), Type: "int", @@ -15,6 +16,10 @@ func TestCompoundAssignOperator(t *testing.T) { ComputationResultType: "int", ChildNodes: []Node{}, }, + 0x2dc5758, + NewPositionFromString("line:5:2, col:7"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/compound_literal_expr_test.go b/ast/compound_literal_expr_test.go index 4c89a90..2180cb6 100644 --- a/ast/compound_literal_expr_test.go +++ b/ast/compound_literal_expr_test.go @@ -5,14 +5,19 @@ import ( ) func TestCompoundLiteralExpr(t *testing.T) { - nodes := map[string]Node{ - `0x5575acce81f0 'struct node':'struct node' lvalue`: &CompoundLiteralExpr{ + nodes := map[string]testNode{ + `0x5575acce81f0 'struct node':'struct node' lvalue`: + testNode{&CompoundLiteralExpr{ Addr: 0x5575acce81f0, Pos: NewPositionFromString("col:21, col:40"), Type1: "struct node", Type2: "struct node", ChildNodes: []Node{}, }, + 0x5575acce81f0, + NewPositionFromString("col:21, col:40"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/compound_stmt_test.go b/ast/compound_stmt_test.go index 8ddd74b..4e9cc47 100644 --- a/ast/compound_stmt_test.go +++ b/ast/compound_stmt_test.go @@ -5,17 +5,27 @@ import ( ) func TestCompoundStmt(t *testing.T) { - nodes := map[string]Node{ - `0x7fbd0f014f18 `: &CompoundStmt{ + nodes := map[string]testNode{ + `0x7fbd0f014f18 `: + testNode{&CompoundStmt{ Addr: 0x7fbd0f014f18, Pos: NewPositionFromString("col:54, line:358:1"), ChildNodes: []Node{}, }, - `0x7fbd0f8360b8 `: &CompoundStmt{ + 0x7fbd0f014f18, + NewPositionFromString("col:54, line:358:1"), + []Node{}, + }, + `0x7fbd0f8360b8 `: + testNode{&CompoundStmt{ Addr: 0x7fbd0f8360b8, Pos: NewPositionFromString("line:4:1, line:13:1"), ChildNodes: []Node{}, }, + 0x7fbd0f8360b8, + NewPositionFromString("line:4:1, line:13:1"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/conditional_operator_test.go b/ast/conditional_operator_test.go index 346d9c5..9707998 100644 --- a/ast/conditional_operator_test.go +++ b/ast/conditional_operator_test.go @@ -5,13 +5,18 @@ import ( ) func TestConditionalOperator(t *testing.T) { - nodes := map[string]Node{ - `0x7fc6ae0bc678 'void'`: &ConditionalOperator{ + nodes := map[string]testNode{ + `0x7fc6ae0bc678 'void'`: + testNode{&ConditionalOperator{ Addr: 0x7fc6ae0bc678, Pos: NewPositionFromString("col:6, col:89"), Type: "void", ChildNodes: []Node{}, }, + 0x7fc6ae0bc678, + NewPositionFromString("col:6, col:89"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/const_attr.go b/ast/const_attr.go index 9bed561..60b0f1d 100644 --- a/ast/const_attr.go +++ b/ast/const_attr.go @@ -14,9 +14,6 @@ func parseConstAttr(line string) Node { "<(?P.*)>(?P.*)", line, ) - if groups == nil { - return &Unknown{} - } return &ConstAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/const_attr_test.go b/ast/const_attr_test.go index 74379d8..aff898b 100644 --- a/ast/const_attr_test.go +++ b/ast/const_attr_test.go @@ -5,13 +5,18 @@ import ( ) func TestConstAttr(t *testing.T) { - nodes := map[string]Node{ - `0x7fa3b88bbb38 foo`: &ConstAttr{ + nodes := map[string]testNode{ + `0x7fa3b88bbb38 foo`: + testNode{&ConstAttr{ Addr: 0x7fa3b88bbb38, Pos: NewPositionFromString("line:4:1, line:13:1"), Tags: "foo", ChildNodes: []Node{}, }, + 0x7fa3b88bbb38, + NewPositionFromString("line:4:1, line:13:1"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/constant_array_type_test.go b/ast/constant_array_type_test.go index 10a97a9..4fa737d 100644 --- a/ast/constant_array_type_test.go +++ b/ast/constant_array_type_test.go @@ -5,19 +5,29 @@ import ( ) func TestConstantArrayType(t *testing.T) { - nodes := map[string]Node{ - `0x7f94ad016a40 'struct __va_list_tag [1]' 1 `: &ConstantArrayType{ + nodes := map[string]testNode{ + `0x7f94ad016a40 'struct __va_list_tag [1]' 1 `: + testNode{&ConstantArrayType{ Addr: 0x7f94ad016a40, Type: "struct __va_list_tag [1]", Size: 1, ChildNodes: []Node{}, }, - `0x7f8c5f059d20 'char [37]' 37 `: &ConstantArrayType{ + 0x7f94ad016a40, + NewPositionFromString(""), + []Node{}, + }, + `0x7f8c5f059d20 'char [37]' 37 `: + testNode{&ConstantArrayType{ Addr: 0x7f8c5f059d20, Type: "char [37]", Size: 37, ChildNodes: []Node{}, }, + 0x7f8c5f059d20, + NewPositionFromString(""), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/continue_stmt_test.go b/ast/continue_stmt_test.go index d768349..5a7fe3b 100644 --- a/ast/continue_stmt_test.go +++ b/ast/continue_stmt_test.go @@ -5,12 +5,17 @@ import ( ) func TestContinueStmt(t *testing.T) { - nodes := map[string]Node{ - `0x1e044e0 `: &ContinueStmt{ + nodes := map[string]testNode{ + `0x1e044e0 `: + testNode{&ContinueStmt{ Addr: 0x1e044e0, Pos: NewPositionFromString("col:20"), ChildNodes: []Node{}, }, + 0x1e044e0, + NewPositionFromString("col:20"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/convert_vector_expr_test.go b/ast/convert_vector_expr_test.go new file mode 100644 index 0000000..6e12a03 --- /dev/null +++ b/ast/convert_vector_expr_test.go @@ -0,0 +1,36 @@ +package ast + +import ( + "testing" +) + +func TestConvertVectorExpr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fdef0862430 `: + testNode{&ConvertVectorExpr{ + Addr: 0x7fdef0862430, + Pos: NewPositionFromString("line:120:1, col:16"), + Type: "", + Type2: "", + ChildNodes: []Node{}, + }, + 0x7fdef0862430, + NewPositionFromString("line:120:1, col:16"), + []Node{}, + }, + `0x113368318 '__v2df':'__attribute__((__vector_size__(2 * sizeof(double)))) double'`: + testNode{&ConvertVectorExpr{ + Addr: 0x113368318, + Pos: NewPositionFromString("line:1354:20, line:1355:70"), + Type: `__v2df`, + Type2: `:'__attribute__((__vector_size__(2 * sizeof(double)))) double'`, + ChildNodes: []Node{}, + }, + 0x113368318, + NewPositionFromString("line:1354:20, line:1355:70"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/decayed_type_test.go b/ast/decayed_type_test.go index e16c17d..e919acc 100644 --- a/ast/decayed_type_test.go +++ b/ast/decayed_type_test.go @@ -5,12 +5,17 @@ import ( ) func TestDecayedType(t *testing.T) { - nodes := map[string]Node{ - `0x7f1234567890 'struct __va_list_tag *' sugar`: &DecayedType{ + nodes := map[string]testNode{ + `0x7f1234567890 'struct __va_list_tag *' sugar`: + testNode{&DecayedType{ Addr: 0x7f1234567890, Type: "struct __va_list_tag *", ChildNodes: []Node{}, }, + 0x7f1234567890, + NewPositionFromString(""), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/decl_ref_expr_test.go b/ast/decl_ref_expr_test.go index 2eedf5c..64a9db8 100644 --- a/ast/decl_ref_expr_test.go +++ b/ast/decl_ref_expr_test.go @@ -5,8 +5,9 @@ import ( ) func TestDeclRefExpr(t *testing.T) { - nodes := map[string]Node{ - `0x7fc972064460 'FILE *' lvalue ParmVar 0x7fc9720642d0 '_p' 'FILE *'`: &DeclRefExpr{ + nodes := map[string]testNode{ + `0x7fc972064460 'FILE *' lvalue ParmVar 0x7fc9720642d0 '_p' 'FILE *'`: + testNode{&DeclRefExpr{ Addr: 0x7fc972064460, Pos: NewPositionFromString("col:8"), Type: "FILE *", @@ -19,7 +20,12 @@ func TestDeclRefExpr(t *testing.T) { Type3: "", ChildNodes: []Node{}, }, - `0x7fc97206a958 'int (int, FILE *)' Function 0x7fc972064198 '__swbuf' 'int (int, FILE *)'`: &DeclRefExpr{ + 0x7fc972064460, + NewPositionFromString("col:8"), + []Node{}, + }, + `0x7fc97206a958 'int (int, FILE *)' Function 0x7fc972064198 '__swbuf' 'int (int, FILE *)'`: + testNode{&DeclRefExpr{ Addr: 0x7fc97206a958, Pos: NewPositionFromString("col:11"), Type: "int (int, FILE *)", @@ -32,7 +38,12 @@ func TestDeclRefExpr(t *testing.T) { Type3: "", ChildNodes: []Node{}, }, - `0x7fa36680f170 'struct programming':'struct programming' lvalue Var 0x7fa36680dc20 'variable' 'struct programming':'struct programming'`: &DeclRefExpr{ + 0x7fc97206a958, + NewPositionFromString("col:11"), + []Node{}, + }, + `0x7fa36680f170 'struct programming':'struct programming' lvalue Var 0x7fa36680dc20 'variable' 'struct programming':'struct programming'`: + testNode{&DeclRefExpr{ Addr: 0x7fa36680f170, Pos: NewPositionFromString("col:19"), Type: "struct programming", @@ -45,7 +56,12 @@ func TestDeclRefExpr(t *testing.T) { Type3: "struct programming", ChildNodes: []Node{}, }, - `0x35cb438 'int' EnumConstant 0x35ca300 'Jan' 'int'`: &DeclRefExpr{ + 0x7fa36680f170, + NewPositionFromString("col:19"), + []Node{}, + }, + `0x35cb438 'int' EnumConstant 0x35ca300 'Jan' 'int'`: + testNode{&DeclRefExpr{ Addr: 0x35cb438, Pos: NewPositionFromString("col:13"), Type: "int", @@ -58,7 +74,12 @@ func TestDeclRefExpr(t *testing.T) { Type3: "", ChildNodes: []Node{}, }, - `0x1ff8770 'T_ENUM':'T_ENUM' lvalue Var 0x1ff8600 'cc' 'T_ENUM':'T_ENUM'`: &DeclRefExpr{ + 0x35cb438, + NewPositionFromString("col:13"), + []Node{}, + }, + `0x1ff8770 'T_ENUM':'T_ENUM' lvalue Var 0x1ff8600 'cc' 'T_ENUM':'T_ENUM'`: + testNode{&DeclRefExpr{ Addr: 0x1ff8770, Pos: NewPositionFromString("col:33"), Type: "T_ENUM", @@ -71,6 +92,10 @@ func TestDeclRefExpr(t *testing.T) { Type3: "T_ENUM", ChildNodes: []Node{}, }, + 0x1ff8770, + NewPositionFromString("col:33"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/decl_stmt_test.go b/ast/decl_stmt_test.go index 79ff721..1f53831 100644 --- a/ast/decl_stmt_test.go +++ b/ast/decl_stmt_test.go @@ -5,12 +5,17 @@ import ( ) func TestDeclStmt(t *testing.T) { - nodes := map[string]Node{ - `0x7fb791846e80 `: &DeclStmt{ + nodes := map[string]testNode{ + `0x7fb791846e80 `: + testNode{&DeclStmt{ Addr: 0x7fb791846e80, Pos: NewPositionFromString("line:11:4, col:31"), ChildNodes: []Node{}, }, + 0x7fb791846e80, + NewPositionFromString("line:11:4, col:31"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/default_stmt_test.go b/ast/default_stmt_test.go index 3633862..e8ff92c 100644 --- a/ast/default_stmt_test.go +++ b/ast/default_stmt_test.go @@ -5,12 +5,17 @@ import ( ) func TestDefaultStmt(t *testing.T) { - nodes := map[string]Node{ - `0x7f951308bfb0 `: &DefaultStmt{ + nodes := map[string]testNode{ + `0x7f951308bfb0 `: + testNode{&DefaultStmt{ Addr: 0x7f951308bfb0, Pos: NewPositionFromString("line:17:5, line:18:34"), ChildNodes: []Node{}, }, + 0x7f951308bfb0, + NewPositionFromString("line:17:5, line:18:34"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/deprecated_attr_test.go b/ast/deprecated_attr_test.go index c6de681..3f90733 100644 --- a/ast/deprecated_attr_test.go +++ b/ast/deprecated_attr_test.go @@ -5,8 +5,9 @@ import ( ) func TestDeprecatedAttr(t *testing.T) { - nodes := map[string]Node{ - `0x7fec4b0ab9c0 "This function is provided for compatibility reasons only. Due to security concerns inherent in the design of tempnam(3), it is highly recommended that you use mkstemp(3) instead." ""`: &DeprecatedAttr{ + nodes := map[string]testNode{ + `0x7fec4b0ab9c0 "This function is provided for compatibility reasons only. Due to security concerns inherent in the design of tempnam(3), it is highly recommended that you use mkstemp(3) instead." ""`: + testNode{&DeprecatedAttr{ Addr: 0x7fec4b0ab9c0, Pos: NewPositionFromString("line:180:48, col:63"), Message1: "This function is provided for compatibility reasons only. Due to security concerns inherent in the design of tempnam(3), it is highly recommended that you use mkstemp(3) instead.", @@ -14,7 +15,12 @@ func TestDeprecatedAttr(t *testing.T) { IsInherited: false, ChildNodes: []Node{}, }, - `0xb75d00 "This function or variable may be unsafe. Consider using _snwprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details." ""`: &DeprecatedAttr{ + 0x7fec4b0ab9c0, + NewPositionFromString("line:180:48, col:63"), + []Node{}, + }, + `0xb75d00 "This function or variable may be unsafe. Consider using _snwprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details." ""`: + testNode{&DeprecatedAttr{ Addr: 0xb75d00, Pos: NewPositionFromString("line:1107:12"), Message1: "This function or variable may be unsafe. Consider using _snwprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.", @@ -22,7 +28,12 @@ func TestDeprecatedAttr(t *testing.T) { IsInherited: false, ChildNodes: []Node{}, }, - `0xb75d00 Inherited "This function or variable may be unsafe. Consider using _snwprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details." ""`: &DeprecatedAttr{ + 0xb75d00, + NewPositionFromString("line:1107:12"), + []Node{}, + }, + `0xb75d00 Inherited "This function or variable may be unsafe. Consider using _snwprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details." ""`: + testNode{&DeprecatedAttr{ Addr: 0xb75d00, Pos: NewPositionFromString("line:1107:12"), Message1: "This function or variable may be unsafe. Consider using _snwprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.", @@ -30,6 +41,10 @@ func TestDeprecatedAttr(t *testing.T) { IsInherited: true, ChildNodes: []Node{}, }, + 0xb75d00, + NewPositionFromString("line:1107:12"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/disable_tail_calls_attr_test.go b/ast/disable_tail_calls_attr_test.go index 5168b33..755e20c 100644 --- a/ast/disable_tail_calls_attr_test.go +++ b/ast/disable_tail_calls_attr_test.go @@ -5,12 +5,17 @@ import ( ) func TestDisableTailCallsAttr(t *testing.T) { - nodes := map[string]Node{ - `0x7fc8fa094558 `: &DisableTailCallsAttr{ + nodes := map[string]testNode{ + `0x7fc8fa094558 `: + testNode{&DisableTailCallsAttr{ Addr: 0x7fc8fa094558, Pos: NewPositionFromString("col:107"), ChildNodes: []Node{}, }, + 0x7fc8fa094558, + NewPositionFromString("col:107"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/do_stmt_test.go b/ast/do_stmt_test.go index fac8350..ea25e68 100644 --- a/ast/do_stmt_test.go +++ b/ast/do_stmt_test.go @@ -5,12 +5,17 @@ import ( ) func TestDoStmt(t *testing.T) { - nodes := map[string]Node{ - `0x7ff36d0a0938 `: &DoStmt{ + nodes := map[string]testNode{ + `0x7ff36d0a0938 `: + testNode{&DoStmt{ Addr: 0x7ff36d0a0938, Pos: NewPositionFromString("line:11:5, line:14:23"), ChildNodes: []Node{}, }, + 0x7ff36d0a0938, + NewPositionFromString("line:11:5, line:14:23"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/elaborated_type_test.go b/ast/elaborated_type_test.go index ba792a2..c786c47 100644 --- a/ast/elaborated_type_test.go +++ b/ast/elaborated_type_test.go @@ -5,13 +5,18 @@ import ( ) func TestElaboratedType(t *testing.T) { - nodes := map[string]Node{ - `0x7f873686c120 'union __mbstate_t' sugar`: &ElaboratedType{ + nodes := map[string]testNode{ + `0x7f873686c120 'union __mbstate_t' sugar`: + testNode{&ElaboratedType{ Addr: 0x7f873686c120, Type: "union __mbstate_t", Tags: "sugar", ChildNodes: []Node{}, }, + 0x7f873686c120, + NewPositionFromString(""), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/empty_decl.go b/ast/empty_decl.go index a47d103..c06ced5 100644 --- a/ast/empty_decl.go +++ b/ast/empty_decl.go @@ -11,7 +11,7 @@ type EmptyDecl struct { func parseEmptyDecl(line string) Node { groups := groupsFromRegex( `<(?P.*)> - ( (?P.*))?`, + ( (?P[^\s]+))?`, line, ) if groups == nil { diff --git a/ast/empty_decl_test.go b/ast/empty_decl_test.go index 2b1d88a..30229b3 100644 --- a/ast/empty_decl_test.go +++ b/ast/empty_decl_test.go @@ -5,13 +5,18 @@ import ( ) func TestEmptyDecl(t *testing.T) { - nodes := map[string]Node{ - `0x480bec8 col:13`: &EmptyDecl{ + nodes := map[string]testNode{ + `0x480bec8 col:13`: + testNode{&EmptyDecl{ Addr: 0x480bec8, Pos: NewPositionFromString("col:13"), Position2: NewPositionFromString("col:13"), ChildNodes: []Node{}, }, + 0x480bec8, + NewPositionFromString("col:13"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/enum_constant_decl_test.go b/ast/enum_constant_decl_test.go index eaf747d..5dfdcbb 100644 --- a/ast/enum_constant_decl_test.go +++ b/ast/enum_constant_decl_test.go @@ -5,8 +5,9 @@ import ( ) func TestEnumConstantDecl(t *testing.T) { - nodes := map[string]Node{ - `0x1660db0 __codecvt_noconv 'int'`: &EnumConstantDecl{ + nodes := map[string]testNode{ + `0x1660db0 __codecvt_noconv 'int'`: + testNode{&EnumConstantDecl{ Addr: 0x1660db0, Pos: NewPositionFromString("line:185:3"), Position2: "", @@ -15,7 +16,12 @@ func TestEnumConstantDecl(t *testing.T) { Type: "int", ChildNodes: []Node{}, }, - `0x3c77ba8 col:3 referenced _ISalnum 'int'`: &EnumConstantDecl{ + 0x1660db0, + NewPositionFromString("line:185:3"), + []Node{}, + }, + `0x3c77ba8 col:3 referenced _ISalnum 'int'`: + testNode{&EnumConstantDecl{ Addr: 0x3c77ba8, Pos: NewPositionFromString("line:59:3, col:65"), Position2: "col:3", @@ -24,6 +30,10 @@ func TestEnumConstantDecl(t *testing.T) { Type: "int", ChildNodes: []Node{}, }, + 0x3c77ba8, + NewPositionFromString("line:59:3, col:65"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/enum_decl_test.go b/ast/enum_decl_test.go index 94296c0..710127f 100644 --- a/ast/enum_decl_test.go +++ b/ast/enum_decl_test.go @@ -5,21 +5,31 @@ import ( ) func TestEnumDecl(t *testing.T) { - nodes := map[string]Node{ - `0x22a6c80 __codecvt_result`: &EnumDecl{ + nodes := map[string]testNode{ + `0x22a6c80 __codecvt_result`: + testNode{&EnumDecl{ Addr: 0x22a6c80, Pos: NewPositionFromString("line:180:1, line:186:1"), Position2: "", Name: "__codecvt_result", ChildNodes: []Node{}, }, - `0x32fb5a0 col:6 week`: &EnumDecl{ + 0x22a6c80, + NewPositionFromString("line:180:1, line:186:1"), + []Node{}, + }, + `0x32fb5a0 col:6 week`: + testNode{&EnumDecl{ Addr: 0x32fb5a0, Pos: NewPositionFromString("enum.c:3:1, col:45"), Position2: " col:6", Name: "week", ChildNodes: []Node{}, }, + 0x32fb5a0, + NewPositionFromString("enum.c:3:1, col:45"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/enum_extensibility_attr.go b/ast/enum_extensibility_attr.go index f3bf17d..059c64f 100644 --- a/ast/enum_extensibility_attr.go +++ b/ast/enum_extensibility_attr.go @@ -13,9 +13,9 @@ func parseEnumExtensibilityAttr(line string) Node { "<(?P.*)>(?P.*)", line, ) - if groups == nil { - return &Unknown{} - } + if groups == nil { + return &Unknown{} + } return &EnumExtensibilityAttr{ Addr: ParseAddress(groups["address"]), diff --git a/ast/enum_extensibility_attr_test.go b/ast/enum_extensibility_attr_test.go new file mode 100644 index 0000000..55b59d8 --- /dev/null +++ b/ast/enum_extensibility_attr_test.go @@ -0,0 +1,23 @@ +package ast + +import ( + "testing" +) + +func TestEnumExtensibilityAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 content`: + testNode{&EnumExtensibilityAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + Content: " content", + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/enum_test.go b/ast/enum_test.go index 970f63e..1234ffe 100644 --- a/ast/enum_test.go +++ b/ast/enum_test.go @@ -5,12 +5,17 @@ import ( ) func TestEnum(t *testing.T) { - nodes := map[string]Node{ - `0x7f980b858308 'foo'`: &Enum{ + nodes := map[string]testNode{ + `0x7f980b858308 'foo'`: + testNode{&Enum{ Addr: 0x7f980b858308, Name: "foo", ChildNodes: []Node{}, }, + 0x7f980b858308, + NewPositionFromString(""), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/enum_type_test.go b/ast/enum_type_test.go index d3fbe35..0023e01 100644 --- a/ast/enum_type_test.go +++ b/ast/enum_type_test.go @@ -5,12 +5,17 @@ import ( ) func TestEnumType(t *testing.T) { - nodes := map[string]Node{ - `0x7f980b858309 'foo'`: &EnumType{ + nodes := map[string]testNode{ + `0x7f980b858309 'foo'`: + testNode{&EnumType{ Addr: 0x7f980b858309, Name: "foo", ChildNodes: []Node{}, }, + 0x7f980b858309, + NewPositionFromString(""), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/field_decl_test.go b/ast/field_decl_test.go index 79151e2..abd6a8d 100644 --- a/ast/field_decl_test.go +++ b/ast/field_decl_test.go @@ -5,8 +5,9 @@ import ( ) func TestFieldDecl(t *testing.T) { - nodes := map[string]Node{ - `0x7fef510c4848 col:6 _ur 'int'`: &FieldDecl{ + nodes := map[string]testNode{ + `0x7fef510c4848 col:6 _ur 'int'`: + testNode{&FieldDecl{ Addr: 0x7fef510c4848, Pos: NewPositionFromString("line:141:2, col:6"), Position2: "col:6", @@ -17,7 +18,12 @@ func TestFieldDecl(t *testing.T) { Referenced: false, ChildNodes: []Node{}, }, - `0x7fef510c46f8 col:16 _ub 'struct __sbuf':'struct __sbuf'`: &FieldDecl{ + 0x7fef510c4848, + NewPositionFromString("line:141:2, col:6"), + []Node{}, + }, + `0x7fef510c46f8 col:16 _ub 'struct __sbuf':'struct __sbuf'`: + testNode{&FieldDecl{ Addr: 0x7fef510c46f8, Pos: NewPositionFromString("line:139:2, col:16"), Position2: "col:16", @@ -28,7 +34,12 @@ func TestFieldDecl(t *testing.T) { Referenced: false, ChildNodes: []Node{}, }, - `0x7fef510c3fe0 col:19 _read 'int (* _Nullable)(void *, char *, int)':'int (*)(void *, char *, int)'`: &FieldDecl{ + 0x7fef510c46f8, + NewPositionFromString("line:139:2, col:16"), + []Node{}, + }, + `0x7fef510c3fe0 col:19 _read 'int (* _Nullable)(void *, char *, int)':'int (*)(void *, char *, int)'`: + testNode{&FieldDecl{ Addr: 0x7fef510c3fe0, Pos: NewPositionFromString("line:134:2, col:19"), Position2: "col:19", @@ -39,7 +50,12 @@ func TestFieldDecl(t *testing.T) { Referenced: false, ChildNodes: []Node{}, }, - `0x7fef51073a60 col:40 __cleanup_stack 'struct __darwin_pthread_handler_rec *'`: &FieldDecl{ + 0x7fef510c3fe0, + NewPositionFromString("line:134:2, col:19"), + []Node{}, + }, + `0x7fef51073a60 col:40 __cleanup_stack 'struct __darwin_pthread_handler_rec *'`: + testNode{&FieldDecl{ Addr: 0x7fef51073a60, Pos: NewPositionFromString("line:105:2, col:40"), Position2: "col:40", @@ -50,7 +66,12 @@ func TestFieldDecl(t *testing.T) { Referenced: false, ChildNodes: []Node{}, }, - `0x7fef510738e8 col:7 __opaque 'char [16]'`: &FieldDecl{ + 0x7fef51073a60, + NewPositionFromString("line:105:2, col:40"), + []Node{}, + }, + `0x7fef510738e8 col:7 __opaque 'char [16]'`: + testNode{&FieldDecl{ Addr: 0x7fef510738e8, Pos: NewPositionFromString("line:100:2, col:43"), Position2: "col:7", @@ -61,7 +82,12 @@ func TestFieldDecl(t *testing.T) { Referenced: false, ChildNodes: []Node{}, }, - `0x7fe9f5072268 col:6 referenced _lbfsize 'int'`: &FieldDecl{ + 0x7fef510738e8, + NewPositionFromString("line:100:2, col:43"), + []Node{}, + }, + `0x7fe9f5072268 col:6 referenced _lbfsize 'int'`: + testNode{&FieldDecl{ Addr: 0x7fe9f5072268, Pos: NewPositionFromString("line:129:2, col:6"), Position2: "col:6", @@ -72,7 +98,12 @@ func TestFieldDecl(t *testing.T) { Referenced: true, ChildNodes: []Node{}, }, - `0x7f9bc9083d00 line:91:5 'unsigned short'`: &FieldDecl{ + 0x7fe9f5072268, + NewPositionFromString("line:129:2, col:6"), + []Node{}, + }, + `0x7f9bc9083d00 line:91:5 'unsigned short'`: + testNode{&FieldDecl{ Addr: 0x7f9bc9083d00, Pos: NewPositionFromString("line:91:5, line:97:8"), Position2: "line:91:5", @@ -83,7 +114,12 @@ func TestFieldDecl(t *testing.T) { Referenced: false, ChildNodes: []Node{}, }, - `0x30363a0 __val 'int [2]'`: &FieldDecl{ + 0x7f9bc9083d00, + NewPositionFromString("line:91:5, line:97:8"), + []Node{}, + }, + `0x30363a0 __val 'int [2]'`: + testNode{&FieldDecl{ Addr: 0x30363a0, Pos: NewPositionFromString("col:18, col:29"), Position2: "", @@ -94,7 +130,12 @@ func TestFieldDecl(t *testing.T) { Referenced: false, ChildNodes: []Node{}, }, - `0x17aeac0 col:9 implicit referenced 'struct vec3d_t::(anonymous at main.c:3:9)'`: &FieldDecl{ + 0x30363a0, + NewPositionFromString("col:18, col:29"), + []Node{}, + }, + `0x17aeac0 col:9 implicit referenced 'struct vec3d_t::(anonymous at main.c:3:9)'`: + testNode{&FieldDecl{ Addr: 0x17aeac0, Pos: NewPositionFromString("line:3:9"), Position2: "col:9", @@ -105,7 +146,12 @@ func TestFieldDecl(t *testing.T) { Referenced: true, ChildNodes: []Node{}, }, - `0x56498bf52160 col:21 type 'enum __pid_type':'enum __pid_type'`: &FieldDecl{ + 0x17aeac0, + NewPositionFromString("line:3:9"), + []Node{}, + }, + `0x56498bf52160 col:21 type 'enum __pid_type':'enum __pid_type'`: + testNode{&FieldDecl{ Addr: 0x56498bf52160, Pos: NewPositionFromString("line:269:5, col:21"), Position2: "col:21", @@ -116,6 +162,10 @@ func TestFieldDecl(t *testing.T) { Referenced: false, ChildNodes: []Node{}, }, + 0x56498bf52160, + NewPositionFromString("line:269:5, col:21"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/field_test.go b/ast/field_test.go index 04c548b..88778da 100644 --- a/ast/field_test.go +++ b/ast/field_test.go @@ -5,13 +5,18 @@ import ( ) func TestField(t *testing.T) { - nodes := map[string]Node{ - `0x44159a0 '' 'union sigcontext::(anonymous at /usr/include/x86_64-linux-gnu/bits/sigcontext.h:165:17)'`: &Field{ + nodes := map[string]testNode{ + `0x44159a0 '' 'union sigcontext::(anonymous at /usr/include/x86_64-linux-gnu/bits/sigcontext.h:165:17)'`: + testNode{&Field{ Addr: 0x44159a0, String1: "", String2: "union sigcontext::(anonymous at /usr/include/x86_64-linux-gnu/bits/sigcontext.h:165:17)", ChildNodes: []Node{}, }, + 0x44159a0, + NewPositionFromString(""), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/flag_enum_attr.go b/ast/flag_enum_attr.go index 5616cc6..71f6cdf 100644 --- a/ast/flag_enum_attr.go +++ b/ast/flag_enum_attr.go @@ -2,48 +2,48 @@ package ast // FlagEnumAttr type FlagEnumAttr struct { - Addr Address - Pos Position - Content string - ChildNodes []Node + Addr Address + Pos Position + Content string + ChildNodes []Node } func parseFlagEnumAttr(line string) Node { - groups := groupsFromRegex( - "<(?P.*)>(?P.*)", - line, - ) + groups := groupsFromRegex( + "<(?P.*)>(?P.*)", + line, + ) if groups == nil { return &Unknown{} } - return &FlagEnumAttr{ - Addr: ParseAddress(groups["address"]), - Pos: NewPositionFromString(groups["position"]), - Content: groups["content"], - ChildNodes: []Node{}, - } + return &FlagEnumAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + Content: groups["content"], + ChildNodes: []Node{}, + } } // AddChild adds a new child node. Child nodes can then be accessed with the // Children attribute. func (n *FlagEnumAttr) AddChild(node Node) { - n.ChildNodes = append(n.ChildNodes, 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 *FlagEnumAttr) Address() Address { - return n.Addr + 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 *FlagEnumAttr) Children() []Node { - return n.ChildNodes + return n.ChildNodes } // Position returns the position in the original source code. func (n *FlagEnumAttr) Position() Position { - return n.Pos + return n.Pos } diff --git a/ast/flag_enum_attr_test.go b/ast/flag_enum_attr_test.go new file mode 100644 index 0000000..1e102e1 --- /dev/null +++ b/ast/flag_enum_attr_test.go @@ -0,0 +1,23 @@ +package ast + +import ( + "testing" +) + +func TestFlagEnumAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 content`: + testNode{&FlagEnumAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + Content: " content", + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/floating_literal_test.go b/ast/floating_literal_test.go index 496aa20..6c7f88d 100644 --- a/ast/floating_literal_test.go +++ b/ast/floating_literal_test.go @@ -5,21 +5,31 @@ import ( ) func TestFloatingLiteral(t *testing.T) { - nodes := map[string]Node{ - `0x7febe106f5e8 'double' 1.230000e+00`: &FloatingLiteral{ + nodes := map[string]testNode{ + `0x7febe106f5e8 'double' 1.230000e+00`: + testNode{&FloatingLiteral{ Addr: 0x7febe106f5e8, Pos: NewPositionFromString("col:24"), Type: "double", Value: 1.23, ChildNodes: []Node{}, }, - `0x21c65b8 'double' 2.718282e+00`: &FloatingLiteral{ + 0x7febe106f5e8, + NewPositionFromString("col:24"), + []Node{}, + }, + `0x21c65b8 'double' 2.718282e+00`: + testNode{&FloatingLiteral{ Addr: 0x21c65b8, Pos: NewPositionFromString("col:41"), Type: "double", Value: 2.718282e+00, ChildNodes: []Node{}, }, + 0x21c65b8, + NewPositionFromString("col:41"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/for_stmt_test.go b/ast/for_stmt_test.go index 351927b..34a9c4a 100644 --- a/ast/for_stmt_test.go +++ b/ast/for_stmt_test.go @@ -5,12 +5,17 @@ import ( ) func TestForStmt(t *testing.T) { - nodes := map[string]Node{ - `0x7f961e018848 `: &ForStmt{ + nodes := map[string]testNode{ + `0x7f961e018848 `: + testNode{&ForStmt{ Addr: 0x7f961e018848, Pos: NewPositionFromString("line:9:4, line:10:70"), ChildNodes: []Node{}, }, + 0x7f961e018848, + NewPositionFromString("line:9:4, line:10:70"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/format_arg_attr_test.go b/ast/format_arg_attr_test.go index 3600360..79eb48e 100644 --- a/ast/format_arg_attr_test.go +++ b/ast/format_arg_attr_test.go @@ -5,13 +5,18 @@ import ( ) func TestFormatArgAttr(t *testing.T) { - nodes := map[string]Node{ - `0x7f1234567890 1`: &FormatArgAttr{ + nodes := map[string]testNode{ + `0x7f1234567890 1`: + testNode{&FormatArgAttr{ Addr: 0x7f1234567890, Pos: NewPositionFromString("col:47, col:57"), Arg: "1", ChildNodes: []Node{}, }, + 0x7f1234567890, + NewPositionFromString("col:47, col:57"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/format_attr_test.go b/ast/format_attr_test.go index 7fa23c7..44093dd 100644 --- a/ast/format_attr_test.go +++ b/ast/format_attr_test.go @@ -5,8 +5,9 @@ import ( ) func TestFormatAttr(t *testing.T) { - nodes := map[string]Node{ - `0x7fcc8d8ecee8 Implicit printf 2 3`: &FormatAttr{ + nodes := map[string]testNode{ + `0x7fcc8d8ecee8 Implicit printf 2 3`: + testNode{&FormatAttr{ Addr: 0x7fcc8d8ecee8, Pos: NewPositionFromString("col:6"), Implicit: true, @@ -16,7 +17,12 @@ func TestFormatAttr(t *testing.T) { Unknown2: 3, ChildNodes: []Node{}, }, - `0x7fcc8d8ecff8 printf 2 3`: &FormatAttr{ + 0x7fcc8d8ecee8, + NewPositionFromString("col:6"), + []Node{}, + }, + `0x7fcc8d8ecff8 printf 2 3`: + testNode{&FormatAttr{ Addr: 0x7fcc8d8ecff8, Pos: NewPositionFromString("/usr/include/sys/cdefs.h:351:18, col:61"), Implicit: false, @@ -26,7 +32,12 @@ func TestFormatAttr(t *testing.T) { Unknown2: 3, ChildNodes: []Node{}, }, - `0x273b4d0 Inherited printf 2 3`: &FormatAttr{ + 0x7fcc8d8ecff8, + NewPositionFromString("/usr/include/sys/cdefs.h:351:18, col:61"), + []Node{}, + }, + `0x273b4d0 Inherited printf 2 3`: + testNode{&FormatAttr{ Addr: 0x273b4d0, Pos: NewPositionFromString("line:357:12"), Implicit: false, @@ -36,6 +47,10 @@ func TestFormatAttr(t *testing.T) { Unknown2: 3, ChildNodes: []Node{}, }, + 0x273b4d0, + NewPositionFromString("line:357:12"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/full_comment_test.go b/ast/full_comment_test.go index 1e4f839..de7d228 100644 --- a/ast/full_comment_test.go +++ b/ast/full_comment_test.go @@ -5,12 +5,17 @@ import ( ) func TestFullComment(t *testing.T) { - nodes := map[string]Node{ - `0x3860920 `: &FullComment{ + nodes := map[string]testNode{ + `0x3860920 `: + testNode{&FullComment{ Addr: 0x3860920, Pos: NewPositionFromString("line:10176:4, line:10180:45"), ChildNodes: []Node{}, }, + 0x3860920, + NewPositionFromString("line:10176:4, line:10180:45"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/function_decl_test.go b/ast/function_decl_test.go index 3f56a6f..91be062 100644 --- a/ast/function_decl_test.go +++ b/ast/function_decl_test.go @@ -5,8 +5,9 @@ import ( ) func TestFunctionDecl(t *testing.T) { - nodes := map[string]Node{ - `0x7fb5a90e60d0 col:7 clearerr 'void (FILE *)'`: &FunctionDecl{ + nodes := map[string]testNode{ + `0x7fb5a90e60d0 col:7 clearerr 'void (FILE *)'`: + testNode{&FunctionDecl{ Addr: 0x7fb5a90e60d0, Pos: NewPositionFromString("line:231:1, col:22"), Prev: "", @@ -22,7 +23,12 @@ func TestFunctionDecl(t *testing.T) { IsInline: false, ChildNodes: []Node{}, }, - `0x7fb5a90e2a50 /usr/include/sys/stdio.h:39:5 renameat 'int (int, const char *, int, const char *)'`: &FunctionDecl{ + 0x7fb5a90e60d0, + NewPositionFromString("line:231:1, col:22"), + []Node{}, + }, + `0x7fb5a90e2a50 /usr/include/sys/stdio.h:39:5 renameat 'int (int, const char *, int, const char *)'`: + testNode{&FunctionDecl{ Addr: 0x7fb5a90e2a50, Pos: NewPositionFromString("/usr/include/sys/stdio.h:39:1, /usr/include/AvailabilityInternal.h:21697:126"), Prev: "", @@ -38,7 +44,12 @@ func TestFunctionDecl(t *testing.T) { IsInline: false, ChildNodes: []Node{}, }, - `0x7fb5a90e9b70 col:6 implicit fprintf 'int (FILE *, const char *, ...)' extern`: &FunctionDecl{ + 0x7fb5a90e2a50, + NewPositionFromString("/usr/include/sys/stdio.h:39:1, /usr/include/AvailabilityInternal.h:21697:126"), + []Node{}, + }, + `0x7fb5a90e9b70 col:6 implicit fprintf 'int (FILE *, const char *, ...)' extern`: + testNode{&FunctionDecl{ Addr: 0x7fb5a90e9b70, Pos: NewPositionFromString("/usr/include/stdio.h:244:6"), Prev: "", @@ -54,7 +65,12 @@ func TestFunctionDecl(t *testing.T) { IsInline: false, ChildNodes: []Node{}, }, - `0x7fb5a90e9d40 prev 0x7fb5a90e9b70 /usr/include/stdio.h:244:6 fprintf 'int (FILE *, const char *, ...)'`: &FunctionDecl{ + 0x7fb5a90e9b70, + NewPositionFromString("/usr/include/stdio.h:244:6"), + []Node{}, + }, + `0x7fb5a90e9d40 prev 0x7fb5a90e9b70 /usr/include/stdio.h:244:6 fprintf 'int (FILE *, const char *, ...)'`: + testNode{&FunctionDecl{ Addr: 0x7fb5a90e9d40, Pos: NewPositionFromString("col:1, /usr/include/sys/cdefs.h:351:63"), Prev: "0x7fb5a90e9b70", @@ -70,7 +86,12 @@ func TestFunctionDecl(t *testing.T) { IsInline: false, ChildNodes: []Node{}, }, - `0x7fb5a90ec210 col:6 implicit used printf 'int (const char *, ...)' extern`: &FunctionDecl{ + 0x7fb5a90e9d40, + NewPositionFromString("col:1, /usr/include/sys/cdefs.h:351:63"), + []Node{}, + }, + `0x7fb5a90ec210 col:6 implicit used printf 'int (const char *, ...)' extern`: + testNode{&FunctionDecl{ Addr: 0x7fb5a90ec210, Pos: NewPositionFromString("line:259:6"), Prev: "", @@ -86,7 +107,12 @@ func TestFunctionDecl(t *testing.T) { IsInline: false, ChildNodes: []Node{}, }, - `0x2ae30d8 :17:1 __acos 'double (double)' extern`: &FunctionDecl{ + 0x7fb5a90ec210, + NewPositionFromString("line:259:6"), + []Node{}, + }, + `0x2ae30d8 :17:1 __acos 'double (double)' extern`: + testNode{&FunctionDecl{ Addr: 0x2ae30d8, Pos: NewPositionFromString("/usr/include/math.h:65:3, /usr/include/x86_64-linux-gnu/sys/cdefs.h:57:54"), Prev: "", @@ -102,7 +128,12 @@ func TestFunctionDecl(t *testing.T) { IsInline: false, ChildNodes: []Node{}, }, - `0x7fc595071500 line:26:5 referenced main 'int (int, char **)'`: &FunctionDecl{ + 0x2ae30d8, + NewPositionFromString("/usr/include/math.h:65:3, /usr/include/x86_64-linux-gnu/sys/cdefs.h:57:54"), + []Node{}, + }, + `0x7fc595071500 line:26:5 referenced main 'int (int, char **)'`: + testNode{&FunctionDecl{ Addr: 0x7fc595071500, Pos: NewPositionFromString("line:26:1, line:69:1"), Prev: "", @@ -118,7 +149,12 @@ func TestFunctionDecl(t *testing.T) { IsInline: false, ChildNodes: []Node{}, }, - `0x55973a008cb0 line:93619:12 used exprIsConst 'int (Expr *, int, int)' static`: &FunctionDecl{ + 0x7fc595071500, + NewPositionFromString("line:26:1, line:69:1"), + []Node{}, + }, + `0x55973a008cb0 line:93619:12 used exprIsConst 'int (Expr *, int, int)' static`: + testNode{&FunctionDecl{ Addr: 0x55973a008cb0, Pos: NewPositionFromString("line:93619:1, line:93630:1"), Prev: "", @@ -134,7 +170,12 @@ func TestFunctionDecl(t *testing.T) { IsInline: false, ChildNodes: []Node{}, }, - `0x563ade547cb8 line:14:2 safe_unary_minus_func_int8_t_s 'int8_t (int8_t)':'int8_t (int8_t)' static`: &FunctionDecl{ + 0x55973a008cb0, + NewPositionFromString("line:93619:1, line:93630:1"), + []Node{}, + }, + `0x563ade547cb8 line:14:2 safe_unary_minus_func_int8_t_s 'int8_t (int8_t)':'int8_t (int8_t)' static`: + testNode{&FunctionDecl{ Addr: 0x563ade547cb8, Pos: NewPositionFromString("safe_math.h:13:1, line:25:1"), Prev: "", @@ -150,7 +191,12 @@ func TestFunctionDecl(t *testing.T) { IsInline: false, ChildNodes: []Node{}, }, - `0x556cac571be0 line:9:26 sqlite3Hwtime1 'unsigned long (void)' inline`: &FunctionDecl{ + 0x563ade547cb8, + NewPositionFromString("safe_math.h:13:1, line:25:1"), + []Node{}, + }, + `0x556cac571be0 line:9:26 sqlite3Hwtime1 'unsigned long (void)' inline`: + testNode{&FunctionDecl{ Addr: 0x556cac571be0, Pos: NewPositionFromString("tests/asm.c:9:1, line:13:1"), Prev: "", @@ -166,7 +212,12 @@ func TestFunctionDecl(t *testing.T) { IsInline: true, ChildNodes: []Node{}, }, - `0x21c3da0 line:8201:25 used insertvertex 'enum insertvertexresult (struct mesh *, struct behavior *, vertex, struct otri *, struct osub *, int, int)'`: &FunctionDecl{ + 0x556cac571be0, + NewPositionFromString("tests/asm.c:9:1, line:13:1"), + []Node{}, + }, + `0x21c3da0 line:8201:25 used insertvertex 'enum insertvertexresult (struct mesh *, struct behavior *, vertex, struct otri *, struct osub *, int, int)'`: + testNode{&FunctionDecl{ Addr: 0x21c3da0, Pos: NewPositionFromString("line:8201:1, line:8786:1"), Prev: "", @@ -182,7 +233,12 @@ func TestFunctionDecl(t *testing.T) { IsInline: false, ChildNodes: []Node{}, }, - `0x30bdba8 parent 0x304fbb0 col:30 used getinfo 'enum countries ()'`: &FunctionDecl{ + 0x21c3da0, + NewPositionFromString("line:8201:1, line:8786:1"), + []Node{}, + }, + `0x30bdba8 parent 0x304fbb0 col:30 used getinfo 'enum countries ()'`: + testNode{&FunctionDecl{ Addr: 0x30bdba8, Pos: NewPositionFromString("col:3, col:38"), Prev: "", @@ -199,7 +255,12 @@ func TestFunctionDecl(t *testing.T) { IsInline: false, ChildNodes: []Node{}, }, - `0x353d3b8 parent 0x31e9ba0 prev 0x33b0810 col:22 used dmatrix 'double **(long, long, long, long)'`: &FunctionDecl{ + 0x30bdba8, + NewPositionFromString("col:3, col:38"), + []Node{}, + }, + `0x353d3b8 parent 0x31e9ba0 prev 0x33b0810 col:22 used dmatrix 'double **(long, long, long, long)'`: + testNode{&FunctionDecl{ Addr: 0x353d3b8, Pos: NewPositionFromString("col:2, col:30"), Prev: "0x33b0810", @@ -216,6 +277,10 @@ func TestFunctionDecl(t *testing.T) { IsInline: false, ChildNodes: []Node{}, }, + 0x353d3b8, + NewPositionFromString("col:2, col:30"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/function_proto_type_test.go b/ast/function_proto_type_test.go index 31b4984..979c540 100644 --- a/ast/function_proto_type_test.go +++ b/ast/function_proto_type_test.go @@ -5,13 +5,18 @@ import ( ) func TestFunctionProtoType(t *testing.T) { - nodes := map[string]Node{ - `0x7fa3b88bbb30 'struct _opaque_pthread_t *' foo`: &FunctionProtoType{ + nodes := map[string]testNode{ + `0x7fa3b88bbb30 'struct _opaque_pthread_t *' foo`: + testNode{&FunctionProtoType{ Addr: 0x7fa3b88bbb30, Type: "struct _opaque_pthread_t *", Kind: "foo", ChildNodes: []Node{}, }, + 0x7fa3b88bbb30, + NewPositionFromString(""), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/gcc_asm_stmt_test.go b/ast/gcc_asm_stmt_test.go index 4c42ecd..870cd53 100644 --- a/ast/gcc_asm_stmt_test.go +++ b/ast/gcc_asm_stmt_test.go @@ -5,12 +5,17 @@ import ( ) func TestGCCAsmStmtStmt(t *testing.T) { - nodes := map[string]Node{ - `0x7fad830c9e38 `: &GCCAsmStmt{ + nodes := map[string]testNode{ + `0x7fad830c9e38 `: + testNode{&GCCAsmStmt{ Addr: 0x7fad830c9e38, Pos: NewPositionFromString("line:13:5, col:57"), ChildNodes: []Node{}, }, + 0x7fad830c9e38, + NewPositionFromString("line:13:5, col:57"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/go_stmt_test.go b/ast/go_stmt_test.go index 0c7cdcc..3654302 100644 --- a/ast/go_stmt_test.go +++ b/ast/go_stmt_test.go @@ -5,14 +5,19 @@ import ( ) func TestGotoStmt(t *testing.T) { - nodes := map[string]Node{ - `0x7fb9cc1994d8 'end_getDigits' 0x7fb9cc199490`: &GotoStmt{ + nodes := map[string]testNode{ + `0x7fb9cc1994d8 'end_getDigits' 0x7fb9cc199490`: + testNode{&GotoStmt{ Addr: 0x7fb9cc1994d8, Pos: NewPositionFromString("line:18893:9, col:14"), Name: "end_getDigits", Position2: "0x7fb9cc199490", ChildNodes: []Node{}, }, + 0x7fb9cc1994d8, + NewPositionFromString("line:18893:9, col:14"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/html_end_tag_comment_test.go b/ast/html_end_tag_comment_test.go index 4b2ff9d..9c63168 100644 --- a/ast/html_end_tag_comment_test.go +++ b/ast/html_end_tag_comment_test.go @@ -5,13 +5,18 @@ import ( ) func TestHTMLEndTagComment(t *testing.T) { - nodes := map[string]Node{ - `0x4259670 Name="i"`: &HTMLEndTagComment{ + nodes := map[string]testNode{ + `0x4259670 Name="i"`: + testNode{&HTMLEndTagComment{ Addr: 0x4259670, Pos: NewPositionFromString("col:27, col:30"), Name: "i", ChildNodes: []Node{}, }, + 0x4259670, + NewPositionFromString("col:27, col:30"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/html_start_tag_comment_test.go b/ast/html_start_tag_comment_test.go index 7822e73..d6e7472 100644 --- a/ast/html_start_tag_comment_test.go +++ b/ast/html_start_tag_comment_test.go @@ -5,13 +5,18 @@ import ( ) func TestHTMLStartTagComment(t *testing.T) { - nodes := map[string]Node{ - `0x4259670 Name="i"`: &HTMLStartTagComment{ + nodes := map[string]testNode{ + `0x4259670 Name="i"`: + testNode{&HTMLStartTagComment{ Addr: 0x4259670, Pos: NewPositionFromString("col:27, col:30"), Name: "i", ChildNodes: []Node{}, }, + 0x4259670, + NewPositionFromString("col:27, col:30"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/ib_action_attr_test.go b/ast/ib_action_attr_test.go new file mode 100644 index 0000000..12c3a62 --- /dev/null +++ b/ast/ib_action_attr_test.go @@ -0,0 +1,22 @@ +package ast + +import ( + "testing" +) + +func TestIBActionAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 `: + testNode{&IBActionAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/ib_outlet_attr_test.go b/ast/ib_outlet_attr_test.go new file mode 100644 index 0000000..f064b92 --- /dev/null +++ b/ast/ib_outlet_attr_test.go @@ -0,0 +1,22 @@ +package ast + +import ( + "testing" +) + +func TestIBOutletAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 `: + testNode{&IBOutletAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/if_stmt_test.go b/ast/if_stmt_test.go index 52c1df1..3646d55 100644 --- a/ast/if_stmt_test.go +++ b/ast/if_stmt_test.go @@ -5,12 +5,17 @@ import ( ) func TestIfStmt(t *testing.T) { - nodes := map[string]Node{ - `0x7fc0a69091d0 `: &IfStmt{ + nodes := map[string]testNode{ + `0x7fc0a69091d0 `: + testNode{&IfStmt{ Addr: 0x7fc0a69091d0, Pos: NewPositionFromString("line:11:7, line:18:7"), ChildNodes: []Node{}, }, + 0x7fc0a69091d0, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/implicit_cast_expr_test.go b/ast/implicit_cast_expr_test.go index b19bab0..14c9aba 100644 --- a/ast/implicit_cast_expr_test.go +++ b/ast/implicit_cast_expr_test.go @@ -5,22 +5,33 @@ import ( ) func TestImplicitCastExpr(t *testing.T) { - nodes := map[string]Node{ - `0x7f9f5b0a1288 'FILE *' `: &ImplicitCastExpr{ + nodes := map[string]testNode{ + `0x7f9f5b0a1288 'FILE *' `: + testNode{&ImplicitCastExpr{ Addr: 0x7f9f5b0a1288, Pos: NewPositionFromString("col:8"), Type: "FILE *", Kind: "LValueToRValue", ChildNodes: []Node{}, }, - `0x7f9f5b0a7828 'int (*)(int, FILE *)' `: &ImplicitCastExpr{ + 0x7f9f5b0a1288, + NewPositionFromString("col:8"), + []Node{}, + }, + `0x7f9f5b0a7828 'int (*)(int, FILE *)' `: + testNode{&ImplicitCastExpr{ Addr: 0x7f9f5b0a7828, Pos: NewPositionFromString("col:11"), Type: "int (*)(int, FILE *)", Kind: "FunctionToPointerDecay", ChildNodes: []Node{}, }, - `0x21267c8 'enum week1':'enum week2' `: &ImplicitCastExpr{ + 0x7f9f5b0a7828, + NewPositionFromString("col:11"), + []Node{}, + }, + `0x21267c8 'enum week1':'enum week2' `: + testNode{&ImplicitCastExpr{ Addr: 0x21267c8, Pos: NewPositionFromString("col:8"), Type: "enum week1", @@ -28,7 +39,12 @@ func TestImplicitCastExpr(t *testing.T) { Kind: "IntegralCast", ChildNodes: []Node{}, }, - `0x26fd2d8 'extCoord':'extCoord' `: &ImplicitCastExpr{ + 0x21267c8, + NewPositionFromString("col:8"), + []Node{}, + }, + `0x26fd2d8 'extCoord':'extCoord' `: + testNode{&ImplicitCastExpr{ Addr: 0x26fd2d8, Pos: NewPositionFromString("col:20, col:32"), Type: "extCoord", @@ -36,6 +52,10 @@ func TestImplicitCastExpr(t *testing.T) { Kind: "LValueToRValue", ChildNodes: []Node{}, }, + 0x26fd2d8, + NewPositionFromString("col:20, col:32"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/implicit_value_init_expr_test.go b/ast/implicit_value_init_expr_test.go index 1ae0350..92ffda1 100644 --- a/ast/implicit_value_init_expr_test.go +++ b/ast/implicit_value_init_expr_test.go @@ -5,21 +5,31 @@ import ( ) func TestImplicitValueInitExpr(t *testing.T) { - nodes := map[string]Node{ - `0x7f8c3396fbd8 <> 'sqlite3StatValueType':'long long'`: &ImplicitValueInitExpr{ + nodes := map[string]testNode{ + `0x7f8c3396fbd8 <> 'sqlite3StatValueType':'long long'`: + testNode{&ImplicitValueInitExpr{ Addr: 0x7f8c3396fbd8, Pos: NewPositionFromString(""), Type1: "sqlite3StatValueType", Type2: "long long", ChildNodes: []Node{}, }, - `0x7feecb0d6af0 <> 'char'`: &ImplicitValueInitExpr{ + 0x7f8c3396fbd8, + NewPositionFromString(""), + []Node{}, + }, + `0x7feecb0d6af0 <> 'char'`: + testNode{&ImplicitValueInitExpr{ Addr: 0x7feecb0d6af0, Pos: NewPositionFromString(""), Type1: "char", Type2: "", ChildNodes: []Node{}, }, + 0x7feecb0d6af0, + NewPositionFromString(""), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/incomplete_array_type_test.go b/ast/incomplete_array_type_test.go index d3d4c71..a8ea32f 100644 --- a/ast/incomplete_array_type_test.go +++ b/ast/incomplete_array_type_test.go @@ -5,12 +5,17 @@ import ( ) func TestIncompleteArrayType(t *testing.T) { - nodes := map[string]Node{ - `0x7fcb7d005c20 'int []' `: &IncompleteArrayType{ + nodes := map[string]testNode{ + `0x7fcb7d005c20 'int []' `: + testNode{&IncompleteArrayType{ Addr: 0x7fcb7d005c20, Type: "int []", ChildNodes: []Node{}, }, + 0x7fcb7d005c20, + NewPositionFromString(""), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/indirect_field_decl_test.go b/ast/indirect_field_decl_test.go index 3079270..619fd36 100644 --- a/ast/indirect_field_decl_test.go +++ b/ast/indirect_field_decl_test.go @@ -5,8 +5,9 @@ import ( ) func TestIndirectFieldDecl(t *testing.T) { - nodes := map[string]Node{ - `0x2be19a8 col:25 implicit fpstate 'struct _fpstate *'`: &IndirectFieldDecl{ + nodes := map[string]testNode{ + `0x2be19a8 col:25 implicit fpstate 'struct _fpstate *'`: + testNode{&IndirectFieldDecl{ Addr: 0x2be19a8, Pos: NewPositionFromString("line:167:25"), Position2: "col:25", @@ -15,6 +16,10 @@ func TestIndirectFieldDecl(t *testing.T) { Type: "struct _fpstate *", ChildNodes: []Node{}, }, + 0x2be19a8, + NewPositionFromString("line:167:25"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/init_list_expr_test.go b/ast/init_list_expr_test.go index a05301a..76f0864 100644 --- a/ast/init_list_expr_test.go +++ b/ast/init_list_expr_test.go @@ -5,26 +5,41 @@ import ( ) func TestInitListExpr(t *testing.T) { - nodes := map[string]Node{ - `0x7fbdd1906c20 'const unsigned char [256]'`: &InitListExpr{ + nodes := map[string]testNode{ + `0x7fbdd1906c20 'const unsigned char [256]'`: + testNode{&InitListExpr{ Addr: 0x7fbdd1906c20, Pos: NewPositionFromString("col:52, line:17160:1"), Type1: "const unsigned char [256]", ChildNodes: []Node{}, }, - `0x32017f0 'struct node [2]'`: &InitListExpr{ + 0x7fbdd1906c20, + NewPositionFromString("col:52, line:17160:1"), + []Node{}, + }, + `0x32017f0 'struct node [2]'`: + testNode{&InitListExpr{ Addr: 0x32017f0, Pos: NewPositionFromString("col:24, col:41"), Type1: "struct node [2]", ChildNodes: []Node{}, }, - `0x3201840 'struct node':'struct node'`: &InitListExpr{ + 0x32017f0, + NewPositionFromString("col:24, col:41"), + []Node{}, + }, + `0x3201840 'struct node':'struct node'`: + testNode{&InitListExpr{ Addr: 0x3201840, Pos: NewPositionFromString("col:25, col:31"), Type1: "struct node", Type2: "struct node", ChildNodes: []Node{}, }, + 0x3201840, + NewPositionFromString("col:25, col:31"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/inline_command_comment_test.go b/ast/inline_command_comment_test.go index 948f65b..b2d361d 100644 --- a/ast/inline_command_comment_test.go +++ b/ast/inline_command_comment_test.go @@ -5,13 +5,18 @@ import ( ) func TestInlineCommandComment(t *testing.T) { - nodes := map[string]Node{ - `0x22e3510 Name="NOTE" RenderNormal`: &InlineCommandComment{ + nodes := map[string]testNode{ + `0x22e3510 Name="NOTE" RenderNormal`: + testNode{&InlineCommandComment{ Addr: 0x22e3510, Pos: NewPositionFromString("col:2, col:6"), Other: "Name=\"NOTE\" RenderNormal", ChildNodes: []Node{}, }, + 0x22e3510, + NewPositionFromString("col:2, col:6"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/integer_literal_test.go b/ast/integer_literal_test.go index 9506e0e..e5916ea 100644 --- a/ast/integer_literal_test.go +++ b/ast/integer_literal_test.go @@ -5,14 +5,19 @@ import ( ) func TestIntegerLiteral(t *testing.T) { - nodes := map[string]Node{ - `0x7fbe9804bcc8 'int' 1`: &IntegerLiteral{ + nodes := map[string]testNode{ + `0x7fbe9804bcc8 'int' 1`: + testNode{&IntegerLiteral{ Addr: 0x7fbe9804bcc8, Pos: NewPositionFromString("col:14"), Type: "int", Value: "1", ChildNodes: []Node{}, }, + 0x7fbe9804bcc8, + NewPositionFromString("col:14"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/label_stmt_test.go b/ast/label_stmt_test.go index a35fcb0..9b704fb 100644 --- a/ast/label_stmt_test.go +++ b/ast/label_stmt_test.go @@ -5,13 +5,18 @@ import ( ) func TestLabelStmt(t *testing.T) { - nodes := map[string]Node{ - `0x7fe3ba82edb8 'end_getDigits'`: &LabelStmt{ + nodes := map[string]testNode{ + `0x7fe3ba82edb8 'end_getDigits'`: + testNode{&LabelStmt{ Addr: 0x7fe3ba82edb8, Pos: NewPositionFromString("line:18906:1, line:18907:22"), Name: "end_getDigits", ChildNodes: []Node{}, }, + 0x7fe3ba82edb8, + NewPositionFromString("line:18906:1, line:18907:22"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/malloc_attr_test.go b/ast/malloc_attr_test.go index dd040c1..51fe854 100644 --- a/ast/malloc_attr_test.go +++ b/ast/malloc_attr_test.go @@ -5,12 +5,17 @@ import ( ) func TestMallocAttr(t *testing.T) { - nodes := map[string]Node{ - `0x7fc0a69091d1 `: &MallocAttr{ + nodes := map[string]testNode{ + `0x7fc0a69091d1 `: + testNode{&MallocAttr{ Addr: 0x7fc0a69091d1, Pos: NewPositionFromString("line:11:7, line:18:7"), ChildNodes: []Node{}, }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/max_field_alignment_attr_test.go b/ast/max_field_alignment_attr_test.go index 41069b8..ac92dbd 100644 --- a/ast/max_field_alignment_attr_test.go +++ b/ast/max_field_alignment_attr_test.go @@ -5,19 +5,29 @@ import ( ) func TestMaxFieldAlignmentAttr(t *testing.T) { - nodes := map[string]Node{ - `0x7fd4b7063ac0 <> Implicit 32`: &MaxFieldAlignmentAttr{ + nodes := map[string]testNode{ + `0x7fd4b7063ac0 <> Implicit 32`: + testNode{&MaxFieldAlignmentAttr{ Addr: 0x7fd4b7063ac0, Pos: NewPositionFromString(""), Size: 32, ChildNodes: []Node{}, }, - `0x7fd4b7063ac0 <> Implicit 8`: &MaxFieldAlignmentAttr{ + 0x7fd4b7063ac0, + NewPositionFromString(""), + []Node{}, + }, + `0x7fd4b7063ac0 <> Implicit 8`: + testNode{&MaxFieldAlignmentAttr{ Addr: 0x7fd4b7063ac0, Pos: NewPositionFromString(""), Size: 8, ChildNodes: []Node{}, }, + 0x7fd4b7063ac0, + NewPositionFromString(""), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/may_alias_attr_test.go b/ast/may_alias_attr_test.go new file mode 100644 index 0000000..a17a673 --- /dev/null +++ b/ast/may_alias_attr_test.go @@ -0,0 +1,22 @@ +package ast + +import ( + "testing" +) + +func TestMayAliasAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 `: + testNode{&MayAliasAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/member_expr.go b/ast/member_expr.go index 83875e3..a00132f 100644 --- a/ast/member_expr.go +++ b/ast/member_expr.go @@ -55,6 +55,7 @@ func (n *MemberExpr) AddChild(node Node) { n.ChildNodes = append(n.ChildNodes, node) } +/* // GetDeclRefExpr gets DeclRefExpr from MemberExpr, or nil if there is no // DeclRefExpr func (n *MemberExpr) GetDeclRefExpr() *DeclRefExpr { @@ -77,6 +78,7 @@ func (n *MemberExpr) GetDeclRefExpr() *DeclRefExpr { // There is no DeclRefExpr return nil } +*/ // Address returns the numeric address of the node. See the documentation for // the Address type for more information. diff --git a/ast/member_expr_test.go b/ast/member_expr_test.go index fb6dad9..1e893cd 100644 --- a/ast/member_expr_test.go +++ b/ast/member_expr_test.go @@ -5,8 +5,9 @@ import ( ) func TestMemberExpr(t *testing.T) { - nodes := map[string]Node{ - `0x7fcc758e34a0 'int' lvalue ->_w 0x7fcc758d60c8`: &MemberExpr{ + nodes := map[string]testNode{ + `0x7fcc758e34a0 'int' lvalue ->_w 0x7fcc758d60c8`: + testNode{&MemberExpr{ Addr: 0x7fcc758e34a0, Pos: NewPositionFromString("col:8, col:12"), Type: "int", @@ -18,7 +19,12 @@ func TestMemberExpr(t *testing.T) { IsPointer: true, ChildNodes: []Node{}, }, - `0x7fcc76004210 'unsigned char *' lvalue ->_p 0x7fcc758d6018`: &MemberExpr{ + 0x7fcc758e34a0, + NewPositionFromString("col:8, col:12"), + []Node{}, + }, + `0x7fcc76004210 'unsigned char *' lvalue ->_p 0x7fcc758d6018`: + testNode{&MemberExpr{ Addr: 0x7fcc76004210, Pos: NewPositionFromString("col:12, col:16"), Type: "unsigned char *", @@ -30,7 +36,12 @@ func TestMemberExpr(t *testing.T) { IsPointer: true, ChildNodes: []Node{}, }, - `0x7f85338325b0 'float' lvalue .constant 0x7f8533832260`: &MemberExpr{ + 0x7fcc76004210, + NewPositionFromString("col:12, col:16"), + []Node{}, + }, + `0x7f85338325b0 'float' lvalue .constant 0x7f8533832260`: + testNode{&MemberExpr{ Addr: 0x7f85338325b0, Pos: NewPositionFromString("col:4, col:13"), Type: "float", @@ -42,7 +53,12 @@ func TestMemberExpr(t *testing.T) { IsPointer: false, ChildNodes: []Node{}, }, - `0x7f8533832670 'char *' lvalue .pointer 0x7f85338322b8`: &MemberExpr{ + 0x7f85338325b0, + NewPositionFromString("col:4, col:13"), + []Node{}, + }, + `0x7f8533832670 'char *' lvalue .pointer 0x7f85338322b8`: + testNode{&MemberExpr{ Addr: 0x7f8533832670, Pos: NewPositionFromString("col:4, col:13"), Type: "char *", @@ -54,7 +70,12 @@ func TestMemberExpr(t *testing.T) { IsPointer: false, ChildNodes: []Node{}, }, - `0x7fb7d5a49ac8 'bft':'unsigned int' lvalue bitfield ->isPrepareV2 0x7fb7d5967f40`: &MemberExpr{ + 0x7f8533832670, + NewPositionFromString("col:4, col:13"), + []Node{}, + }, + `0x7fb7d5a49ac8 'bft':'unsigned int' lvalue bitfield ->isPrepareV2 0x7fb7d5967f40`: + testNode{&MemberExpr{ Addr: 0x7fb7d5a49ac8, Pos: NewPositionFromString("col:3, col:6"), Type: "bft", @@ -66,7 +87,12 @@ func TestMemberExpr(t *testing.T) { IsPointer: true, ChildNodes: []Node{}, }, - `0x2914fb8 'union vec3d_t::(anonymous at main.c:2:5)' lvalue . 0x2914920`: &MemberExpr{ + 0x7fb7d5a49ac8, + NewPositionFromString("col:3, col:6"), + []Node{}, + }, + `0x2914fb8 'union vec3d_t::(anonymous at main.c:2:5)' lvalue . 0x2914920`: + testNode{&MemberExpr{ Addr: 0x2914fb8, Pos: NewPositionFromString("col:12, col:14"), Type: "union vec3d_t::(anonymous at main.c:2:5)", @@ -78,7 +104,12 @@ func TestMemberExpr(t *testing.T) { IsPointer: false, ChildNodes: []Node{}, }, - `0x3180ef0 'int' .n 0x317f450`: &MemberExpr{ + 0x2914fb8, + NewPositionFromString("col:12, col:14"), + []Node{}, + }, + `0x3180ef0 'int' .n 0x317f450`: + testNode{&MemberExpr{ Addr: 0x3180ef0, Pos: NewPositionFromString("col:32, col:48"), Type: "int", @@ -90,6 +121,10 @@ func TestMemberExpr(t *testing.T) { IsPointer: false, ChildNodes: []Node{}, }, + 0x3180ef0, + NewPositionFromString("col:32, col:48"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/min_vector_width_attr.go b/ast/min_vector_width_attr.go index 1332f30..65cd1fd 100644 --- a/ast/min_vector_width_attr.go +++ b/ast/min_vector_width_attr.go @@ -2,48 +2,48 @@ package ast // MinVectorWidthAttr type MinVectorWidthAttr struct { - Addr Address - Pos Position - Content string - ChildNodes []Node + Addr Address + Pos Position + Content string + ChildNodes []Node } func parseMinVectorWidthAttr(line string) Node { - groups := groupsFromRegex( - "<(?P.*)>(?P.*)", - line, - ) + groups := groupsFromRegex( + "<(?P.*)>(?P.*)", + line, + ) if groups == nil { return &Unknown{} } - return &MinVectorWidthAttr{ - Addr: ParseAddress(groups["address"]), - Pos: NewPositionFromString(groups["position"]), - Content: groups["content"], - ChildNodes: []Node{}, - } + return &MinVectorWidthAttr{ + Addr: ParseAddress(groups["address"]), + Pos: NewPositionFromString(groups["position"]), + Content: groups["content"], + ChildNodes: []Node{}, + } } // AddChild adds a new child node. Child nodes can then be accessed with the // Children attribute. func (n *MinVectorWidthAttr) AddChild(node Node) { - n.ChildNodes = append(n.ChildNodes, 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 *MinVectorWidthAttr) Address() Address { - return n.Addr + 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 *MinVectorWidthAttr) Children() []Node { - return n.ChildNodes + return n.ChildNodes } // Position returns the position in the original source code. func (n *MinVectorWidthAttr) Position() Position { - return n.Pos + return n.Pos } diff --git a/ast/min_vector_width_attr_test.go b/ast/min_vector_width_attr_test.go new file mode 100644 index 0000000..b030e9b --- /dev/null +++ b/ast/min_vector_width_attr_test.go @@ -0,0 +1,23 @@ +package ast + +import ( + "testing" +) + +func TestMinVectorWidthAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 content`: + testNode{&MinVectorWidthAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + Content: " content", + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/mode_attr_test.go b/ast/mode_attr_test.go index df87dd5..4d1f9b4 100644 --- a/ast/mode_attr_test.go +++ b/ast/mode_attr_test.go @@ -5,13 +5,18 @@ import ( ) func Test(t *testing.T) { - nodes := map[string]Node{ - `0x7f980b858309 foo`: &ModeAttr{ + nodes := map[string]testNode{ + `0x7f980b858309 foo`: + testNode{&ModeAttr{ Addr: 0x7f980b858309, Pos: NewPositionFromString("line:11:7, line:18:7"), Name: "foo", ChildNodes: []Node{}, }, + 0x7f980b858309, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/no_debug_attr_test.go b/ast/no_debug_attr_test.go new file mode 100644 index 0000000..bdcdf30 --- /dev/null +++ b/ast/no_debug_attr_test.go @@ -0,0 +1,22 @@ +package ast + +import ( + "testing" +) + +func TestNoDebugAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 `: + testNode{&NoDebugAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/no_escape_attr_test.go b/ast/no_escape_attr_test.go new file mode 100644 index 0000000..e5eae6c --- /dev/null +++ b/ast/no_escape_attr_test.go @@ -0,0 +1,22 @@ +package ast + +import ( + "testing" +) + +func TestNoEscapeAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 `: + testNode{&NoEscapeAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/no_inline_attr_test.go b/ast/no_inline_attr_test.go index 308f705..344426d 100644 --- a/ast/no_inline_attr_test.go +++ b/ast/no_inline_attr_test.go @@ -5,12 +5,17 @@ import ( ) func TestNoInlineAttr(t *testing.T) { - nodes := map[string]Node{ - `0x7fc02a8a6730 `: &NoInlineAttr{ + nodes := map[string]testNode{ + `0x7fc02a8a6730 `: + testNode{&NoInlineAttr{ Addr: 0x7fc02a8a6730, Pos: NewPositionFromString("line:24619:23"), ChildNodes: []Node{}, }, + 0x7fc02a8a6730, + NewPositionFromString("line:24619:23"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/no_throw_attr_test.go b/ast/no_throw_attr_test.go index fcc4749..780f68c 100644 --- a/ast/no_throw_attr_test.go +++ b/ast/no_throw_attr_test.go @@ -5,35 +5,55 @@ import ( ) func TestNoThrowAttr(t *testing.T) { - nodes := map[string]Node{ - `0x7fa1488273a0 `: &NoThrowAttr{ + nodes := map[string]testNode{ + `0x7fa1488273a0 `: + testNode{&NoThrowAttr{ Addr: 0x7fa1488273a0, Pos: NewPositionFromString("line:7:4, line:11:4"), ChildNodes: []Node{}, Inherited: false, Implicit: false, }, - `0x5605ceaf4b88 Implicit`: &NoThrowAttr{ + 0x7fa1488273a0, + NewPositionFromString("line:7:4, line:11:4"), + []Node{}, + }, + `0x5605ceaf4b88 Implicit`: + testNode{&NoThrowAttr{ Addr: 0x5605ceaf4b88, Pos: NewPositionFromString("col:12"), ChildNodes: []Node{}, Inherited: false, Implicit: true, }, - `0x4153c50 Inherited`: &NoThrowAttr{ + 0x5605ceaf4b88, + NewPositionFromString("col:12"), + []Node{}, + }, + `0x4153c50 Inherited`: + testNode{&NoThrowAttr{ Addr: 0x4153c50, Pos: NewPositionFromString("/usr/include/unistd.h:779:46"), ChildNodes: []Node{}, Inherited: true, Implicit: false, }, - `0x1038b8828 Inherited Implicit`: &NoThrowAttr{ + 0x4153c50, + NewPositionFromString("/usr/include/unistd.h:779:46"), + []Node{}, + }, + `0x1038b8828 Inherited Implicit`: + testNode{&NoThrowAttr{ Addr: 0x1038b8828, Pos: NewPositionFromString("col:20"), ChildNodes: []Node{}, Inherited: true, Implicit: true, }, + 0x1038b8828, + NewPositionFromString("col:20"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/non_null_attr_test.go b/ast/non_null_attr_test.go index ab47193..e4934c2 100644 --- a/ast/non_null_attr_test.go +++ b/ast/non_null_attr_test.go @@ -5,8 +5,9 @@ import ( ) func TestNonNullAttr(t *testing.T) { - nodes := map[string]Node{ - `0x7fa1488273b0 1`: &NonNullAttr{ + nodes := map[string]testNode{ + `0x7fa1488273b0 1`: + testNode{&NonNullAttr{ Addr: 0x7fa1488273b0, Pos: NewPositionFromString("line:7:4, line:11:4"), Inherited: false, @@ -16,7 +17,12 @@ func TestNonNullAttr(t *testing.T) { D: 0, ChildNodes: []Node{}, }, - `0x2cce280 1`: &NonNullAttr{ + 0x7fa1488273b0, + NewPositionFromString("line:7:4, line:11:4"), + []Node{}, + }, + `0x2cce280 1`: + testNode{&NonNullAttr{ Addr: 0x2cce280, Pos: NewPositionFromString("/sys/cdefs.h:286:44, /bits/mathcalls.h:115:69"), Inherited: false, @@ -26,7 +32,12 @@ func TestNonNullAttr(t *testing.T) { D: 0, ChildNodes: []Node{}, }, - `0x201ede0 0`: &NonNullAttr{ + 0x2cce280, + NewPositionFromString("/sys/cdefs.h:286:44, /bits/mathcalls.h:115:69"), + []Node{}, + }, + `0x201ede0 0`: + testNode{&NonNullAttr{ Addr: 0x201ede0, Pos: NewPositionFromString("line:145:79, col:93"), Inherited: false, @@ -36,7 +47,12 @@ func TestNonNullAttr(t *testing.T) { D: 0, ChildNodes: []Node{}, }, - `0x1b89b20 2 3`: &NonNullAttr{ + 0x201ede0, + NewPositionFromString("line:145:79, col:93"), + []Node{}, + }, + `0x1b89b20 2 3`: + testNode{&NonNullAttr{ Addr: 0x1b89b20, Pos: NewPositionFromString("col:76, col:93"), Inherited: false, @@ -46,7 +62,12 @@ func TestNonNullAttr(t *testing.T) { D: 0, ChildNodes: []Node{}, }, - `0x55f0219e20d0 0 1 4`: &NonNullAttr{ + 0x1b89b20, + NewPositionFromString("col:76, col:93"), + []Node{}, + }, + `0x55f0219e20d0 0 1 4`: + testNode{&NonNullAttr{ Addr: 0x55f0219e20d0, Pos: NewPositionFromString("line:717:22, col:42"), Inherited: false, @@ -56,7 +77,12 @@ func TestNonNullAttr(t *testing.T) { D: 0, ChildNodes: []Node{}, }, - `0x248ea60 0 1 2 4`: &NonNullAttr{ + 0x55f0219e20d0, + NewPositionFromString("line:717:22, col:42"), + []Node{}, + }, + `0x248ea60 0 1 2 4`: + testNode{&NonNullAttr{ Addr: 0x248ea60, Pos: NewPositionFromString("line:155:26, col:49"), Inherited: false, @@ -66,7 +92,12 @@ func TestNonNullAttr(t *testing.T) { D: 4, ChildNodes: []Node{}, }, - `0x39cf2b0 Inherited 0 1`: &NonNullAttr{ + 0x248ea60, + NewPositionFromString("line:155:26, col:49"), + []Node{}, + }, + `0x39cf2b0 Inherited 0 1`: + testNode{&NonNullAttr{ Addr: 0x39cf2b0, Pos: NewPositionFromString("col:53"), Inherited: true, @@ -76,6 +107,10 @@ func TestNonNullAttr(t *testing.T) { D: 0, ChildNodes: []Node{}, }, + 0x39cf2b0, + NewPositionFromString("col:53"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/not_tail_called_attr_test.go b/ast/not_tail_called_attr_test.go index bf7c9f8..60d06c8 100644 --- a/ast/not_tail_called_attr_test.go +++ b/ast/not_tail_called_attr_test.go @@ -5,12 +5,17 @@ import ( ) func TestNotTailCalledAttr(t *testing.T) { - nodes := map[string]Node{ - `0x7fc8fa094558 `: &NotTailCalledAttr{ + nodes := map[string]testNode{ + `0x7fc8fa094558 `: + testNode{&NotTailCalledAttr{ Addr: 0x7fc8fa094558, Pos: NewPositionFromString("col:107"), ChildNodes: []Node{}, }, + 0x7fc8fa094558, + NewPositionFromString("col:107"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/ns_consumed_attr_test.go b/ast/ns_consumed_attr_test.go new file mode 100644 index 0000000..71eaf4a --- /dev/null +++ b/ast/ns_consumed_attr_test.go @@ -0,0 +1,23 @@ +package ast + +import ( + "testing" +) + +func TestNSConsumedAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 content`: + testNode{&NSConsumedAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + Content: " content", + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/ns_consumes_self_attr_test.go b/ast/ns_consumes_self_attr_test.go new file mode 100644 index 0000000..2c5850d --- /dev/null +++ b/ast/ns_consumes_self_attr_test.go @@ -0,0 +1,22 @@ +package ast + +import ( + "testing" +) + +func TestNSConsumesSelfAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 `: + testNode{&NSConsumesSelfAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/ns_error_domain_attr_test.go b/ast/ns_error_domain_attr_test.go new file mode 100644 index 0000000..9e88b1a --- /dev/null +++ b/ast/ns_error_domain_attr_test.go @@ -0,0 +1,23 @@ +package ast + +import ( + "testing" +) + +func TestNSErrorDomainAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 content`: + testNode{&NSErrorDomainAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + Content: " content", + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/ns_returns_retained_attr_test.go b/ast/ns_returns_retained_attr_test.go new file mode 100644 index 0000000..a1b50a1 --- /dev/null +++ b/ast/ns_returns_retained_attr_test.go @@ -0,0 +1,22 @@ +package ast + +import ( + "testing" +) + +func TestNSReturnsRetainedAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 `: + testNode{&NSReturnsRetainedAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/objc_bool_literal_expr_test.go b/ast/objc_bool_literal_expr_test.go new file mode 100644 index 0000000..ed533e5 --- /dev/null +++ b/ast/objc_bool_literal_expr_test.go @@ -0,0 +1,38 @@ +package ast + +import ( + "testing" +) + +func TestObjCBoolLiteralExpr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fcd0f9e7fe8 'BOOL':'signed char' __objc_yes`: + testNode{&ObjCBoolLiteralExpr{ + Addr: 0x7fcd0f9e7fe8, + Pos: NewPositionFromString("col:13"), + Type: "BOOL", + Type2: ":'signed char'", + Attr: " __objc_yes", + ChildNodes: []Node{}, + }, + 0x7fcd0f9e7fe8, + NewPositionFromString("col:13"), + []Node{}, + }, + `0x7fcd0f9ed000 'BOOL':'signed char' __objc_no`: + testNode{&ObjCBoolLiteralExpr{ + Addr: 0x7fcd0f9ed000, + Pos: NewPositionFromString("col:13"), + Type: "BOOL", + Type2: ":'signed char'", + Attr: " __objc_no", + ChildNodes: []Node{}, + }, + 0x7fcd0f9ed000, + NewPositionFromString("col:13"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/objc_boxable_attr_test.go b/ast/objc_boxable_attr_test.go new file mode 100644 index 0000000..edd308d --- /dev/null +++ b/ast/objc_boxable_attr_test.go @@ -0,0 +1,22 @@ +package ast + +import ( + "testing" +) + +func TestObjCBoxableAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 `: + testNode{&ObjCBoxableAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/objc_bridge_attr_test.go b/ast/objc_bridge_attr_test.go new file mode 100644 index 0000000..65bb62f --- /dev/null +++ b/ast/objc_bridge_attr_test.go @@ -0,0 +1,23 @@ +package ast + +import ( + "testing" +) + +func TestObjCBridgeAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 content`: + testNode{&ObjCBridgeAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + Content: " content", + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/objc_bridge_mutable_attr_test.go b/ast/objc_bridge_mutable_attr_test.go new file mode 100644 index 0000000..963c3cd --- /dev/null +++ b/ast/objc_bridge_mutable_attr_test.go @@ -0,0 +1,23 @@ +package ast + +import ( + "testing" +) + +func TestObjCBridgeMutableAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 content`: + testNode{&ObjCBridgeMutableAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + Content: " content", + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/objc_bridge_related_attr_test.go b/ast/objc_bridge_related_attr_test.go new file mode 100644 index 0000000..d71a3b7 --- /dev/null +++ b/ast/objc_bridge_related_attr_test.go @@ -0,0 +1,23 @@ +package ast + +import ( + "testing" +) + +func TestObjCBridgeRelatedAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 content`: + testNode{&ObjCBridgeRelatedAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + Content: " content", + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/objc_category_decl_test.go b/ast/objc_category_decl_test.go index 3d223e5..e870a8a 100644 --- a/ast/objc_category_decl_test.go +++ b/ast/objc_category_decl_test.go @@ -5,15 +5,19 @@ import ( ) func TestObjCCategoryDecl(t *testing.T) { - nodes := map[string]Node{ + nodes := map[string]testNode{ `0x7fdef0862430 col:16 NSObject`: - &ObjCCategoryDecl{ + testNode{&ObjCCategoryDecl{ Addr: 0x7fdef0862430, Pos: NewPositionFromString("line:120:1, col:16"), Position2: "", Name: "NSObject", ChildNodes: []Node{}, }, + 0x7fdef0862430, + NewPositionFromString("line:120:1, col:16"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/objc_designated_initializer_attr_test.go b/ast/objc_designated_initializer_attr_test.go new file mode 100644 index 0000000..90d1c61 --- /dev/null +++ b/ast/objc_designated_initializer_attr_test.go @@ -0,0 +1,22 @@ +package ast + +import ( + "testing" +) + +func TestObjCDesignatedInitializerAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 `: + testNode{&ObjCDesignatedInitializerAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/objc_exception_attr_test.go b/ast/objc_exception_attr_test.go new file mode 100644 index 0000000..b57dddf --- /dev/null +++ b/ast/objc_exception_attr_test.go @@ -0,0 +1,22 @@ +package ast + +import ( + "testing" +) + +func TestObjCExceptionAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 `: + testNode{&ObjCExceptionAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/objc_explicit_protocol_impl_attr_test.go b/ast/objc_explicit_protocol_impl_attr_test.go new file mode 100644 index 0000000..39ec025 --- /dev/null +++ b/ast/objc_explicit_protocol_impl_attr_test.go @@ -0,0 +1,22 @@ +package ast + +import ( + "testing" +) + +func TestObjCExplicitProtocolImplAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 `: + testNode{&ObjCExplicitProtocolImplAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/objc_independent_class_attr_test.go b/ast/objc_independent_class_attr_test.go new file mode 100644 index 0000000..b32a59c --- /dev/null +++ b/ast/objc_independent_class_attr_test.go @@ -0,0 +1,22 @@ +package ast + +import ( + "testing" +) + +func TestObjCIndependentClassAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 `: + testNode{&ObjCIndependentClassAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/objc_interface_decl_test.go b/ast/objc_interface_decl_test.go index cd4fe6f..bcda801 100644 --- a/ast/objc_interface_decl_test.go +++ b/ast/objc_interface_decl_test.go @@ -5,9 +5,9 @@ import ( ) func TestObjCInterfaceDecl(t *testing.T) { - nodes := map[string]Node{ + nodes := map[string]testNode{ `0x7fdef0862430 col:16 NSObject`: - &ObjCInterfaceDecl{ + testNode{&ObjCInterfaceDecl{ Addr: 0x7fdef0862430, Pos: NewPositionFromString("line:120:1, col:16"), Position2: "", @@ -15,8 +15,12 @@ func TestObjCInterfaceDecl(t *testing.T) { Implicit: false, ChildNodes: []Node{}, }, + 0x7fdef0862430, + NewPositionFromString("line:120:1, col:16"), + []Node{}, + }, `0x7fdef0862430 prev 0x7fca43341430 col:16 NSObject`: - &ObjCInterfaceDecl{ + testNode{&ObjCInterfaceDecl{ Addr: 0x7fdef0862430, Pos: NewPositionFromString("line:120:1, col:16"), Position2: "", @@ -24,8 +28,12 @@ func TestObjCInterfaceDecl(t *testing.T) { Implicit: false, ChildNodes: []Node{}, }, + 0x7fdef0862430, + NewPositionFromString("line:120:1, col:16"), + []Node{}, + }, `0x7fdef0862430 <> implicit Protocol`: - &ObjCInterfaceDecl{ + testNode{&ObjCInterfaceDecl{ Addr: 0x7fdef0862430, Pos: Position{}, Position2: "", @@ -33,6 +41,10 @@ func TestObjCInterfaceDecl(t *testing.T) { Implicit: true, ChildNodes: []Node{}, }, + 0x7fdef0862430, + Position{}, + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/objc_interface_test.go b/ast/objc_interface_test.go index d559427..6bde0f4 100644 --- a/ast/objc_interface_test.go +++ b/ast/objc_interface_test.go @@ -5,24 +5,33 @@ import ( ) func TestObjCInterface(t *testing.T) { + i := 1 runNodeTest(t, Parse(`ObjCInterface 0x7f84d10dc1d0 'NSObject'`), - &ObjCInterface{ + testNode{&ObjCInterface{ Addr: 0x7f84d10dc1d0, Name: `NSObject`, Super: false, ChildNodes: []Node{}, }, - 1, + 0x7f84d10dc1d0, + NewPositionFromString(""), + []Node{}, + }, + &i, ) runNodeTest(t, Parse(`super ObjCInterface 0x7f84d10dc1d0 'NSObject'`), - &ObjCInterface{ + testNode{&ObjCInterface{ Addr: 0x7f84d10dc1d0, Name: `NSObject`, Super: true, ChildNodes: []Node{}, }, - 2, + 0x7f84d10dc1d0, + NewPositionFromString(""), + []Node{}, + }, + &i, ) } diff --git a/ast/objc_interface_type_test.go b/ast/objc_interface_type_test.go index d25faf4..d600863 100644 --- a/ast/objc_interface_type_test.go +++ b/ast/objc_interface_type_test.go @@ -5,13 +5,17 @@ import ( ) func TestObjCInterfaceType(t *testing.T) { - nodes := map[string]Node{ + nodes := map[string]testNode{ `0x7fdef0862430 'NSObject'`: - &ObjCInterfaceType{ + testNode{&ObjCInterfaceType{ Addr: 0x7fdef0862430, Type: "NSObject", ChildNodes: []Node{}, }, + 0x7fdef0862430, + NewPositionFromString(""), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/objc_ivar_decl_test.go b/ast/objc_ivar_decl_test.go new file mode 100644 index 0000000..142d240 --- /dev/null +++ b/ast/objc_ivar_decl_test.go @@ -0,0 +1,27 @@ +package ast + +import ( + "testing" +) + +func TestObjCIvarDecl(t *testing.T) { + nodes := map[string]testNode{ + `0x7fcd103e8270 col:11 isa 'Class':'Class' protected`: + testNode{&ObjCIvarDecl{ + Addr: 0x7fcd103e8270, + Pos: NewPositionFromString("/usr/include/objc/NSObject.h:56:5, col:11"), + Position2: "col:11", + Name: "isa", + Type: "Class", + Type2: "", + Attr: "protected", + ChildNodes: []Node{}, + }, + 0x7fcd103e8270, + NewPositionFromString("/usr/include/objc/NSObject.h:56:5, col:11"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/objc_message_expr_test.go b/ast/objc_message_expr_test.go new file mode 100644 index 0000000..515b8c1 --- /dev/null +++ b/ast/objc_message_expr_test.go @@ -0,0 +1,23 @@ +package ast + +import ( + "testing" +) + +func TestObjCMessageExpr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 content`: + testNode{&ObjCMessageExpr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + Content: " content", + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/objc_method_decl_test.go b/ast/objc_method_decl_test.go index 51280d6..9046c8c 100644 --- a/ast/objc_method_decl_test.go +++ b/ast/objc_method_decl_test.go @@ -5,9 +5,9 @@ import ( ) func TestObjCMethodDecl(t *testing.T) { - nodes := map[string]Node{ + nodes := map[string]testNode{ `0x7f92a58a7570 col:1 - isEqual: 'BOOL':'signed char'`: - &ObjCMethodDecl{ + testNode{&ObjCMethodDecl{ Addr: 0x7f92a58a7570, Pos: NewPositionFromString("line:17:1, col:27"), Position2: "", @@ -19,8 +19,12 @@ func TestObjCMethodDecl(t *testing.T) { Implicit: false, ChildNodes: []Node{}, }, + 0x7f92a58a7570, + NewPositionFromString("line:17:1, col:27"), + []Node{}, + }, `0x7f92a58a7978 col:1 - self 'instancetype':'id'`: - &ObjCMethodDecl{ + testNode{&ObjCMethodDecl{ Addr: 0x7f92a58a7978, Pos: NewPositionFromString("/usr/include/objc/NSObject.h:22:1, col:21"), Position2: "", @@ -32,8 +36,12 @@ func TestObjCMethodDecl(t *testing.T) { Implicit: false, ChildNodes: []Node{}, }, + 0x7f92a58a7978, + NewPositionFromString("/usr/include/objc/NSObject.h:22:1, col:21"), + []Node{}, + }, `0x7f92a58a82b0 col:1 - respondsToSelector: 'BOOL':'signed char'`: - &ObjCMethodDecl{ + testNode{&ObjCMethodDecl{ Addr: 0x7f92a58a82b0, Pos: NewPositionFromString("line:34:1, col:42"), Position2: "", @@ -45,8 +53,12 @@ func TestObjCMethodDecl(t *testing.T) { Implicit: false, ChildNodes: []Node{}, }, + 0x7f92a58a82b0, + NewPositionFromString("line:34:1, col:42"), + []Node{}, + }, `0x7f92a58a82b0 col:1 + instancesRespondToSelector: 'BOOL':'signed char'`: - &ObjCMethodDecl{ + testNode{&ObjCMethodDecl{ Addr: 0x7f92a58a82b0, Pos: NewPositionFromString("line:34:1, col:42"), Position2: "", @@ -58,8 +70,12 @@ func TestObjCMethodDecl(t *testing.T) { Implicit: false, ChildNodes: []Node{}, }, + 0x7f92a58a82b0, + NewPositionFromString("line:34:1, col:42"), + []Node{}, + }, `0x7f92a58a7cd8 col:1 - performSelector:withObject:withObject: 'id':'id'`: - &ObjCMethodDecl{ + testNode{&ObjCMethodDecl{ Addr: 0x7f92a58a7cd8, Pos: NewPositionFromString("line:26:1, col:83"), Position2: "", @@ -71,8 +87,12 @@ func TestObjCMethodDecl(t *testing.T) { Implicit: false, ChildNodes: []Node{}, }, + 0x7f92a58a7cd8, + NewPositionFromString("line:26:1, col:83"), + []Node{}, + }, `0x7f92a4459318 col:71 implicit - writableTypeIdentifiersForItemProvider 'NSArray * _Nonnull':'NSArray *'`: - &ObjCMethodDecl{ + testNode{&ObjCMethodDecl{ Addr: 0x7f92a4459318, Pos: NewPositionFromString("line:41:71"), Position2: "", @@ -84,6 +104,10 @@ func TestObjCMethodDecl(t *testing.T) { Implicit: true, ChildNodes: []Node{}, }, + 0x7f92a4459318, + NewPositionFromString("line:41:71"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/objc_method_test.go b/ast/objc_method_test.go index 25186f7..7c1ebd1 100644 --- a/ast/objc_method_test.go +++ b/ast/objc_method_test.go @@ -5,22 +5,31 @@ import ( ) func TestObjCMethod(t *testing.T) { + i := 1 runNodeTest(t, Parse(`ObjCMethod 0x7f84d10dc1d0 'isValid'`), - &ObjCMethod{ + testNode{&ObjCMethod{ Addr: 0x7f84d10dc1d0, Name: `isValid`, ChildNodes: []Node{}, }, - 1, + 0x7f84d10dc1d0, + NewPositionFromString(""), + []Node{}, + }, + &i, ) runNodeTest(t, Parse(`getter ObjCMethod 0x7f84d10dc1d0 'isValid'`), - &ObjCMethod{ + testNode{&ObjCMethod{ Addr: 0x7f84d10dc1d0, Name: `isValid`, ChildNodes: []Node{}, }, - 2, + 0x7f84d10dc1d0, + NewPositionFromString(""), + []Node{}, + }, + &i, ) } diff --git a/ast/objc_object_pointer_type_test.go b/ast/objc_object_pointer_type_test.go index 4cbf3f5..ef41b62 100644 --- a/ast/objc_object_pointer_type_test.go +++ b/ast/objc_object_pointer_type_test.go @@ -5,25 +5,37 @@ import ( ) func TestObjCObjectPointerType(t *testing.T) { - nodes := map[string]Node{ + nodes := map[string]testNode{ `0x10c101ab0 'NSObject *'`: - &ObjCObjectPointerType{ + testNode{&ObjCObjectPointerType{ Addr: 0x10c101ab0, Type: `NSObject *`, ChildNodes: []Node{}, }, + 0x10c101ab0, + NewPositionFromString(""), + []Node{}, + }, `0x7faa18805fc0 'id'`: - &ObjCObjectPointerType{ + testNode{&ObjCObjectPointerType{ Addr: 0x7faa18805fc0, Type: `id`, ChildNodes: []Node{}, }, + 0x7faa18805fc0, + NewPositionFromString(""), + []Node{}, + }, `0x7fca45a08a60 'NSAppleEventDescriptor *'`: - &ObjCObjectPointerType{ + testNode{&ObjCObjectPointerType{ Addr: 0x7fca45a08a60, Type: `NSAppleEventDescriptor *`, ChildNodes: []Node{}, }, + 0x7fca45a08a60, + NewPositionFromString(""), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/objc_object_type_test.go b/ast/objc_object_type_test.go index 689a712..7aadba0 100644 --- a/ast/objc_object_type_test.go +++ b/ast/objc_object_type_test.go @@ -5,19 +5,27 @@ import ( ) func TestObjCObjectType(t *testing.T) { - nodes := map[string]Node{ + nodes := map[string]testNode{ `0x10c101ab0 'NSObject'`: - &ObjCObjectType{ + testNode{&ObjCObjectType{ Addr: 0x10c101ab0, Type: `NSObject`, ChildNodes: []Node{}, }, + 0x10c101ab0, + NewPositionFromString(""), + []Node{}, + }, `0x7faa18805fc0 'id'`: - &ObjCObjectType{ + testNode{&ObjCObjectType{ Addr: 0x7faa18805fc0, Type: `id`, ChildNodes: []Node{}, }, + 0x7faa18805fc0, + NewPositionFromString(""), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/objc_property_decl_test.go b/ast/objc_property_decl_test.go index 29bd183..43bd2ab 100644 --- a/ast/objc_property_decl_test.go +++ b/ast/objc_property_decl_test.go @@ -5,9 +5,9 @@ import ( ) func TestObjCPropertyDecl(t *testing.T) { - nodes := map[string]Node{ + nodes := map[string]testNode{ `0x10a9be000 col:46 blueColor 'NSColor * _Nonnull':'NSColor *' readonly atomic strong class`: - &ObjCPropertyDecl{ + testNode{&ObjCPropertyDecl{ Addr: 0x10a9be000, Pos: NewPositionFromString("line:157:1, col:46"), Position2: "col:46", @@ -17,8 +17,12 @@ func TestObjCPropertyDecl(t *testing.T) { Attr: "readonly atomic strong class", ChildNodes: []Node{}, }, + 0x10a9be000, + NewPositionFromString("line:157:1, col:46"), + []Node{}, + }, `0x7fca44e4a180 col:61 undoRegistrationEnabled 'BOOL':'signed char' readonly atomic getter`: - &ObjCPropertyDecl{ + testNode{&ObjCPropertyDecl{ Addr: 0x7fca44e4a180, Pos: NewPositionFromString("line:50:1, col:61"), Position2: "col:61", @@ -28,6 +32,10 @@ func TestObjCPropertyDecl(t *testing.T) { Attr: "readonly atomic getter", ChildNodes: []Node{}, }, + 0x7fca44e4a180, + NewPositionFromString("line:50:1, col:61"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/objc_protocol_decl_test.go b/ast/objc_protocol_decl_test.go index 2ed0f37..ce22a52 100644 --- a/ast/objc_protocol_decl_test.go +++ b/ast/objc_protocol_decl_test.go @@ -5,23 +5,31 @@ import ( ) func TestObjCProtocolDecl(t *testing.T) { - nodes := map[string]Node{ + nodes := map[string]testNode{ `0x10a9da630 col:11 NSBrowserDelegate`: - &ObjCProtocolDecl{ + testNode{&ObjCProtocolDecl{ Addr: 0x10a9da630, Pos: NewPositionFromString("line:22:1, col:11"), Position2: "", Name: "NSBrowserDelegate", ChildNodes: []Node{}, }, + 0x10a9da630, + NewPositionFromString("line:22:1, col:11"), + []Node{}, + }, `0x10c37fc70 line:58:11 NSPrintPanelAccessorizing`: - &ObjCProtocolDecl{ + testNode{&ObjCProtocolDecl{ Addr: 0x10c37fc70, Pos: NewPositionFromString("/System/Library/Frameworks/AppKit.framework/Headers/NSPrintPanel.h:58:1, line:70:2"), Position2: "", Name: "NSPrintPanelAccessorizing", ChildNodes: []Node{}, }, + 0x10c37fc70, + NewPositionFromString("/System/Library/Frameworks/AppKit.framework/Headers/NSPrintPanel.h:58:1, line:70:2"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/objc_protocol_test.go b/ast/objc_protocol_test.go index e6dca29..c71181e 100644 --- a/ast/objc_protocol_test.go +++ b/ast/objc_protocol_test.go @@ -5,13 +5,17 @@ import ( ) func TestObjCProtocol(t *testing.T) { - nodes := map[string]Node{ + nodes := map[string]testNode{ `0x10c26d630 'NSColorPickingDefault'`: - &ObjCProtocol{ + testNode{&ObjCProtocol{ Addr: 0x10c26d630, Name: "NSColorPickingDefault", ChildNodes: []Node{}, }, + 0x10c26d630, + NewPositionFromString(""), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/objc_requires_super_attr_test.go b/ast/objc_requires_super_attr_test.go new file mode 100644 index 0000000..7fe92a0 --- /dev/null +++ b/ast/objc_requires_super_attr_test.go @@ -0,0 +1,22 @@ +package ast + +import ( + "testing" +) + +func TestObjCRequiresSuperAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 `: + testNode{&ObjCRequiresSuperAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/objc_returns_inner_pointer_attr_test.go b/ast/objc_returns_inner_pointer_attr_test.go new file mode 100644 index 0000000..852c3a8 --- /dev/null +++ b/ast/objc_returns_inner_pointer_attr_test.go @@ -0,0 +1,23 @@ +package ast + +import ( + "testing" +) + +func TestObjCReturnsInnerPointerAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 content`: + testNode{&ObjCReturnsInnerPointerAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + Content: " content", + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/objc_root_class_attr_test.go b/ast/objc_root_class_attr_test.go new file mode 100644 index 0000000..74b48c1 --- /dev/null +++ b/ast/objc_root_class_attr_test.go @@ -0,0 +1,22 @@ +package ast + +import ( + "testing" +) + +func TestObjCRootClassAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 `: + testNode{&ObjCRootClassAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/objc_type_param_decl.go b/ast/objc_type_param_decl.go index fa53c5a..d3f81d2 100644 --- a/ast/objc_type_param_decl.go +++ b/ast/objc_type_param_decl.go @@ -40,11 +40,6 @@ func parseObjCTypeParamDecl(line string) Node { type2 = type2[2 : len(type2)-1] }*/ - if strings.Index(groups["position"], "") > -1 { - groups["position"] = "" - groups["position2"] = "" - } - return &ObjCTypeParamDecl{ Addr: ParseAddress(groups["address"]), Pos: NewPositionFromString(groups["position"]), diff --git a/ast/objc_type_param_decl_test.go b/ast/objc_type_param_decl_test.go index bff7c72..417552e 100644 --- a/ast/objc_type_param_decl_test.go +++ b/ast/objc_type_param_decl_test.go @@ -5,9 +5,9 @@ import ( ) func TestObjCTypeParamDecl(t *testing.T) { - nodes := map[string]Node{ + nodes := map[string]testNode{ `0x10c2d1a78 col:27 AnchorType 'id':'id'`: - &ObjCTypeParamDecl{ + testNode{&ObjCTypeParamDecl{ Addr: 0x10c2d1a78, Pos: NewPositionFromString("col:27"), Position2: "", @@ -19,8 +19,12 @@ func TestObjCTypeParamDecl(t *testing.T) { IsBounded: false, ChildNodes: []Node{}, }, + 0x10c2d1a78, + NewPositionFromString("col:27"), + []Node{}, + }, `0x7faa181df328 col:16 ObjectType covariant 'id':'id'`: - &ObjCTypeParamDecl{ + testNode{&ObjCTypeParamDecl{ Addr: 0x7faa181df328, Pos: NewPositionFromString("col:16"), Position2: "", @@ -32,8 +36,12 @@ func TestObjCTypeParamDecl(t *testing.T) { IsBounded: false, ChildNodes: []Node{}, }, + 0x7faa181df328, + NewPositionFromString("col:16"), + []Node{}, + }, `0x7faa18216cf0 col:26 referenced UnitType bounded 'NSUnit *'`: - &ObjCTypeParamDecl{ + testNode{&ObjCTypeParamDecl{ Addr: 0x7faa18216cf0, Pos: NewPositionFromString("col:26, col:43"), Position2: "", @@ -45,8 +53,12 @@ func TestObjCTypeParamDecl(t *testing.T) { IsBounded: true, ChildNodes: []Node{}, }, + 0x7faa18216cf0, + NewPositionFromString("col:26, col:43"), + []Node{}, + }, `0x7faa18ba2ba8 col:25 referenced K covariant 'id':'id'`: - &ObjCTypeParamDecl{ + testNode{&ObjCTypeParamDecl{ Addr: 0x7faa18ba2ba8, Pos: NewPositionFromString("col:25"), Position2: "", @@ -58,8 +70,12 @@ func TestObjCTypeParamDecl(t *testing.T) { IsBounded: false, ChildNodes: []Node{}, }, + 0x7faa18ba2ba8, + NewPositionFromString("col:25"), + []Node{}, + }, `0x7faa18ba2c18 col:28 V covariant 'id':'id'`: - &ObjCTypeParamDecl{ + testNode{&ObjCTypeParamDecl{ Addr: 0x7faa18ba2c18, Pos: NewPositionFromString("col:28"), Position2: "", @@ -71,6 +87,10 @@ func TestObjCTypeParamDecl(t *testing.T) { IsBounded: false, ChildNodes: []Node{}, }, + 0x7faa18ba2c18, + NewPositionFromString("col:28"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/offset_of_expr_test.go b/ast/offset_of_expr_test.go index 222a59e..8848bb3 100644 --- a/ast/offset_of_expr_test.go +++ b/ast/offset_of_expr_test.go @@ -5,13 +5,18 @@ import ( ) func TestOffsetOfExpr(t *testing.T) { - nodes := map[string]Node{ - `0x7fa855aab838 'unsigned long'`: &OffsetOfExpr{ + nodes := map[string]testNode{ + `0x7fa855aab838 'unsigned long'`: + testNode{&OffsetOfExpr{ Addr: 0x7fa855aab838, Pos: NewPositionFromString("col:63, col:95"), Type: "unsigned long", ChildNodes: []Node{}, }, + 0x7fa855aab838, + NewPositionFromString("col:63, col:95"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/packed_attr_test.go b/ast/packed_attr_test.go index 5975523..1c52493 100644 --- a/ast/packed_attr_test.go +++ b/ast/packed_attr_test.go @@ -5,12 +5,17 @@ import ( ) func TestPackedAttr(t *testing.T) { - nodes := map[string]Node{ - `0x7fae33b1ed40 `: &PackedAttr{ + nodes := map[string]testNode{ + `0x7fae33b1ed40 `: + testNode{&PackedAttr{ Addr: 0x7fae33b1ed40, Pos: NewPositionFromString("line:551:18"), ChildNodes: []Node{}, }, + 0x7fae33b1ed40, + NewPositionFromString("line:551:18"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/paragraph_comment_test.go b/ast/paragraph_comment_test.go index 0b6f5ac..b6adf87 100644 --- a/ast/paragraph_comment_test.go +++ b/ast/paragraph_comment_test.go @@ -5,12 +5,17 @@ import ( ) func TestParagraphComment(t *testing.T) { - nodes := map[string]Node{ - `0x3860920 `: &ParagraphComment{ + nodes := map[string]testNode{ + `0x3860920 `: + testNode{&ParagraphComment{ Addr: 0x3860920, Pos: NewPositionFromString("line:10176:4, line:10180:45"), ChildNodes: []Node{}, }, + 0x3860920, + NewPositionFromString("line:10176:4, line:10180:45"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/param_command_comment_test.go b/ast/param_command_comment_test.go index 4b09122..0345cdf 100644 --- a/ast/param_command_comment_test.go +++ b/ast/param_command_comment_test.go @@ -5,13 +5,18 @@ import ( ) func TestParamCommandComment(t *testing.T) { - nodes := map[string]Node{ - `0x104bca8d0 [in] implicitly Param="__attr" ParamIndex=0`: &ParamCommandComment{ + nodes := map[string]testNode{ + `0x104bca8d0 [in] implicitly Param="__attr" ParamIndex=0`: + testNode{&ParamCommandComment{ Addr: 0x104bca8d0, Pos: NewPositionFromString("col:4, line:59:45"), Other: "[in] implicitly Param=\"__attr\" ParamIndex=0", ChildNodes: []Node{}, }, + 0x104bca8d0, + NewPositionFromString("col:4, line:59:45"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/paren_expr_test.go b/ast/paren_expr_test.go index cb135c2..47023ca 100644 --- a/ast/paren_expr_test.go +++ b/ast/paren_expr_test.go @@ -5,8 +5,9 @@ import ( ) func TestParenExpr(t *testing.T) { - nodes := map[string]Node{ - `0x7fb0bc8b2308 'unsigned char'`: &ParenExpr{ + nodes := map[string]testNode{ + `0x7fb0bc8b2308 'unsigned char'`: + testNode{&ParenExpr{ Addr: 0x7fb0bc8b2308, Pos: NewPositionFromString("col:10, col:25"), Type: "unsigned char", @@ -15,7 +16,12 @@ func TestParenExpr(t *testing.T) { IsBitfield: false, ChildNodes: []Node{}, }, - `0x1ff8708 'T_ENUM':'T_ENUM' lvalue`: &ParenExpr{ + 0x7fb0bc8b2308, + NewPositionFromString("col:10, col:25"), + []Node{}, + }, + `0x1ff8708 'T_ENUM':'T_ENUM' lvalue`: + testNode{&ParenExpr{ Addr: 0x1ff8708, Pos: NewPositionFromString("col:14, col:17"), Type: "T_ENUM", @@ -24,7 +30,12 @@ func TestParenExpr(t *testing.T) { IsBitfield: false, ChildNodes: []Node{}, }, - `0x55efc60798b0 'bft':'unsigned int' lvalue bitfield`: &ParenExpr{ + 0x1ff8708, + NewPositionFromString("col:14, col:17"), + []Node{}, + }, + `0x55efc60798b0 'bft':'unsigned int' lvalue bitfield`: + testNode{&ParenExpr{ Addr: 0x55efc60798b0, Pos: NewPositionFromString("col:15, col:27"), Type: "bft", @@ -33,6 +44,10 @@ func TestParenExpr(t *testing.T) { IsBitfield: true, ChildNodes: []Node{}, }, + 0x55efc60798b0, + NewPositionFromString("col:15, col:27"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/paren_type_test.go b/ast/paren_type_test.go index 8513974..96b0c1d 100644 --- a/ast/paren_type_test.go +++ b/ast/paren_type_test.go @@ -5,13 +5,18 @@ import ( ) func TestParenType(t *testing.T) { - nodes := map[string]Node{ - `0x7faf820a4c60 'void (int)' sugar`: &ParenType{ + nodes := map[string]testNode{ + `0x7faf820a4c60 'void (int)' sugar`: + testNode{&ParenType{ Addr: 0x7faf820a4c60, Type: "void (int)", Sugar: true, ChildNodes: []Node{}, }, + 0x7faf820a4c60, + NewPositionFromString(""), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/parm_var_decl_test.go b/ast/parm_var_decl_test.go index 9994866..ef20b55 100644 --- a/ast/parm_var_decl_test.go +++ b/ast/parm_var_decl_test.go @@ -5,8 +5,9 @@ import ( ) func TestParmVarDecl(t *testing.T) { - nodes := map[string]Node{ - `0x7f973380f000 col:17 'int'`: &ParmVarDecl{ + nodes := map[string]testNode{ + `0x7f973380f000 col:17 'int'`: + testNode{&ParmVarDecl{ Addr: 0x7f973380f000, Pos: NewPositionFromString("col:14"), Position2: "col:17", @@ -18,7 +19,12 @@ func TestParmVarDecl(t *testing.T) { IsRegister: false, ChildNodes: []Node{}, }, - `0x7f973380f070 col:31 'const char *'`: &ParmVarDecl{ + 0x7f973380f000, + NewPositionFromString("col:14"), + []Node{}, + }, + `0x7f973380f070 col:31 'const char *'`: + testNode{&ParmVarDecl{ Addr: 0x7f973380f070, Pos: NewPositionFromString("col:19, col:30"), Position2: "col:31", @@ -29,7 +35,12 @@ func TestParmVarDecl(t *testing.T) { IsReferenced: false, ChildNodes: []Node{}, }, - `0x7f9733816e50 col:37 __filename 'const char *__restrict'`: &ParmVarDecl{ + 0x7f973380f070, + NewPositionFromString("col:19, col:30"), + []Node{}, + }, + `0x7f9733816e50 col:37 __filename 'const char *__restrict'`: + testNode{&ParmVarDecl{ Addr: 0x7f9733816e50, Pos: NewPositionFromString("col:13, col:37"), Position2: "col:37", @@ -41,7 +52,12 @@ func TestParmVarDecl(t *testing.T) { IsRegister: false, ChildNodes: []Node{}, }, - `0x7f9733817418 <> 'FILE *'`: &ParmVarDecl{ + 0x7f9733816e50, + NewPositionFromString("col:13, col:37"), + []Node{}, + }, + `0x7f9733817418 <> 'FILE *'`: + testNode{&ParmVarDecl{ Addr: 0x7f9733817418, Pos: NewPositionFromString(""), Position2: "", @@ -53,7 +69,12 @@ func TestParmVarDecl(t *testing.T) { IsRegister: false, ChildNodes: []Node{}, }, - `0x7f9733817c30 col:47 __size 'size_t':'unsigned long'`: &ParmVarDecl{ + 0x7f9733817418, + NewPositionFromString(""), + []Node{}, + }, + `0x7f9733817c30 col:47 __size 'size_t':'unsigned long'`: + testNode{&ParmVarDecl{ Addr: 0x7f9733817c30, Pos: NewPositionFromString("col:40, col:47"), Position2: "col:47", @@ -65,7 +86,12 @@ func TestParmVarDecl(t *testing.T) { IsRegister: false, ChildNodes: []Node{}, }, - `0x7f973382fa10 col:34 'int (* _Nullable)(void *, char *, int)':'int (*)(void *, char *, int)'`: &ParmVarDecl{ + 0x7f9733817c30, + NewPositionFromString("col:40, col:47"), + []Node{}, + }, + `0x7f973382fa10 col:34 'int (* _Nullable)(void *, char *, int)':'int (*)(void *, char *, int)'`: + testNode{&ParmVarDecl{ Addr: 0x7f973382fa10, Pos: NewPositionFromString("line:476:18, col:25"), Position2: "col:34", @@ -77,7 +103,12 @@ func TestParmVarDecl(t *testing.T) { IsRegister: false, ChildNodes: []Node{}, }, - `0x7f97338355b8 col:14 used argc 'int'`: &ParmVarDecl{ + 0x7f973382fa10, + NewPositionFromString("line:476:18, col:25"), + []Node{}, + }, + `0x7f97338355b8 col:14 used argc 'int'`: + testNode{&ParmVarDecl{ Addr: 0x7f97338355b8, Pos: NewPositionFromString("col:10, col:14"), Position2: "col:14", @@ -89,7 +120,12 @@ func TestParmVarDecl(t *testing.T) { IsRegister: false, ChildNodes: []Node{}, }, - `0x1d82850 col:16 referenced foo 'char *':'char *'`: &ParmVarDecl{ + 0x7f97338355b8, + NewPositionFromString("col:10, col:14"), + []Node{}, + }, + `0x1d82850 col:16 referenced foo 'char *':'char *'`: + testNode{&ParmVarDecl{ Addr: 0x1d82850, Pos: NewPositionFromString("col:11, col:22"), Position2: "col:16", @@ -101,7 +137,12 @@ func TestParmVarDecl(t *testing.T) { IsRegister: false, ChildNodes: []Node{}, }, - `0x7f95f30ed9d0 col:51 used eptr 'const char *' register`: &ParmVarDecl{ + 0x1d82850, + NewPositionFromString("col:11, col:22"), + []Node{}, + }, + `0x7f95f30ed9d0 col:51 used eptr 'const char *' register`: + testNode{&ParmVarDecl{ Addr: 0x7f95f30ed9d0, Pos: NewPositionFromString("col:23, col:51"), Position2: "col:51", @@ -113,6 +154,10 @@ func TestParmVarDecl(t *testing.T) { IsRegister: true, ChildNodes: []Node{}, }, + 0x7f95f30ed9d0, + NewPositionFromString("col:23, col:51"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/pointer_type_test.go b/ast/pointer_type_test.go index 763f679..36c211b 100644 --- a/ast/pointer_type_test.go +++ b/ast/pointer_type_test.go @@ -5,12 +5,17 @@ import ( ) func TestPointerType(t *testing.T) { - nodes := map[string]Node{ - `0x7fa3b88bbb30 'struct _opaque_pthread_t *'`: &PointerType{ + nodes := map[string]testNode{ + `0x7fa3b88bbb30 'struct _opaque_pthread_t *'`: + testNode{&PointerType{ Addr: 0x7fa3b88bbb30, Type: "struct _opaque_pthread_t *", ChildNodes: []Node{}, }, + 0x7fa3b88bbb30, + NewPositionFromString(""), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/position.go b/ast/position.go index 4911b1b..8569835 100644 --- a/ast/position.go +++ b/ast/position.go @@ -1,8 +1,8 @@ package ast import ( - "fmt" - "path/filepath" + //"fmt" + //"path/filepath" "git.wow.st/gmp/nswrap/util" ) @@ -24,13 +24,14 @@ type Position struct { // GetSimpleLocation - return a string like : "file:line" in // according to position // Example : " /tmp/1.c:200 " +/* func (p Position) GetSimpleLocation() (loc string) { file := p.File if f, err := filepath.Abs(p.File); err != nil { file = f } return fmt.Sprintf(" %s:%d ", file, p.Line) -} +}*/ func NewPositionFromString(s string) Position { if !TrackPositions { @@ -183,6 +184,7 @@ func NewPositionFromString(s string) Position { panic("unable to understand position '" + s + "'") } +/* func mergePositions(p1, p2 Position) Position { if p2.File != "" { p1.File = p2.File @@ -416,4 +418,4 @@ func setPosition(node Node, position Position) { default: panic(fmt.Sprintf("unknown node type: %+#v", node)) } -} +}*/ diff --git a/ast/position_test.go b/ast/position_test.go index 26f21f6..2eaef0b 100644 --- a/ast/position_test.go +++ b/ast/position_test.go @@ -1,6 +1,7 @@ package ast import ( + "reflect" "testing" ) @@ -107,3 +108,22 @@ func TestNewPositionFromString(t *testing.T) { }) } } + +func TestTrackPositions(t *testing.T) { + TrackPositions = false + t.Run("TrackPositions1", func(t *testing.T) { + pos := NewPositionFromString("line:120:1, col:16") + if !reflect.DeepEqual(pos,Position{}) { + t.Errorf("TrackPositions = false but NewPositionFromString did not return Position{}\n") + } + }) + + t.Run("TrackPositions2", func(t *testing.T) { + addr := ParseAddress("0x7fdef0862430") + if addr != 0 { + t.Errorf("TrackPositions = false but ParseAddress did not return 0\n") + } + }) + TrackPositions = true +} + diff --git a/ast/predefined_expr_test.go b/ast/predefined_expr_test.go index d9ffc4c..569bc43 100644 --- a/ast/predefined_expr_test.go +++ b/ast/predefined_expr_test.go @@ -5,8 +5,9 @@ import ( ) func TestPredefinedExpr(t *testing.T) { - nodes := map[string]Node{ - `0x33d6e08 'const char [25]' lvalue __PRETTY_FUNCTION__`: &PredefinedExpr{ + nodes := map[string]testNode{ + `0x33d6e08 'const char [25]' lvalue __PRETTY_FUNCTION__`: + testNode{&PredefinedExpr{ Addr: 0x33d6e08, Pos: NewPositionFromString("col:30"), Type: "const char [25]", @@ -14,6 +15,10 @@ func TestPredefinedExpr(t *testing.T) { Name: "__PRETTY_FUNCTION__", ChildNodes: []Node{}, }, + 0x33d6e08, + NewPositionFromString("col:30"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/pure_attr_test.go b/ast/pure_attr_test.go index b590e89..44bd809 100644 --- a/ast/pure_attr_test.go +++ b/ast/pure_attr_test.go @@ -5,21 +5,31 @@ import ( ) func TestPureAttr(t *testing.T) { - nodes := map[string]Node{ - `0x7fe9eb899198 Implicit`: &PureAttr{ + nodes := map[string]testNode{ + `0x7fe9eb899198 Implicit`: + testNode{&PureAttr{ Addr: 0x7fe9eb899198, Pos: NewPositionFromString("col:1"), Implicit: true, Inherited: false, ChildNodes: []Node{}, }, - `0x7fe8d60992a0 Inherited Implicit`: &PureAttr{ + 0x7fe9eb899198, + NewPositionFromString("col:1"), + []Node{}, + }, + `0x7fe8d60992a0 Inherited Implicit`: + testNode{&PureAttr{ Addr: 0x7fe8d60992a0, Pos: NewPositionFromString("col:1"), Implicit: true, Inherited: true, ChildNodes: []Node{}, }, + 0x7fe8d60992a0, + NewPositionFromString("col:1"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/qual_type_test.go b/ast/qual_type_test.go index 80d41f8..a714eee 100644 --- a/ast/qual_type_test.go +++ b/ast/qual_type_test.go @@ -5,13 +5,18 @@ import ( ) func TestQualType(t *testing.T) { - nodes := map[string]Node{ - `0x7fa3b88bbb31 'struct _opaque_pthread_t *' foo`: &QualType{ + nodes := map[string]testNode{ + `0x7fa3b88bbb31 'struct _opaque_pthread_t *' foo`: + testNode{&QualType{ Addr: 0x7fa3b88bbb31, Type: "struct _opaque_pthread_t *", Kind: "foo", ChildNodes: []Node{}, }, + 0x7fa3b88bbb31, + NewPositionFromString(""), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/record_decl_test.go b/ast/record_decl_test.go index e887f67..72a419e 100644 --- a/ast/record_decl_test.go +++ b/ast/record_decl_test.go @@ -5,8 +5,9 @@ import ( ) func TestRecordDecl(t *testing.T) { - nodes := map[string]Node{ - `0x7f913c0dbb50 line:76:9 union definition`: &RecordDecl{ + nodes := map[string]testNode{ + `0x7f913c0dbb50 line:76:9 union definition`: + testNode{&RecordDecl{ Addr: 0x7f913c0dbb50, Pos: NewPositionFromString("line:76:9, line:79:1"), Prev: "", @@ -16,7 +17,12 @@ func TestRecordDecl(t *testing.T) { Definition: true, ChildNodes: []Node{}, }, - `0x7f85360285c8 line:57:8 struct __darwin_pthread_handler_rec definition`: &RecordDecl{ + 0x7f913c0dbb50, + NewPositionFromString("line:76:9, line:79:1"), + []Node{}, + }, + `0x7f85360285c8 line:57:8 struct __darwin_pthread_handler_rec definition`: + testNode{&RecordDecl{ Addr: 0x7f85360285c8, Pos: NewPositionFromString("/usr/include/sys/_pthread/_pthread_types.h:57:1, line:61:1"), Prev: "", @@ -26,7 +32,12 @@ func TestRecordDecl(t *testing.T) { Definition: true, ChildNodes: []Node{}, }, - `0x7f85370248a0 col:8 struct __sFILEX`: &RecordDecl{ + 0x7f85360285c8, + NewPositionFromString("/usr/include/sys/_pthread/_pthread_types.h:57:1, line:61:1"), + []Node{}, + }, + `0x7f85370248a0 col:8 struct __sFILEX`: + testNode{&RecordDecl{ Addr: 0x7f85370248a0, Pos: NewPositionFromString("line:94:1, col:8"), Prev: "", @@ -36,7 +47,12 @@ func TestRecordDecl(t *testing.T) { Definition: false, ChildNodes: []Node{}, }, - `0x5564ed488a10 parent 0x5564ed3ffe00 line:7232:10 struct sqlite3_index_constraint definition`: &RecordDecl{ + 0x7f85370248a0, + NewPositionFromString("line:94:1, col:8"), + []Node{}, + }, + `0x5564ed488a10 parent 0x5564ed3ffe00 line:7232:10 struct sqlite3_index_constraint definition`: + testNode{&RecordDecl{ Addr: 0x5564ed488a10, Pos: NewPositionFromString("line:7232:3, line:7237:3"), Prev: "", @@ -46,7 +62,12 @@ func TestRecordDecl(t *testing.T) { Definition: true, ChildNodes: []Node{}, }, - `0x56454e55e4b8 prev 0x56454e55e360 line:86428:8 struct Incrblob definition`: &RecordDecl{ + 0x5564ed488a10, + NewPositionFromString("line:7232:3, line:7237:3"), + []Node{}, + }, + `0x56454e55e4b8 prev 0x56454e55e360 line:86428:8 struct Incrblob definition`: + testNode{&RecordDecl{ Addr: 0x56454e55e4b8, Pos: NewPositionFromString("line:86428:1, line:86437:1"), Prev: "0x56454e55e360", @@ -56,6 +77,10 @@ func TestRecordDecl(t *testing.T) { Definition: true, ChildNodes: []Node{}, }, + 0x56454e55e4b8, + NewPositionFromString("line:86428:1, line:86437:1"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/record_test.go b/ast/record_test.go index be12fd8..08e88d2 100644 --- a/ast/record_test.go +++ b/ast/record_test.go @@ -5,12 +5,17 @@ import ( ) func TestRecord(t *testing.T) { - nodes := map[string]Node{ - `0x7fd3ab857950 '__sFILE'`: &Record{ + nodes := map[string]testNode{ + `0x7fd3ab857950 '__sFILE'`: + testNode{&Record{ Addr: 0x7fd3ab857950, Type: "__sFILE", ChildNodes: []Node{}, }, + 0x7fd3ab857950, + NewPositionFromString(""), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/record_type_test.go b/ast/record_type_test.go index f1dffb6..655706a 100644 --- a/ast/record_type_test.go +++ b/ast/record_type_test.go @@ -5,12 +5,17 @@ import ( ) func TestRecordType(t *testing.T) { - nodes := map[string]Node{ - `0x7fd3ab84dda0 'struct _opaque_pthread_condattr_t'`: &RecordType{ + nodes := map[string]testNode{ + `0x7fd3ab84dda0 'struct _opaque_pthread_condattr_t'`: + testNode{&RecordType{ Addr: 0x7fd3ab84dda0, Type: "struct _opaque_pthread_condattr_t", ChildNodes: []Node{}, }, + 0x7fd3ab84dda0, + NewPositionFromString(""), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/restrict_attr_test.go b/ast/restrict_attr_test.go index 5ed5443..a48fa91 100644 --- a/ast/restrict_attr_test.go +++ b/ast/restrict_attr_test.go @@ -5,13 +5,18 @@ import ( ) func TestRestrictAttr(t *testing.T) { - nodes := map[string]Node{ - `0x7f980b858305 foo`: &RestrictAttr{ + nodes := map[string]testNode{ + `0x7f980b858305 foo`: + testNode{&RestrictAttr{ Addr: 0x7f980b858305, Pos: NewPositionFromString("line:11:7, line:18:7"), Name: "foo", ChildNodes: []Node{}, }, + 0x7f980b858305, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/return_stmt_test.go b/ast/return_stmt_test.go index f453409..945699f 100644 --- a/ast/return_stmt_test.go +++ b/ast/return_stmt_test.go @@ -5,12 +5,17 @@ import ( ) func TestReturnStmt(t *testing.T) { - nodes := map[string]Node{ - `0x7fbb7a8325e0 `: &ReturnStmt{ + nodes := map[string]testNode{ + `0x7fbb7a8325e0 `: + testNode{&ReturnStmt{ Addr: 0x7fbb7a8325e0, Pos: NewPositionFromString("line:13:4, col:11"), ChildNodes: []Node{}, }, + 0x7fbb7a8325e0, + NewPositionFromString("line:13:4, col:11"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/returns_twice_attr_test.go b/ast/returns_twice_attr_test.go index 2e87bae..f971721 100644 --- a/ast/returns_twice_attr_test.go +++ b/ast/returns_twice_attr_test.go @@ -5,21 +5,31 @@ import ( ) func TestReturnsTwiceAttr(t *testing.T) { - nodes := map[string]Node{ - `0x7ff8e9091640 Implicit`: &ReturnsTwiceAttr{ + nodes := map[string]testNode{ + `0x7ff8e9091640 Implicit`: + testNode{&ReturnsTwiceAttr{ Addr: 0x7ff8e9091640, Pos: NewPositionFromString("col:7"), ChildNodes: []Node{}, Inherited: false, Implicit: true, }, - `0x564a73a5ccc8 Inherited Implicit`: &ReturnsTwiceAttr{ + 0x7ff8e9091640, + NewPositionFromString("col:7"), + []Node{}, + }, + `0x564a73a5ccc8 Inherited Implicit`: + testNode{&ReturnsTwiceAttr{ Addr: 0x564a73a5ccc8, Pos: NewPositionFromString("col:16"), ChildNodes: []Node{}, Inherited: true, Implicit: true, }, + 0x564a73a5ccc8, + NewPositionFromString("col:16"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/sentinel_attr_test.go b/ast/sentinel_attr_test.go index e30546e..a4694fb 100644 --- a/ast/sentinel_attr_test.go +++ b/ast/sentinel_attr_test.go @@ -5,14 +5,19 @@ import ( ) func TestSentinelAttr(t *testing.T) { - nodes := map[string]Node{ - `0x346df70 0 0`: &SentinelAttr{ + nodes := map[string]testNode{ + `0x346df70 0 0`: + testNode{&SentinelAttr{ Addr: 0x346df70, Pos: NewPositionFromString("line:3571:19, col:33"), A: 0, B: 0, ChildNodes: []Node{}, }, + 0x346df70, + NewPositionFromString("line:3571:19, col:33"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/shuffle_vector_expr_test.go b/ast/shuffle_vector_expr_test.go new file mode 100644 index 0000000..90f055a --- /dev/null +++ b/ast/shuffle_vector_expr_test.go @@ -0,0 +1,36 @@ +package ast + +import ( + "testing" +) + +func TestShuffleVectorExpr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fdef0862430 `: + testNode{&ShuffleVectorExpr{ + Addr: 0x7fdef0862430, + Pos: NewPositionFromString("line:120:1, col:16"), + Type: "", + Type2: "", + ChildNodes: []Node{}, + }, + 0x7fdef0862430, + NewPositionFromString("line:120:1, col:16"), + []Node{}, + }, + `0x113368318 '__v4sf':'__attribute__((__vector_size__(4 * sizeof(float)))) float'`: + testNode{&ShuffleVectorExpr{ + Addr: 0x113368318, + Pos: NewPositionFromString("line:1354:20, line:1355:70"), + Type: `__v4sf`, + Type2: `:'__attribute__((__vector_size__(4 * sizeof(float)))) float'`, + ChildNodes: []Node{}, + }, + 0x113368318, + NewPositionFromString("line:1354:20, line:1355:70"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/stmt_expr_test.go b/ast/stmt_expr_test.go index 6cf670c..707a474 100644 --- a/ast/stmt_expr_test.go +++ b/ast/stmt_expr_test.go @@ -5,13 +5,18 @@ import ( ) func TestStmtExpr(t *testing.T) { - nodes := map[string]Node{ - `0x7ff4f9100d28 'int'`: &StmtExpr{ + nodes := map[string]testNode{ + `0x7ff4f9100d28 'int'`: + testNode{&StmtExpr{ Addr: 0x7ff4f9100d28, Pos: NewPositionFromString("col:11, col:18"), Type: "int", ChildNodes: []Node{}, }, + 0x7ff4f9100d28, + NewPositionFromString("col:11, col:18"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/string_literal_test.go b/ast/string_literal_test.go index 304630f..f9cbf61 100644 --- a/ast/string_literal_test.go +++ b/ast/string_literal_test.go @@ -5,8 +5,9 @@ import ( ) func TestStringLiteral(t *testing.T) { - nodes := map[string]Node{ - `0x7fe16f0b4d58 'char [45]' lvalue "Number of command line arguments passed: %d\n"`: &StringLiteral{ + nodes := map[string]testNode{ + `0x7fe16f0b4d58 'char [45]' lvalue "Number of command line arguments passed: %d\n"`: + testNode{&StringLiteral{ Addr: 0x7fe16f0b4d58, Pos: NewPositionFromString("col:11"), Type: "char [45]", @@ -14,7 +15,12 @@ func TestStringLiteral(t *testing.T) { Value: "Number of command line arguments passed: %d\n", ChildNodes: []Node{}, }, - `0x22ac548 'char [14]' lvalue "x\vx\000xxx\axx\tx\n"`: &StringLiteral{ + 0x7fe16f0b4d58, + NewPositionFromString("col:11"), + []Node{}, + }, + `0x22ac548 'char [14]' lvalue "x\vx\000xxx\axx\tx\n"`: + testNode{&StringLiteral{ Addr: 0x22ac548, Pos: NewPositionFromString("col:14"), Type: "char [14]", @@ -22,6 +28,10 @@ func TestStringLiteral(t *testing.T) { Value: "x\vx\x00xxx\axx\tx\n", ChildNodes: []Node{}, }, + 0x22ac548, + NewPositionFromString("col:14"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/swift_bridged_typedef_attr_test.go b/ast/swift_bridged_typedef_attr_test.go new file mode 100644 index 0000000..157fc3f --- /dev/null +++ b/ast/swift_bridged_typedef_attr_test.go @@ -0,0 +1,22 @@ +package ast + +import ( + "testing" +) + +func TestSwiftBridgedTypedefAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 `: + testNode{&SwiftBridgedTypedefAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/swift_error_attr_test.go b/ast/swift_error_attr_test.go new file mode 100644 index 0000000..89069ef --- /dev/null +++ b/ast/swift_error_attr_test.go @@ -0,0 +1,23 @@ +package ast + +import ( + "testing" +) + +func TestSwiftErrorAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 content`: + testNode{&SwiftErrorAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + Content: " content", + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/swift_name_attr_test.go b/ast/swift_name_attr_test.go new file mode 100644 index 0000000..6eee785 --- /dev/null +++ b/ast/swift_name_attr_test.go @@ -0,0 +1,23 @@ +package ast + +import ( + "testing" +) + +func TestSwiftNameAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 content`: + testNode{&SwiftNameAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + Content: " content", + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/swift_newtype_attr_test.go b/ast/swift_newtype_attr_test.go new file mode 100644 index 0000000..5f14b42 --- /dev/null +++ b/ast/swift_newtype_attr_test.go @@ -0,0 +1,23 @@ +package ast + +import ( + "testing" +) + +func TestSwiftNewtypeAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 content`: + testNode{&SwiftNewtypeAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + Content: " content", + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/swift_private_attr_test.go b/ast/swift_private_attr_test.go new file mode 100644 index 0000000..368a90f --- /dev/null +++ b/ast/swift_private_attr_test.go @@ -0,0 +1,22 @@ +package ast + +import ( + "testing" +) + +func TestSwiftPrivateAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 `: + testNode{&SwiftPrivateAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/switch_stmt_test.go b/ast/switch_stmt_test.go index edd0431..64ea83f 100644 --- a/ast/switch_stmt_test.go +++ b/ast/switch_stmt_test.go @@ -5,12 +5,17 @@ import ( ) func TestSwitchStmt(t *testing.T) { - nodes := map[string]Node{ - `0x7fbca3894638 `: &SwitchStmt{ + nodes := map[string]testNode{ + `0x7fbca3894638 `: + testNode{&SwitchStmt{ Addr: 0x7fbca3894638, Pos: NewPositionFromString("line:9:5, line:20:5"), ChildNodes: []Node{}, }, + 0x7fbca3894638, + NewPositionFromString("line:9:5, line:20:5"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/target_attr_test.go b/ast/target_attr_test.go new file mode 100644 index 0000000..bd6ebc5 --- /dev/null +++ b/ast/target_attr_test.go @@ -0,0 +1,23 @@ +package ast + +import ( + "testing" +) + +func TestTargetAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 content`: + testNode{&TargetAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + Content: " content", + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/text_comment_test.go b/ast/text_comment_test.go index f32cb27..08efedb 100644 --- a/ast/text_comment_test.go +++ b/ast/text_comment_test.go @@ -5,13 +5,18 @@ import ( ) func TestTextComment(t *testing.T) { - nodes := map[string]Node{ - `0x3085bc0 Text="* CUSTOM AUXILIARY FUNCTIONS"`: &TextComment{ + nodes := map[string]testNode{ + `0x3085bc0 Text="* CUSTOM AUXILIARY FUNCTIONS"`: + testNode{&TextComment{ Addr: 0x3085bc0, Pos: NewPositionFromString("line:9950:2, col:29"), Text: "* CUSTOM AUXILIARY FUNCTIONS", ChildNodes: []Node{}, }, + 0x3085bc0, + NewPositionFromString("line:9950:2, col:29"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/translation_unit_decl_test.go b/ast/translation_unit_decl_test.go index 079f5e5..9437647 100644 --- a/ast/translation_unit_decl_test.go +++ b/ast/translation_unit_decl_test.go @@ -5,11 +5,16 @@ import ( ) func TestTranslationUnitDecl(t *testing.T) { - nodes := map[string]Node{ - `0x7fe78a815ed0 <> `: &TranslationUnitDecl{ + nodes := map[string]testNode{ + `0x7fe78a815ed0 <> `: + testNode{&TranslationUnitDecl{ Addr: 0x7fe78a815ed0, ChildNodes: []Node{}, }, + 0x7fe78a815ed0, + NewPositionFromString(""), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/transparent_union_attr_test.go b/ast/transparent_union_attr_test.go index c9aa28e..6313b91 100644 --- a/ast/transparent_union_attr_test.go +++ b/ast/transparent_union_attr_test.go @@ -5,12 +5,17 @@ import ( ) func TestTransparentUnionAttr(t *testing.T) { - nodes := map[string]Node{ - `0x304f700 `: &TransparentUnionAttr{ + nodes := map[string]testNode{ + `0x304f700 `: + testNode{&TransparentUnionAttr{ Addr: 0x304f700, Pos: NewPositionFromString("col:35"), ChildNodes: []Node{}, }, + 0x304f700, + NewPositionFromString("col:35"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/traverse.go b/ast/traverse.go index c2efc1a..1676a53 100644 --- a/ast/traverse.go +++ b/ast/traverse.go @@ -1,5 +1,5 @@ package ast - +/* import ( "reflect" ) @@ -25,4 +25,4 @@ func GetAllNodesOfType(root Node, t reflect.Type) []Node { } return nodes -} +}*/ diff --git a/ast/typedef_decl_test.go b/ast/typedef_decl_test.go index d6423a5..49ff128 100644 --- a/ast/typedef_decl_test.go +++ b/ast/typedef_decl_test.go @@ -5,8 +5,9 @@ import ( ) func TestTypedefDecl(t *testing.T) { - nodes := map[string]Node{ - `0x7fdef0862430 col:16`: &TypedefDecl{ + nodes := map[string]testNode{ + `0x7fdef0862430 col:16`: + testNode{&TypedefDecl{ Addr: 0x7fdef0862430, Pos: NewPositionFromString("line:120:1, col:16"), Position2: "col:16", @@ -17,7 +18,12 @@ func TestTypedefDecl(t *testing.T) { IsReferenced: false, ChildNodes: []Node{}, }, - `0x7ffb9f824278 <> implicit __uint128_t 'unsigned __int128'`: &TypedefDecl{ + 0x7fdef0862430, + NewPositionFromString("line:120:1, col:16"), + []Node{}, + }, + `0x7ffb9f824278 <> implicit __uint128_t 'unsigned __int128'`: + testNode{&TypedefDecl{ Addr: 0x7ffb9f824278, Pos: NewPositionFromString(""), Position2: "", @@ -28,7 +34,12 @@ func TestTypedefDecl(t *testing.T) { IsReferenced: false, ChildNodes: []Node{}, }, - `0x7ffb9f824898 <> implicit referenced __builtin_va_list 'struct __va_list_tag [1]'`: &TypedefDecl{ + 0x7ffb9f824278, + NewPositionFromString(""), + []Node{}, + }, + `0x7ffb9f824898 <> implicit referenced __builtin_va_list 'struct __va_list_tag [1]'`: + testNode{&TypedefDecl{ Addr: 0x7ffb9f824898, Pos: NewPositionFromString(""), Position2: "", @@ -39,7 +50,12 @@ func TestTypedefDecl(t *testing.T) { IsReferenced: true, ChildNodes: []Node{}, }, - `0x7ffb9f8248f8 col:24 __int8_t 'signed char'`: &TypedefDecl{ + 0x7ffb9f824898, + NewPositionFromString(""), + []Node{}, + }, + `0x7ffb9f8248f8 col:24 __int8_t 'signed char'`: + testNode{&TypedefDecl{ Addr: 0x7ffb9f8248f8, Pos: NewPositionFromString("/usr/include/i386/_types.h:37:1, col:24"), Position2: "col:24", @@ -50,7 +66,12 @@ func TestTypedefDecl(t *testing.T) { IsReferenced: false, ChildNodes: []Node{}, }, - `0x7ffb9f8dbf50 col:27 referenced __darwin_va_list '__builtin_va_list':'struct __va_list_tag [1]'`: &TypedefDecl{ + 0x7ffb9f8248f8, + NewPositionFromString("/usr/include/i386/_types.h:37:1, col:24"), + []Node{}, + }, + `0x7ffb9f8dbf50 col:27 referenced __darwin_va_list '__builtin_va_list':'struct __va_list_tag [1]'`: + testNode{&TypedefDecl{ Addr: 0x7ffb9f8dbf50, Pos: NewPositionFromString("line:98:1, col:27"), Position2: "col:27", @@ -61,7 +82,12 @@ func TestTypedefDecl(t *testing.T) { IsReferenced: true, ChildNodes: []Node{}, }, - `0x34461f0 __io_read_fn '__ssize_t (void *, char *, size_t)'`: &TypedefDecl{ + 0x7ffb9f8dbf50, + NewPositionFromString("line:98:1, col:27"), + []Node{}, + }, + `0x34461f0 __io_read_fn '__ssize_t (void *, char *, size_t)'`: + testNode{&TypedefDecl{ Addr: 0x34461f0, Pos: NewPositionFromString("line:338:1, col:77"), Position2: "", @@ -72,7 +98,12 @@ func TestTypedefDecl(t *testing.T) { IsReferenced: false, ChildNodes: []Node{}, }, - `0x55b9da8784b0 line:341:19 __io_write_fn '__ssize_t (void *, const char *, size_t)'`: &TypedefDecl{ + 0x34461f0, + NewPositionFromString("line:338:1, col:77"), + []Node{}, + }, + `0x55b9da8784b0 line:341:19 __io_write_fn '__ssize_t (void *, const char *, size_t)'`: + testNode{&TypedefDecl{ Addr: 0x55b9da8784b0, Pos: NewPositionFromString("line:341:1, line:342:16"), Position2: "line:341:19", @@ -83,7 +114,12 @@ func TestTypedefDecl(t *testing.T) { IsReferenced: false, ChildNodes: []Node{}, }, - `0x3f0b9b0 col:3 referenced extCoord 'struct extCoord':'extCoord'`: &TypedefDecl{ + 0x55b9da8784b0, + NewPositionFromString("line:341:1, line:342:16"), + []Node{}, + }, + `0x3f0b9b0 col:3 referenced extCoord 'struct extCoord':'extCoord'`: + testNode{&TypedefDecl{ Addr: 0x3f0b9b0, Pos: NewPositionFromString("line:12:1, line:15:3"), Position2: "col:3", @@ -94,6 +130,10 @@ func TestTypedefDecl(t *testing.T) { IsReferenced: true, ChildNodes: []Node{}, }, + 0x3f0b9b0, + NewPositionFromString("line:12:1, line:15:3"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/typedef_test.go b/ast/typedef_test.go index f7ec9e0..89a3a44 100644 --- a/ast/typedef_test.go +++ b/ast/typedef_test.go @@ -5,12 +5,17 @@ import ( ) func TestTypedef(t *testing.T) { - nodes := map[string]Node{ - `0x7f84d10dc1d0 '__darwin_ssize_t'`: &Typedef{ + nodes := map[string]testNode{ + `0x7f84d10dc1d0 '__darwin_ssize_t'`: + testNode{&Typedef{ Addr: 0x7f84d10dc1d0, Type: "__darwin_ssize_t", ChildNodes: []Node{}, }, + 0x7f84d10dc1d0, + NewPositionFromString(""), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/typedef_type_test.go b/ast/typedef_type_test.go index 9662c45..082a0a3 100644 --- a/ast/typedef_type_test.go +++ b/ast/typedef_type_test.go @@ -5,13 +5,18 @@ import ( ) func TestTypedefType(t *testing.T) { - nodes := map[string]Node{ - `0x7f887a0dc760 '__uint16_t' sugar`: &TypedefType{ + nodes := map[string]testNode{ + `0x7f887a0dc760 '__uint16_t' sugar`: + testNode{&TypedefType{ Addr: 0x7f887a0dc760, Type: "__uint16_t", Tags: "sugar", ChildNodes: []Node{}, }, + 0x7f887a0dc760, + NewPositionFromString(""), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/unary_expr_or_type_trait_expr_test.go b/ast/unary_expr_or_type_trait_expr_test.go index 0519a39..aeee1f6 100644 --- a/ast/unary_expr_or_type_trait_expr_test.go +++ b/ast/unary_expr_or_type_trait_expr_test.go @@ -5,8 +5,9 @@ import ( ) func TestUnaryExprOrTypeTraitExpr(t *testing.T) { - nodes := map[string]Node{ - `0x7fccd70adf50 'unsigned long' sizeof 'char'`: &UnaryExprOrTypeTraitExpr{ + nodes := map[string]testNode{ + `0x7fccd70adf50 'unsigned long' sizeof 'char'`: + testNode{&UnaryExprOrTypeTraitExpr{ Addr: 0x7fccd70adf50, Pos: NewPositionFromString("col:29, col:40"), Type1: "unsigned long", @@ -15,7 +16,12 @@ func TestUnaryExprOrTypeTraitExpr(t *testing.T) { Type3: "", ChildNodes: []Node{}, }, - `0x7fae1a800190 'unsigned long' sizeof`: &UnaryExprOrTypeTraitExpr{ + 0x7fccd70adf50, + NewPositionFromString("col:29, col:40"), + []Node{}, + }, + `0x7fae1a800190 'unsigned long' sizeof`: + testNode{&UnaryExprOrTypeTraitExpr{ Addr: 0x7fae1a800190, Pos: NewPositionFromString("col:36, col:44"), Type1: "unsigned long", @@ -24,7 +30,12 @@ func TestUnaryExprOrTypeTraitExpr(t *testing.T) { Type3: "", ChildNodes: []Node{}, }, - `0x557e575e70b8 'unsigned long' sizeof 'union MyUnion':'union MyUnion'`: &UnaryExprOrTypeTraitExpr{ + 0x7fae1a800190, + NewPositionFromString("col:36, col:44"), + []Node{}, + }, + `0x557e575e70b8 'unsigned long' sizeof 'union MyUnion':'union MyUnion'`: + testNode{&UnaryExprOrTypeTraitExpr{ Addr: 0x557e575e70b8, Pos: NewPositionFromString("col:432, col:452"), Type1: "unsigned long", @@ -33,7 +44,12 @@ func TestUnaryExprOrTypeTraitExpr(t *testing.T) { Type3: "union MyUnion", ChildNodes: []Node{}, }, - `0x3f142d8 'unsigned long' sizeof 'extCoord':'extCoord'`: &UnaryExprOrTypeTraitExpr{ + 0x557e575e70b8, + NewPositionFromString("col:432, col:452"), + []Node{}, + }, + `0x3f142d8 'unsigned long' sizeof 'extCoord':'extCoord'`: + testNode{&UnaryExprOrTypeTraitExpr{ Addr: 0x3f142d8, Pos: NewPositionFromString("col:30, col:45"), Type1: "unsigned long", @@ -42,6 +58,10 @@ func TestUnaryExprOrTypeTraitExpr(t *testing.T) { Type3: "extCoord", ChildNodes: []Node{}, }, + 0x3f142d8, + NewPositionFromString("col:30, col:45"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/unary_operator_test.go b/ast/unary_operator_test.go index 7549c09..961f1b4 100644 --- a/ast/unary_operator_test.go +++ b/ast/unary_operator_test.go @@ -5,8 +5,9 @@ import ( ) func TestUnaryOperator(t *testing.T) { - nodes := map[string]Node{ - `0x7fe0260f50d8 'int' prefix '--'`: &UnaryOperator{ + nodes := map[string]testNode{ + `0x7fe0260f50d8 'int' prefix '--'`: + testNode{&UnaryOperator{ Addr: 0x7fe0260f50d8, Pos: NewPositionFromString("col:6, col:12"), Type: "int", @@ -16,7 +17,12 @@ func TestUnaryOperator(t *testing.T) { Operator: "--", ChildNodes: []Node{}, }, - `0x7fe0260fb468 'unsigned char' lvalue prefix '*'`: &UnaryOperator{ + 0x7fe0260f50d8, + NewPositionFromString("col:6, col:12"), + []Node{}, + }, + `0x7fe0260fb468 'unsigned char' lvalue prefix '*'`: + testNode{&UnaryOperator{ Addr: 0x7fe0260fb468, Pos: NewPositionFromString("col:11, col:18"), Type: "unsigned char", @@ -26,7 +32,12 @@ func TestUnaryOperator(t *testing.T) { Operator: "*", ChildNodes: []Node{}, }, - `0x7fe0260fb448 'unsigned char *' postfix '++'`: &UnaryOperator{ + 0x7fe0260fb468, + NewPositionFromString("col:11, col:18"), + []Node{}, + }, + `0x7fe0260fb448 'unsigned char *' postfix '++'`: + testNode{&UnaryOperator{ Addr: 0x7fe0260fb448, Pos: NewPositionFromString("col:12, col:18"), Type: "unsigned char *", @@ -36,7 +47,12 @@ func TestUnaryOperator(t *testing.T) { Operator: "++", ChildNodes: []Node{}, }, - `0x26fd2b8 'extCoord':'extCoord' lvalue prefix '*'`: &UnaryOperator{ + 0x7fe0260fb448, + NewPositionFromString("col:12, col:18"), + []Node{}, + }, + `0x26fd2b8 'extCoord':'extCoord' lvalue prefix '*'`: + testNode{&UnaryOperator{ Addr: 0x26fd2b8, Pos: NewPositionFromString("col:20, col:32"), Type: "extCoord", @@ -46,6 +62,10 @@ func TestUnaryOperator(t *testing.T) { Operator: "*", ChildNodes: []Node{}, }, + 0x26fd2b8, + NewPositionFromString("col:20, col:32"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/unavailable_attr_test.go b/ast/unavailable_attr_test.go index 77e31e6..cfdc898 100644 --- a/ast/unavailable_attr_test.go +++ b/ast/unavailable_attr_test.go @@ -5,23 +5,31 @@ import ( ) func TestUnavailableAttr(t *testing.T) { - nodes := map[string]Node{ + nodes := map[string]testNode{ `0x7faa18a445d8 "" IR_None`: - &UnavailableAttr{ + testNode{&UnavailableAttr{ Addr: 0x7faa18a445d8, Pos: NewPositionFromString("line:66:45"), Position2: "", Content: `"" IR_None`, ChildNodes: []Node{}, }, + 0x7faa18a445d8, + NewPositionFromString("line:66:45"), + []Node{}, + }, `0x7faa18a289f8 "use a (__bridge id) cast instead" IR_None`: - &UnavailableAttr{ + testNode{&UnavailableAttr{ Addr: 0x7faa18a289f8, Pos: NewPositionFromString("line:150:54, col:70"), Position2: "", Content: `"use a (__bridge id) cast instead" IR_None`, ChildNodes: []Node{}, }, + 0x7faa18a289f8, + NewPositionFromString("line:150:54, col:70"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/unknown_test.go b/ast/unknown_test.go index c3b8619..0ebb317 100644 --- a/ast/unknown_test.go +++ b/ast/unknown_test.go @@ -1,21 +1,831 @@ package ast import ( + "fmt" "testing" ) func TestUnknown(t *testing.T) { - nodes := map[string]Node{ - `0x7faa18a445d8 "asdf" aoeu`: - &Unknown{ + i := 1 + runNodeTest(t, + Parse(`SomeNode 0x7faa18a445d8 "asdf" aoeu`), + testNode{&Unknown{ Addr: 0x7faa18a445d8, - Name: "Unknown", + Name: "SomeNode", Pos: NewPositionFromString("line:66:45"), - Position2: "", Content: ` "asdf" aoeu`, ChildNodes: []Node{}, }, - } - - runNodeTests(t, nodes) + 0x7faa18a445d8, + NewPositionFromString("line:66:45"), + []Node{}, + }, + &i, + ) + runNodeTest(t, + Parse(`AlignedAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`AllocSizeAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`AlwaysInlineAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ArcWeakrefUnavailableAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ArraySubscriptExpr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`AsmLabelAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`AttributedType 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`AvailabilityAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`BinaryOperator 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`BlockCommandComment 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`BlockPointerType 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`BreakStmt 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`BuiltinType 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`CFAuditedTransferAttr invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`CFConsumedAttr invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`CFReturnsNotRetainedAttr invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`CFReturnsRetainedAttr invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`CStyleCastExpr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`CallExpr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`CaseStmt 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`CharacterLiteral 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`CompoundAssignOperator 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`CompoundLiteralExpr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`CompoundStmt 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ConditionalOperator 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ConstantArrayType 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ContinueStmt 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ConvertVectorExpr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`DecayedType 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`DeclRefExpr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`DeclRefExpr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`DeclStmt 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`DefaultStmt 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`DeprecatedAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`DisableTailCallsAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`DoStmt 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ElaboratedType 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`EmptyDecl 0x7faa18a445d8 col:12 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`Enum 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`EnumConstantDecl 0x7faa18a445d8 col: 32 invalid invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`EnumDecl 0x7faa18a445d8 invalid invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`EnumType 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`EnumExtensibilityAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`Field 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`FieldDecl 0x7faa18a445d8 invalid invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`FlagEnumAttr invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`FloatingLiteral 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ForStmt 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`FormatArgAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`FormatAttr 0x7faa18a445d8 invalid invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`FullComment 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`FunctionDecl 0x7faa18a445d8 invalid invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`FunctionProtoType 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`GCCAsmStmt 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`GotoStmt 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`HTMLEndTagComment 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`HTMLStartTagComment 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`IBActionAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`IBOutletAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`IfStmt 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ImplicitCastExpr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ImplicitValueInitExpr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`IncompleteArrayType 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`IndirectFieldDecl 0x7faa18a445d8 invalid invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`InitListExpr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`InlineCommandComment 0x7faa18a445d8 `), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`IntegerLiteral 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`LabelStmt 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`MallocAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`MaxFieldAlignmentAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`MayAliasAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`MemberExpr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`MinVectorWidthAttr invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ModeAttr 0x7faa18a445d8 `), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`NoDebugAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`NoEscapeAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`NoInlineAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`NoThrowAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`NonNullAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`NotTailCalledAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`NSConsumedAttr invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`NSConsumesSelfAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`NSErrorDomainAttr invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`NSReturnsRetainedAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCBoolLiteralExpr invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCBoxableAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCBridgeAttr invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCBridgeMutableAttr invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCBridgeRelatedAttr invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCCategoryDecl 0x7faa18a445d8 invalid invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCDesignatedInitializerAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCExceptionAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCExplicitProtocolImplAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCIndependentClassAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCInterface 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCInterfaceDecl 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCInterfaceType 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCIvarDecl 0x7faa18a445d8 invalid invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCMessageExpr invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCMethod 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCMethodDecl 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCObjectPointerType 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCObjectType 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCPropertyDecl 0x7faa18a445d8 invalid invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCProtocol 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCProtocolDecl invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCRequiresSuperAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCReturnsInnerPointerAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCRootClassAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ObjCTypeParamDecl 0x7faa18a445d8 invalid invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`OffsetOfExpr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`PackedAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ParagraphComment 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ParamCommandComment 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ParenExpr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ParenType 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ParmVarDecl 0x7faa18a445d8 invalid invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`PointerType 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`PredefinedExpr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`PureAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`QualType 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`Record 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`RecordDecl 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`RecordType 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`RestrictAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ReturnStmt 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ReturnsTwiceAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`SentinelAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`ShuffleVectorExpr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`StmtExpr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`StringLiteral 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`SwiftBridgedTypedefAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`SwiftErrorAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`SwiftNameAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`SwiftNewtypeAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`SwiftPrivateAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`SwitchStmt 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`TargetAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`TextComment 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`TranslationUnitDecl 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`TransparentUnionAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`Typedef 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`TypedefDecl 0x7faa18a445d8 invalid invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`TypedefType 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`UnaryExprOrTypeTraitExpr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`UnaryOperator 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`UnavailableAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`UnusedAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`UsedAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`VAArgExpr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`VarDecl 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`VectorType 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`VerbatimBlockComment 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`VerbatimBlockLineComment 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`VerbatimLineComment 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`VisibilityAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`WarnUnusedResultAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`WeakAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`WeakImportAttr 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + runNodeTest(t, + Parse(`WhileStmt 0x7faa18a445d8 invalid`), + testNode{&Unknown{ }, 0, NewPositionFromString(""), nil}, + &i, + ) + t.Run(fmt.Sprintf("Example%d",i),func(t *testing.T) { + node := Parse(`NullStmt`) + if node != nil { + t.Errorf("Parse(NullStmt) did not return nil\n") + } + }) } diff --git a/ast/unused_attr_test.go b/ast/unused_attr_test.go index 7463c9a..5eda410 100644 --- a/ast/unused_attr_test.go +++ b/ast/unused_attr_test.go @@ -5,19 +5,29 @@ import ( ) func TestUnusedAttr(t *testing.T) { - nodes := map[string]Node{ - `0x7fe3e01416d0 unused`: &UnusedAttr{ + nodes := map[string]testNode{ + `0x7fe3e01416d0 unused`: + testNode{&UnusedAttr{ Addr: 0x7fe3e01416d0, Pos: NewPositionFromString("col:47"), ChildNodes: []Node{}, IsUnused: true, }, - `0x7fe3e01416d0 `: &UnusedAttr{ + 0x7fe3e01416d0, + NewPositionFromString("col:47"), + []Node{}, + }, + `0x7fe3e01416d0 `: + testNode{&UnusedAttr{ Addr: 0x7fe3e01416d0, Pos: NewPositionFromString("col:47"), ChildNodes: []Node{}, IsUnused: false, }, + 0x7fe3e01416d0, + NewPositionFromString("col:47"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/used_attr_test.go b/ast/used_attr_test.go new file mode 100644 index 0000000..1dbb529 --- /dev/null +++ b/ast/used_attr_test.go @@ -0,0 +1,22 @@ +package ast + +import ( + "testing" +) + +func TestUsedAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 `: + testNode{&UsedAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/util.go b/ast/util.go index 07a6b6f..2ae3ffa 100644 --- a/ast/util.go +++ b/ast/util.go @@ -19,7 +19,7 @@ func removeQuotes(s string) string { } if len(s) >= 2 && s[0] == '"' && s[len(s)-1] == '"' { - return s[1 : len(s)-2] + return s[1 : len(s)-1] } if len(s) >= 2 && s[0] == '\'' && s[len(s)-1] == '\'' { return s[1 : len(s)-1] diff --git a/ast/util_test.go b/ast/util_test.go new file mode 100644 index 0000000..03e492e --- /dev/null +++ b/ast/util_test.go @@ -0,0 +1,24 @@ +package ast + +import ( + "testing" +) + +func TestRemoveQuotes(t *testing.T) { + t.Run("RemoveQuotes1",func(t *testing.T) { + if removeQuotes(`''`) != "" { + t.Errorf("Empty single quoted string test failed\n") + } + }) + t.Run("RemoveQuotes2",func(t *testing.T) { + if removeQuotes(`"hi there"`) != `hi there` { + t.Errorf("Double quoted string test failed: %s -> %s\n",`"hi there"`,removeQuotes(`"hi there"`)) + } + }) + t.Run("TypesTree",func(t *testing.T) { + if typesTree(nil,0) != "" { + t.Errorf(`typesTree(nil,0) did not return ""`) + } + }) +} + diff --git a/ast/va_arg_expr_test.go b/ast/va_arg_expr_test.go index fc9881f..6defaab 100644 --- a/ast/va_arg_expr_test.go +++ b/ast/va_arg_expr_test.go @@ -5,13 +5,18 @@ import ( ) func TestVAArgExpr(t *testing.T) { - nodes := map[string]Node{ - `0x7ff7d314bca8 'int *'`: &VAArgExpr{ + nodes := map[string]testNode{ + `0x7ff7d314bca8 'int *'`: + testNode{&VAArgExpr{ Addr: 0x7ff7d314bca8, Pos: NewPositionFromString("col:6, col:31"), Type: "int *", ChildNodes: []Node{}, }, + 0x7ff7d314bca8, + NewPositionFromString("col:6, col:31"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/var_decl_test.go b/ast/var_decl_test.go index 8d81114..73c2e9b 100644 --- a/ast/var_decl_test.go +++ b/ast/var_decl_test.go @@ -5,8 +5,9 @@ import ( ) func TestVarDecl(t *testing.T) { - nodes := map[string]Node{ - `0x7fd5e90e5a00 col:17 'int'`: &VarDecl{ + nodes := map[string]testNode{ + `0x7fd5e90e5a00 col:17 'int'`: + testNode{&VarDecl{ Addr: 0x7fd5e90e5a00, Pos: NewPositionFromString("col:14"), Position2: "col:17", @@ -22,7 +23,12 @@ func TestVarDecl(t *testing.T) { Parent: 0, ChildNodes: []Node{}, }, - `0x7fd5e90e9078 col:14 __stdinp 'FILE *' extern`: &VarDecl{ + 0x7fd5e90e5a00, + NewPositionFromString("col:14"), + []Node{}, + }, + `0x7fd5e90e9078 col:14 __stdinp 'FILE *' extern`: + testNode{&VarDecl{ Addr: 0x7fd5e90e9078, Pos: NewPositionFromString("line:156:1, col:14"), Position2: "col:14", @@ -38,7 +44,12 @@ func TestVarDecl(t *testing.T) { Parent: 0, ChildNodes: []Node{}, }, - `0x7fd5e90ed630 col:47 __size 'size_t':'unsigned long'`: &VarDecl{ + 0x7fd5e90e9078, + NewPositionFromString("line:156:1, col:14"), + []Node{}, + }, + `0x7fd5e90ed630 col:47 __size 'size_t':'unsigned long'`: + testNode{&VarDecl{ Addr: 0x7fd5e90ed630, Pos: NewPositionFromString("col:40, col:47"), Position2: "col:47", @@ -54,7 +65,12 @@ func TestVarDecl(t *testing.T) { Parent: 0, ChildNodes: []Node{}, }, - `0x7fee35907a78 col:8 used c 'int'`: &VarDecl{ + 0x7fd5e90ed630, + NewPositionFromString("col:40, col:47"), + []Node{}, + }, + `0x7fee35907a78 col:8 used c 'int'`: + testNode{&VarDecl{ Addr: 0x7fee35907a78, Pos: NewPositionFromString("col:4, col:8"), Position2: "col:8", @@ -70,7 +86,12 @@ func TestVarDecl(t *testing.T) { Parent: 0, ChildNodes: []Node{}, }, - `0x7fb0fd90ba30 tests/assert/assert.c:13:9 used b 'int *' cinit`: &VarDecl{ + 0x7fee35907a78, + NewPositionFromString("col:4, col:8"), + []Node{}, + }, + `0x7fb0fd90ba30 tests/assert/assert.c:13:9 used b 'int *' cinit`: + testNode{&VarDecl{ Addr: 0x7fb0fd90ba30, Pos: NewPositionFromString("col:3, /usr/include/sys/_types.h:52:33"), Position2: "tests/assert/assert.c:13:9", @@ -86,7 +107,12 @@ func TestVarDecl(t *testing.T) { Parent: 0, ChildNodes: []Node{}, }, - `0x7fb20308bd40 col:11 referenced a 'short'`: &VarDecl{ + 0x7fb0fd90ba30, + NewPositionFromString("col:3, /usr/include/sys/_types.h:52:33"), + []Node{}, + }, + `0x7fb20308bd40 col:11 referenced a 'short'`: + testNode{&VarDecl{ Addr: 0x7fb20308bd40, Pos: NewPositionFromString("col:5, col:11"), Position2: "col:11", @@ -102,7 +128,12 @@ func TestVarDecl(t *testing.T) { Parent: 0, ChildNodes: []Node{}, }, - `0x55a040ddd798 line:66:27 used sqlite3azCompileOpt 'const char *const [2]' static cinit`: &VarDecl{ + 0x7fb20308bd40, + NewPositionFromString("col:5, col:11"), + []Node{}, + }, + `0x55a040ddd798 line:66:27 used sqlite3azCompileOpt 'const char *const [2]' static cinit`: + testNode{&VarDecl{ Addr: 0x55a040ddd798, Pos: NewPositionFromString("sqlite3.c:66:1, line:770:1"), Position2: "line:66:27", @@ -118,7 +149,12 @@ func TestVarDecl(t *testing.T) { Parent: 0, ChildNodes: []Node{}, }, - `0x55772c7774d0 col:27 used a 'unsigned char *' register`: &VarDecl{ + 0x55a040ddd798, + NewPositionFromString("sqlite3.c:66:1, line:770:1"), + []Node{}, + }, + `0x55772c7774d0 col:27 used a 'unsigned char *' register`: + testNode{&VarDecl{ Addr: 0x55772c7774d0, Pos: NewPositionFromString("col:3, col:27"), Position2: "col:27", @@ -134,7 +170,12 @@ func TestVarDecl(t *testing.T) { Parent: 0, ChildNodes: []Node{}, }, - `0x26fd180 col:13 used aExt 'extCoord':'extCoord' cinit`: &VarDecl{ + 0x55772c7774d0, + NewPositionFromString("col:3, col:27"), + []Node{}, + }, + `0x26fd180 col:13 used aExt 'extCoord':'extCoord' cinit`: + testNode{&VarDecl{ Addr: 0x26fd180, Pos: NewPositionFromString("col:4, col:32"), Position2: "col:13", @@ -150,7 +191,12 @@ func TestVarDecl(t *testing.T) { Parent: 0, ChildNodes: []Node{}, }, - `0x7f985e0ffb10 parent 0x7f985e0246d0 col:20 used DEFAULT_MEM_ALLOCATOR 'cmark_mem':'struct cmark_mem' extern`: &VarDecl{ + 0x26fd180, + NewPositionFromString("col:4, col:32"), + []Node{}, + }, + `0x7f985e0ffb10 parent 0x7f985e0246d0 col:20 used DEFAULT_MEM_ALLOCATOR 'cmark_mem':'struct cmark_mem' extern`: + testNode{&VarDecl{ Addr: 0x7f985e0ffb10, Pos: NewPositionFromString("col:3, col:20"), Position2: "col:20", @@ -166,6 +212,10 @@ func TestVarDecl(t *testing.T) { Parent: 0x7f985e0246d0, ChildNodes: []Node{}, }, + 0x7f985e0ffb10, + NewPositionFromString("col:3, col:20"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/variadic_test.go b/ast/variadic_test.go index 35cd7b7..578f5e4 100644 --- a/ast/variadic_test.go +++ b/ast/variadic_test.go @@ -5,11 +5,16 @@ import ( ) func TestVariadic(t *testing.T) { + i := 1 runNodeTest(t, Parse(`...`), - &Variadic{ + testNode{&Variadic{ ChildNodes: []Node{}, }, - 1, + 0, + NewPositionFromString(""), + []Node{}, + }, + &i, ) } diff --git a/ast/vector_type_test.go b/ast/vector_type_test.go index 93e694d..49f660a 100644 --- a/ast/vector_type_test.go +++ b/ast/vector_type_test.go @@ -5,21 +5,29 @@ import ( ) func TestVectorType(t *testing.T) { - nodes := map[string]Node{ + nodes := map[string]testNode{ `0x7faa18f2d520 '__attribute__((__vector_size__(1 * sizeof(long long)))) long long' 1`: - &VectorType{ + testNode{&VectorType{ Addr: 0x7faa18f2d520, Type: `__attribute__((__vector_size__(1 * sizeof(long long)))) long long`, Length: 1, ChildNodes: []Node{}, }, + 0x7faa18f2d520, + NewPositionFromString(""), + []Node{}, + }, `0x7fca42b88f30 '__attribute__((__vector_size__(16 * sizeof(signed char)))) signed char' 16`: - &VectorType{ + testNode{&VectorType{ Addr: 0x7fca42b88f30, Type: `__attribute__((__vector_size__(16 * sizeof(signed char)))) signed char`, Length: 16, ChildNodes: []Node{}, }, + 0x7fca42b88f30, + NewPositionFromString(""), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/verbatim_block_comment_test.go b/ast/verbatim_block_comment_test.go index 69106fa..ee6b7d6 100644 --- a/ast/verbatim_block_comment_test.go +++ b/ast/verbatim_block_comment_test.go @@ -5,14 +5,19 @@ import ( ) func TestVerbatimBlockComment(t *testing.T) { - nodes := map[string]Node{ - `0x107781dd0 Name="link" CloseName=""`: &VerbatimBlockComment{ + nodes := map[string]testNode{ + `0x107781dd0 Name="link" CloseName=""`: + testNode{&VerbatimBlockComment{ Addr: 0x107781dd0, Pos: NewPositionFromString("col:34, col:39"), Name: "link", CloseName: "", ChildNodes: []Node{}, }, + 0x107781dd0, + NewPositionFromString("col:34, col:39"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/verbatim_block_line_comment_test.go b/ast/verbatim_block_line_comment_test.go index 152b843..27ee843 100644 --- a/ast/verbatim_block_line_comment_test.go +++ b/ast/verbatim_block_line_comment_test.go @@ -5,13 +5,18 @@ import ( ) func TestVerbatimBlockLineComment(t *testing.T) { - nodes := map[string]Node{ - `0x10f8e8e20 Text=" OSAtomicAdd32}"`: &VerbatimBlockLineComment{ + nodes := map[string]testNode{ + `0x10f8e8e20 Text=" OSAtomicAdd32}"`: + testNode{&VerbatimBlockLineComment{ Addr: 0x10f8e8e20, Pos: NewPositionFromString("col:39, col:54"), Text: " OSAtomicAdd32}", ChildNodes: []Node{}, }, + 0x10f8e8e20, + NewPositionFromString("col:39, col:54"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/verbatim_line_comment_test.go b/ast/verbatim_line_comment_test.go index 2dd0f3e..ece9157 100644 --- a/ast/verbatim_line_comment_test.go +++ b/ast/verbatim_line_comment_test.go @@ -5,13 +5,18 @@ import ( ) func TestVerbatimLineComment(t *testing.T) { - nodes := map[string]Node{ - `0x108af4dd0 Text=" qos_class_self"`: &VerbatimLineComment{ + nodes := map[string]testNode{ + `0x108af4dd0 Text=" qos_class_self"`: + testNode{&VerbatimLineComment{ Addr: 0x108af4dd0, Pos: NewPositionFromString("col:4, col:28"), Text: " qos_class_self", ChildNodes: []Node{}, }, + 0x108af4dd0, + NewPositionFromString("col:4, col:28"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/visibility_attr_test.go b/ast/visibility_attr_test.go index 2d33a38..9591ad2 100644 --- a/ast/visibility_attr_test.go +++ b/ast/visibility_attr_test.go @@ -5,21 +5,31 @@ import ( ) func TestVisibilityAttr(t *testing.T) { - nodes := map[string]Node{ - `0x55c49d8dd1d8 Default`: &VisibilityAttr{ + nodes := map[string]testNode{ + `0x55c49d8dd1d8 Default`: + testNode{&VisibilityAttr{ Addr: 0x55c49d8dd1d8, Pos: NewPositionFromString("col:16, col:36"), ChildNodes: []Node{}, IsInherited: false, IsDefault: true, }, - `0x7f8e7b00bb80 Inherited Default`: &VisibilityAttr{ + 0x55c49d8dd1d8, + NewPositionFromString("col:16, col:36"), + []Node{}, + }, + `0x7f8e7b00bb80 Inherited Default`: + testNode{&VisibilityAttr{ Addr: 0x7f8e7b00bb80, Pos: NewPositionFromString("/cmark/src/cmark.h:497:16, col:36"), ChildNodes: []Node{}, IsInherited: true, IsDefault: true, }, + 0x7f8e7b00bb80, + NewPositionFromString("/cmark/src/cmark.h:497:16, col:36"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/warn_unused_result_attr_test.go b/ast/warn_unused_result_attr_test.go index e155f12..db86b58 100644 --- a/ast/warn_unused_result_attr_test.go +++ b/ast/warn_unused_result_attr_test.go @@ -5,17 +5,27 @@ import ( ) func TestWarnUnusedResultAttr(t *testing.T) { - nodes := map[string]Node{ - `0x7fa1d704d420 warn_unused_result`: &WarnUnusedResultAttr{ + nodes := map[string]testNode{ + `0x7fa1d704d420 warn_unused_result`: + testNode{&WarnUnusedResultAttr{ Addr: 0x7fa1d704d420, Pos: NewPositionFromString("col:60"), ChildNodes: []Node{}, }, - `0x1fac810 `: &WarnUnusedResultAttr{ + 0x7fa1d704d420, + NewPositionFromString("col:60"), + []Node{}, + }, + `0x1fac810 `: + testNode{&WarnUnusedResultAttr{ Addr: 0x1fac810, Pos: NewPositionFromString("line:481:52"), ChildNodes: []Node{}, }, + 0x1fac810, + NewPositionFromString("line:481:52"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/weak_attr_test.go b/ast/weak_attr_test.go index be33c9e..2fe630d 100644 --- a/ast/weak_attr_test.go +++ b/ast/weak_attr_test.go @@ -5,12 +5,17 @@ import ( ) func TestWeakAttr(t *testing.T) { - nodes := map[string]Node{ - `0x56069ece5110 `: &WeakAttr{ + nodes := map[string]testNode{ + `0x56069ece5110 `: + testNode{&WeakAttr{ Addr: 0x56069ece5110, Pos: NewPositionFromString("line:736:22"), ChildNodes: []Node{}, }, + 0x56069ece5110, + NewPositionFromString("line:736:22"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/ast/weak_import_attr_test.go b/ast/weak_import_attr_test.go new file mode 100644 index 0000000..a30c36f --- /dev/null +++ b/ast/weak_import_attr_test.go @@ -0,0 +1,22 @@ +package ast + +import ( + "testing" +) + +func TestWeakImportAttr(t *testing.T) { + nodes := map[string]testNode{ + `0x7fc0a69091d1 `: + testNode{&WeakImportAttr{ + Addr: 0x7fc0a69091d1, + Pos: NewPositionFromString("line:11:7, line:18:7"), + ChildNodes: []Node{}, + }, + 0x7fc0a69091d1, + NewPositionFromString("line:11:7, line:18:7"), + []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/while_stmt_test.go b/ast/while_stmt_test.go index 005ea3f..280e047 100644 --- a/ast/while_stmt_test.go +++ b/ast/while_stmt_test.go @@ -5,12 +5,17 @@ import ( ) func TestWhileStmt(t *testing.T) { - nodes := map[string]Node{ - `0x7fa1478273a0 `: &WhileStmt{ + nodes := map[string]testNode{ + `0x7fa1478273a0 `: + testNode{&WhileStmt{ Addr: 0x7fa1478273a0, Pos: NewPositionFromString("line:7:4, line:11:4"), ChildNodes: []Node{}, }, + 0x7fa1478273a0, + NewPositionFromString("line:7:4, line:11:4"), + []Node{}, + }, } runNodeTests(t, nodes) diff --git a/main.go b/main.go index e1da232..9e116ef 100644 --- a/main.go +++ b/main.go @@ -319,6 +319,7 @@ func main() { fmt.Printf("Cannot decode config file nswrap.yaml. %s\n",err) os.Exit(-1) } + ast.Debug = Config.Debugast if err := Start(); err != nil { fmt.Printf("Error: %v\n", err) os.Exit(-1) diff --git a/types/cparser.go b/types/cparser.go index 6d53c20..255d9a9 100644 --- a/types/cparser.go +++ b/types/cparser.go @@ -35,17 +35,29 @@ func init() { func MethodSignature(s string, n *Node) (string, *Node) { return ChildOf(NewNode("MethodSignature"),Seq( Parenthesized(TypeName), - Identifier, + MethodName, Opt(MethodParameterList), ))(s,n) } +func MethodName(s string, n *Node) (string, *Node) { + return Seq( + Identifier, + Opt(Seq( + Lit(":"), + Parenthesized(TypeName), + Identifier, + )), + )(s,n) +} + func MethodParameterList(s string, n *Node) (string, *Node) { return OneOrMore(MethodParameter)(s,n) } func MethodParameter(s string, n *Node) (string, *Node) { return ChildOf(NewNode("MethodParameter"),Seq( + Identifier, Lit(":"), Parenthesized(TypeName), Identifier, diff --git a/types/main_test.go b/types/main_test.go new file mode 100644 index 0000000..fbd3ed4 --- /dev/null +++ b/types/main_test.go @@ -0,0 +1,599 @@ +package types + +import ( + "fmt" + "reflect" + "testing" +) + +func TestParse(t *testing.T) { + i := 1 + chk := func(input string,n *Node,expected string) { + t.Run(fmt.Sprintf("Parse%d",i), func(t *testing.T) { + if n.String() != expected { + t.Errorf("Mismatch parsing %s -- Got:\n%s\nExpected:\n%s\n",input,n.String(),expected) + } + }) + i++ + } + + runParseTest := func(input, expected string) { + n,err := Parse(input) + if err != nil { + t.Errorf("Parse error parsing %s\n",input) + } + chk(input,n,expected) + } + + runSigTest := func(input, expected string) { + rem,n := MethodSignature(input,NewNode("AST")) + if rem != "" { + t.Errorf("Parse error parsing %s. Remainder = %s\n",input,rem) + } + chk(input,n,expected) + } + + runParseTest(`int`, +` '' +- 'int' +`) + runParseTest(`int`, +` '' +- 'int' +`) + runParseTest(`char*`, +` '' +- 'char' +- '*' +`) + runParseTest(`struct Str`, +` '' +- 'struct' +-- 'Str' +`) + runParseTest(`uint`, +` '' +- 'uint' +`) + runParseTest(`uind`, +` '' +- 'uind' +`) + runParseTest(`void ()`, +` '' +- 'void' +- '' +`) + runParseTest(`void (*)(struct NSRange)`, +` '' +- 'void' +- '' +-- '*' +- '' +-- '' +--- 'struct' +---- 'NSRange' +`) + runParseTest(`void (* _Nullable)(int)`, +` '' +- 'void' +- '' +-- '*' +-- '_Nullable' +- '' +-- '' +--- 'int' +`) + runParseTest(`NSRange[3]`, +` '' +- 'NSRange' +- '' +-- '3' +`) + runParseTest(`struct _NSRange[3]`, +` '' +- 'struct' +-- '_NSRange' +- '' +-- '3' +`) + runParseTest(`struct _NSRange (*)(int, char[])`, +` '' +- 'struct' +-- '_NSRange' +- '' +-- '*' +- '' +-- '' +--- 'int' +-- '' +--- 'char' +--- '' +`) + runParseTest(`struct _NSRange (*)(int, char[],NSRange)`, +` '' +- 'struct' +-- '_NSRange' +- '' +-- '*' +- '' +-- '' +--- 'int' +-- '' +--- 'char' +--- '' +-- '' +--- 'NSRange' +`) + runParseTest(`struct _NSRange (*)(int, char[],struct _NSRange)`, +` '' +- 'struct' +-- '_NSRange' +- '' +-- '*' +- '' +-- '' +--- 'int' +-- '' +--- 'char' +--- '' +-- '' +--- 'struct' +---- '_NSRange' +`) + runParseTest(`mytype`, +` '' +- 'mytype' +`) + runParseTest(`const int`, +` '' +- 'const' +- 'int' +`) + runParseTest(`int[*]`, +` '' +- 'int' +- '' +-- '*' +`) + runParseTest(`int[3][5]`, +` '' +- 'int' +- '' +-- '3' +- '' +-- '5' +`) + runParseTest(`int *`, +` '' +- 'int' +- '*' +`) + runParseTest(`int * _Nonnull`, +` '' +- 'int' +- '*' +- '_Nonnull' +`) + runParseTest(`int **`, +` '' +- 'int' +- '*' +- '*' +`) + runParseTest(`int *[3]`, +` '' +- 'int' +- '*' +- '' +-- '3' +`) + runParseTest(`int (*)[3]`, +` '' +- 'int' +- '' +-- '*' +- '' +-- '3' +`) + runParseTest(`int (*)[*]`, +` '' +- 'int' +- '' +-- '*' +- '' +-- '*' +`) + runParseTest(`int *()`, +` '' +- 'int' +- '*' +- '' +`) + runParseTest(`int (*)(void)`, +` '' +- 'int' +- '' +-- '*' +- '' +-- '' +--- 'void' +`) + runParseTest(`int (*)(int, unsigned int)`, +` '' +- 'int' +- '' +-- '*' +- '' +-- '' +--- 'int' +-- '' +--- 'unsigned' +--- 'int' +`) + runParseTest(`int (* _Nullable)(int, unsigned int)`, +` '' +- 'int' +- '' +-- '*' +-- '_Nullable' +- '' +-- '' +--- 'int' +-- '' +--- 'unsigned' +--- 'int' +`) + runParseTest(`int (*const [])(unsigned int, ...)`, +` '' +- 'int' +- '' +-- '*' +-- 'const' +-- '' +- '' +-- '' +--- 'unsigned' +--- 'int' +-- '' +--- '...' +`) + runParseTest(`BOOL (* _Nullable)()`, +` '' +- 'BOOL' +- '' +-- '*' +-- '_Nullable' +- '' +`) + runParseTest(`BOOL (* _Nullable)(const void * _Nonnull, const void * _Nonnull)`, +` '' +- 'BOOL' +- '' +-- '*' +-- '_Nullable' +- '' +-- '' +--- 'const' +--- 'void' +--- '*' +--- '_Nonnull' +-- '' +--- 'const' +--- 'void' +--- '*' +--- '_Nonnull' +`) + runParseTest(`BOOL (* _Nullable)(const void * _Nonnull, const void * _Nonnull, int (* _Nullable)(const void * _Nonnull))`, +` '' +- 'BOOL' +- '' +-- '*' +-- '_Nullable' +- '' +-- '' +--- 'const' +--- 'void' +--- '*' +--- '_Nonnull' +-- '' +--- 'const' +--- 'void' +--- '*' +--- '_Nonnull' +-- '' +--- 'int' +--- '' +---- '*' +---- '_Nullable' +--- '' +---- '' +----- 'const' +----- 'void' +----- '*' +----- '_Nonnull' +`) + runParseTest(`BOOL (* _Nullable)(const void * _Nonnull, const void * _Nonnull, NSUInteger (* _Nullable)(const void * _Nonnull))`, +` '' +- 'BOOL' +- '' +-- '*' +-- '_Nullable' +- '' +-- '' +--- 'const' +--- 'void' +--- '*' +--- '_Nonnull' +-- '' +--- 'const' +--- 'void' +--- '*' +--- '_Nonnull' +-- '' +--- 'NSUInteger' +--- '' +---- '*' +---- '_Nullable' +--- '' +---- '' +----- 'const' +----- 'void' +----- '*' +----- '_Nonnull' +`) + runParseTest(`NSEnumerator * _Nonnull`, +` '' +- 'NSEnumerator' +- '' +-- '' +--- 'ObjectType' +- '*' +- '_Nonnull' +`) + runParseTest(`NSArray * _Nonnull`, +` '' +- 'NSArray' +- '' +-- '' +--- 'NSString' +--- '*' +- '*' +- '_Nonnull' +`) + runParseTest(`id _Nonnull (^ _Nonnull)(id _Nullable, NSArray * _Nonnull, NSMutableDictionary * _Nullable)`, +` '' +- 'id' +- '_Nonnull' +- '' +-- '^' +-- '_Nonnull' +- '' +-- '' +--- 'id' +--- '_Nullable' +-- '' +--- 'NSArray' +--- '' +---- '' +----- 'NSExpression' +----- '*' +--- '*' +--- '_Nonnull' +-- '' +--- 'NSMutableDictionary' +--- '*' +--- '_Nullable' +`) + runSigTest(`(void)pressed`, +` '' +- '' +-- 'void' +- 'pressed' +`) + runSigTest(`(void)performSelector:(SEL)aSelector target:(id)target argument:(id)arg order:(NSUInteger)order modes:(NSArray *)modes`, +` '' +- '' +-- 'void' +- 'performSelector' +- '' +-- 'SEL' +- 'aSelector' +- '' +-- 'target' +-- '' +--- 'id' +-- 'target' +- '' +-- 'argument' +-- '' +--- 'id' +-- 'arg' +- '' +-- 'order' +-- '' +--- 'NSUInteger' +-- 'order' +- '' +-- 'modes' +-- '' +--- 'NSArray' +--- '' +---- '' +----- 'NSRunLoopMode' +--- '*' +-- 'modes' +`) +} + +func TestFuncs(t *testing.T) { + i := 1 + var n *Node + var err error + f := func(input string, actual, expected interface{}) { + t.Run(fmt.Sprintf("TestFunc%d",i),func (t *testing.T) { + if err != nil { + t.Errorf("Error parsing %s\n",input) + } + if actual == nil && expected == nil { return } + if !reflect.DeepEqual(actual,expected) { + t.Errorf("Test failed for %s\n",input) + } + }) + i++ + } + str := "int*" + n,err = Parse(str) + f(str,n.HasFunc(),false) + str = "int (*)(void)" + n,err = Parse(str) + f(str,n.HasFunc(),true) + n,err = nil,nil + f("",n.HasFunc(),false) + f("",n.IsId(),false) + f("",n.IsFunction(),false) + f("",n.IsInstancetype(),false) + f("",n.IsArray(),false) + f("",n.IsStruct(),false) + if n.BaseType() != nil { + t.Errorf("BaseType() for nil node is not nil\n") + } + if n.PointsTo() != nil { + t.Errorf("PointsTo() for nil node is not nil\n") + } + if n.ReturnType() != nil { + t.Errorf("ReturnType() for nil node is not nil\n") + } + f("",n.String(),"") + f("",n.Qualifiers(),"") + f("",n.Annotations(),"") + + str = "int" + n,err = Parse(str) + f(str,n.isIndirect("Pointer"),false) + if n.ReturnType() != nil { + t.Errorf("Return type for non-function is not nil\n") + } + + str = "int*" + n,err = Parse(str) + f(str,n.isIndirect("Pointer"),true) + f(str,n.isIndirect("Array"),false) + + str = "int* _Nullable" + n,err = Parse(str) + f(str,n.isIndirect("Pointer"),true) + + str = "int* _Nonnull" + n,err = Parse(str) + f(str,n.isIndirect("Pointer"),true) + f(str,n.CType(),"int* _Nonnull") + f(str,n.CTypeSimplified(),"int*") + f(str,n.Annotations(),"_Nonnull") + + n,err = Parse("int[]") + n2,err2 := Parse("int") + if err2 != nil { + t.Errorf("Cannot parse int") + } + f(str,n.isIndirect("Pointer"),false) + f(str,n.isIndirect("Array"),true) + f(str,n.ArrayOf(),n2) + f(str,n.CType(),"int[]") + f(str,n.CTypeSimplified(),"int[]") + + str = "const int*[]" + n,err = Parse(str) + f(str,n.isIndirect("Array"),true) + f(str,n.Qualifiers(),"const") + + str = "int (*)[]" + n,err = Parse(str) + f(str,n.isIndirect("Array"),true) + f(str,n.isIndirect("Pointer"),true) + + str = "int (* _Nullable * _Nonnull)[]" + n,err = Parse(str) + f(str,n.isIndirect("Pointer"),true) + + str = "int (*)(void)" + n,err = Parse(str) + n2,err2 = Parse("int(void)") + if err2 != nil { + t.Errorf("Failed to parse int(void)") + } + f(str,n.PointsTo(),n2) + f(str,n.IsPointer(),true) + f(str,n.IsFunction(),false) + f(str,n.CType(),"int (*)(void)") + + str = "int *(void)" + n,err = Parse(str) + f(str,n.IsFunction(),true) + n2,_ = Parse("int*") + f(str,n.ReturnType(),n2) + + str = "__kindof NSRange" + n,err = Parse(str) + f(str,n.IsStruct(),false) + f(str,n.IsInstancetype(),false) + + str = "struct NSRange" + n,err = Parse(str) + f(str,n.IsStruct(),true) + f(str,n.IsFunction(),false) + + str = "id" + n,err = Parse(str) + f(str,n.IsId(),true) + + str = "int * _Nullable * _Nonnull" + n,err = Parse(str) + n2,_ = Parse("int") + f(str,n.BaseType(),n2) + + str = "__kindof id" + n,err = Parse(str) + f(str,n.IsId(),true) + f(str,n.IsPointer(),true) + + + str = "NSArray *" + n,err = Parse(str) + f(str,n.CType(),"NSArray *") + f(str,n.CTypeSimplified(),"NSArray*") + + str = "NSRange *(int, NSRange *)" + n,err = Parse(str) + f(str,n.renameTypedefs("NSRange","struct NSRange"),true) + f(str,n.CType(),"struct NSRange* (int, struct NSRange*)") + + str = "int*%&#$" + n,err = Parse(str) + if err == nil { + fmt.Printf("%s\n",n.String()) + t.Errorf("Parse should have failed for %s\n",str) + } + + var r func(i int) *Node + r = func(i int) *Node { + n := &Node{} + if i > 0 { + n.Children = []*Node{ r(i-1) } + } + return n + } + n = r(150) + str = n.String() + if str[len(str)-8:] != "too deep" { + fmt.Printf(str[len(str)-8:]) + t.Errorf("Deep recursion did not produce an error from (*Node)String()\n") + } +} + +func ExampleDebug() { + Debug = true + dbg("one %s two %d","string",15) + // Output: one string two 15 + Debug = false +} diff --git a/types/node.go b/types/node.go index 8613708..55ed991 100644 --- a/types/node.go +++ b/types/node.go @@ -34,8 +34,7 @@ func (n *Node) String(ls ...int) string { if len(ls) > 0 { level = ls[0] if level > 100 { - fmt.Println("(*Node)String(): Recursion too deep") - os.Exit(-1) + return "(*Node)String(): Recursion too deep" } } prefix := strings.Repeat("-",level)