tomparse 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.index +2 -2
- data/HISTORY.md +10 -0
- data/lib/tomparse.yml +2 -2
- data/lib/tomparse/parser.rb +37 -36
- data/test/helper.rb +8 -0
- data/test/test_examples.rb +124 -0
- data/test/test_tomdoc.rb +0 -4
- metadata +4 -2
data/.index
CHANGED
data/HISTORY.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
## 0.4.1 / 2013-02-14
|
4
|
+
|
5
|
+
This release fixes exmaple parsing.
|
6
|
+
|
7
|
+
Changes:
|
8
|
+
|
9
|
+
* Handle variable indention in examples.
|
10
|
+
* Do not remove newlines for single example.
|
11
|
+
|
12
|
+
|
3
13
|
## 0.4.0 / 2013-02-10
|
4
14
|
|
5
15
|
For this release, the document parser has been substantially refactored.
|
data/lib/tomparse.yml
CHANGED
data/lib/tomparse/parser.rb
CHANGED
@@ -540,33 +540,28 @@ module TomParse
|
|
540
540
|
|
541
541
|
# Parse example.
|
542
542
|
#
|
543
|
-
# section - String starting with `
|
544
|
-
# sections - All sections subsequent to section.
|
543
|
+
# section - String starting with `Example`.
|
545
544
|
#
|
546
545
|
# Returns nothing.
|
547
546
|
def parse_example(section)
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
@examples << section unless section.strip.empty?
|
547
|
+
# remove the initial `Example` line and right strip
|
548
|
+
section = section.sub(/.*?\n/, '')
|
549
|
+
example = clean_example(section)
|
550
|
+
@examples << example unless example.strip.empty?
|
554
551
|
end
|
555
552
|
|
556
553
|
# Parse examples.
|
557
554
|
#
|
558
555
|
# section - String starting with `Examples`.
|
559
|
-
# sections - All sections subsequent to section.
|
560
556
|
#
|
561
557
|
# Returns nothing.
|
562
558
|
def parse_examples(section)
|
563
|
-
#
|
564
|
-
|
565
|
-
# TODO: make the unidention smarter (could be more than 2 spaces)
|
566
|
-
section = section.sub('Examples', '')
|
567
|
-
|
559
|
+
# remove the initial `Examples` line and right strip
|
560
|
+
section = section.sub(/.*?\n/, '')
|
568
561
|
section.split("\n\n").each do |ex|
|
569
|
-
|
562
|
+
next if ex.strip.empty?
|
563
|
+
example = clean_example(ex)
|
564
|
+
@examples << example
|
570
565
|
end
|
571
566
|
end
|
572
567
|
|
@@ -587,27 +582,6 @@ module TomParse
|
|
587
582
|
def parse_returns(section)
|
588
583
|
text = section.gsub(/\s+/, ' ').strip
|
589
584
|
@returns << text
|
590
|
-
|
591
|
-
#returns, raises, current = [], [], []
|
592
|
-
#
|
593
|
-
#lines = section.split("\n")
|
594
|
-
#lines.each do |line|
|
595
|
-
# case line
|
596
|
-
# when /^Returns/
|
597
|
-
# returns << line
|
598
|
-
# current = returns
|
599
|
-
# when /^Raises/
|
600
|
-
# raises << line
|
601
|
-
# current = raises
|
602
|
-
# when /^\s+/
|
603
|
-
# current.last << line.squeeze(' ')
|
604
|
-
# else
|
605
|
-
# current << line # TODO: What to do with non-compliant line?
|
606
|
-
# end
|
607
|
-
#end
|
608
|
-
#
|
609
|
-
#@returns.concat(returns)
|
610
|
-
#@raises.concat(raises)
|
611
585
|
end
|
612
586
|
|
613
587
|
# Parse raises section.
|
@@ -694,6 +668,33 @@ module TomParse
|
|
694
668
|
@tags << [label, desc.strip] if label
|
695
669
|
end
|
696
670
|
|
671
|
+
private
|
672
|
+
|
673
|
+
def clean_example(text)
|
674
|
+
lines = text.rstrip.lines.to_a
|
675
|
+
# remove blank lines from top
|
676
|
+
lines.shift while lines.first.strip.empty?
|
677
|
+
# determine the indention
|
678
|
+
indent = least_indent(lines)
|
679
|
+
# remove the indention
|
680
|
+
tab = " " * indent
|
681
|
+
lines = lines.map{ |line| line.sub(tab, '') }
|
682
|
+
# put the lines back together
|
683
|
+
lines.join
|
684
|
+
end
|
685
|
+
|
686
|
+
# Given a multi-line string, determine the minimum indention.
|
687
|
+
def least_indent(lines)
|
688
|
+
indents = []
|
689
|
+
lines.map do |line|
|
690
|
+
next if line.strip.empty?
|
691
|
+
if md = /^\ */.match(line)
|
692
|
+
indents << md[0].size
|
693
|
+
end
|
694
|
+
end
|
695
|
+
indents.min || 0
|
696
|
+
end
|
697
|
+
|
697
698
|
end
|
698
699
|
|
699
700
|
end
|
data/test/helper.rb
CHANGED
@@ -0,0 +1,124 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
testcase "Examples" do
|
4
|
+
|
5
|
+
context "plural form one example" do
|
6
|
+
setup do
|
7
|
+
@comment = TomParse::TomDoc.new %{
|
8
|
+
# Duplicate some text an abitrary number of times.
|
9
|
+
#
|
10
|
+
# Examples
|
11
|
+
# multiplex('Tom', 4)
|
12
|
+
# # => 'TomTomTomTom'
|
13
|
+
#
|
14
|
+
# Returns something or another.
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
test "there is one examples" do
|
19
|
+
@comment.examples.size.assert == 1
|
20
|
+
end
|
21
|
+
|
22
|
+
test "the example" do
|
23
|
+
@comment.examples.first.assert == "multiplex('Tom', 4)\n# => 'TomTomTomTom'"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "plural form multiple examples" do
|
28
|
+
setup do
|
29
|
+
@comment = TomParse::TomDoc.new %{
|
30
|
+
# Duplicate some text an abitrary number of times.
|
31
|
+
#
|
32
|
+
# Examples
|
33
|
+
# multiplex('Tom', 4)
|
34
|
+
# # => 'TomTomTomTom'
|
35
|
+
#
|
36
|
+
# multiplex('Bo', 2)
|
37
|
+
# # => 'BoBo'
|
38
|
+
#
|
39
|
+
# Returns something or another.
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
test "there are two examples" do
|
44
|
+
@comment.examples.size.assert == 2
|
45
|
+
end
|
46
|
+
|
47
|
+
test "the first example" do
|
48
|
+
@comment.examples.first.assert == "multiplex('Tom', 4)\n# => 'TomTomTomTom'"
|
49
|
+
end
|
50
|
+
|
51
|
+
test "the second example" do
|
52
|
+
@comment.examples.last.assert == "multiplex('Bo', 2)\n# => 'BoBo'"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "singular form" do
|
57
|
+
setup do
|
58
|
+
@comment = TomParse::TomDoc.new %{
|
59
|
+
# Duplicate some text an abitrary number of times.
|
60
|
+
#
|
61
|
+
# Example
|
62
|
+
# answer = multiplex('Tom', 4)
|
63
|
+
#
|
64
|
+
# return answer
|
65
|
+
#
|
66
|
+
# Returns something or another.
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
test "there is one example" do
|
71
|
+
@comment.examples.size.assert == 1
|
72
|
+
end
|
73
|
+
|
74
|
+
test "the example" do
|
75
|
+
@comment.examples.first.assert == "answer = multiplex('Tom', 4)\n\nreturn answer"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "multiple example clauses" do
|
80
|
+
setup do
|
81
|
+
@comment = TomParse::TomDoc.new %{
|
82
|
+
# Duplicate some text an abitrary number of times.
|
83
|
+
#
|
84
|
+
# Examples
|
85
|
+
# multiplex('Tom', 4)
|
86
|
+
# # => 'TomTomTomTom'
|
87
|
+
#
|
88
|
+
# multiplex('Bo', 2)
|
89
|
+
# # => 'BoBo'
|
90
|
+
#
|
91
|
+
# Example
|
92
|
+
# answer = multiplex('Tom', 4)
|
93
|
+
#
|
94
|
+
# return answer
|
95
|
+
#
|
96
|
+
# Returns something or another.
|
97
|
+
}
|
98
|
+
end
|
99
|
+
|
100
|
+
test "there are three examples" do
|
101
|
+
@comment.examples.size.assert == 3
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "handles whitespace in examples" do
|
106
|
+
setup do
|
107
|
+
@comment = TomParse::TomDoc.new %{
|
108
|
+
# Duplicate some text an abitrary number of times.
|
109
|
+
#
|
110
|
+
# Examples
|
111
|
+
#
|
112
|
+
# def multiplex(str, length)
|
113
|
+
# str * length
|
114
|
+
# end
|
115
|
+
}
|
116
|
+
end
|
117
|
+
|
118
|
+
test "correctly handles whitespace with examples" do
|
119
|
+
eg = @comment.examples[0].to_s
|
120
|
+
eg.assert == "def multiplex(str, length)\n str * length\nend"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
data/test/test_tomdoc.rb
CHANGED
@@ -104,7 +104,6 @@ testcase TomParse::TomDoc do
|
|
104
104
|
end
|
105
105
|
|
106
106
|
context "handles multiple paragraph descriptions" do
|
107
|
-
|
108
107
|
setup do
|
109
108
|
@comment = TomParse::TomDoc.new %{
|
110
109
|
# Has an initial paragraph.
|
@@ -122,11 +121,9 @@ testcase TomParse::TomDoc do
|
|
122
121
|
test "correctly handles multiple paragraphs" do
|
123
122
|
@comment.description.assert == "Has an initial paragraph.\n\nHas another paragraph in the description."
|
124
123
|
end
|
125
|
-
|
126
124
|
end
|
127
125
|
|
128
126
|
context "handles whitespace in examples" do
|
129
|
-
|
130
127
|
setup do
|
131
128
|
@comment = TomParse::TomDoc.new %{
|
132
129
|
# Duplicate some text an abitrary number of times.
|
@@ -143,7 +140,6 @@ testcase TomParse::TomDoc do
|
|
143
140
|
eg = @comment.examples[0].to_s
|
144
141
|
eg.assert == "def multiplex(str, length)\n str * length\nend"
|
145
142
|
end
|
146
|
-
|
147
143
|
end
|
148
144
|
|
149
145
|
context "without arguments or examples" do
|
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.4.
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: citron
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- lib/tomparse.yml
|
84
84
|
- test/helper.rb
|
85
85
|
- test/test_description.rb
|
86
|
+
- test/test_examples.rb
|
86
87
|
- test/test_prefixes.rb
|
87
88
|
- test/test_signatures.rb
|
88
89
|
- test/test_tags.rb
|
@@ -119,6 +120,7 @@ summary: TomDoc parser for Ruby
|
|
119
120
|
test_files:
|
120
121
|
- test/test_description.rb
|
121
122
|
- test/helper.rb
|
123
|
+
- test/test_examples.rb
|
122
124
|
- test/test_yields.rb
|
123
125
|
- test/test_signatures.rb
|
124
126
|
- test/test_tags.rb
|