rbgccxml 0.1.1 → 0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,13 +25,17 @@ module RbGCCXML
25
25
  # Returns the first found node
26
26
  def self.find(options = {})
27
27
  return nil if options.empty?
28
-
29
28
  type = options.delete(:type)
30
- attrs = options.map {|key, value| "[@#{key}='#{value}']"}.join
29
+
30
+ # Look value up in the cache for common operations if a type was given
31
+ if(type && options.length == 1 && options.keys[0] == :id)
32
+ return cache(type, options[:id])
33
+ end
31
34
 
35
+ attrs = options.map {|key, value| "[@#{key}='#{value}']"}.join
32
36
  xpath = "//#{type}#{attrs}"
33
37
 
34
- got = @@doc_root.search(xpath)[0]
38
+ got = @@doc_root.at(xpath)
35
39
 
36
40
  if got
37
41
  RbGCCXML.const_get(type || got.name).new(got)
@@ -39,6 +43,36 @@ module RbGCCXML
39
43
  nil
40
44
  end
41
45
  end
46
+
47
+ # Generic finding of nodes according to attributes.
48
+ # Special options:
49
+ #
50
+ # <tt>:type</tt>:: Specify a certain node type to search by
51
+ #
52
+ # Any other options is directly mapped to attributes on the node. For example, to find all
53
+ # Function nodes:
54
+ #
55
+ # XMLParsing.find_all(:type => "Function")
56
+ #
57
+ # Returns all matching nodes
58
+ def self.find_all(options = {})
59
+ return nil if options.empty?
60
+
61
+ type = options.delete(:type)
62
+ attrs = options.map {|key, value| "[@#{key}='#{value}']"}.join
63
+
64
+ xpath = "//#{type}#{attrs}"
65
+
66
+ results = @@doc_root.search(xpath)
67
+
68
+ if results
69
+ results.collect do |got|
70
+ RbGCCXML.const_get(type || got.name).new(got)
71
+ end
72
+ else
73
+ nil
74
+ end
75
+ end
42
76
 
43
77
  # Look through the DOM under +node+ for +node_type+ nodes.
44
78
  # +node_type+ must be the string name of an existing Node subclass.
@@ -46,7 +80,7 @@ module RbGCCXML
46
80
  # Returns a QueryResult with the findings.
47
81
  def self.find_nested_nodes_of_type(node, node_type)
48
82
  results = QueryResult.new
49
-
83
+
50
84
  # First of all limit which elements we're searching for, to ease processing.
51
85
  # In the GCCXML output, node heirarchy is designated by id, members, and context
52
86
  # attributes:
@@ -56,22 +90,27 @@ module RbGCCXML
56
90
  # context => The parent node id of this node
57
91
  #
58
92
  # We only want those nodes in node's context.
59
- xpath = "//#{node_type}[@context='#{node.attributes["id"]}']"
60
-
61
- @@doc_root.search(xpath).each do |found|
62
- results << RbGCCXML.const_get(node_type).new(found)
63
- end
64
-
65
- results.flatten
93
+ return nested_cache(node_type, node.attributes["id"]).flatten
66
94
  end
67
95
 
68
96
  # Arguments are a special case in gccxml as they are actual children of
69
97
  # the functions / methods they are a part of.
70
98
  def self.find_arguments_for(node)
99
+ get_children_nodes_of_type(node, "Argument")
100
+ end
101
+
102
+ # Enumeration values are children of the Enumeration element
103
+ def self.get_values_of(enum)
104
+ get_children_nodes_of_type(enum.node, "EnumValue")
105
+ end
106
+
107
+ # Generic lookup method for nodes that are XML children of the passed in node.
108
+ # See find_arguments_for and get_values_of for example usage
109
+ def self.get_children_nodes_of_type(node, type)
71
110
  results = QueryResult.new
72
111
 
73
- node.get_elements_by_tag_name("Argument").each do |argument|
74
- results << Argument.new(argument)
112
+ node.get_elements_by_tag_name(type).each do |found|
113
+ results << RbGCCXML.const_get(type).new(found)
75
114
  end
76
115
 
77
116
  results.flatten
@@ -83,7 +122,63 @@ module RbGCCXML
83
122
  #
84
123
  # +find_type_of(func_node, "returns")+ could return "std::string" node, "int" node, etc
85
124
  def self.find_type_of(node, attribute)
86
- XMLParsing.find(:id => node.attributes[attribute])
125
+ id = node.attributes[attribute]
126
+ %w( PointerType ReferenceType FundamentalType Typedef Enumeration CvQualifiedType Class Struct ).each do |type|
127
+ return cache(type, id) if cache(type, id)
128
+ end
129
+ return nil
130
+ end
131
+
132
+ #
133
+ # Returns the element in cache for type at id.
134
+ # Used internally.
135
+ #
136
+ def self.cache(type, id)
137
+ @@types_cache ||= {}
138
+ @@types_cache[type] ||= {}
139
+ build_cache(type) if @@types_cache[type].empty?
140
+ return @@types_cache[type][id]
141
+ end
142
+
143
+ #
144
+ # Creates a cache to work off of.
145
+ # Used internally
146
+ #
147
+ def self.build_cache(type)
148
+ XMLParsing.find_all(:type => type).each do |result|
149
+ @@types_cache[type][result.attributes["id"]] = result
150
+ end
151
+ end
152
+
153
+ #
154
+ # Returns the element in cache for type at id
155
+ # Used internally
156
+ #
157
+ def self.nested_cache(type, context)
158
+ @@nested_cache ||= {}
159
+ @@nested_cache[type] ||= {}
160
+ build_nested_cache(type) if @@nested_cache[type].empty?
161
+ return @@nested_cache[type][context] || QueryResult.new
162
+ end
163
+
164
+ #
165
+ # Creates a nested cache to work off of.
166
+ # Used internally
167
+ #
168
+ def self.build_nested_cache(type)
169
+ XMLParsing.find_all(:type => type).each do |result|
170
+ @@nested_cache[type][result.attributes["context"]] ||= QueryResult.new
171
+ @@nested_cache[type][result.attributes["context"]] << result
172
+ end
173
+ end
174
+
175
+
176
+ #
177
+ # Clears the cache. Use this if you are querying two seperate libraries.
178
+ #
179
+ def self.clear_cache
180
+ @@nested_cache = nil
181
+ @@types_cache = nil
87
182
  end
88
183
  end
89
184
  end
data/lib/rbgccxml.rb CHANGED
@@ -21,11 +21,15 @@ module RbGCCXML
21
21
  autoload :Method, "rbgccxml/nodes/method"
22
22
  autoload :Namespace, "rbgccxml/nodes/namespace"
23
23
  autoload :Struct, "rbgccxml/nodes/struct"
24
+ autoload :Enumeration, "rbgccxml/nodes/enumeration"
25
+ autoload :EnumValue, "rbgccxml/nodes/enum_value"
24
26
 
25
27
  # Type Management
26
28
  autoload :Type, "rbgccxml/nodes/type"
27
29
  autoload :FundamentalType, "rbgccxml/nodes/types/fundamental_type"
28
30
  autoload :PointerType, "rbgccxml/nodes/types/pointer_type"
29
31
  autoload :Typedef, "rbgccxml/nodes/types/typedef"
32
+ autoload :ReferenceType, "rbgccxml/nodes/types/reference_type"
33
+ autoload :CvQualifiedType, "rbgccxml/nodes/types/cv_qualified_type"
30
34
 
31
35
  end
data/test/classes_test.rb CHANGED
@@ -7,7 +7,7 @@ context "Querying for classes" do
7
7
 
8
8
  specify "can find all classes in a given namespace" do
9
9
  classes = @@source.classes
10
- classes.size.should == 3
10
+ classes.size.should == 4
11
11
 
12
12
  %w(Test1 Test2 Test3).each do |t|
13
13
  assert classes.detect {|c| c.node == @@source.classes(t).node },
@@ -39,7 +39,7 @@ context "Querying for class constructors" do
39
39
 
40
40
  specify "should have a list of constructors" do
41
41
  test1 = @@source.classes.find(:name => "Test1")
42
- test1.constructors.size.should == 1
42
+ test1.constructors.size.should == 2
43
43
 
44
44
  test2 = @@source.classes.find(:name => "Test2")
45
45
  test2.constructors.size.should == 2
@@ -0,0 +1,44 @@
1
+
2
+ require File.dirname(__FILE__) + '/test_helper'
3
+
4
+ context "Querying for enumerations" do
5
+ setup do
6
+ @@enum_source ||= RbGCCXML.parse(full_dir("headers/enums.h")).namespaces("enums")
7
+ end
8
+
9
+ specify "can query for enumerations" do
10
+ 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"
15
+ end
16
+
17
+ specify "can find specific enum values" do
18
+ 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"
23
+ end
24
+
25
+ specify "can find the given value of enum entries" do
26
+ 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
30
+ end
31
+
32
+ specify "properly prints out fully qualified C++ identifier for enum values" do
33
+ 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"
38
+
39
+ 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"
42
+ end
43
+ end
44
+
@@ -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 == 6
10
+ @@functions_source.functions.length.should == 2
11
11
  end
12
12
 
13
13
  specify "can find functions by name" do
@@ -21,18 +21,6 @@ context "Querying for functions" do
21
21
  bool.name.should == "bool_method"
22
22
  end
23
23
 
24
- specify "can find names by regex" do
25
- bool = @@functions_source.functions.find(:name => /bool/)
26
- bool.should.be.a.kind_of RbGCCXML::Function
27
- bool.name.should == "bool_method"
28
- end
29
-
30
- xspecify "can find names by fully qualified name" do
31
- nested = @@functions_source.functions.find(:name => "nested1::nested2::nestedFunction")
32
- nested.should.be.a.kind_of RbGCCXML::Function
33
- nested.name.should == "nestedFunction"
34
- end
35
-
36
24
  specify "should not have a classes finder" do
37
25
  test1 = @@functions_source.functions("test1")
38
26
  should.raise RbGCCXML::NotQueryableException do
@@ -54,49 +42,3 @@ context "Querying for functions" do
54
42
  end
55
43
  end
56
44
  end
57
-
58
- context "Finding functions via arguments and return type" do
59
-
60
- setup do
61
- @@functions_source ||= RbGCCXML.parse(full_dir("headers/functions.h")).namespaces("functions")
62
- end
63
-
64
- specify "by return type" do
65
- funcs = @@functions_source.functions.find(:returns => :void)
66
- funcs.size.should == 3
67
- assert funcs.find {|f| f.name == "test1" }
68
- assert funcs.find {|f| f.name == "test2" }
69
- assert funcs.find {|f| f.name == "test3" }
70
- end
71
-
72
- specify "no arguments" do
73
- funcs = @@functions_source.functions.find(:arguments => [])
74
- funcs.size.should == 2
75
- assert funcs.find {|f| f.name == "test1" }
76
- assert funcs.find {|f| f.name == "bool_method" }
77
- end
78
-
79
- specify "multiple arguments" do
80
- # If we find just one result, we get it back
81
- func = @@functions_source.functions.find(:arguments => [:int])
82
- assert func.is_a?(RbGCCXML::Function)
83
- func.name.should == "test2"
84
-
85
- func = @@functions_source.functions.find(:arguments => [:int, :float])
86
- assert func.is_a?(RbGCCXML::Function)
87
- func.name.should == "test3"
88
- end
89
-
90
- specify "when searching arguments, can specify catch-all" do
91
- funcs = @@functions_source.functions.find(:arguments => [:int, nil])
92
- funcs.size.should == 2
93
- assert funcs.find {|f| f.name == "test3" }
94
- assert funcs.find {|f| f.name == "test4" }
95
- end
96
-
97
- specify "by both return type and arguments (AND form, not OR)" do
98
- func = @@functions_source.functions.find(:returns => :int, :arguments => [nil, nil])
99
- assert func.is_a?(RbGCCXML::Function)
100
- func.name.should == "test4"
101
- end
102
- end
data/test/methods_test.rb CHANGED
@@ -56,4 +56,15 @@ context "Properties on Methods" do
56
56
  assert !test2.methods("func1").static?
57
57
  end
58
58
 
59
+ specify "should be able to tell if a given method is virtual or not" do
60
+ test4 = @@classes_source.classes("Test4")
61
+ assert test4.methods("func1").virtual?
62
+ assert !test4.methods("func1").purely_virtual?
63
+
64
+ assert test4.methods("func2").virtual?
65
+ assert !test4.methods("func2").purely_virtual?
66
+
67
+ assert test4.methods("func3").virtual?
68
+ assert test4.methods("func3").purely_virtual?
69
+ end
59
70
  end
data/test/node_test.rb CHANGED
@@ -63,4 +63,23 @@ context "Equality testing" do
63
63
  inner = upper.namespaces("inner1")
64
64
  assert !(upper == inner)
65
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
+ context "Misc access methods" do
75
+
76
+ specify "can tell if something is public, protected, and private" do
77
+ source = RbGCCXML.parse(full_dir("headers/misc.h"))
78
+ access = source.namespaces("misc").classes("AccessSettings")
79
+
80
+ assert access.methods("privateMethod").private?
81
+ assert access.methods("protectedMethod").protected?
82
+ assert access.methods("publicMethod").public?
83
+ end
84
+
66
85
  end
@@ -0,0 +1,228 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ context "Managing Query results" do
4
+
5
+ class MyObj
6
+ attr_accessor :call_me_called, :other_thingy_called
7
+
8
+ def call_me
9
+ @call_me_called = true
10
+ end
11
+
12
+ def other_thingy
13
+ @other_thingy_called = true
14
+ end
15
+ end
16
+
17
+ specify "should forward off unknown methods to the results" do
18
+ obj1 = MyObj.new
19
+ obj2 = MyObj.new
20
+
21
+ q = RbGCCXML::QueryResult.new
22
+ q << obj1 << obj2
23
+
24
+ should.not.raise NoMethodError do
25
+ q.call_me
26
+ q.other_thingy
27
+ end
28
+
29
+ assert obj1.call_me_called
30
+ assert obj1.other_thingy_called
31
+
32
+ assert obj2.call_me_called
33
+ assert obj2.other_thingy_called
34
+
35
+ should.raise NoMethodError do
36
+ q.not_here
37
+ end
38
+ end
39
+
40
+ specify "should throw appropriately with an empty result set" do
41
+ should.raise NoMethodError do
42
+ RbGCCXML::QueryResult.new.some_method
43
+ end
44
+ end
45
+
46
+ specify "should error out with unknown keys" do
47
+ should.raise do
48
+ RbGCCXML::QueryResult.new.find(:key_bad => :hi_mom)
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ context "QueryResult#find :name" do
55
+
56
+ setup do
57
+ @@query_source ||= RbGCCXML.parse(full_dir("headers/queryable.h")).namespaces("query")
58
+ end
59
+
60
+ specify "can find by regular name" do
61
+ func = @@query_source.functions.find(:name => "test4")
62
+ func.should.be.a.kind_of RbGCCXML::Function
63
+ func.name.should == "test4"
64
+ end
65
+
66
+ specify "can find names by regex" do
67
+ bool = @@query_source.functions.find(:name => /bool/)
68
+ bool.should.be.a.kind_of RbGCCXML::Function
69
+ bool.name.should == "bool_method"
70
+ end
71
+
72
+ end
73
+
74
+ context "QueryResult#find :arguments" do
75
+
76
+ setup do
77
+ @@query_source ||= RbGCCXML.parse(full_dir("headers/queryable.h")).namespaces("query")
78
+ end
79
+
80
+ specify "no arguments" do
81
+ funcs = @@query_source.functions.find(:arguments => [])
82
+ assert funcs.detect {|f| f.name == "test1" }
83
+ assert funcs.detect {|f| f.name == "bool_method" }
84
+ end
85
+
86
+ specify "multiple arguments" do
87
+ # If we find just one result, we get it back
88
+ func = @@query_source.functions.find(:arguments => [:int])
89
+ assert func.is_a?(RbGCCXML::Function)
90
+ func.name.should == "test2"
91
+
92
+ func = @@query_source.functions.find(:arguments => [:int, :float])
93
+ assert func.is_a?(RbGCCXML::Function)
94
+ func.name.should == "test3"
95
+ end
96
+
97
+ specify "when searching arguments, can specify catch-all" do
98
+ funcs = @@query_source.functions.find(:arguments => [:int, nil])
99
+ funcs.size.should == 2
100
+ assert funcs.detect {|f| f.name == "test3" }
101
+ assert funcs.detect {|f| f.name == "test4" }
102
+ end
103
+
104
+ specify "works when using custom defined types" do
105
+ func = @@query_source.functions.find(:arguments => ["MyType"])
106
+ func.name.should == "testMyTypeArgs"
107
+ end
108
+
109
+ specify "works with pointers and references" do
110
+ func = @@query_source.functions.find(:arguments => ["MyType *"])
111
+ func.name.should == "testMyTypeArgsPtr"
112
+
113
+ func = @@query_source.functions.find(:arguments => ["MyType &"])
114
+ func.name.should == "testMyTypeArgsRef"
115
+ end
116
+
117
+ specify "works with qualified names" do
118
+ func = @@query_source.functions.find(:arguments => ["query::MyType"])
119
+ func.name.should == "testMyTypeArgs"
120
+
121
+ func = @@query_source.functions.find(:arguments => ["::query::MyType"])
122
+ func.name.should == "testMyTypeArgs"
123
+ end
124
+
125
+ specify "works with qualifiers like const" do
126
+ func = @@query_source.functions.find(:arguments => ["const MyType*"])
127
+ func.name.should == "testMyTypeArgsConstPtr"
128
+ end
129
+ end
130
+
131
+ context "QueryResult#find :returns" do
132
+
133
+ setup do
134
+ @@query_source ||= RbGCCXML.parse(full_dir("headers/queryable.h")).namespaces("query")
135
+ end
136
+
137
+ specify "by return type" do
138
+ funcs = @@query_source.functions.find(:returns => :void)
139
+ assert funcs.detect {|f| f.name == "test1" }
140
+ assert funcs.detect {|f| f.name == "test2" }
141
+ assert funcs.detect {|f| f.name == "test3" }
142
+ end
143
+
144
+ specify "works with custom defined types" do
145
+ func = @@query_source.functions.find(:returns => "MyType")
146
+ func.name.should == "testMyType"
147
+ end
148
+
149
+ specify "work with qualified names" do
150
+ func = @@query_source.functions.find(:returns => "query::MyType")
151
+ func.name.should == "testMyType"
152
+
153
+ func = @@query_source.functions.find(:returns => "::query::MyType")
154
+ func.name.should == "testMyType"
155
+ end
156
+
157
+ specify "works with pointers and references" do
158
+ func = @@query_source.functions.find(:returns => "MyType *")
159
+ func.name.should == "testMyTypePtr"
160
+
161
+ func = @@query_source.functions.find(:returns => "MyType&")
162
+ func.name.should == "testMyTypeRef"
163
+ end
164
+
165
+ specify "works with type modifiers (const)" do
166
+ func = @@query_source.functions.find(:returns => "const MyType")
167
+ func.name.should == "testMyTypeConst"
168
+ end
169
+ end
170
+
171
+ context "QueryResult#find access type" do
172
+
173
+ setup do
174
+ @@query_source ||= RbGCCXML.parse(full_dir("headers/queryable.h")).namespaces("query")
175
+ end
176
+
177
+ specify "can find according to public / private / protected" do
178
+ klass = @@query_source.classes("AccessTester")
179
+ m = klass.methods.find(:access => :public)
180
+ m.name.should == "publicMethod"
181
+
182
+ m = klass.methods.find(:access => :protected)
183
+ m.name.should == "protectedMethod"
184
+
185
+ m = klass.methods.find(:access => :private)
186
+ m.name.should == "privateMethod"
187
+ end
188
+
189
+ end
190
+
191
+ context "QueryResult#find multiple options" do
192
+
193
+ setup do
194
+ @@query_source ||= RbGCCXML.parse(full_dir("headers/queryable.h")).namespaces("query")
195
+ end
196
+
197
+ specify "by both return type and arguments (AND form, not OR)" do
198
+ func = @@query_source.functions.find(:returns => :int, :arguments => [nil, nil])
199
+ assert func.is_a?(RbGCCXML::Function)
200
+ func.name.should == "test4"
201
+ end
202
+
203
+ end
204
+
205
+ context "QueryResult#find :all - Flag full source search" do
206
+
207
+ setup do
208
+ @@query_source ||= RbGCCXML.parse(full_dir("headers/queryable.h")).namespaces("query")
209
+ end
210
+
211
+ specify "can find all :names regardless of nesting" do
212
+ func = @@query_source.functions.find(:all, :name => "nestedFunction")
213
+ func.name.should == "nestedFunction"
214
+ end
215
+
216
+ specify "can find according to :arguments" do
217
+ func = @@query_source.functions.find(:all, :arguments => ["MyType", "MyType"])
218
+ func.name.should == "nestedMyTypeArg"
219
+ end
220
+
221
+ specify "can find according to :returns " do
222
+ funcs = @@query_source.functions.find(:all, :returns => ["MyType"])
223
+ funcs.size.should == 2
224
+ assert funcs.detect {|f| f.name == "nestedMyTypeReturns"}
225
+ assert funcs.detect {|f| f.name == "testMyType"}
226
+ end
227
+
228
+ end
data/test/test_helper.rb CHANGED
@@ -9,6 +9,10 @@ class Test::Unit::TestCase
9
9
  def full_dir(path)
10
10
  File.expand_path(File.join(File.dirname(__FILE__), path))
11
11
  end
12
+
13
+ def teardown
14
+ RbGCCXML::XMLParsing.clear_cache
15
+ end
12
16
 
13
17
  end
14
18
 
data/test/types_test.rb CHANGED
@@ -38,4 +38,82 @@ context "Proper Type handling" do
38
38
  assert @@types_source.functions.find(:returns => "myLongType*") == "returnsLongTypePointer"
39
39
  end
40
40
 
41
+ specify "reference types" do
42
+ assert @@types_source.functions.find(:returns => "struct_type&") == "returnStructReference"
43
+ end
44
+
45
+ specify "const definitions (fundamental types)" do
46
+ assert @@types_source.functions.find(:returns => "const int") == "returnConstInt"
47
+ end
48
+
49
+ specify "const definitions (defined types)" do
50
+ assert @@types_source.functions.find(:returns => "const struct_type") == "returnConstStruct"
51
+ end
52
+
53
+ specify "const references" do
54
+ assert @@types_source.functions.find(:returns => "const user_type&") == "returnConstUserTypeRef"
55
+ end
56
+
57
+ specify "const pointers" do
58
+ assert @@types_source.functions.find(:returns => "const int*") == "returnConstIntPointer"
59
+ end
60
+
61
+ specify "enumerations" do
62
+ assert @@types_source.functions.find(:returns => "myEnum") == "returnMyEnum"
63
+ end
64
+
65
+ end
66
+
67
+ context "Printing types" do
68
+
69
+ setup do
70
+ @@types_source ||= RbGCCXML.parse(full_dir("headers/types.h")).namespaces("types")
71
+ end
72
+
73
+ specify "types should print back properly into string format" do
74
+ @@types_source.functions.find(:returns => "int").return_type.to_s.should == "int"
75
+ @@types_source.functions.find(:returns => "int").return_type.to_s(true).should == "int"
76
+
77
+ @@types_source.functions.find(:returns => "float").return_type.to_s.should == "float"
78
+
79
+ # pointers
80
+ @@types_source.functions.find(:returns => "int*").return_type.to_s.should == "int*"
81
+
82
+ # references
83
+ @@types_source.functions.find(:returns => "struct_type&").return_type.to_s.should == "struct_type&"
84
+ @@types_source.functions.find(:returns => "struct_type&").return_type.to_s(true).should == "types::struct_type&"
85
+
86
+ # printout full from the global namespace
87
+ @@types_source.functions.find(:returns => "string").return_type.to_s(true).should == "others::string"
88
+
89
+ # const
90
+ @@types_source.functions.find(:returns => "const int").return_type.to_s.should == "const int"
91
+
92
+ # const pointers
93
+ @@types_source.functions.find(:returns => "const int*").return_type.to_s.should == "const int*"
94
+
95
+ # const references
96
+ @@types_source.functions.find(:returns => "const user_type&").return_type.to_s.should == "const user_type&"
97
+ @@types_source.functions.find(:returns => "const user_type&").return_type.to_s(true).should == "const types::user_type&"
98
+
99
+ # Enumerations
100
+ @@types_source.functions.find(:returns => "myEnum").return_type.to_s.should == "myEnum"
101
+ @@types_source.functions.find(:returns => "myEnum").return_type.to_s(true).should == "types::myEnum"
102
+ end
103
+
104
+ specify "can get to the base C++ construct of given types" do
105
+ @@types_source.functions.find(:returns => "const user_type&").return_type.base_type.to_s.should == "user_type"
106
+ @@types_source.functions.find(:returns => "const int*").return_type.base_type.to_s.should == "int"
107
+ end
108
+
109
+ end
110
+
111
+ context "Type comparitors" do
112
+ specify "can tell of a given type is a const" do
113
+ assert @@types_source.functions.find(:returns => "const user_type&").return_type.const?
114
+ assert @@types_source.functions.find(:returns => "const int*").return_type.const?
115
+ assert !@@types_source.functions.find(:returns => "user_type").return_type.const?
116
+ assert !@@types_source.functions.find(:returns => "string").return_type.const?
117
+ assert !@@types_source.functions.find(:returns => "int").return_type.const?
118
+ end
41
119
  end