tomdoc 0.1.0

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,47 @@
1
+ module TomDoc
2
+ module Fixtures
3
+ class Multiplex
4
+ # Duplicate some text an abitrary number of times.
5
+ #
6
+ # text - The String to be duplicated.
7
+ # count - The Integer number of times to duplicate the text.
8
+ #
9
+ # Examples
10
+ # multiplex('Tom', 4)
11
+ # # => 'TomTomTomTom'
12
+ #
13
+ # multiplex('Bo', 2)
14
+ # # => 'BoBo'
15
+ #
16
+ # multiplex('Chris', -1)
17
+ # # => nil
18
+ #
19
+ # Returns the duplicated String when the count is > 1.
20
+ # Returns nil when the count is < 1.
21
+ # Returns the atomic mass of the element as a Float. The value is in
22
+ # unified atomic mass units.
23
+ def multiplex(text, count)
24
+ text * count
25
+ end
26
+
27
+ # Duplicate some text an abitrary number of times.
28
+ #
29
+ # Returns the duplicated String.
30
+ def multiplex2(text, count)
31
+ text * count
32
+ end
33
+
34
+ # Duplicate some text an abitrary number of times.
35
+ #
36
+ # Examples
37
+ # multiplex('Tom', 4)
38
+ # # => 'TomTomTomTom'
39
+ #
40
+ # multiplex('Bo', 2)
41
+ # # => 'BoBo'
42
+ def multiplex3(text, count)
43
+ text * count
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,10 @@
1
+ class Simple
2
+ # Just a simple method.
3
+ #
4
+ # text - The String to return.
5
+ #
6
+ # Returns a String.
7
+ def string(text)
8
+ text
9
+ end
10
+ end
@@ -0,0 +1,47 @@
1
+ require 'test/helper'
2
+
3
+ class GeneratorTest < TomDoc::Test
4
+ def setup
5
+ @class = Class.new(TomDoc::Generator) do
6
+ def write_method(method, prefix = '')
7
+ @buffer = [] if @buffer.is_a?(String)
8
+ @buffer << method.name
9
+ end
10
+ end
11
+
12
+ @generator = @class.new
13
+ end
14
+
15
+ test "can ignore validation methods" do
16
+ @generator.options[:validate] = false
17
+ methods = @generator.generate(fixture(:chimney))
18
+ assert_equal 47, methods.size
19
+ end
20
+
21
+ test "ignores invalid methods" do
22
+ @generator.options[:validate] = true
23
+ methods = @generator.generate(fixture(:chimney))
24
+ assert_equal 39, methods.size
25
+ end
26
+
27
+ test "detects built-in constants" do
28
+ assert @generator.constant?('Object')
29
+ assert @generator.constant?('Kernel')
30
+ assert @generator.constant?('String')
31
+ end
32
+
33
+ test "detects common constants" do
34
+ assert @generator.constant?('Boolean')
35
+ assert @generator.constant?('Test::Unit::TestCase')
36
+ end
37
+
38
+ test "picks up constants from the thing we're TomDocin'" do
39
+ scope = { :Chimney => TomDoc::Scope.new('Chimney') }
40
+ @generator.instance_variable_set(:@scopes, scope)
41
+ assert @generator.constant?('Chimney')
42
+ end
43
+
44
+ test "ignores non-constants" do
45
+ assert !@generator.constant?('Dog')
46
+ end
47
+ end
@@ -0,0 +1,21 @@
1
+ require 'test/unit'
2
+
3
+ require 'test/fixtures/multiplex'
4
+
5
+ require 'tomdoc'
6
+
7
+ module TomDoc
8
+ class Test < Test::Unit::TestCase
9
+ def self.test(name, &block)
10
+ define_method("test_#{name.gsub(/\W/,'_')}", &block) if block
11
+ end
12
+
13
+ def default_test
14
+ end
15
+
16
+ def fixture(name)
17
+ @fixtures ||= {}
18
+ @fixtures[name] ||= File.read("test/fixtures/#{name}.rb")
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ require 'test/helper'
2
+
3
+ class HTMLGeneratorTest < TomDoc::Test
4
+ def setup
5
+ @html = TomDoc::Generators::HTML.generate(fixture(:simple))
6
+ end
7
+
8
+ test "works" do
9
+ assert_equal <<html, @html
10
+ <ul>
11
+ <li><b>Simple#string(text)</b><pre>Just a simple method.
12
+
13
+ text - The String to return.
14
+
15
+ Returns a String.</pre></li></ul>
16
+ html
17
+ end
18
+ end
@@ -0,0 +1,66 @@
1
+ require 'test/helper'
2
+
3
+ class ChimneySourceParserTest < TomDoc::Test
4
+ def setup
5
+ @parser = TomDoc::SourceParser.new
6
+ @result = @parser.parse(fixture(:chimney))
7
+
8
+ @chimney = @result[:GitHub][:Chimney]
9
+ end
10
+
11
+ test "finds instance methods" do
12
+ assert_equal 35, @chimney.instance_methods.size
13
+ end
14
+
15
+ test "attaches TomDoc" do
16
+ m = @chimney.instance_methods.detect { |m| m.name == :get_user_route }
17
+ assert_equal [:user], m.tomdoc.args.map { |a| a.name }
18
+ end
19
+
20
+ test "finds class methods" do
21
+ assert_equal 9, @chimney.class_methods.size
22
+ end
23
+
24
+ test "finds namespaces" do
25
+ assert @result[:GitHub][:Math]
26
+ assert_equal 2, @result.keys.size
27
+ assert_equal 3, @result[:GitHub].keys.size
28
+ end
29
+
30
+ test "finds methods in a namespace" do
31
+ assert_equal 1, @result[:GitHub].class_methods.size
32
+ end
33
+
34
+ test "finds multiple classes in one file" do
35
+ assert_equal 1, @result[:GitHub][:Math].instance_methods.size
36
+ assert_equal 1, @result[:GitHub][:Jobs].instance_methods.size
37
+ end
38
+ end
39
+
40
+ class SourceParserTest < TomDoc::Test
41
+ def setup
42
+ @parser = TomDoc::SourceParser.new
43
+ end
44
+
45
+ test "finds single class in one file" do
46
+ result = @parser.parse(fixture(:simple))
47
+
48
+ assert result[:Simple]
49
+
50
+ methods = result[:Simple].instance_methods
51
+ assert_equal 1, methods.size
52
+ assert_equal [:string], methods.map { |m| m.name }
53
+ end
54
+
55
+ test "finds single module in one file"
56
+ test "finds module in a module"
57
+ test "finds module in a class"
58
+ test "finds class in a class"
59
+
60
+ test "finds class in a module in a module" do
61
+ result = @parser.parse(fixture(:multiplex))
62
+ klass = result[:TomDoc][:Fixtures][:Multiplex]
63
+ assert klass
64
+ assert_equal 3, klass.instance_methods.size
65
+ end
66
+ end
@@ -0,0 +1,127 @@
1
+ require 'test/helper'
2
+
3
+ class TomDocParserTest < TomDoc::Test
4
+ def setup
5
+ @comment = TomDoc::TomDoc.new(<<comment)
6
+ # Duplicate some text an abitrary number of times.
7
+ #
8
+ # text - The String to be duplicated.
9
+ # count - The Integer number of times to
10
+ # duplicate the text.
11
+ # reverse - An optional Boolean indicating
12
+ # whether to reverse the result text or not.
13
+ #
14
+ # Examples
15
+ # multiplex('Tom', 4)
16
+ # # => 'TomTomTomTom'
17
+ #
18
+ # multiplex('Bo', 2)
19
+ # # => 'BoBo'
20
+ #
21
+ # multiplex('Chris', -1)
22
+ # # => nil
23
+ #
24
+ # Returns the duplicated String when the count is > 1.
25
+ # Returns the atomic mass of the element as a Float. The value is in
26
+ # unified atomic mass units.
27
+ # Returns nil when the count is < 1.
28
+ # Raises ExpectedString if the first argument is not a String.
29
+ # Raises ExpectedInteger if the second argument is not an Integer.
30
+ comment
31
+
32
+ @comment2 = TomDoc::TomDoc.new(<<comment2)
33
+ # Duplicate some text an abitrary number of times.
34
+ #
35
+ # Returns the duplicated String.
36
+ comment2
37
+
38
+ @comment3 = TomDoc::TomDoc.new(<<comment3)
39
+ # Duplicate some text an abitrary number of times.
40
+ #
41
+ # Examples
42
+ #
43
+ # multiplex('Tom', 4)
44
+ # # => 'TomTomTomTom'
45
+ #
46
+ # multiplex('Bo', 2)
47
+ # # => 'BoBo'
48
+ comment3
49
+ end
50
+
51
+ test "knows when TomDoc is invalid" do
52
+ assert_raises TomDoc::InvalidTomDoc do
53
+ @comment3.validate
54
+ end
55
+ end
56
+
57
+ test "parses a description" do
58
+ assert_equal "Duplicate some text an abitrary number of times.",
59
+ @comment.description
60
+ end
61
+
62
+ test "parses args" do
63
+ assert_equal 3, @comment.args.size
64
+ end
65
+
66
+ test "knows an arg's name" do
67
+ assert_equal :text, @comment.args.first.name
68
+ assert_equal :count, @comment.args[1].name
69
+ assert_equal :reverse, @comment.args[2].name
70
+ end
71
+
72
+ test "knows an arg's description" do
73
+ assert_equal 'The Integer number of times to duplicate the text.',
74
+ @comment.args[1].description
75
+
76
+ reverse = 'An optional Boolean indicating whether to reverse the'
77
+ reverse << ' result text or not.'
78
+ assert_equal reverse, @comment.args[2].description
79
+ end
80
+
81
+ test "knows an arg's optionality" do
82
+ assert_equal false, @comment.args.first.optional?
83
+ assert_equal true, @comment.args.last.optional?
84
+ end
85
+
86
+ test "knows what to do when there are no args" do
87
+ assert_equal 0, @comment2.args.size
88
+ end
89
+
90
+ test "knows how many examples there are" do
91
+ assert_equal 3, @comment.examples.size
92
+ end
93
+
94
+ test "knows each example" do
95
+ assert_equal " multiplex('Bo', 2)\n # => 'BoBo'",
96
+ @comment.examples[1].to_s
97
+ end
98
+
99
+ test "knows what to do when there are no examples" do
100
+ assert_equal 0, @comment2.examples.size
101
+ end
102
+
103
+ test "knows how many return examples there are" do
104
+ assert_equal 3, @comment.returns.size
105
+ end
106
+
107
+ test "knows if the method raises anything" do
108
+ assert_equal 2, @comment.raises.size
109
+ end
110
+
111
+ test "knows each return example" do
112
+ assert_equal "Returns the duplicated String when the count is > 1.",
113
+ @comment.returns.first.to_s
114
+
115
+ string = ''
116
+ string << "Returns the atomic mass of the element as a Float. "
117
+ string << "The value is in unified atomic mass units."
118
+ assert_equal string, @comment.returns[1].to_s
119
+
120
+ assert_equal "Returns nil when the count is < 1.",
121
+ @comment.returns[2].to_s
122
+ end
123
+
124
+ test "knows what to do when there are no return examples" do
125
+ assert_equal 0, @comment2.examples.size
126
+ end
127
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tomdoc
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Chris Wanstrath
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-11 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: sexp_processor
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 3
29
+ - 0
30
+ - 4
31
+ version: 3.0.4
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: ParseTree
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 3
43
+ - 0
44
+ - 5
45
+ version: 3.0.5
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: RubyInline
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 3
57
+ - 7
58
+ - 0
59
+ version: 3.7.0
60
+ type: :runtime
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: ruby_parser
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 2
71
+ - 0
72
+ - 4
73
+ version: 2.0.4
74
+ type: :runtime
75
+ version_requirements: *id004
76
+ description: " TomDoc is flexible code documentation with human readers in\n mind. The tomdoc gem is a Ruby library to discover and display\n TomDoc'd methods and classes.\n\n Given a Ruby file with TomDoc'd methods, tomdoc can generate HTML or\n print to the console. You can use it to query up a single method or\n a group of methods, and it's usable from irb.\n\n If you're using TomDoc, tomdoc is for you.\n"
77
+ email: chris@ozmm.org
78
+ executables:
79
+ - tomdoc
80
+ extensions: []
81
+
82
+ extra_rdoc_files: []
83
+
84
+ files:
85
+ - README.md
86
+ - Rakefile
87
+ - LICENSE
88
+ - lib/tomdoc/arg.rb
89
+ - lib/tomdoc/cli.rb
90
+ - lib/tomdoc/generator.rb
91
+ - lib/tomdoc/generators/console.rb
92
+ - lib/tomdoc/generators/html.rb
93
+ - lib/tomdoc/method.rb
94
+ - lib/tomdoc/scope.rb
95
+ - lib/tomdoc/source_parser.rb
96
+ - lib/tomdoc/tomdoc.rb
97
+ - lib/tomdoc/version.rb
98
+ - lib/tomdoc.rb
99
+ - bin/tomdoc
100
+ - man/tomdoc.5
101
+ - man/tomdoc.5.html
102
+ - man/tomdoc.5.ronn
103
+ - test/console_generator_test.rb
104
+ - test/fixtures/chimney.rb
105
+ - test/fixtures/multiplex.rb
106
+ - test/fixtures/simple.rb
107
+ - test/generator_test.rb
108
+ - test/helper.rb
109
+ - test/html_generator_test.rb
110
+ - test/source_parser_test.rb
111
+ - test/tomdoc_parser_test.rb
112
+ has_rdoc: true
113
+ homepage: http://github.com/defunkt/tomdoc
114
+ licenses: []
115
+
116
+ post_install_message:
117
+ rdoc_options: []
118
+
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ segments:
126
+ - 0
127
+ version: "0"
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ segments:
133
+ - 0
134
+ version: "0"
135
+ requirements: []
136
+
137
+ rubyforge_project:
138
+ rubygems_version: 1.3.6
139
+ signing_key:
140
+ specification_version: 3
141
+ summary: A TomDoc library for Ruby.
142
+ test_files: []
143
+