rbgccxml 0.8 → 0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/Rakefile +5 -5
  2. data/lib/rbgccxml/node.rb +75 -73
  3. data/lib/rbgccxml/nodes/argument.rb +13 -2
  4. data/lib/rbgccxml/nodes/base.rb +14 -0
  5. data/lib/rbgccxml/nodes/class.rb +46 -8
  6. data/lib/rbgccxml/nodes/constructor.rb +8 -1
  7. data/lib/rbgccxml/nodes/destructor.rb +7 -0
  8. data/lib/rbgccxml/nodes/enum_value.rb +6 -4
  9. data/lib/rbgccxml/nodes/enumeration.rb +21 -2
  10. data/lib/rbgccxml/nodes/field.rb +18 -0
  11. data/lib/rbgccxml/nodes/file.rb +4 -1
  12. data/lib/rbgccxml/nodes/function.rb +6 -4
  13. data/lib/rbgccxml/nodes/function_type.rb +7 -0
  14. data/lib/rbgccxml/nodes/method.rb +6 -4
  15. data/lib/rbgccxml/nodes/struct.rb +3 -2
  16. data/lib/rbgccxml/nodes/type.rb +5 -3
  17. data/lib/rbgccxml/nodes/types/array_type.rb +29 -0
  18. data/lib/rbgccxml/nodes/types/cv_qualified_type.rb +9 -5
  19. data/lib/rbgccxml/nodes/types/fundamental_type.rb +3 -2
  20. data/lib/rbgccxml/nodes/types/pointer_type.rb +6 -3
  21. data/lib/rbgccxml/nodes/types/reference_type.rb +6 -3
  22. data/lib/rbgccxml/nodes/types/typedef.rb +2 -2
  23. data/lib/rbgccxml/nodes/variable.rb +7 -0
  24. data/lib/rbgccxml/parser.rb +47 -32
  25. data/lib/rbgccxml/query_result.rb +62 -25
  26. data/lib/rbgccxml/rbgccxml.rb +13 -16
  27. data/lib/rbgccxml/xml_parsing.rb +65 -97
  28. data/lib/rbgccxml.rb +26 -22
  29. data/test/arguments_test.rb +29 -0
  30. data/test/classes_test.rb +164 -26
  31. data/test/enumerations_test.rb +27 -19
  32. data/test/function_pointers_test.rb +18 -0
  33. data/test/functions_test.rb +7 -2
  34. data/test/methods_test.rb +3 -3
  35. data/test/namespaces_test.rb +1 -1
  36. data/test/node_test.rb +11 -31
  37. data/test/parser_test.rb +1 -1
  38. data/test/query_results_test.rb +15 -14
  39. data/test/structs_test.rb +10 -12
  40. data/test/test_helper.rb +10 -2
  41. data/test/types_test.rb +63 -38
  42. data/test/variables_test.rb +26 -0
  43. metadata +46 -31
data/lib/rbgccxml.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'hpricot'
2
- gem 'gccxml_gem'
3
1
  require 'gccxml'
4
2
 
5
3
  require 'rbgccxml/rbgccxml'
@@ -7,29 +5,35 @@ require 'rbgccxml/rbgccxml'
7
5
  module RbGCCXML
8
6
 
9
7
  # Core classes
10
- autoload :Parser, "rbgccxml/parser"
11
- autoload :Node, "rbgccxml/node"
12
- autoload :QueryResult, "rbgccxml/query_result"
13
- autoload :XMLParsing, "rbgccxml/xml_parsing"
8
+ autoload :Node, "rbgccxml/node"
9
+ autoload :Parser, "rbgccxml/parser"
10
+ autoload :XMLParsing, "rbgccxml/xml_parsing"
11
+ autoload :QueryResult, "rbgccxml/query_result"
14
12
 
15
13
  # Nodes
16
- autoload :Argument, "rbgccxml/nodes/argument"
17
- autoload :Class, "rbgccxml/nodes/class"
18
- autoload :Constructor, "rbgccxml/nodes/constructor"
19
- autoload :File, "rbgccxml/nodes/file"
20
- autoload :Function, "rbgccxml/nodes/function"
21
- autoload :Method, "rbgccxml/nodes/method"
22
- autoload :Namespace, "rbgccxml/nodes/namespace"
23
- autoload :Struct, "rbgccxml/nodes/struct"
24
- autoload :Enumeration, "rbgccxml/nodes/enumeration"
25
- autoload :EnumValue, "rbgccxml/nodes/enum_value"
14
+ autoload :Argument, "rbgccxml/nodes/argument"
15
+ autoload :Base, "rbgccxml/nodes/base"
16
+ autoload :Class, "rbgccxml/nodes/class"
17
+ autoload :Constructor, "rbgccxml/nodes/constructor"
18
+ autoload :Destructor, "rbgccxml/nodes/destructor"
19
+ autoload :Enumeration, "rbgccxml/nodes/enumeration"
20
+ autoload :EnumValue, "rbgccxml/nodes/enum_value"
21
+ autoload :Field, "rbgccxml/nodes/field"
22
+ autoload :File, "rbgccxml/nodes/file"
23
+ autoload :FunctionType, "rbgccxml/nodes/function_type"
24
+ autoload :Function, "rbgccxml/nodes/function"
25
+ autoload :Method, "rbgccxml/nodes/method"
26
+ autoload :Namespace, "rbgccxml/nodes/namespace"
27
+ autoload :Struct, "rbgccxml/nodes/struct"
28
+ autoload :Variable, "rbgccxml/nodes/variable"
26
29
 
27
30
  # Type Management
28
- autoload :Type, "rbgccxml/nodes/type"
29
- autoload :FundamentalType, "rbgccxml/nodes/types/fundamental_type"
30
- autoload :PointerType, "rbgccxml/nodes/types/pointer_type"
31
- autoload :Typedef, "rbgccxml/nodes/types/typedef"
32
- autoload :ReferenceType, "rbgccxml/nodes/types/reference_type"
33
- autoload :CvQualifiedType, "rbgccxml/nodes/types/cv_qualified_type"
31
+ autoload :Type, "rbgccxml/nodes/type"
32
+ autoload :Typedef, "rbgccxml/nodes/types/typedef"
33
+ autoload :ArrayType, "rbgccxml/nodes/types/array_type"
34
+ autoload :PointerType, "rbgccxml/nodes/types/pointer_type"
35
+ autoload :ReferenceType, "rbgccxml/nodes/types/reference_type"
36
+ autoload :CvQualifiedType, "rbgccxml/nodes/types/cv_qualified_type"
37
+ autoload :FundamentalType, "rbgccxml/nodes/types/fundamental_type"
34
38
 
35
39
  end
@@ -0,0 +1,29 @@
1
+ require "test_helper"
2
+
3
+ context "Function and Method Arguments" do
4
+
5
+ setup do
6
+ @@arguments_source ||= RbGCCXML.parse(full_dir("headers/functions.h")).namespaces("functions")
7
+ end
8
+
9
+ specify "have type and to_cpp" do
10
+ test1 = @@arguments_source.functions("test1")
11
+ test1.arguments.length.should.equal 2
12
+
13
+ test1.arguments[0].to_cpp.should.equal "int x"
14
+ test1.arguments[0].cpp_type.to_cpp.should.equal "int"
15
+
16
+ test1.arguments[1].to_cpp.should.equal "double y"
17
+ test1.arguments[1].cpp_type.to_cpp.should.equal "double"
18
+ end
19
+
20
+ specify "can have a default value" do
21
+ test1 = @@arguments_source.functions("test1")
22
+ test1.arguments[0].value.should.be nil
23
+ test1.arguments[1].value.should.equal "3.0e+0"
24
+
25
+ rockin = @@arguments_source.functions("rockin")
26
+ rockin.arguments[1].value.should.equal "functions::test()"
27
+ end
28
+ end
29
+
data/test/classes_test.rb CHANGED
@@ -1,60 +1,198 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require "test_helper"
2
2
 
3
3
  context "Querying for classes" do
4
4
  setup do
5
- @@source ||= RbGCCXML.parse(full_dir("headers/classes.h")).namespaces("classes")
5
+ @source ||= RbGCCXML.parse(full_dir("headers/classes.h")).namespaces("classes")
6
6
  end
7
7
 
8
8
  specify "can find all classes in a given namespace" do
9
- classes = @@source.classes
10
- classes.size.should == 4
9
+ classes = @source.classes
10
+ classes.size.should.equal 4
11
11
 
12
- %w(Test1 Test2 Test3).each do |t|
13
- assert classes.detect {|c| c.node == @@source.classes(t).node },
14
- "unable to find node for #{t}"
15
- end
12
+ classes.find(:name => "Test1").should.not.be.nil
13
+ classes.find(:name => "Test2").should.not.be.nil
14
+ classes.find(:name => "Test3").should.not.be.nil
16
15
  end
17
16
 
18
17
  specify "can find classes within classes" do
19
- test1 = @@source.classes.find(:name => "Test1")
18
+ test1 = @source.classes.find(:name => "Test1")
20
19
  test1.should.not.be.nil
21
-
20
+ test1.should.be.kind_of RbGCCXML::Class
21
+ test1.name.should.equal "Test1"
22
+
22
23
  inner1 = test1.classes("Inner1")
23
24
  inner1.should.not.be.nil
24
-
25
+ inner1.should.be.kind_of RbGCCXML::Class
26
+ inner1.name.should.equal "Inner1"
27
+
25
28
  inner2 = inner1.classes("Inner1")
26
29
  inner2.should.not.be.nil
30
+ inner2.should.be.kind_of Array
31
+ inner2.should.be.empty
32
+
33
+ inner2 = inner1.classes("Inner2")
34
+ inner2.should.not.be.nil
35
+ inner2.should.be.kind_of RbGCCXML::Class
36
+ inner2.name.should.equal "Inner2"
37
+ end
38
+
39
+ specify "can find classes within classes by regex" do
40
+ test1 = @source.classes(/t1/)
41
+ test1.should.not.be.nil
42
+ test1.should.be.kind_of RbGCCXML::Class
43
+ test1.name.should.equal "Test1"
44
+
45
+ inner1 = test1.classes(/In.*1/)
46
+ inner1.should.not.be.nil
47
+ inner1.should.be.kind_of RbGCCXML::Class
48
+ inner1.name.should.equal "Inner1"
49
+
50
+ inner2 = inner1.classes(/1/)
51
+ inner2.should.not.be.nil
52
+ inner2.should.be.kind_of Array
53
+ inner2.should.be.empty
54
+
55
+ inner2 = inner1.classes(/2/)
56
+ inner2.should.not.be.nil
57
+ inner2.should.be.kind_of RbGCCXML::Class
58
+ inner2.name.should.equal "Inner2"
27
59
  end
28
60
 
29
- specify "can find out which file said class is in" do
30
- test1 = @@source.classes.find(:name => "Test1")
31
- test1.file_name.should == "classes.h"
61
+ specify "can find classes within classes by block" do
62
+ # We're looking for any class that has virtual methods.
63
+ test4 = @source.classes { |c| c.methods.any? { |m| m.virtual? } }
64
+ test4.should.not.be.nil
65
+ test4.should.be.kind_of RbGCCXML::Class
66
+ test4.name.should.equal "Test4"
67
+
68
+ # Fail case -- there's no methods that return double.
69
+ test0 = @source.classes { |c| c.methods.any? { |m| m.return_type == "double" }}
70
+ test0.should.not.be.nil
71
+ test0.should.be.kind_of Array
72
+ test0.should.be.empty
73
+ end
74
+
75
+ specify "can tell if a class is pure virtual" do
76
+ test1 = @source.classes("Test1")
77
+ test4 = @source.classes("Test4")
78
+
79
+ test1.pure_virtual?.should.be false
80
+ test4.pure_virtual?.should.be true
32
81
  end
33
82
  end
34
83
 
35
84
  context "Querying for class constructors" do
36
85
  setup do
37
- @@source ||= RbGCCXML.parse(full_dir("headers/classes.h")).namespaces("classes")
86
+ @source ||= RbGCCXML.parse(full_dir("headers/classes.h")).namespaces("classes")
38
87
  end
39
88
 
40
89
  specify "should have a list of constructors" do
41
- test1 = @@source.classes.find(:name => "Test1")
42
- test1.constructors.size.should == 2
90
+ test1 = @source.classes.find(:name => "Test1")
91
+ test1.constructors.size.should.equal 2
43
92
 
44
- test2 = @@source.classes.find(:name => "Test2")
45
- test2.constructors.size.should == 2
93
+ test2 = @source.classes.find(:name => "Test2")
94
+ test2.constructors.size.should.equal 3
46
95
  end
47
96
 
48
97
  specify "constructors should have arguments" do
49
- test2 = @@source.classes.find(:name => "Test2")
50
- test2.constructors.size.should == 2
98
+ test2 = @source.classes.find(:name => "Test2")
99
+ test2.constructors.size.should.equal 3
100
+
101
+ # GCC generated copy constructors
102
+ copy = test2.constructors[0]
103
+ copy.attributes[:artificial].should.equal "1"
51
104
 
52
- default = test2.constructors[0]
53
- default.arguments.size.should == 0
105
+ default = test2.constructors[1]
106
+ default.arguments.size.should.equal 0
54
107
 
55
- specific = test2.constructors[1]
56
- specific.arguments.size.should == 1
57
- assert(specific.arguments[0].cpp_type == "int")
108
+ specific = test2.constructors[2]
109
+ specific.arguments.size.should.equal 1
110
+ specific.arguments[0].cpp_type.name.should.equal "int"
58
111
  end
59
112
  end
60
113
 
114
+ context "Querying for the class's deconstructor" do
115
+ setup do
116
+ @source ||= RbGCCXML.parse(full_dir("headers/classes.h")).namespaces("classes")
117
+ end
118
+
119
+ specify "can tell if a class has an explicit destructor" do
120
+ test1 = @source.classes("Test1")
121
+ test1.destructor.should.not.be.nil
122
+ test1.destructor.attributes[:artificial].should.be.nil
123
+
124
+ test2 = @source.classes("Test2")
125
+ test2.destructor.should.not.be.nil
126
+ test2.destructor.attributes[:artificial].should.not.be.nil
127
+ end
128
+
129
+ end
130
+
131
+ context "Query for class variables" do
132
+ setup do
133
+ @source ||= RbGCCXML.parse(full_dir("headers/classes.h")).namespaces("classes")
134
+ end
135
+
136
+ specify "find all i-vars" do
137
+ test1 = @source.classes("Test1")
138
+ test1.variables.length.should.equal 4
139
+ end
140
+
141
+ specify "can find by access level" do
142
+ test1 = @source.classes("Test1")
143
+ test1.variables.find(:access => "public").length.should.equal 2
144
+ test1.variables.find(:access => "protected").name.should.equal "protVariable"
145
+ test1.variables.find(:access => "private").name.should.equal "privateVariable"
146
+ end
147
+ end
148
+
149
+ context "Query inheritance heirarchy" do
150
+ setup do
151
+ @source ||= RbGCCXML.parse(full_dir("headers/inheritance.h")).namespaces("inheritance")
152
+ end
153
+
154
+ specify "can find a class's superclass" do
155
+ pc = @source.classes("ParentClass")
156
+ pc.superclass.should.be.nil
157
+
158
+ base1 = @source.classes("Base1")
159
+ base1.superclass.should.not.be.nil
160
+ base1.superclass.name.should.equal "ParentClass"
161
+ end
162
+
163
+ specify "can query for multiple inheritance" do
164
+ multi = @source.classes("MultiBase")
165
+ multi.superclasses.length.should.equal 2
166
+ assert multi.superclasses.select {|sp| sp.name == "ParentClass"}
167
+ assert multi.superclasses.select {|sp| sp.name == "Parent2"}
168
+ end
169
+
170
+ specify "calling #superclasses always returns an array" do
171
+ pc = @source.classes("ParentClass")
172
+ pc.superclasses.should.be.empty
173
+
174
+ base1 = @source.classes("Base1")
175
+ base1.superclasses.length.should.equal 1
176
+ base1.superclasses[0].name.should.equal "ParentClass"
177
+ end
178
+
179
+ specify "can infinitely climb the inheritance heirarchy" do
180
+ low = @source.classes("VeryLow")
181
+ low.superclass.superclass.superclass.name.should.equal "ParentClass"
182
+ end
183
+
184
+ specify "can query for types of inheritance" do
185
+ pvb1 = @source.classes("PrivateBase1")
186
+ pvb1.superclass(:public).should.be.nil
187
+ pvb1.superclass(:protected).should.be.nil
188
+ pvb1.superclass(:private).should.not.be.nil
189
+
190
+ pvb1.superclass(:private).name.should.equal "ParentClass"
191
+
192
+ pvb1.superclasses(:public).length.should.equal 0
193
+ pvb1.superclasses(:protected).length.should.equal 0
194
+ pvb1.superclasses(:private).length.should.equal 1
195
+ end
196
+
197
+ end
198
+
@@ -1,5 +1,4 @@
1
-
2
- require File.dirname(__FILE__) + '/test_helper'
1
+ require "test_helper"
3
2
 
4
3
  context "Querying for enumerations" do
5
4
  setup do
@@ -8,37 +7,46 @@ context "Querying for enumerations" do
8
7
 
9
8
  specify "can query for enumerations" do
10
9
  enums = @@enum_source.enumerations
11
- enums.length.should == 2
12
-
13
- assert @@enum_source.enumerations("TestEnum") == "TestEnum"
14
- assert @@enum_source.enumerations.find(:name => "MyEnum") == "MyEnum"
10
+ enums.length.should.equal 3
15
11
  end
16
12
 
17
13
  specify "can find specific enum values" do
18
14
  enum = @@enum_source.enumerations("TestEnum")
19
- enum.values.length.should == 3
20
- assert enum.values[0] == "VALUE1"
21
- assert enum.values[1] == "VALUE2"
22
- assert enum.values[2] == "VALUE3"
15
+ enum.values.length.should.equal 3
16
+ enum.values[0].name.should.equal "VALUE1"
17
+ enum.values[1].name.should.equal "VALUE2"
18
+ enum.values[2].name.should.equal "VALUE3"
23
19
  end
24
20
 
25
21
  specify "can find the given value of enum entries" do
26
22
  enum = @@enum_source.enumerations.find(:name => "MyEnum")
27
- enum.values[0].value.should == 3
28
- enum.values[1].value.should == 4
29
- enum.values[2].value.should == 7
23
+ enum.values[0].value.should.equal 3
24
+ enum.values[1].value.should.equal 4
25
+ enum.values[2].value.should.equal 7
30
26
  end
31
27
 
32
28
  specify "properly prints out fully qualified C++ identifier for enum values" do
33
29
  enum = @@enum_source.enumerations("TestEnum")
34
- enum.values.length.should == 3
35
- assert enum.values[0].qualified_name == "enums::VALUE1"
36
- assert enum.values[1].qualified_name == "enums::VALUE2"
37
- assert enum.values[2].qualified_name == "enums::VALUE3"
30
+ enum.values.length.should.equal 3
31
+ enum.values[0].qualified_name.should.equal "enums::VALUE1"
32
+ enum.values[1].qualified_name.should.equal "enums::VALUE2"
33
+ enum.values[2].qualified_name.should.equal "enums::VALUE3"
38
34
 
39
35
  enum = @@enum_source.classes("Inner").enumerations("InnerEnum")
40
- assert enum.values[0].qualified_name == "enums::Inner::INNER_1"
41
- assert enum.values[1].qualified_name == "enums::Inner::INNER_2"
36
+ enum.values[0].qualified_name.should.equal "enums::Inner::INNER_1"
37
+ enum.values[1].qualified_name.should.equal "enums::Inner::INNER_2"
38
+ end
39
+
40
+ specify "knows if an enumeration is anonymous" do
41
+ found = @@enum_source.enumerations.select {|e| e.anonymous? }
42
+ found.length.should.equal 1
43
+ found = found[0]
44
+
45
+ assert found.is_a?(RbGCCXML::Enumeration)
46
+ found.values[0].value.should.equal 0
47
+ found.values[1].value.should.equal 1
48
+ found.values[2].value.should.equal 2
42
49
  end
50
+
43
51
  end
44
52
 
@@ -0,0 +1,18 @@
1
+ require "test_helper"
2
+
3
+ context "Function pointers" do
4
+ setup do
5
+ @@fp_source ||= RbGCCXML.parse(full_dir("headers/types.h")).namespaces("types")
6
+ end
7
+
8
+ specify "have arguments" do
9
+ fp = @@fp_source.functions("takesCallback").arguments[0].cpp_type.base_type
10
+ fp.arguments.length.should == 1
11
+ fp.arguments[0].cpp_type.name.should.equal "int"
12
+ end
13
+
14
+ specify "have return value" do
15
+ fp = @@fp_source.functions("takesCallbackWithReturn").arguments[0].cpp_type.base_type
16
+ fp.return_type.name.should.equal "int"
17
+ end
18
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require "test_helper"
2
2
 
3
3
  context "Querying for functions" do
4
4
 
@@ -7,7 +7,7 @@ context "Querying for functions" do
7
7
  end
8
8
 
9
9
  specify "should be able to find all functions" do
10
- @@functions_source.functions.length.should == 2
10
+ @@functions_source.functions.length.should == 4
11
11
  end
12
12
 
13
13
  specify "can find functions by name" do
@@ -41,4 +41,9 @@ context "Querying for functions" do
41
41
  test1.functions
42
42
  end
43
43
  end
44
+
45
+ specify "can get list of arguments" do
46
+ test1 = @@functions_source.functions("test1")
47
+ test1.arguments.length.should.equal 2
48
+ end
44
49
  end
data/test/methods_test.rb CHANGED
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require "test_helper"
2
2
 
3
3
  context "Querying for class methods" do
4
4
  setup do
@@ -32,12 +32,12 @@ context "Querying for class methods" do
32
32
 
33
33
  specify "can search methods via return type" do
34
34
  adder = @@adder_source.classes("Adder")
35
- adder.methods.find(:returns => [:float]).name.should == "addFloats"
35
+ adder.methods.find(:returns => :float).name.should == "addFloats"
36
36
  end
37
37
 
38
38
  specify "can search via all options (AND)" do
39
39
  adder = @@adder_source.classes("Adder")
40
- got = adder.methods.find(:returns => [:int], :arguments => [nil, nil])
40
+ got = adder.methods.find(:returns => :int, :arguments => [nil, nil])
41
41
  got.name.should == "addIntegers"
42
42
  end
43
43
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require "test_helper"
2
2
 
3
3
  context "Querying for namespaces" do
4
4
 
data/test/node_test.rb CHANGED
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require "test_helper"
2
2
 
3
3
  context "Qualified name generation" do
4
4
 
@@ -41,36 +41,6 @@ context "Qualified name generation" do
41
41
 
42
42
  end
43
43
 
44
- context "Equality testing" do
45
-
46
- specify "testing against a string will test against the name" do
47
- source = RbGCCXML.parse(full_dir("headers/namespaces.h"))
48
- assert(source.namespaces("upper") == "upper")
49
- end
50
-
51
- specify "c++ nesting should be usable as well" do
52
- source = RbGCCXML.parse(full_dir("headers/classes.h")).namespaces("classes")
53
- klass = source.classes("Test1").classes("Inner1")
54
- assert !(klass == "Inner2")
55
- assert(klass == "Inner1")
56
- assert(klass == "Test1::Inner1")
57
- assert(klass == "classes::Test1::Inner1")
58
- end
59
-
60
- specify "but should be able to test against nodes as well" do
61
- source = RbGCCXML.parse(full_dir("headers/namespaces.h"))
62
- upper = source.namespaces("upper")
63
- inner = upper.namespaces("inner1")
64
- assert !(upper == inner)
65
- end
66
-
67
- specify "should find explicit over matches" do
68
- source = RbGCCXML.parse(full_dir("headers/classes.h")).namespaces("classes")
69
- f = source.classes("Test2").methods("func")
70
- f.name.should == "func"
71
- end
72
- end
73
-
74
44
  context "Misc access methods" do
75
45
 
76
46
  specify "can tell if something is public, protected, and private" do
@@ -82,4 +52,14 @@ context "Misc access methods" do
82
52
  assert access.methods("publicMethod").public?
83
53
  end
84
54
 
55
+ specify "can get the full file path of a node" do
56
+ source = RbGCCXML.parse(full_dir("headers/enums.h")).namespaces("enums")
57
+ source.enumerations("TestEnum").file.should =~ "enums.h"
58
+ end
59
+
60
+ specify "returns nil if no file node is found" do
61
+ source = RbGCCXML.parse(full_dir("headers/enums.h")).namespaces("enums")
62
+ source.file.should.be nil
63
+ end
64
+
85
65
  end
data/test/parser_test.rb CHANGED
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require "test_helper"
2
2
 
3
3
  context "Default parsing configuration" do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require "test_helper"
2
2
 
3
3
  context "Managing Query results" do
4
4
 
@@ -94,7 +94,7 @@ context "QueryResult#find :arguments" do
94
94
  func.name.should == "test3"
95
95
  end
96
96
 
97
- specify "when searching arguments, can specify catch-all" do
97
+ specify "when searching arguments, can xspecify catch-all" do
98
98
  funcs = @@query_source.functions.find(:arguments => [:int, nil])
99
99
  funcs.size.should == 2
100
100
  assert funcs.detect {|f| f.name == "test3" }
@@ -103,23 +103,23 @@ context "QueryResult#find :arguments" do
103
103
 
104
104
  specify "works when using custom defined types" do
105
105
  func = @@query_source.functions.find(:arguments => ["MyType"])
106
- func.name.should == "testMyTypeArgs"
106
+ func.name.should.equal "testMyTypeArgs"
107
107
  end
108
108
 
109
109
  specify "works with pointers and references" do
110
- func = @@query_source.functions.find(:arguments => ["MyType *"])
111
- func.name.should == "testMyTypeArgsPtr"
110
+ func = @@query_source.functions.find(:arguments => ["MyType*"])
111
+ func.length.should.equal 2
112
112
 
113
- func = @@query_source.functions.find(:arguments => ["MyType &"])
113
+ func = @@query_source.functions.find(:arguments => ["MyType&"])
114
114
  func.name.should == "testMyTypeArgsRef"
115
115
  end
116
116
 
117
117
  specify "works with qualified names" do
118
118
  func = @@query_source.functions.find(:arguments => ["query::MyType"])
119
- func.name.should == "testMyTypeArgs"
119
+ func.name.should.equal "testMyTypeArgs"
120
120
 
121
121
  func = @@query_source.functions.find(:arguments => ["::query::MyType"])
122
- func.name.should == "testMyTypeArgs"
122
+ func.name.should.equal "testMyTypeArgs"
123
123
  end
124
124
 
125
125
  specify "works with qualifiers like const" do
@@ -143,19 +143,19 @@ context "QueryResult#find :returns" do
143
143
 
144
144
  specify "works with custom defined types" do
145
145
  func = @@query_source.functions.find(:returns => "MyType")
146
- func.name.should == "testMyType"
146
+ func.length.should.equal 2
147
147
  end
148
148
 
149
149
  specify "work with qualified names" do
150
150
  func = @@query_source.functions.find(:returns => "query::MyType")
151
- func.name.should == "testMyType"
151
+ func.length.should.equal 2
152
152
 
153
153
  func = @@query_source.functions.find(:returns => "::query::MyType")
154
- func.name.should == "testMyType"
154
+ func.length.should.equal 2
155
155
  end
156
156
 
157
157
  specify "works with pointers and references" do
158
- func = @@query_source.functions.find(:returns => "MyType *")
158
+ func = @@query_source.functions.find(:returns => "MyType*")
159
159
  func.name.should == "testMyTypePtr"
160
160
 
161
161
  func = @@query_source.functions.find(:returns => "MyType&")
@@ -219,10 +219,11 @@ context "QueryResult#find :all - Flag full source search" do
219
219
  end
220
220
 
221
221
  specify "can find according to :returns " do
222
- funcs = @@query_source.functions.find(:all, :returns => ["MyType"])
223
- funcs.size.should == 2
222
+ funcs = @@query_source.functions.find(:all, :returns => "MyType")
223
+ funcs.size.should == 3
224
224
  assert funcs.detect {|f| f.name == "nestedMyTypeReturns"}
225
225
  assert funcs.detect {|f| f.name == "testMyType"}
226
+ assert funcs.detect {|f| f.name == "testMyTypeConst"}
226
227
  end
227
228
 
228
229
  end
data/test/structs_test.rb CHANGED
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require "test_helper"
2
2
 
3
3
  context "Querying for structs" do
4
4
  setup do
@@ -25,11 +25,6 @@ context "Querying for structs" do
25
25
  inner2 = inner1.structs("Inner1")
26
26
  inner2.should.not.be.nil
27
27
  end
28
-
29
- specify "can find out which file said class is in" do
30
- test1 = @@structs_source.structs.find(:name => "Test1")
31
- test1.file_name.should == "structs.h"
32
- end
33
28
  end
34
29
 
35
30
  context "Querying for struct constructors" do
@@ -39,22 +34,25 @@ context "Querying for struct constructors" do
39
34
 
40
35
  specify "should have a list of constructors" do
41
36
  test1 = @@structs_source.structs.find(:name => "Test1")
42
- test1.constructors.size.should == 1
37
+ test1.constructors.size.should == 2
43
38
 
44
39
  test2 = @@structs_source.structs.find(:name => "Test2")
45
- test2.constructors.size.should == 2
40
+ test2.constructors.size.should == 3
46
41
  end
47
42
 
48
43
  specify "constructors should have arguments" do
49
44
  test2 = @@structs_source.structs.find(:name => "Test2")
50
- test2.constructors.size.should == 2
51
45
 
52
- default = test2.constructors[0]
46
+ # GCC generated copy constructors
47
+ copy = test2.constructors[0]
48
+ copy.attributes[:artificial].should == "1"
49
+
50
+ default = test2.constructors[1]
53
51
  default.arguments.size.should == 0
54
52
 
55
- specific = test2.constructors[1]
53
+ specific = test2.constructors[2]
56
54
  specific.arguments.size.should == 1
57
- assert(specific.arguments[0].cpp_type == "int")
55
+ specific.arguments[0].cpp_type.name.should.equal "int"
58
56
  end
59
57
  end
60
58