rbgccxml 0.1

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.
@@ -0,0 +1,60 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ context "Querying for classes" do
4
+ setup do
5
+ @@source ||= RbGCCXML.parse(full_dir("headers/classes.h")).namespaces("classes")
6
+ end
7
+
8
+ specify "can find all classes in a given namespace" do
9
+ classes = @@source.classes
10
+ classes.size.should == 3
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
16
+ end
17
+
18
+ specify "can find classes within classes" do
19
+ test1 = @@source.classes.find(:name => "Test1")
20
+ test1.should.not.be.nil
21
+
22
+ inner1 = test1.classes("Inner1")
23
+ inner1.should.not.be.nil
24
+
25
+ inner2 = inner1.classes("Inner1")
26
+ inner2.should.not.be.nil
27
+ end
28
+
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"
32
+ end
33
+ end
34
+
35
+ context "Querying for class constructors" do
36
+ setup do
37
+ @@source ||= RbGCCXML.parse(full_dir("headers/classes.h")).namespaces("classes")
38
+ end
39
+
40
+ specify "should have a list of constructors" do
41
+ test1 = @@source.classes.find(:name => "Test1")
42
+ test1.constructors.size.should == 1
43
+
44
+ test2 = @@source.classes.find(:name => "Test2")
45
+ test2.constructors.size.should == 2
46
+ end
47
+
48
+ specify "constructors should have arguments" do
49
+ test2 = @@source.classes.find(:name => "Test2")
50
+ test2.constructors.size.should == 2
51
+
52
+ default = test2.constructors[0]
53
+ default.arguments.size.should == 0
54
+
55
+ specific = test2.constructors[1]
56
+ specific.arguments.size.should == 1
57
+ assert(specific.arguments[0].cpp_type == "int")
58
+ end
59
+ end
60
+
@@ -0,0 +1,102 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ context "Querying for functions" do
4
+
5
+ setup do
6
+ @@functions_source ||= RbGCCXML.parse(full_dir("headers/functions.h")).namespaces("functions")
7
+ end
8
+
9
+ specify "should be able to find all functions" do
10
+ @@functions_source.functions.length.should == 6
11
+ end
12
+
13
+ specify "can find functions by name" do
14
+ # Short-hand finding does #find(:name => "")
15
+ test1 = @@functions_source.functions("test1")
16
+ test1.should.be.a.kind_of RbGCCXML::Function
17
+ test1.name.should == "test1"
18
+
19
+ bool = @@functions_source.functions.find(:name => "bool_method")
20
+ bool.should.be.a.kind_of RbGCCXML::Function
21
+ bool.name.should == "bool_method"
22
+ end
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
+ specify "should not have a classes finder" do
37
+ test1 = @@functions_source.functions("test1")
38
+ should.raise RbGCCXML::NotQueryableException do
39
+ test1.classes
40
+ end
41
+ end
42
+
43
+ specify "should not have a namespaces finder" do
44
+ test1 = @@functions_source.functions("test1")
45
+ should.raise RbGCCXML::NotQueryableException do
46
+ test1.namespaces
47
+ end
48
+ end
49
+
50
+ specify "should not have a functions finder" do
51
+ test1 = @@functions_source.functions("test1")
52
+ should.raise RbGCCXML::NotQueryableException do
53
+ test1.functions
54
+ end
55
+ end
56
+ 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
@@ -0,0 +1,59 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ context "Querying for class methods" do
4
+ setup do
5
+ @@adder_source ||= RbGCCXML.parse(full_dir("headers/Adder.h")).namespaces("classes")
6
+ end
7
+
8
+ specify "should be able to get the methods on a class" do
9
+ adder = @@adder_source.classes.find(:name => "Adder")
10
+ methods = adder.methods
11
+
12
+ methods.size.should == 4
13
+ methods[0].name.should == "addIntegers"
14
+ methods[1].name.should == "addFloats"
15
+ methods[2].name.should == "addStrings"
16
+ methods[3].name.should == "getClassName"
17
+ end
18
+
19
+ # The following are simplistic. functions_test tests the
20
+ # finder options much more completely. This is just to test
21
+ # that it works on Method objects fine
22
+ specify "should be able to get methods by name" do
23
+ adder = @@adder_source.classes("Adder")
24
+ adder.methods("addIntegers").name.should == "addIntegers"
25
+ adder.methods.find(:name => "addStrings").name.should == "addStrings"
26
+ end
27
+
28
+ specify "can search methods via arguments" do
29
+ adder = @@adder_source.classes("Adder")
30
+ adder.methods.find(:arguments => [:int, :int]).name.should == "addIntegers"
31
+ end
32
+
33
+ specify "can search methods via return type" do
34
+ adder = @@adder_source.classes("Adder")
35
+ adder.methods.find(:returns => [:float]).name.should == "addFloats"
36
+ end
37
+
38
+ specify "can search via all options (AND)" do
39
+ adder = @@adder_source.classes("Adder")
40
+ got = adder.methods.find(:returns => [:int], :arguments => [nil, nil])
41
+ got.name.should == "addIntegers"
42
+ end
43
+
44
+ end
45
+
46
+ context "Properties on Methods" do
47
+ setup do
48
+ @@classes_source ||= RbGCCXML.parse(full_dir("headers/classes.h")).namespaces("classes")
49
+ end
50
+
51
+ specify "should be able to tell if a given method is static or not" do
52
+ test1 = @@classes_source.classes("Test1")
53
+ assert test1.methods("staticMethod").static?
54
+
55
+ test2 = @@classes_source.classes.find(:name => "Test2")
56
+ assert !test2.methods("func1").static?
57
+ end
58
+
59
+ end
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ context "Querying for namespaces" do
4
+
5
+ setup do
6
+ @source ||= RbGCCXML.parse(full_dir("headers/namespaces.h"))
7
+ end
8
+
9
+ specify "can find a namespace" do
10
+ upper = @source.namespaces.find(:name => "upper")
11
+ upper.should.be.a.kind_of RbGCCXML::Namespace
12
+
13
+ inner1 = upper.namespaces("inner1")
14
+ inner1.should.be.a.kind_of RbGCCXML::Namespace
15
+ inner1.name.should == "inner1"
16
+
17
+ inner2 = upper.namespaces("inner2")
18
+ inner2.should.be.a.kind_of RbGCCXML::Namespace
19
+ inner2.name.should == "inner2"
20
+
21
+ nested = inner2.namespaces("nested")
22
+ nested.should.be.a.kind_of RbGCCXML::Namespace
23
+ nested.name.should == "nested"
24
+ end
25
+ end
data/test/node_test.rb ADDED
@@ -0,0 +1,66 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ context "Qualified name generation" do
4
+
5
+ specify "for namespaces" do
6
+ source = RbGCCXML.parse(full_dir("headers/namespaces.h"))
7
+
8
+ upper = source.namespaces.find(:name => "upper")
9
+ upper.qualified_name.should == "upper"
10
+
11
+ inner2 = upper.namespaces("inner2")
12
+ inner2.qualified_name.should == "upper::inner2"
13
+ end
14
+
15
+ specify "for classes" do
16
+ source = RbGCCXML.parse(full_dir("headers/classes.h")).namespaces("classes")
17
+
18
+ test1 = source.classes.find(:name => "Test1")
19
+ test1.qualified_name.should == "classes::Test1"
20
+
21
+ inner1 = test1.classes("Inner1")
22
+ inner1.qualified_name.should == "classes::Test1::Inner1"
23
+
24
+ inner2 = inner1.classes("Inner2")
25
+ inner2.qualified_name.should == "classes::Test1::Inner1::Inner2"
26
+ end
27
+
28
+ specify "for functions" do
29
+ source = RbGCCXML.parse(full_dir("headers/functions.h")).namespaces("functions")
30
+ test1 = source.functions("test1")
31
+ test1.qualified_name.should == "functions::test1"
32
+ end
33
+
34
+ specify "for methods in classes" do
35
+ source = RbGCCXML.parse(full_dir("headers/classes.h")).namespaces("classes")
36
+ inner = source.classes("Test1").classes("Inner1")
37
+ func = inner.methods("innerFunc")
38
+
39
+ func.qualified_name.should == "classes::Test1::Inner1::innerFunc"
40
+ end
41
+
42
+ end
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
+ end
@@ -0,0 +1,65 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ context "Default parsing configuration" do
4
+
5
+ specify "can parse a single header file" do
6
+ should.not.raise do
7
+ RbGCCXML.parse(full_dir("headers/Adder.h"))
8
+ end
9
+ end
10
+
11
+ specify "can parse a glob" do
12
+ should.not.raise do
13
+ RbGCCXML.parse(full_dir("headers/*.hpp"))
14
+ end
15
+ end
16
+
17
+ specify "can parse all files in a directory" do
18
+ should.not.raise do
19
+ RbGCCXML.parse(full_dir("headers"),
20
+ :includes => full_dir("headers/include"))
21
+ end
22
+ end
23
+
24
+ specify "can take an array of files" do
25
+ files = [full_dir("headers/Adder.h"),
26
+ full_dir("headers/Subtracter.hpp")]
27
+ should.not.raise do
28
+ RbGCCXML.parse(files)
29
+ end
30
+ end
31
+
32
+ specify "can take an array of globs" do
33
+ files = [full_dir("headers/*.h"),
34
+ full_dir("headers/*.hpp")]
35
+ should.not.raise do
36
+ RbGCCXML.parse(files, :includes => full_dir("headers/include"))
37
+ end
38
+ end
39
+
40
+ specify "should throw an error if files aren't found" do
41
+ should.raise RbGCCXML::SourceNotFoundError do
42
+ RbGCCXML.parse(full_dir("headers/Broken.hcc"))
43
+ end
44
+
45
+ should.raise RbGCCXML::SourceNotFoundError do
46
+ RbGCCXML.parse(full_dir("hockers"))
47
+ end
48
+
49
+ should.raise RbGCCXML::SourceNotFoundError do
50
+ RbGCCXML.parse(full_dir("something/*"))
51
+ end
52
+
53
+ should.raise RbGCCXML::SourceNotFoundError do
54
+ RbGCCXML.parse([full_dir("something/*"), full_dir("anotherthing/*")])
55
+ end
56
+ end
57
+ end
58
+
59
+ context "Configurable parsing configuration" do
60
+ specify "can give extra include directories for parsing" do
61
+ found = RbGCCXML.parse full_dir("headers/with_includes.h"),
62
+ :includes => full_dir("headers/include")
63
+ found.namespaces("code").should.not.be.nil
64
+ end
65
+ end
@@ -0,0 +1,60 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ context "Querying for structs" do
4
+ setup do
5
+ @@structs_source ||= RbGCCXML.parse(full_dir("headers/structs.h")).namespaces("structs")
6
+ end
7
+
8
+ specify "can find all structs in a given namespace" do
9
+ structs = @@structs_source.structs
10
+ structs.size.should == 3
11
+
12
+ %w(Test1 Test2 Test3).each do |t|
13
+ assert structs.detect {|c| c.node == @@structs_source.structs(t).node },
14
+ "unable to find node for #{t}"
15
+ end
16
+ end
17
+
18
+ specify "can find structs within structs" do
19
+ test1 = @@structs_source.structs.find(:name => "Test1")
20
+ test1.should.not.be.nil
21
+
22
+ inner1 = test1.structs("Inner1")
23
+ inner1.should.not.be.nil
24
+
25
+ inner2 = inner1.structs("Inner1")
26
+ inner2.should.not.be.nil
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
+ end
34
+
35
+ context "Querying for struct constructors" do
36
+ setup do
37
+ @@structs_source ||= RbGCCXML.parse(full_dir("headers/structs.h")).namespaces("structs")
38
+ end
39
+
40
+ specify "should have a list of constructors" do
41
+ test1 = @@structs_source.structs.find(:name => "Test1")
42
+ test1.constructors.size.should == 1
43
+
44
+ test2 = @@structs_source.structs.find(:name => "Test2")
45
+ test2.constructors.size.should == 2
46
+ end
47
+
48
+ specify "constructors should have arguments" do
49
+ test2 = @@structs_source.structs.find(:name => "Test2")
50
+ test2.constructors.size.should == 2
51
+
52
+ default = test2.constructors[0]
53
+ default.arguments.size.should == 0
54
+
55
+ specific = test2.constructors[1]
56
+ specific.arguments.size.should == 1
57
+ assert(specific.arguments[0].cpp_type == "int")
58
+ end
59
+ end
60
+
@@ -0,0 +1,14 @@
1
+ $: << File.expand_path(File.dirname(__FILE__) + "/../lib")
2
+
3
+ require 'rubygems'
4
+ require 'test/spec'
5
+ require 'rbgccxml'
6
+
7
+ class Test::Unit::TestCase
8
+
9
+ def full_dir(path)
10
+ File.expand_path(File.join(File.dirname(__FILE__), path))
11
+ end
12
+
13
+ end
14
+
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ context "Proper Type handling" do
4
+
5
+ setup do
6
+ @@types_source ||= RbGCCXML.parse(full_dir("headers/types.h")).namespaces("types")
7
+ end
8
+
9
+ specify "fundamental types" do
10
+ assert @@types_source.functions.find(:returns => "int") == "returnsInt"
11
+ assert @@types_source.functions.find(:returns => "float") == "returnsFloat"
12
+ end
13
+
14
+ xspecify "unsigned fundamental types" do
15
+ end
16
+
17
+ specify "typedefs" do
18
+ assert @@types_source.functions.find(:returns => "myLongType") == "returnsLongType"
19
+ assert @@types_source.functions.find(:returns => "myShortType") == "returnsShortType"
20
+ end
21
+
22
+ specify "user defined types (classes / structs)" do
23
+ assert @@types_source.functions.find(:returns => "user_type") == "returnsUserType"
24
+ assert @@types_source.functions.find(:returns => "struct_type") == "returnsStructType"
25
+ end
26
+
27
+ # Are these three necessary or can it be just one?
28
+ specify "pointers to user defined types" do
29
+ assert @@types_source.functions.find(:returns => "user_type*") == "returnsUserTypePointer"
30
+ assert @@types_source.functions.find(:returns => "struct_type*") == "returnsStructTypePointer"
31
+ end
32
+
33
+ specify "pointers to fundamental types" do
34
+ assert @@types_source.functions.find(:returns => "int*") == "returnsIntPointer"
35
+ end
36
+
37
+ specify "pointers to typedefs" do
38
+ assert @@types_source.functions.find(:returns => "myLongType*") == "returnsLongTypePointer"
39
+ end
40
+
41
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbgccxml
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - Jason Roelofs
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-05-04 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hpricot
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - "="
21
+ - !ruby/object:Gem::Version
22
+ version: "0.6"
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: gccxml_gem
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - "="
30
+ - !ruby/object:Gem::Version
31
+ version: "0.9"
32
+ version:
33
+ description: Rbgccxml is a library that parses out GCCXML (http://www.gccxml.org) output and provides a simple but very powerful querying API for finding exactly what you want out of the C++ source code
34
+ email: jameskilton@gmail.com
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files: []
40
+
41
+ files:
42
+ - TODO
43
+ - Rakefile
44
+ - lib/rbgccxml/parser.rb
45
+ - lib/rbgccxml/nodes/types/fundamental_type.rb
46
+ - lib/rbgccxml/nodes/types/pointer_type.rb
47
+ - lib/rbgccxml/nodes/types/typedef.rb
48
+ - lib/rbgccxml/nodes/struct.rb
49
+ - lib/rbgccxml/nodes/function.rb
50
+ - lib/rbgccxml/nodes/file.rb
51
+ - lib/rbgccxml/nodes/namespace.rb
52
+ - lib/rbgccxml/nodes/argument.rb
53
+ - lib/rbgccxml/nodes/type.rb
54
+ - lib/rbgccxml/nodes/constructor.rb
55
+ - lib/rbgccxml/nodes/method.rb
56
+ - lib/rbgccxml/nodes/class.rb
57
+ - lib/rbgccxml/query_result.rb
58
+ - lib/rbgccxml/xml_parsing.rb
59
+ - lib/rbgccxml/node.rb
60
+ - lib/rbgccxml/rbgccxml.rb
61
+ - lib/jamis.rb
62
+ - lib/rbgccxml.rb
63
+ has_rdoc: false
64
+ homepage: http://rbplusplus.rubyforge.org/rbgccxml
65
+ post_install_message:
66
+ rdoc_options: []
67
+
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ version:
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ version:
82
+ requirements: []
83
+
84
+ rubyforge_project: rbplusplus
85
+ rubygems_version: 1.1.1
86
+ signing_key:
87
+ specification_version: 2
88
+ summary: Ruby interface to GCCXML
89
+ test_files:
90
+ - test/classes_test.rb
91
+ - test/node_test.rb
92
+ - test/methods_test.rb
93
+ - test/structs_test.rb
94
+ - test/parser_test.rb
95
+ - test/functions_test.rb
96
+ - test/test_helper.rb
97
+ - test/types_test.rb
98
+ - test/namespaces_test.rb