tomparse 0.2.0 → 0.2.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.
data/.ruby CHANGED
@@ -9,7 +9,7 @@ copyrights:
9
9
  year: '2012'
10
10
  license: BSD-2-Clause
11
11
  requirements:
12
- - name: microtest
12
+ - name: citron
13
13
  groups:
14
14
  - test
15
15
  development: true
@@ -25,10 +25,18 @@ repositories:
25
25
  scm: git
26
26
  name: upstream
27
27
  resources:
28
- home: http://rubyworks.github.com/tomparse
29
- docs: http://rubydoc.info/gems/tomparse
30
- code: http://github.com/rubyworks/tomparse
31
- mail: http://groups.google.com/groups/rubyworks-mailinglist
28
+ - uri: http://rubyworks.github.com/tomparse
29
+ name: home
30
+ type: home
31
+ - uri: http://rubydoc.info/gems/tomparse
32
+ name: docs
33
+ type: doc
34
+ - uri: http://github.com/rubyworks/tomparse
35
+ name: code
36
+ type: code
37
+ - uri: http://groups.google.com/groups/rubyworks-mailinglist
38
+ name: mail
39
+ type: mail
32
40
  extra: {}
33
41
  load_path:
34
42
  - lib
@@ -36,7 +44,7 @@ revision: 0
36
44
  created: '2012-03-04'
37
45
  summary: TomDoc parser for Ruby
38
46
  title: TomParse
39
- version: 0.2.0
47
+ version: 0.2.1
40
48
  name: tomparse
41
49
  description: ! 'TomParse is a Ruby TomDoc parser. It contains no other functionality
42
50
 
@@ -44,4 +52,4 @@ description: ! 'TomParse is a Ruby TomDoc parser. It contains no other functiona
44
52
 
45
53
  TomDoc standard.'
46
54
  organization: rubyworks
47
- date: '2012-03-04'
55
+ date: '2012-04-30'
data/Config.rb ADDED
@@ -0,0 +1,19 @@
1
+ config 'rubytest' do |run|
2
+ run.files << 'test/test_*.rb'
3
+
4
+ $:.unshift('test')
5
+ $:.unshift('lib')
6
+ end
7
+
8
+ config 'rubytest', :profile=>'coverage' do |run|
9
+ run.files << 'test/test_*.rb'
10
+
11
+ $:.unshift('test')
12
+ $:.unshift('lib')
13
+
14
+ require 'simplecov'
15
+ SimpleCov.start do
16
+ coverage_dir 'log/coverage'
17
+ end
18
+ end
19
+
data/HISTORY.md CHANGED
@@ -1,7 +1,16 @@
1
1
  # Release History
2
2
 
3
+ ## 0.2.1 / 2012-04-30
3
4
 
4
- ## 0.2.0 / 2012-03-5
5
+ This release fixes indention with multi-line examples.
6
+
7
+ Changes:
8
+
9
+ * Correctly indent multiline code examples.
10
+ * Swtich to Citron for testing.
11
+
12
+
13
+ ## 0.2.0 / 2012-03-07
5
14
 
6
15
  This release improves support of TomDoc, in particular, named parameters. It also
7
16
  fixes a bug with appending to argument and option descriptions.
data/lib/tomparse.rb CHANGED
@@ -97,7 +97,7 @@ module TomParse
97
97
 
98
98
  space = spaces.min || 0
99
99
  lines = lines.map do |line|
100
- if line.empty?
100
+ if line.strip.empty?
101
101
  line.strip
102
102
  else
103
103
  line[space..-1]
@@ -312,11 +312,11 @@ module TomParse
312
312
  def parse_examples(section, sections)
313
313
  examples = []
314
314
 
315
- section = section.sub('Examples', '').strip
315
+ section = section.sub('Examples', '').gsub(/^\s{2}/,'')
316
316
 
317
317
  examples << section unless section.empty?
318
318
  while sections.first && sections.first !~ /^\S/
319
- examples << sections.shift.strip
319
+ examples << sections.shift.gsub(/^\s{2}/,'')
320
320
  end
321
321
 
322
322
  @examples = examples
data/lib/tomparse.yml CHANGED
@@ -9,7 +9,7 @@ copyrights:
9
9
  year: '2012'
10
10
  license: BSD-2-Clause
11
11
  requirements:
12
- - name: microtest
12
+ - name: citron
13
13
  groups:
14
14
  - test
15
15
  development: true
@@ -25,10 +25,18 @@ repositories:
25
25
  scm: git
26
26
  name: upstream
27
27
  resources:
28
- home: http://rubyworks.github.com/tomparse
29
- docs: http://rubydoc.info/gems/tomparse
30
- code: http://github.com/rubyworks/tomparse
31
- mail: http://groups.google.com/groups/rubyworks-mailinglist
28
+ - uri: http://rubyworks.github.com/tomparse
29
+ name: home
30
+ type: home
31
+ - uri: http://rubydoc.info/gems/tomparse
32
+ name: docs
33
+ type: doc
34
+ - uri: http://github.com/rubyworks/tomparse
35
+ name: code
36
+ type: code
37
+ - uri: http://groups.google.com/groups/rubyworks-mailinglist
38
+ name: mail
39
+ type: mail
32
40
  extra: {}
33
41
  load_path:
34
42
  - lib
@@ -36,7 +44,7 @@ revision: 0
36
44
  created: '2012-03-04'
37
45
  summary: TomDoc parser for Ruby
38
46
  title: TomParse
39
- version: 0.2.0
47
+ version: 0.2.1
40
48
  name: tomparse
41
49
  description: ! 'TomParse is a Ruby TomDoc parser. It contains no other functionality
42
50
 
@@ -44,4 +52,4 @@ description: ! 'TomParse is a Ruby TomDoc parser. It contains no other functiona
44
52
 
45
53
  TomDoc standard.'
46
54
  organization: rubyworks
47
- date: '2012-03-04'
55
+ date: '2012-04-30'
data/test/helper.rb CHANGED
@@ -1,20 +1,25 @@
1
1
  #require 'microtest/testunit'
2
- #require 'test/unit'
2
+ #require 'microtest/assertions'
3
3
  #require 'test/fixtures/multiplex'
4
- require 'tomparse'
5
4
 
6
- module TomParse
7
- class Test < ::Test::Unit::TestCase
8
- def self.test(name, &block)
9
- define_method("test_#{name.gsub(/\W/,'_')}", &block) if block
10
- end
5
+ require 'citron'
6
+ require 'ae'
7
+
8
+ require 'tomparse'
11
9
 
12
- def default_test
13
- end
10
+ #module TomParse
11
+ # class Test < ::Test::Unit::TestCase
12
+ # def self.test(name, &block)
13
+ # define_method("test_#{name.gsub(/\W/,'_')}", &block) if block
14
+ # end
15
+ #
16
+ # def default_test
17
+ # end
18
+ #
19
+ # def fixture(name)
20
+ # @fixtures ||= {}
21
+ # @fixtures[name] ||= File.read("test/fixtures/#{name}.rb")
22
+ # end
23
+ # end
24
+ #end
14
25
 
15
- def fixture(name)
16
- @fixtures ||= {}
17
- @fixtures[name] ||= File.read("test/fixtures/#{name}.rb")
18
- end
19
- end
20
- end
@@ -0,0 +1,42 @@
1
+ require 'helper'
2
+
3
+ testcase "Prefixes" do
4
+
5
+ context "Internal" do
6
+
7
+ setup do
8
+ @tomdoc = TomParse::TomDoc.new(<<-END)
9
+ # Internal: Some example text.
10
+ END
11
+ end
12
+
13
+ test "internal?" do
14
+ assert @tomdoc.internal?
15
+ end
16
+
17
+ test "description" do
18
+ @tomdoc.description.assert == "Some example text."
19
+ end
20
+
21
+ end
22
+
23
+ context "Public" do
24
+
25
+ setup do
26
+ @tomdoc = TomParse::TomDoc.new(<<-END)
27
+ # Public: Some example text.
28
+ END
29
+ end
30
+
31
+ test "public?" do
32
+ assert @tomdoc.public?
33
+ end
34
+
35
+ test "description" do
36
+ @tomdoc.description.assert == "Some example text."
37
+ end
38
+
39
+ end
40
+
41
+
42
+ end
@@ -0,0 +1,36 @@
1
+ require 'helper'
2
+
3
+ testcase "Signatures" do
4
+
5
+ setup do
6
+ @comment = TomParse::TomDoc.new %{
7
+ # Duplicate some text an abitrary number of times.
8
+ #
9
+ # Yields the Integer index of the iteration.
10
+ #
11
+ # Signature
12
+ #
13
+ # find_by_<field>[_and_<field>...](args)
14
+ #
15
+ # field - A field name.
16
+ }
17
+ end
18
+
19
+ test "knows what the method yields" do
20
+ @comment.yields.assert == "Yields the Integer index of the iteration."
21
+ end
22
+
23
+ test "knows if the method has alternate signatures" do
24
+ @comment.signatures.size.assert == 1
25
+ @comment.signatures.first.assert == "find_by_<field>[_and_<field>...](args)"
26
+ end
27
+
28
+ test "knows the fields associated with signatures" do
29
+ @comment.signature_fields.size.assert == 1
30
+
31
+ arg = @comment.signature_fields.first
32
+ arg.name.assert == :field
33
+ arg.description.assert == "A field name."
34
+ end
35
+
36
+ end
data/test/test_tomdoc.rb CHANGED
@@ -1,175 +1,186 @@
1
1
  require 'helper'
2
2
 
3
- class TomDocTestCase < TomParse::Test
4
-
5
- def setup
6
- @comment = TomParse::TomDoc.new(<<comment)
7
- # Duplicate some text an abitrary number of times.
8
- #
9
- # text - The String to be duplicated.
10
- # count - The Integer number of times to
11
- # duplicate the text.
12
- # reverse - An optional Boolean indicating
13
- # whether to reverse the result text or not.
14
- #
15
- # Examples
16
- # multiplex('Tom', 4)
17
- # # => 'TomTomTomTom'
18
- #
19
- # multiplex('Bo', 2)
20
- # # => 'BoBo'
21
- #
22
- # multiplex('Chris', -1)
23
- # # => nil
24
- #
25
- # Returns the duplicated String when the count is > 1.
26
- # Returns the atomic mass of the element as a Float. The value is in
27
- # unified atomic mass units.
28
- # Returns nil when the count is < 1.
29
- # Raises ExpectedString if the first argument is not a String.
30
- # Raises ExpectedInteger if the second argument is not an Integer.
31
- comment
32
-
33
- @comment2 = TomParse::TomDoc.new(<<comment2)
34
- # Duplicate some text an abitrary number of times.
35
- #
36
- # Returns the duplicated String.
37
- comment2
38
-
39
- @comment3 = TomParse::TomDoc.new(<<comment3)
40
- # Duplicate some text an abitrary number of times.
41
- #
42
- # Examples
43
- #
44
- # multiplex('Tom', 4)
45
- # # => 'TomTomTomTom'
46
- #
47
- # multiplex('Bo', 2)
48
- # # => 'BoBo'
49
- comment3
50
-
51
- @comment4 = TomParse::TomDoc.new(<<comment4)
52
- # Duplicate some text an abitrary number of times.
53
- #
54
- # Yields the Integer index of the iteration.
55
- #
56
- # Signature
57
- #
58
- # find_by_<field>[_and_<field>...](args)
59
- #
60
- # field - A field name.
61
- comment4
62
-
63
- @comment5 = TomParse::TomDoc.new(<<comment5)
64
- Duplicate some text an abitrary number of times.
65
-
66
- Yields the Integer index of the iteration.
67
-
68
- Signature
69
-
70
- find_by_<field>[_and_<field>...](args)
71
-
72
- field - A field name.
73
- comment5
3
+ testcase TomParse::TomDoc do
4
+
5
+ context "general parsing" do
6
+
7
+ setup do
8
+ @comment = TomParse::TomDoc.new %{
9
+ # Duplicate some text an abitrary number of times.
10
+ #
11
+ # text - The String to be duplicated.
12
+ # count - The Integer number of times to
13
+ # duplicate the text.
14
+ # reverse - An optional Boolean indicating
15
+ # whether to reverse the result text or not.
16
+ #
17
+ # Examples
18
+ # multiplex('Tom', 4)
19
+ # # => 'TomTomTomTom'
20
+ #
21
+ # multiplex('Bo', 2)
22
+ # # => 'BoBo'
23
+ #
24
+ # multiplex('Chris', -1)
25
+ # # => nil
26
+ #
27
+ # Returns the duplicated String when the count is > 1.
28
+ # Returns the atomic mass of the element as a Float. The value is in
29
+ # unified atomic mass units.
30
+ # Returns nil when the count is < 1.
31
+ # Raises ExpectedString if the first argument is not a String.
32
+ # Raises ExpectedInteger if the second argument is not an Integer.
33
+ }
34
+ end
74
35
 
75
- end
36
+ test "parses a description" do
37
+ @comment.description.assert == "Duplicate some text an abitrary number of times."
38
+ end
76
39
 
77
- test "knows when TomDoc is invalid" do
78
- assert_raises TomParse::ParseError do
79
- @comment3.validate
40
+ test "parses args" do
41
+ @comment.args.size.assert == 3
80
42
  end
81
- end
82
43
 
83
- test "parses a description" do
84
- assert_equal "Duplicate some text an abitrary number of times.",
85
- @comment.description
86
- end
44
+ test "knows an arg's name" do
45
+ @comment.args.first.name.assert == :text
46
+ @comment.args[1].name.assert == :count
47
+ @comment.args[2].name.assert == :reverse
48
+ end
87
49
 
88
- test "parses args" do
89
- assert_equal 3, @comment.args.size
90
- end
50
+ test "knows an arg's description" do
51
+ @comment.args[1].description.assert == 'The Integer number of times to duplicate the text.'
91
52
 
92
- test "knows an arg's name" do
93
- assert_equal :text, @comment.args.first.name
94
- assert_equal :count, @comment.args[1].name
95
- assert_equal :reverse, @comment.args[2].name
96
- end
53
+ reverse = 'An optional Boolean indicating whether to reverse the'
54
+ reverse << ' result text or not.'
55
+ @comment.args[2].description.assert == reverse
56
+ end
97
57
 
98
- test "knows an arg's description" do
99
- assert_equal 'The Integer number of times to duplicate the text.',
100
- @comment.args[1].description
58
+ test "knows an arg's optionality" do
59
+ refute @comment.args.first.optional?
60
+ assert @comment.args.last.optional?
61
+ end
101
62
 
102
- reverse = 'An optional Boolean indicating whether to reverse the'
103
- reverse << ' result text or not.'
104
- assert_equal reverse, @comment.args[2].description
105
- end
63
+ test "knows how many examples there are" do
64
+ @comment.examples.size.assert == 3
65
+ end
106
66
 
107
- test "knows an arg's optionality" do
108
- assert_equal false, @comment.args.first.optional?
109
- assert_equal true, @comment.args.last.optional?
110
- end
67
+ test "knows each example" do
68
+ @comment.examples[1].to_s.assert == "multiplex('Bo', 2)\n# => 'BoBo'"
69
+ end
111
70
 
112
- test "knows what to do when there are no args" do
113
- assert_equal 0, @comment2.args.size
114
- end
71
+ test "knows how many return examples there are" do
72
+ @comment.returns.size.assert == 3
73
+ end
115
74
 
116
- test "knows how many examples there are" do
117
- assert_equal 3, @comment.examples.size
118
- end
75
+ test "knows if the method raises anything" do
76
+ @comment.raises.size.assert == 2
77
+ end
119
78
 
120
- test "knows each example" do
121
- assert_equal "multiplex('Bo', 2)\n # => 'BoBo'",
122
- @comment.examples[1].to_s
123
- end
79
+ test "knows each return example" do
80
+ rtn = @comment.returns.first.to_s
81
+ rtn.assert == "Returns the duplicated String when the count is > 1."
124
82
 
125
- test "knows what to do when there are no examples" do
126
- assert_equal 0, @comment2.examples.size
127
- end
83
+ string = ''
84
+ string << "Returns the atomic mass of the element as a Float. "
85
+ string << "The value is in unified atomic mass units."
86
+ @comment.returns[1].to_s.assert == string
128
87
 
129
- test "knows how many return examples there are" do
130
- assert_equal 3, @comment.returns.size
131
- end
88
+ @comment.returns[2].to_s.assert == "Returns nil when the count is < 1."
89
+ end
132
90
 
133
- test "knows if the method raises anything" do
134
- assert_equal 2, @comment.raises.size
135
91
  end
136
92
 
137
- test "knows each return example" do
138
- assert_equal "Returns the duplicated String when the count is > 1.",
139
- @comment.returns.first.to_s
93
+ context "handles whitespace in examples" do
94
+
95
+ setup do
96
+ @comment = TomParse::TomDoc.new %{
97
+ # Duplicate some text an abitrary number of times.
98
+ #
99
+ # Examples
100
+ #
101
+ # def multiplex(str, length)
102
+ # str * length
103
+ # end
104
+ }
105
+ end
140
106
 
141
- string = ''
142
- string << "Returns the atomic mass of the element as a Float. "
143
- string << "The value is in unified atomic mass units."
144
- assert_equal string, @comment.returns[1].to_s
107
+ test "correctly handles whitespace with examples" do
108
+ eg = @comment.examples[0].to_s
109
+ eg.assert == "def multiplex(str, length)\n str * length\nend"
110
+ end
145
111
 
146
- assert_equal "Returns nil when the count is < 1.",
147
- @comment.returns[2].to_s
148
112
  end
149
113
 
150
- test "knows what to do when there are no return examples" do
151
- assert_equal 0, @comment2.examples.size
152
- end
114
+ context "without arguments or examples" do
153
115
 
154
- test "knows what the method yields" do
155
- assert_equal "Yields the Integer index of the iteration.", @comment4.yields
156
- end
116
+ setup do
117
+ @comment = TomParse::TomDoc.new %{
118
+ # Duplicate some text an abitrary number of times.
119
+ #
120
+ # Returns the duplicated String.
121
+ }
122
+ end
123
+
124
+ test "knows what to do when there are no args" do
125
+ @comment.args.size.assert == 0
126
+ end
127
+
128
+ test "knows what to do when there are no examples" do
129
+ @comment.examples.size.assert == 0
130
+ end
131
+
132
+ test "knows what to do when there are no return examples" do
133
+ @comment.examples.size.assert == 0
134
+ end
157
135
 
158
- test "knows if the method has alternate signatures" do
159
- assert_equal 1, @comment4.signatures.size
160
- assert_equal "find_by_<field>[_and_<field>...](args)", @comment4.signatures.first
161
136
  end
162
137
 
163
- test "knows the fields associated with signatures" do
164
- assert_equal 1, @comment4.signature_fields.size
165
138
 
166
- arg = @comment4.signature_fields.first
167
- assert_equal :field, arg.name
168
- assert_equal "A field name.", arg.description
139
+ context "invalid documentation" do
140
+
141
+ setup do
142
+ @comment = TomParse::TomDoc.new %{
143
+ # Duplicate some text an abitrary number of times.
144
+ #
145
+ # Examples
146
+ #
147
+ # multiplex('Tom', 4)
148
+ # # => 'TomTomTomTom'
149
+ #
150
+ # multiplex('Bo', 2)
151
+ # # => 'BoBo'
152
+ }
153
+ end
154
+
155
+ test "knows when TomDoc is invalid" do
156
+ expect TomParse::ParseError do
157
+ @comment.validate
158
+ end
159
+ end
160
+
169
161
  end
170
162
 
171
- test "can hande comments without comment marker" do
172
- assert_equal "Duplicate some text an abitrary number of times.",
173
- @comment5.description
163
+
164
+ context "without comment marker" do
165
+
166
+ setup do
167
+ @comment = TomParse::TomDoc.new %{
168
+ Duplicate some text an abitrary number of times.
169
+
170
+ Yields the Integer index of the iteration.
171
+
172
+ Signature
173
+
174
+ find_by_<field>[_and_<field>...](args)
175
+
176
+ field - A field name.
177
+ }
178
+ end
179
+
180
+ test "can handle comments without comment marker" do
181
+ @comment.description.assert == "Duplicate some text an abitrary number of times."
182
+ end
183
+
174
184
  end
185
+
175
186
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tomparse
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-08 00:00:00.000000000 Z
12
+ date: 2012-04-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: microtest
16
- requirement: &28469660 !ruby/object:Gem::Requirement
15
+ name: citron
16
+ requirement: &21084040 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *28469660
24
+ version_requirements: *21084040
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: detroit
27
- requirement: &28468540 !ruby/object:Gem::Requirement
27
+ requirement: &21077200 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *28468540
35
+ version_requirements: *21077200
36
36
  description: ! 'TomParse is a Ruby TomDoc parser. It contains no other functionality
37
37
 
38
38
  than the ability to take a comment and parse it in accordance to the
@@ -51,10 +51,13 @@ files:
51
51
  - lib/tomparse.rb
52
52
  - lib/tomparse.yml
53
53
  - test/helper.rb
54
+ - test/test_prefixes.rb
55
+ - test/test_signatures.rb
54
56
  - test/test_tomdoc.rb
55
57
  - LICENSE.txt
56
58
  - HISTORY.md
57
59
  - README.md
60
+ - Config.rb
58
61
  homepage: http://rubyworks.github.com/tomparse
59
62
  licenses:
60
63
  - BSD-2-Clause