murdoc 0.1.13 → 0.2.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.
@@ -8,35 +8,44 @@ describe Murdoc::Annotator do
8
8
  end
9
9
 
10
10
  it "should set source type from second argument" do
11
- Murdoc::Annotator.new("# Hello", "ruby").source_type.should == "ruby"
12
- Murdoc::Annotator.new("# Hello", :ruby).source_type.should == "ruby"
13
- end
14
-
15
- it "should set options from hash" do
16
- Murdoc::Annotator.new("", "", :foo => :bar).options[:foo].should == :bar
11
+ Murdoc::Annotator.new("# Hello", "ruby").source_type.should == :ruby
12
+ Murdoc::Annotator.new("# Hello", :ruby).source_type.should == :ruby
17
13
  end
18
14
  end
19
15
 
20
16
  describe ".from_file" do
21
- after(:each) { FileUtils.rm "annotator_test.rb", :force => true }
17
+ after(:each) do
18
+ FileUtils.rm "annotator_test.rb", :force => true
19
+ FileUtils.rm "annotator_test.", :force => true
20
+ end
21
+
22
22
  it "should set #source from file contents" do
23
23
  File.open("annotator_test.rb", "w+") do |f|
24
24
  f.puts "# Comment"
25
25
  f.puts "puts 'Hello, world!'"
26
26
  end
27
-
28
27
  described_class.from_file("annotator_test.rb").source.should =~ /# Comment\s+puts 'Hello, world!'/
29
28
  end
30
29
 
30
+ it "can handle failure of non-detection" do
31
+ File.open('annotator_test.', 'w+')
32
+ described_class.from_file("annotator_test.").source_type.should == :base
33
+ end
34
+
35
+ it "properly detects ruby" do
36
+ File.open("annotator_test.rb", "w+")
37
+ described_class.from_file("annotator_test.rb").source_type.should == :ruby
38
+ end
39
+
31
40
  it "should detect source type from extension" do
32
41
  File.open("annotator_test.rb", "w+")
33
- described_class.stub!(:detect_source_type_from_filename).and_return("test")
34
- described_class.from_file("annotator_test.rb").source_type.should == "test"
42
+ Murdoc::Languages.stub('detect' => :test)
43
+ described_class.from_file("annotator_test.rb").source_type.should == :test
35
44
  end
36
45
 
37
46
  it "should still let me force source type" do
38
- File.open("annotator_test.rb", "w+")
39
- described_class.from_file("annotator_test.rb", "code").source_type.should == "code"
47
+ File.open("annotator_test.rb", "w+")
48
+ described_class.from_file("annotator_test.rb", :code).source_type.should == :code
40
49
  end
41
50
  end
42
51
 
@@ -48,7 +57,7 @@ describe Murdoc::Annotator do
48
57
  let(:source) { "# Block one\n# Block one!!!!\n def hi\nputs 'hello'\nend\n\n# Block two\ndef yo\nputs 'rap'\nend\n" }
49
58
 
50
59
  it "should split source into paragraphs" do
51
- subject.should have_exactly(2).paragraphs
60
+ subject.paragraphs.count.should == 2
52
61
  subject.paragraphs[0].source.should =~ /\A\s*def hi\s*puts 'hello'\s*end\s*\Z/m
53
62
  subject.paragraphs[0].annotation.should =~ /\ABlock one\s*Block one!!!!\Z/m
54
63
  subject.paragraphs[1].source.should =~ /\A\s*def yo\s*puts 'rap'\s*end\s*\Z/m
@@ -56,29 +65,23 @@ describe Murdoc::Annotator do
56
65
  end
57
66
 
58
67
  it "should remove trailing comment blank line" do
59
- subject.source = "# Hello\n# \n \n\n"
60
- subject.should have_exactly(1).paragraphs
68
+ subject = described_class.new("# Hello\n# \n \n\n", :ruby)
69
+ subject.paragraphs.count.should == 1
61
70
  subject.paragraphs[0].annotation.should == "Hello"
62
71
  end
63
-
64
- it "should not remove more than one space" do
65
- subject.source = "# Hello"
66
- subject.should have_exactly(1).paragraphs
67
- subject.paragraphs[0].annotation.should == " Hello"
68
- end
69
72
  end
70
73
 
71
74
  context "for source with multi-line comments" do
72
75
  let(:source) { "=begin\n Block one\n Block one!!!!\n=end\n def hi\nputs 'hello'\nend\n=begin\nBlock two\n=end\ndef yo\nputs 'rap'\nend\n" }
73
76
 
74
77
  it "should split source into paragraphs" do
75
- subject.should have_exactly(2).paragraphs
78
+ subject.paragraphs.count.should == 2
76
79
  subject.paragraphs[0].source.should =~ /\A\s*def hi\s*puts 'hello'\s*end\s*\Z/m
77
80
  subject.paragraphs[0].annotation.should =~ /\ABlock one\s*Block one!!!!\Z/m
78
81
  subject.paragraphs[1].source.should =~ /\A\s*def yo\s*puts 'rap'\s*end\s*\Z/m
79
82
  subject.paragraphs[1].annotation.should =~ /\ABlock two\Z/m
80
83
  end
81
-
84
+
82
85
  it "should not hang upon non-closed comments" do
83
86
  source = "=begin\n"
84
87
  lambda {
@@ -90,56 +93,35 @@ describe Murdoc::Annotator do
90
93
  context "for comment without code" do
91
94
  let(:source) { "# Header\n\n\n# Comment\ndef body\nend" }
92
95
  it "should create a separate paragraph" do
93
- subject.should have_exactly(2).paragraphs
96
+ subject.paragraphs.count.should == 2
94
97
  subject.paragraphs[0].source.should == ""
95
98
  subject.paragraphs[0].annotation.should == "Header"
96
99
  end
97
100
  end
98
-
99
- context "for commented code" do
100
- let(:source) { "# :code:\n# def hello\n# end\n\n\# Comment\ndef hi\nend" }
101
- it "should not create paragraphs" do
102
- subject.should have_exactly(1).paragraphs
103
- subject.paragraphs[0].source.should == "def hi\nend"
104
- subject.paragraphs[0].annotation.should == "Comment"
105
- end
106
-
107
- it "should not swallow wrong code" do
108
- source = "# :code:\n# def hi\n# end\n\ndef hallo\nend"
109
- subject = described_class.new(source, :ruby)
110
- subject.should have_exactly(1).paragraphs
111
- subject.paragraphs[0].annotation.to_s.should == ""
112
- subject.paragraphs[0].source.should == "def hallo\nend"
113
- end
114
- end
115
101
 
116
102
  it "should not choke on edge cases" do
117
- subject.source = ""
118
- subject.source = "#"
119
- subject.source = "# A\n#"
120
- subject.source = " # A\n # "
121
- subject.source = "# A\n=begin\n"
122
- subject.source = "# A\n=begin\n\n =end yo"
123
- subject.source = "# A\n=begin\n\n asdasd =end yo"
124
- subject.source = "# A\n=begin\n\n !!$$ =end yo"
125
- subject.source = "\n =begin\n\n =end yo"
126
- subject.source = "=begin YO =end\n\n\n\n asdasd asd"
103
+ expect {
104
+ described_class.new("", :ruby)
105
+ described_class.new("#", :ruby)
106
+ described_class.new("# A\n#", :ruby)
107
+ described_class.new(" # A\n # ", :ruby)
108
+ described_class.new("# A\n=begin\n", :ruby)
109
+ described_class.new("# A\n=begin\n\n =end yo", :ruby)
110
+ described_class.new("# A\n=begin\n\n asdasd =end yo", :ruby)
111
+ described_class.new("# A\n=begin\n\n !!$$ =end yo", :ruby)
112
+ described_class.new("\n =begin\n\n =end yo", :ruby)
113
+ described_class.new("=begin YO =end\n\n\n\n asdasd asd", :ruby)
114
+ }.not_to raise_error
127
115
  end
128
116
 
129
117
  it "should remove totally empty source" do
130
- subject.source = "# Comment\n\n\n\n"
118
+ subject = described_class.new("# Comment\n\n\n\n", :ruby)
131
119
  subject.paragraphs[0].source.should be_empty
132
120
  end
133
121
 
134
122
  it "should remove semi-empty lines" do
135
- subject.source = "def hi\n\nend"
123
+ subject = described_class.new("def hi\n\nend", :ruby)
136
124
  subject.paragraphs[0].source.should == "def hi\n\nend"
137
125
  end
138
126
  end
139
-
140
-
141
- describe "#annotated" do
142
- let(:source) { "# this" }
143
- subject { described_class.new(source, :ruby) }
144
- end
145
- end
127
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Murdoc::Languages do
4
+ subject { described_class }
5
+
6
+ describe '#detect' do
7
+ it "detects ruby files" do
8
+ subject.detect('hello.rb').should == :ruby
9
+ end
10
+
11
+ it "detects javascript files" do
12
+ subject.detect('hello.js').should == :js
13
+ end
14
+
15
+ it "detects html files" do
16
+ subject.detect('hello.html').should == :html
17
+ end
18
+
19
+ it "returns nil in case of failure" do
20
+ subject.detect('hello.txt').should == nil
21
+ end
22
+ end
23
+ end
@@ -11,15 +11,11 @@ describe Murdoc::Paragraph do
11
11
  end
12
12
 
13
13
  it "should optionally set source_type" do
14
- described_class.new("", "", 0, :ruby).source_type.should == "ruby"
14
+ described_class.new("", "", 0, :ruby).source_type.should == :ruby
15
15
  end
16
16
 
17
17
  it "should optionally set starting line" do
18
18
  described_class.new("", "", 666, :ruby).starting_line.should == 666
19
19
  end
20
-
21
- it "should optionally set options" do
22
- described_class.new("", "", 666, :ruby, {:foo => :bar}).options.should == {:foo => :bar}
23
- end
24
20
  end
25
- end
21
+ end
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
  require "tempfile"
3
- describe Murdoc::Formatter do
3
+ describe Murdoc::Renderer do
4
4
  describe "#initialize" do
5
5
  it "should set template from given string" do
6
6
  described_class.new("%p Hello").template.should == "%p Hello"
@@ -19,9 +19,9 @@ describe Murdoc::Formatter do
19
19
  it "should render with haml" do
20
20
  described_class.new("%p Hello").render.should =~ %r{<p>Hello</p>}
21
21
  end
22
-
22
+
23
23
  it "should send locals to haml" do
24
24
  described_class.new("%p= foo").render(:foo => 123).should =~ %r{<p>123</p>}
25
25
  end
26
26
  end
27
- end
27
+ end
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+
3
+ describe Murdoc::Scanner do
4
+ subject { described_class.new(Murdoc::Languages::Ruby) }
5
+
6
+ describe "null scanner" do
7
+ subject { described_class.new(Murdoc::Languages::Base) }
8
+
9
+ it "returns a single paragraph with all the text" do
10
+ paragraphs = subject.call("hello\nworld")
11
+ paragraphs.count.should == 1
12
+ paragraphs[0].source.should == "hello\nworld"
13
+ paragraphs[0].annotation.should be_empty
14
+ end
15
+ end
16
+
17
+ it "detect single line comment block annotations" do
18
+ # for example
19
+ # something like
20
+ # this
21
+
22
+ paragraphs = subject.call("# hello\n# hello 2\n\nworld")
23
+ paragraphs.count.should == 1
24
+ paragraphs[0].annotation.should == "hello\nhello 2"
25
+ paragraphs[0].source.should == 'world'
26
+ end
27
+
28
+ it "detects multi-line comment block annotations" do
29
+ # =begin
30
+ # this should become annotation
31
+ # =end
32
+
33
+ paragraphs = subject.call("=begin\nhello\n=endworld")
34
+ paragraphs.count.should == 1
35
+ paragraphs[0].annotation.should == 'hello'
36
+ paragraphs[0].source.should == 'world'
37
+ end
38
+
39
+ it "works with zero code lines" do
40
+ paragraphs = subject.call('# foo')
41
+ paragraphs.count.should == 1
42
+ paragraphs[0].annotation.should == 'foo'
43
+ paragraphs[0].source.should == ''
44
+ end
45
+
46
+ it "works with zero annotation lines" do
47
+ paragraphs = subject.call("foo bar\nbaz bool")
48
+ paragraphs.count.should == 1
49
+ paragraphs[0].source.should == "foo bar\nbaz bool"
50
+ end
51
+
52
+ it "works with more than one paragraph" do
53
+ paragraphs = subject.call("# hello\nworld\n# foo\nbar")
54
+ paragraphs.count.should == 2
55
+ paragraphs[1].annotation.should == "foo"
56
+ paragraphs[1].source.should == "bar"
57
+ end
58
+
59
+ it "removes common space prefix from multiline comment blocks" do
60
+ paragraphs = subject.call("=begin\n foo\n bar\n baz\n=end")
61
+ paragraphs[0].annotation.should == "foo\nbar\n baz"
62
+ end
63
+
64
+ context 'line numbers' do
65
+ context 'when counting normally' do
66
+ it "counts every line for paragraph numbering" do
67
+ rs = subject.call("# l1\n# l2\nl3")
68
+ rs[0].starting_line.should == 2
69
+ end
70
+
71
+ it "keeps counting empty lines" do
72
+ rs = subject.call("# l1\n\n\n\nl5")
73
+ rs[0].starting_line.should == 4
74
+ end
75
+
76
+ it "works with multiple paragraphs" do
77
+ rs = subject.call("# l1\nl2\n\n\n\n# l6\nl7")
78
+ rs[0].starting_line.should == 1
79
+ rs[1].starting_line.should == 6
80
+ end
81
+ end
82
+
83
+ context 'when ignoring comment lines' do
84
+ it "ignores comment lines" do
85
+ rs = subject.call("# l1\n# l2\nl3", true)
86
+ rs[0].starting_line.should == 0
87
+ end
88
+
89
+ it "keeps counting empty lines" do
90
+ rs = subject.call("# l1\n\n\n\nl5", true)
91
+ rs[0].starting_line.should == 3
92
+ end
93
+
94
+ it "works with multiple paragraphs" do
95
+ rs = subject.call("# l1\nl2\n\n\n\n# l6\nl7", true)
96
+ rs[0].starting_line.should == 0
97
+ rs[1].starting_line.should == 4
98
+ end
99
+ end
100
+ end
101
+ end
@@ -2,4 +2,13 @@ require "rubygems"
2
2
  require "bundler/setup"
3
3
  require "rspec"
4
4
 
5
- require "murdoc"
5
+ require "murdoc"
6
+
7
+ RSpec.configure do |config|
8
+ config.expect_with(:rspec) {|expectations| expectations.syntax = [:should, :expect] }
9
+ config.mock_with(:rspec) {|mocks| mocks.syntax = :should }
10
+ config.raise_errors_for_deprecations!
11
+
12
+ config.filter_run :focus => true
13
+ config.run_all_when_everything_filtered = true
14
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: murdoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Abramov
@@ -14,32 +14,32 @@ dependencies:
14
14
  name: kramdown
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '0.13'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '0.13'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: haml
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 3.0.0
33
+ version: '3.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 3.0.0
40
+ version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: jeweler
42
+ name: pry
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 2.4.0
75
+ version: '3.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 2.4.0
82
+ version: '3.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rdiscount
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -100,35 +100,40 @@ executables:
100
100
  - murdoc
101
101
  - murdoc-strip-comments
102
102
  extensions: []
103
- extra_rdoc_files:
104
- - README.md
103
+ extra_rdoc_files: []
105
104
  files:
106
105
  - ".document"
106
+ - ".gitignore"
107
107
  - ".rspec"
108
108
  - ".travis.yml"
109
109
  - Gemfile
110
- - Gemfile.lock
111
110
  - README.md
112
111
  - Rakefile
113
112
  - UNLICENSE
114
- - VERSION
115
- - autotest/discover.rb
116
113
  - bin/murdoc
117
114
  - bin/murdoc-strip-comments
118
115
  - lib/murdoc.rb
119
116
  - lib/murdoc/annotator.rb
120
- - lib/murdoc/formatter.rb
117
+ - lib/murdoc/formatted_paragraph.rb
118
+ - lib/murdoc/languages/base.rb
119
+ - lib/murdoc/languages/coffeescript.rb
121
120
  - lib/murdoc/languages/html.rb
122
121
  - lib/murdoc/languages/javascript.rb
122
+ - lib/murdoc/languages/markdown.rb
123
123
  - lib/murdoc/languages/ruby.rb
124
124
  - lib/murdoc/paragraph.rb
125
+ - lib/murdoc/renderer.rb
126
+ - lib/murdoc/scanner.rb
127
+ - lib/murdoc/version.rb
125
128
  - markup/stylesheet.css
126
129
  - markup/template.haml
127
130
  - markup/template_multifile.haml
128
131
  - murdoc.gemspec
129
132
  - spec/murdoc/annotator_spec.rb
130
- - spec/murdoc/formatter_spec.rb
133
+ - spec/murdoc/languages/base_spec.rb
131
134
  - spec/murdoc/paragraph_spec.rb
135
+ - spec/murdoc/renderer_spec.rb
136
+ - spec/murdoc/scanner_spec.rb
132
137
  - spec/spec_helper.rb
133
138
  homepage: http://github.com/markiz/murdoc
134
139
  licenses:
@@ -154,4 +159,10 @@ rubygems_version: 2.4.5
154
159
  signing_key:
155
160
  specification_version: 4
156
161
  summary: Annotated documentation generator
157
- test_files: []
162
+ test_files:
163
+ - spec/murdoc/annotator_spec.rb
164
+ - spec/murdoc/languages/base_spec.rb
165
+ - spec/murdoc/paragraph_spec.rb
166
+ - spec/murdoc/renderer_spec.rb
167
+ - spec/murdoc/scanner_spec.rb
168
+ - spec/spec_helper.rb