devver-germinate 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/History.txt +4 -0
- data/README.rdoc +132 -0
- data/Rakefile +43 -0
- data/bin/germ +133 -0
- data/cucumber.yml +2 -0
- data/examples/basic.rb +118 -0
- data/examples/short.rb +17 -0
- data/features/author-formats-article.feature +108 -0
- data/features/author-lists-info.feature +45 -0
- data/features/author-publishes-article-source.feature +5 -0
- data/features/author-publishes-article.feature +5 -0
- data/features/author-republishes-article.feature +5 -0
- data/features/author-selects-hunks.feature +26 -0
- data/features/author-updates-article-source.feature +5 -0
- data/features/author-views-stuff.feature +48 -0
- data/features/bin/quoter +6 -0
- data/features/bin/sorter +4 -0
- data/features/example_articles/code_samples.rb +89 -0
- data/features/example_articles/escaping.txt +12 -0
- data/features/example_articles/hello.rb +9 -0
- data/features/example_articles/pipelines.txt +25 -0
- data/features/example_articles/regexen.rb +24 -0
- data/features/example_articles/sample_offsets.rb +18 -0
- data/features/example_articles/specials.rb +19 -0
- data/features/example_articles/wrapping.rb +8 -0
- data/features/example_output/code_samples.txt +186 -0
- data/features/example_output/escaping.out +5 -0
- data/features/example_output/hello.txt +1 -0
- data/features/example_output/pipelines.out +28 -0
- data/features/example_output/regexen.txt +22 -0
- data/features/example_output/sample_offsets.txt +15 -0
- data/features/example_output/specials.txt +36 -0
- data/features/example_output/wrapping.txt +3 -0
- data/features/step_definitions/germinate.rb +30 -0
- data/features/support/env.rb +18 -0
- data/germinate.gemspec +55 -0
- data/lib/germinate.rb +54 -0
- data/lib/germinate/application.rb +62 -0
- data/lib/germinate/article_editor.rb +20 -0
- data/lib/germinate/article_formatter.rb +75 -0
- data/lib/germinate/formatter.rb +119 -0
- data/lib/germinate/hunk.rb +149 -0
- data/lib/germinate/implicit_insertion.rb +9 -0
- data/lib/germinate/insertion.rb +15 -0
- data/lib/germinate/librarian.rb +179 -0
- data/lib/germinate/pipeline.rb +11 -0
- data/lib/germinate/process.rb +67 -0
- data/lib/germinate/reader.rb +212 -0
- data/lib/germinate/selector.rb +95 -0
- data/lib/germinate/shared_style_attributes.rb +23 -0
- data/lib/germinate/text_transforms.rb +90 -0
- data/spec/germinate/application_spec.rb +14 -0
- data/spec/germinate/article_editor_spec.rb +97 -0
- data/spec/germinate/article_formatter_spec.rb +153 -0
- data/spec/germinate/code_hunk_spec.rb +45 -0
- data/spec/germinate/formatter_spec.rb +160 -0
- data/spec/germinate/hunk_spec.rb +77 -0
- data/spec/germinate/implicit_insertion_spec.rb +33 -0
- data/spec/germinate/insertion_spec.rb +18 -0
- data/spec/germinate/librarian_spec.rb +336 -0
- data/spec/germinate/pipeline_spec.rb +24 -0
- data/spec/germinate/process_spec.rb +64 -0
- data/spec/germinate/reader_spec.rb +306 -0
- data/spec/germinate/selector_spec.rb +65 -0
- data/spec/germinate/text_hunk_spec.rb +53 -0
- data/spec/germinate/text_transforms_spec.rb +154 -0
- data/spec/germinate_spec.rb +8 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +16 -0
- data/tasks/ann.rake +80 -0
- data/tasks/bones.rake +20 -0
- data/tasks/cucumber.rake +5 -0
- data/tasks/gem.rake +201 -0
- data/tasks/git.rake +40 -0
- data/tasks/notes.rake +27 -0
- data/tasks/post_load.rake +34 -0
- data/tasks/rdoc.rake +51 -0
- data/tasks/rubyforge.rake +55 -0
- data/tasks/setup.rb +292 -0
- data/tasks/spec.rake +54 -0
- data/tasks/svn.rake +47 -0
- data/tasks/test.rake +40 -0
- data/tasks/zentest.rake +36 -0
- data/test/test_germinate.rb +0 -0
- metadata +209 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path(
|
2
|
+
File.join(File.dirname(__FILE__), %w[.. .. lib germinate]))
|
3
|
+
|
4
|
+
module Germinate
|
5
|
+
describe CodeHunk do
|
6
|
+
before :each do
|
7
|
+
@it = CodeHunk.new(["foo", "bar"])
|
8
|
+
end
|
9
|
+
|
10
|
+
context "when visited by a formatter" do
|
11
|
+
before :each do
|
12
|
+
@formatter = stub("Formatter")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should call #formate_code! for self" do
|
16
|
+
@formatter.should_receive(:format_code!).with(@it, anything)
|
17
|
+
@it.format_with(@formatter)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "with a nested hunk" do
|
22
|
+
before :each do
|
23
|
+
@formatter = stub("Formatter")
|
24
|
+
@comment_prefix = ">>"
|
25
|
+
@nested_hunk = stub("Nested Hunk", :empty? => false)
|
26
|
+
contents = [
|
27
|
+
"foo",
|
28
|
+
"bar",
|
29
|
+
@nested_hunk,
|
30
|
+
"baz"
|
31
|
+
]
|
32
|
+
@it = CodeHunk.new(contents,
|
33
|
+
:comment_prefix => @comment_prefix)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should pass formatter on to nested hunks" do
|
37
|
+
@formatter.should_receive(:format_code!).with(["foo", "bar"], ">>").ordered
|
38
|
+
@nested_hunk.should_receive(:format_with).with(@formatter).ordered
|
39
|
+
@formatter.should_receive(:format_code!).with(["baz"], ">>").ordered
|
40
|
+
@it.format_with(@formatter)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
require File.expand_path(
|
2
|
+
File.join(File.dirname(__FILE__), %w[.. .. lib germinate]))
|
3
|
+
|
4
|
+
module Germinate
|
5
|
+
describe Formatter do
|
6
|
+
before :each do
|
7
|
+
@output = StringIO.new
|
8
|
+
@it = Formatter.new(@output)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should start in the :initial state" do
|
12
|
+
@it.state.should == :initial
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
def output_string
|
17
|
+
@output.rewind
|
18
|
+
@output.string
|
19
|
+
end
|
20
|
+
|
21
|
+
context "which has been started" do
|
22
|
+
before :each do
|
23
|
+
@it.start!
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should be in the :code state" do
|
27
|
+
@it.state.should == :code
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should ignore initial lines" do
|
31
|
+
@it.add_line!("TEST")
|
32
|
+
output_string.should == ""
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
context "after the :TEXT: keyword" do
|
38
|
+
before :each do
|
39
|
+
@it.start!
|
40
|
+
@it.add_line!(":TEXT:\n")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should be in the :paragraph state" do
|
44
|
+
@it.state.should == :paragraph
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should start outputting text" do
|
48
|
+
@it.add_line!("check 1 2 3\n")
|
49
|
+
@it.add_line!("\n")
|
50
|
+
output_string.should == "check 1 2 3\n"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "after the :TEXT: keyword followed by :CUT:" do
|
55
|
+
before :each do
|
56
|
+
@it.start!
|
57
|
+
@it.add_line!(":TEXT:\n")
|
58
|
+
@it.add_line!(":CUT:\n")
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should be in the :code state" do
|
62
|
+
@it.state.should == :code
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should stop outputting text" do
|
66
|
+
@it.add_line!("check 1 2 3\n")
|
67
|
+
output_string.should == ""
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "after a :TEXT: keyword prefixed with '#'" do
|
72
|
+
before :each do
|
73
|
+
@it.start!
|
74
|
+
@it.add_line!("# :TEXT:\n")
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should be in the :paragraph state" do
|
78
|
+
@it.state.should == :paragraph
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should have a comment prefix of '#'" do
|
82
|
+
@it.comment_prefix.should == '#'
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should strip '#' prefixes from text" do
|
86
|
+
@it.add_line!("# Line 1\n")
|
87
|
+
@it.add_line!(" ## Line 2\n")
|
88
|
+
@it.add_line!("\n")
|
89
|
+
output_string.should == "Line 1 Line 2\n"
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should ignore uncommented lines" do
|
93
|
+
@it.add_line!("; Not a comment #")
|
94
|
+
output_string.should == ""
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should ignore blank lines" do
|
98
|
+
@it.add_line!(" \t\n")
|
99
|
+
output_string.should == ""
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should ignore commented blank lines" do
|
103
|
+
@it.add_line!("# \t\n")
|
104
|
+
output_string.should == ""
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "after a :TEXT: keyword prefixed with ';'" do
|
109
|
+
before :each do
|
110
|
+
@it.start!
|
111
|
+
@it.add_line!(" ; :TEXT:\n")
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should have a comment prefix of ';'" do
|
115
|
+
@it.comment_prefix.should == ';'
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should strip ';' prefixes from text" do
|
119
|
+
@it.add_line!("; Line 1\n")
|
120
|
+
@it.add_line!(" ;; Line 2\n")
|
121
|
+
@it.add_line!(";\n")
|
122
|
+
output_string.should == "Line 1 Line 2\n"
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should ignore lines with '#' prefixes" do
|
126
|
+
@it.add_line!("# Line 1\n")
|
127
|
+
output_string.should == ""
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context "in a text section " do
|
132
|
+
before :each do
|
133
|
+
@it.start!
|
134
|
+
@it.add_line!("# :TEXT:\n")
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should join adjacent lines" do
|
138
|
+
@it.add_line!("# foo\n")
|
139
|
+
@it.add_line!("# bar\n")
|
140
|
+
@it.add_line!("\n")
|
141
|
+
output_string.should == "foo bar\n"
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context "in a linebreak section" do
|
146
|
+
before :each do
|
147
|
+
@it.start!
|
148
|
+
@it.add_line!("# :TEXT:\n")
|
149
|
+
@it.add_line!("# P1\n")
|
150
|
+
@it.add_line!("\n")
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should finish the section with a double newline" do
|
154
|
+
@it.add_line!("# P2\n")
|
155
|
+
@it.add_line!("\n")
|
156
|
+
output_string.should == "P1\n\nP2\n"
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.expand_path(
|
2
|
+
File.join(File.dirname(__FILE__), %w[.. .. lib germinate]))
|
3
|
+
|
4
|
+
module Germinate
|
5
|
+
describe Hunk, "(attributes)" do
|
6
|
+
Germinate::SharedStyleAttributes.fattrs.each do |attribute|
|
7
|
+
it "should support the #{attribute} style attribute" do
|
8
|
+
@it = Germinate::Hunk.new([], attribute => "test")
|
9
|
+
@it.send(attribute).should == "test"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should pass the #{attribute} attribute on to duplicates" do
|
13
|
+
@it = Germinate::Hunk.new([], attribute => "test")
|
14
|
+
@it.dup.send(attribute).should == "test"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should pass the #{attribute} attribute on to clones" do
|
18
|
+
@it = Germinate::Hunk.new([], attribute => "test")
|
19
|
+
@it.clone.send(attribute).should == "test"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should pass the #{attribute} attribute on to slices" do
|
23
|
+
@it = Germinate::Hunk.new([], attribute => "test")
|
24
|
+
@it[0..-1].send(attribute).should == "test"
|
25
|
+
@it.slice(0..-1).send(attribute).should == "test"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should copy #{attribute} from given template" do
|
29
|
+
@template = Object.new
|
30
|
+
@template.extend SharedStyleAttributes
|
31
|
+
@template.send(attribute, "test")
|
32
|
+
@it = Germinate::Hunk.new([], @template)
|
33
|
+
@it.send(attribute).should == "test"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe Hunk do
|
39
|
+
before :each do
|
40
|
+
@it = Hunk.new
|
41
|
+
end
|
42
|
+
|
43
|
+
context "with an insertion" do
|
44
|
+
before :each do
|
45
|
+
@nested_hunk = stub("Nested Hunk")
|
46
|
+
@insertion = stub("Insertion", :resolve => @nested_hunk)
|
47
|
+
@it << "line 1"
|
48
|
+
@it << @insertion
|
49
|
+
@it << "line 2"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should be able to resolve the insertion" do
|
53
|
+
@it.resolve_insertions.should == [
|
54
|
+
"line 1",
|
55
|
+
@nested_hunk,
|
56
|
+
"line 2"
|
57
|
+
]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "with some content" do
|
62
|
+
before :each do
|
63
|
+
@it.push("foo", "bar", "foo", "baz")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should be able to find indexes of elements matching a regex" do
|
67
|
+
@it.index_matching(/ba/).should == 1
|
68
|
+
@it.index_matching(/fo/).should == 0
|
69
|
+
@it.index_matching(/fo/, 1).should == 2
|
70
|
+
@it.index_matching(/fo/, 2).should == 2
|
71
|
+
@it.index_matching(/fo/, 3).should be_nil
|
72
|
+
@it.index_matching(/za/, 3).should be_nil
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path(
|
2
|
+
File.join(File.dirname(__FILE__), %w[.. .. lib germinate]))
|
3
|
+
|
4
|
+
module Germinate
|
5
|
+
describe ImplicitInsertion do
|
6
|
+
before :each do
|
7
|
+
@hunk = stub("Hunk")
|
8
|
+
@library = stub("Library")
|
9
|
+
@selector = stub("Selector")
|
10
|
+
@it = Germinate::ImplicitInsertion.new(@selector, @library)
|
11
|
+
end
|
12
|
+
|
13
|
+
context "when the librarian can find the selection" do
|
14
|
+
before :each do
|
15
|
+
@library.stub!(:[]).and_return(@hunk)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should resolve to the hunk the librarian returns" do
|
19
|
+
@it.resolve.should equal(@hunk)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when the librarian cannot find the selection" do
|
24
|
+
before :each do
|
25
|
+
@library.stub!(:[]).and_raise(IndexError.new)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should resolve to a null hunk" do
|
29
|
+
@it.resolve.should be_a_kind_of(NullHunk)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path(
|
2
|
+
File.join(File.dirname(__FILE__), %w[.. .. lib germinate]))
|
3
|
+
|
4
|
+
module Germinate
|
5
|
+
describe Insertion, "given a library and a selector" do
|
6
|
+
before :each do
|
7
|
+
@hunk = stub("Hunk")
|
8
|
+
@library = stub("Library", :[] => @hunk)
|
9
|
+
@selector = stub("Selector")
|
10
|
+
@it = Germinate::Insertion.new(@selector, @library)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should use the library to resolve itself" do
|
14
|
+
@library.should_receive(:[]).with(@selector).and_return(@hunk)
|
15
|
+
@it.resolve.should == @hunk
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,336 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'arrayfields'
|
3
|
+
|
4
|
+
require File.expand_path(
|
5
|
+
File.join(File.dirname(__FILE__), %w[.. .. lib germinate]))
|
6
|
+
|
7
|
+
|
8
|
+
module Germinate
|
9
|
+
describe Librarian do
|
10
|
+
before :each do
|
11
|
+
@it = Librarian.new
|
12
|
+
end
|
13
|
+
|
14
|
+
context "by default" do
|
15
|
+
it "should not have a comment prefix" do
|
16
|
+
@it.comment_prefix.should == nil
|
17
|
+
@it.comment_prefix_known?.should be_false
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should not have code brackets" do
|
21
|
+
@it.code_open_bracket.should be_nil
|
22
|
+
@it.code_close_bracket.should be_nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Germinate::SharedStyleAttributes.fattrs.each do |attribute|
|
27
|
+
it "should pass the #{attribute} attribute on to text hunks" do
|
28
|
+
@it.send(attribute, "#{attribute}_test")
|
29
|
+
@it.add_text!("first", "hello")
|
30
|
+
@it.section("first").send(attribute).should == "#{attribute}_test"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should pass the #{attribute} attribute on to code hunks" do
|
34
|
+
@it.send(attribute, "#{attribute}_test")
|
35
|
+
@it.add_code!("first", "hello")
|
36
|
+
@it.sample("first").send(attribute).should == "#{attribute}_test"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "given a comment prefix" do
|
41
|
+
before :each do
|
42
|
+
@it.comment_prefix = "||"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should remember the comment prefix" do
|
46
|
+
@it.comment_prefix.should == "||"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should know it has a comment prefix" do
|
50
|
+
@it.comment_prefix_known?.should be_true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "given code brackets" do
|
55
|
+
before :each do
|
56
|
+
@it.code_open_bracket = "{"
|
57
|
+
@it.code_close_bracket = "}"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should remember the open bracket" do
|
61
|
+
@it.code_open_bracket.should == "{"
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should remember the close bracket" do
|
65
|
+
@it.code_close_bracket.should == "}"
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
context "given custom code attributes" do
|
71
|
+
before :each do
|
72
|
+
@it.set_code_attributes!(
|
73
|
+
"sample1",
|
74
|
+
:code_open_bracket => "<<",
|
75
|
+
:code_close_bracket => ">>")
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should create the sample (if needed) and assign the attributes" do
|
79
|
+
@it.sample("sample1").code_open_bracket.should == "<<"
|
80
|
+
@it.sample("sample1").code_close_bracket.should == ">>"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "given an insertion in my_section with selector @my_selector" do
|
85
|
+
before :each do
|
86
|
+
@it.add_insertion!("my_section", "@my_selector")
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should add an Insertion to the named section" do
|
90
|
+
@it.section("my_section").last.should be_a_kind_of(Insertion)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should give the insertion the selector @my_selector" do
|
94
|
+
@it.section("my_section").last.selector.to_s.should == "@my_selector"
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should give the insertion a reference to the library" do
|
98
|
+
@it.section("my_section").last.library.should == @it
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "given a process to file" do
|
103
|
+
before :each do
|
104
|
+
@it.add_process!("myproc", "cowsay")
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should make the process available as a Process object" do
|
108
|
+
@it.process("myproc").should be_a_kind_of(Germinate::Process)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should store the process name" do
|
112
|
+
@it.process("myproc").name.should == "myproc"
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should store the process command" do
|
116
|
+
@it.process("myproc").command.should == "cowsay"
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should include the process when listing known processes" do
|
120
|
+
@it.process_names.should include("myproc")
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context "given a code sample and some processes" do
|
125
|
+
before :each do
|
126
|
+
@output_a = ["line 1a", "line 2a"]
|
127
|
+
@output_b = ["line 1b", "line 2b"]
|
128
|
+
@process_a = stub("Process A", :call => @output_a)
|
129
|
+
@process_b = stub("Process B", :call => @output_b)
|
130
|
+
Germinate::Process.stub!(:new).
|
131
|
+
with("foo", "aaa").
|
132
|
+
and_return(@process_a)
|
133
|
+
Germinate::Process.stub!(:new).
|
134
|
+
with("bar", "bbb").
|
135
|
+
and_return(@process_b)
|
136
|
+
|
137
|
+
@it.add_code!("A", "line 1")
|
138
|
+
@it.add_code!("A", "line 2")
|
139
|
+
@it.add_process!("foo", "aaa")
|
140
|
+
@it.add_process!("bar", "bbb")
|
141
|
+
end
|
142
|
+
|
143
|
+
context "when the processes are included in a selection" do
|
144
|
+
before :each do
|
145
|
+
@selector = "@A|foo|bar"
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should call the processes on the selected text" do
|
149
|
+
@process_a.should_receive(:call).with(["line 1", "line 2"]).
|
150
|
+
and_return(@output_a)
|
151
|
+
@process_b.should_receive(:call).with(@output_a).
|
152
|
+
and_return(@output_b)
|
153
|
+
|
154
|
+
@it[@selector].should == ["line 1b", "line 2b"]
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
context "given an assortment of lines" do
|
160
|
+
before :each do
|
161
|
+
@it.add_front_matter!("FM 1")
|
162
|
+
@it.add_front_matter!("FM 2")
|
163
|
+
@it.add_control!("CONTROL 1")
|
164
|
+
@it.add_text!("SECTION1", "TEXT 1")
|
165
|
+
@it.add_text!("SECTION1", "TEXT 2")
|
166
|
+
@it.add_control!("CONTROL 2")
|
167
|
+
@it.add_code!("SECTION1", "CODE 1")
|
168
|
+
@it.add_control!("CONTROL 3")
|
169
|
+
@it.add_text!("SECTION2", "TEXT 3")
|
170
|
+
@it.add_text!("SECTION2", "TEXT 4")
|
171
|
+
@it.add_code!("SECTION2", "CODE 2")
|
172
|
+
@it.add_code!("SECTION2", "CODE 2l2")
|
173
|
+
@it.add_code!("SECTION2", "CODE 2l3")
|
174
|
+
@it.add_code!("SECTION2", "CODE 2l4")
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should be able to retrieve all the lines in order" do
|
178
|
+
@it.lines.should == [
|
179
|
+
"FM 1",
|
180
|
+
"FM 2",
|
181
|
+
"CONTROL 1",
|
182
|
+
"TEXT 1",
|
183
|
+
"TEXT 2",
|
184
|
+
"CONTROL 2",
|
185
|
+
"CODE 1",
|
186
|
+
"CONTROL 3",
|
187
|
+
"TEXT 3",
|
188
|
+
"TEXT 4",
|
189
|
+
"CODE 2",
|
190
|
+
"CODE 2l2",
|
191
|
+
"CODE 2l3",
|
192
|
+
"CODE 2l4",
|
193
|
+
]
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should be able to retrieve text lines" do
|
197
|
+
@it.text_lines.should == [
|
198
|
+
"TEXT 1",
|
199
|
+
"TEXT 2",
|
200
|
+
"TEXT 3",
|
201
|
+
"TEXT 4"
|
202
|
+
]
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should be able to retrieve code lines" do
|
206
|
+
@it.code_lines.should == [
|
207
|
+
"CODE 1",
|
208
|
+
"CODE 2",
|
209
|
+
"CODE 2l2",
|
210
|
+
"CODE 2l3",
|
211
|
+
"CODE 2l4",
|
212
|
+
]
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should be able to retrieve front matter" do
|
216
|
+
@it.front_matter_lines.should == [
|
217
|
+
"FM 1",
|
218
|
+
"FM 2",
|
219
|
+
]
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should be able to retrieve text by section" do
|
223
|
+
@it.section("SECTION1").should == [
|
224
|
+
"TEXT 1",
|
225
|
+
"TEXT 2"
|
226
|
+
]
|
227
|
+
@it.section("SECTION2").should == [
|
228
|
+
"TEXT 3",
|
229
|
+
"TEXT 4"
|
230
|
+
]
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should be able to retrieve code by sample name" do
|
234
|
+
@it.sample("SECTION1").should == [
|
235
|
+
"CODE 1"
|
236
|
+
]
|
237
|
+
@it.sample("SECTION2").should == [
|
238
|
+
"CODE 2",
|
239
|
+
"CODE 2l2",
|
240
|
+
"CODE 2l3",
|
241
|
+
"CODE 2l4",
|
242
|
+
]
|
243
|
+
end
|
244
|
+
|
245
|
+
it "should be able to return a list of section names" do
|
246
|
+
@it.section_names.should == [
|
247
|
+
"SECTION1",
|
248
|
+
"SECTION2"
|
249
|
+
]
|
250
|
+
end
|
251
|
+
|
252
|
+
it "should be able to return a list of sample names" do
|
253
|
+
@it.sample_names.should == [
|
254
|
+
"SECTION1",
|
255
|
+
"SECTION2"
|
256
|
+
]
|
257
|
+
end
|
258
|
+
|
259
|
+
it "should be able to tell if a section exists" do
|
260
|
+
@it.should have_section("SECTION1")
|
261
|
+
@it.should_not have_section("SECTION5")
|
262
|
+
end
|
263
|
+
|
264
|
+
it "should be able to tell if a sample exists" do
|
265
|
+
@it.should have_sample("SECTION1")
|
266
|
+
@it.should_not have_sample("SECTION5")
|
267
|
+
end
|
268
|
+
|
269
|
+
it "should be able to retrieve lines using a selector" do
|
270
|
+
@it[Selector.new("@SECTION1", nil)].should == ["CODE 1"]
|
271
|
+
@it["@SECTION1"].should == ["CODE 1"]
|
272
|
+
end
|
273
|
+
|
274
|
+
SELECTOR_EXAMPLES = [
|
275
|
+
# Selector Expected Excerpt Expected Type
|
276
|
+
[ "@SECTION1", ["CODE 1"], CodeHunk ],
|
277
|
+
[ "@SECTION2:1", ["CODE 2"], CodeHunk ],
|
278
|
+
[ "@SECTION2:2..3", ["CODE 2l2", "CODE 2l3"], CodeHunk ],
|
279
|
+
[ "@SECTION2:2,2", ["CODE 2l2", "CODE 2l3"], CodeHunk ],
|
280
|
+
[ "@SECTION2:/l2/../l3/", ["CODE 2l2", "CODE 2l3"], CodeHunk ],
|
281
|
+
[ "@SECTION2:/l2/.../l3/", ["CODE 2l2"], CodeHunk ],
|
282
|
+
[ "@SECTION2:/2/,3", [
|
283
|
+
"CODE 2",
|
284
|
+
"CODE 2l2",
|
285
|
+
"CODE 2l3"], CodeHunk ],
|
286
|
+
[ "@SECTION2:/l2/..-1", [
|
287
|
+
"CODE 2l2",
|
288
|
+
"CODE 2l3",
|
289
|
+
"CODE 2l4"], CodeHunk ],
|
290
|
+
[ "$CODE", [
|
291
|
+
"CODE 1",
|
292
|
+
"CODE 2",
|
293
|
+
"CODE 2l2",
|
294
|
+
"CODE 2l3",
|
295
|
+
"CODE 2l4", ], CodeHunk
|
296
|
+
],
|
297
|
+
[ "$SOURCE", [
|
298
|
+
"FM 1",
|
299
|
+
"FM 2",
|
300
|
+
"CONTROL 1",
|
301
|
+
"TEXT 1",
|
302
|
+
"TEXT 2",
|
303
|
+
"CONTROL 2",
|
304
|
+
"CODE 1",
|
305
|
+
"CONTROL 3",
|
306
|
+
"TEXT 3",
|
307
|
+
"TEXT 4",
|
308
|
+
"CODE 2",
|
309
|
+
"CODE 2l2",
|
310
|
+
"CODE 2l3",
|
311
|
+
"CODE 2l4",
|
312
|
+
], CodeHunk
|
313
|
+
],
|
314
|
+
[ "$TEXT", [
|
315
|
+
"TEXT 1",
|
316
|
+
"TEXT 2",
|
317
|
+
"TEXT 3",
|
318
|
+
"TEXT 4"
|
319
|
+
], CodeHunk
|
320
|
+
],
|
321
|
+
|
322
|
+
]
|
323
|
+
|
324
|
+
SELECTOR_EXAMPLES.each do |example|
|
325
|
+
example.fields = [:selector, :hunk, :type]
|
326
|
+
it "should be able to locate #{example[:selector]}" do
|
327
|
+
@it[example[:selector]].should == example[:hunk]
|
328
|
+
end
|
329
|
+
|
330
|
+
it "should return #{example[:selector]} as #{example[:type]}" do
|
331
|
+
@it[example[:selector]].should be_a_kind_of(example[:type])
|
332
|
+
end
|
333
|
+
end
|
334
|
+
end
|
335
|
+
end
|
336
|
+
end
|