wortsammler 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,299 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'wortsammler', 'class.Traceable.rb'))
2
+
3
+ require 'tmpdir'
4
+
5
+ describe TraceableSet do
6
+
7
+ before :all do
8
+ @set=TraceableSet.new
9
+ @second_set=TraceableSet.new
10
+ end
11
+
12
+ it "should return a blank instance" do
13
+ TraceableSet.new.class.should == TraceableSet
14
+ end
15
+
16
+ it "allows to add Traceables" do
17
+ x=Traceable.new
18
+ x.id="foo0"
19
+ x.origin="0"
20
+ @set.add(x)
21
+
22
+ @set["foo"].nil?.should == true
23
+ @set["foo0"].id.should == "foo0"
24
+ end
25
+
26
+ it "delivers the first of the duplicates" do
27
+ x=Traceable.new
28
+ x.id="xfoo"
29
+ x.origin="1"
30
+ @set.add(x)
31
+
32
+ x=Traceable.new
33
+ x.id="xfoo"
34
+ x.origin="2"
35
+ @set.add(x)
36
+ y=@set["xfoo"]
37
+
38
+
39
+ y.id.should == "xfoo"
40
+ y.class.should == Traceable
41
+ y.origin.should == "1"
42
+
43
+ x.origin="2.2"
44
+ @set["xfoo"].origin.should == "1"
45
+ end
46
+
47
+ it "advertises duplicates" do
48
+ x=Traceable.new
49
+ x.id="foo"
50
+ x.origin="1"
51
+ @set.add(x)
52
+
53
+ x=Traceable.new
54
+ x.id="bar"
55
+ x.origin="2"
56
+ @set.add(x)
57
+
58
+ x=Traceable.new
59
+ x.id="foo"
60
+ x.origin="3"
61
+ @set.add(x)
62
+
63
+ x=Traceable.new
64
+ x.id="bar"
65
+ x.origin="4"
66
+ @set.add(x)
67
+
68
+ x=Traceable.new
69
+ x.id="foobar"
70
+ x.origin="5"
71
+ @set.add(x)
72
+
73
+ @set.duplicate_ids.count.should == 3
74
+ @set.duplicate_ids[0].should == "bar"
75
+ @set.duplicate_ids[1].should == "foo"
76
+
77
+ @set.duplicate_traces[0][0].origin.should == "2"
78
+ @set.duplicate_traces[0][1].origin.should == "4"
79
+ @set.duplicate_traces[1][0].origin.should == "1"
80
+ @set.duplicate_traces[1][1].origin.should == "3"
81
+
82
+ end
83
+
84
+ it "adertises undefined traceables" do
85
+ x=Traceable.new
86
+ x.id="rs_xy_001"
87
+ x.origin="1"
88
+ x.contributes_to = ["rs_xy_002", "rs_xy_003", "rs_xy_004", "rs_xy_005"]
89
+ @set.add(x)
90
+
91
+ x=Traceable.new
92
+ x.id="rs_xy_002"
93
+ x.origin="2"
94
+ x.contributes_to = ["rs_xy_001", "rs_xy_003", "rs_xy_004", "rs_xy_005"]
95
+ @set.add(x)
96
+
97
+
98
+ undefineds = @set.undefined_ids
99
+ undefineds.count.should == 3
100
+ end
101
+
102
+ it "advertises all traceables" do
103
+ @set.all_trace_ids.should == ["bar", "foo", "foo0", "foobar", "rs_xy_001", "rs_xy_002", "xfoo"]
104
+ end
105
+
106
+ it "advertises a hash of supporting traces" do
107
+ @set.uptrace_ids["rs_xy_001"].should == ["rs_xy_002"]
108
+ end
109
+
110
+ it "advertises traceable ids of a particular category" do
111
+ x=Traceable.new
112
+ x.id="rs_spec_000"
113
+ x.origin="1"
114
+ x.category=:spec_item
115
+ @set.add(x)
116
+
117
+ x=Traceable.new
118
+ x.id="rs_spec_001"
119
+ x.origin="2"
120
+ x.category=:spec_item
121
+ @set.add(x)
122
+
123
+ @set.all_trace_ids(:spec_item).should == ["rs_spec_000", "rs_spec_001"]
124
+ end
125
+
126
+ it "advertises ttraceables of a particular category" do
127
+ @set.all_traces(:spec_item).first.id.should == "rs_spec_000"
128
+ end
129
+
130
+ it "merges traceables" do
131
+ x=Traceable.new
132
+ x.id="rs_merge_001"
133
+ x.origin="2"
134
+ @second_set.add(x)
135
+
136
+ x=Traceable.new
137
+ x.id="rs_merge_002"
138
+ x.origin="2"
139
+ x.category=:spec_item
140
+ @second_set.add(x)
141
+
142
+ x=Traceable.new
143
+ x.id="rs_merge_002"
144
+ x.origin="2"
145
+ x.category=:spec_item
146
+ @set.add(x)
147
+
148
+ @second_set.merge(@set)
149
+ wanted = ["bar", "foo", "foo0", "foobar", "rs_merge_001", "rs_merge_002", "rs_spec_000", "rs_spec_001", "rs_xy_001", "rs_xy_002", "xfoo"]
150
+ got = @second_set.all_trace_ids
151
+ dups = @second_set.duplicate_ids
152
+ @second_set.all_trace_ids.should == wanted
153
+ end
154
+
155
+ it "exposes deleted Traceables" do
156
+ x=Traceable.new
157
+ x.id="rs_deleted_001"
158
+ x.origin="2"
159
+ x.category=:spec_item
160
+ @second_set.add(x)
161
+
162
+ @set.deleted_trace_ids(@second_set).should == ["rs_deleted_001", "rs_merge_001"]
163
+ end
164
+
165
+ it "exposes added Traceables" do
166
+ x=Traceable.new
167
+ x.id="rs_added_001"
168
+ x.origin="2"
169
+ x.category=:spec_item
170
+ @set.add(x)
171
+
172
+ @set.added_trace_ids(@second_set).should == ["rs_added_001"]
173
+ end
174
+
175
+ it "exposes deleted Traceables of category" do
176
+ @set.deleted_trace_ids(@second_set, :spec_item).should == ["rs_deleted_001"]
177
+ end
178
+
179
+ it "exposes added Traceables of category" do
180
+ x=Traceable.new
181
+ @set.added_trace_ids(@second_set, :spec_item).should == ["rs_added_001"]
182
+ end
183
+
184
+ it "exploses changed traceids as array of [Traceid, levensthein, diff_as_html]" do
185
+ x=Traceable.new
186
+ x.id="rs_changed_001"
187
+ x.header_orig="this is headline"
188
+ x.body_orig="Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."
189
+ x.origin="3"
190
+ x.category=:spec_item
191
+ @set.add(x)
192
+
193
+ y=Traceable.new
194
+ y.id="rs_changed_001"
195
+ y.header_orig="this is the headline"
196
+ y.body_orig="Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sede diam nonumy diadem tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."
197
+ y.origin="4"
198
+ y.category=:spec_item
199
+ y.origin="4"
200
+ @second_set.add(y)
201
+
202
+ puts @set.changed_trace_ids(@second_set).should == [["rs_changed_001", "n/a", "<div class=\"diff\">\n <ul>\n <li class=\"unchanged\"><span></span></li>\n </ul>\n</div>\n"]]
203
+ end
204
+
205
+ it "exposes unchanged Traceables" do
206
+ @set.unchanged_trace_ids(@second_set).should == ["bar", "foo", "foo0", "foobar", "rs_merge_002", "rs_spec_000", "rs_spec_001", "rs_xy_001", "rs_xy_002", "xfoo"]
207
+ end
208
+
209
+ it "can be marshalled to a file" do
210
+ dumpfile = "#{Dir.mktmpdir}/traceable-set.dmp"
211
+
212
+ @set.dump_to_marshal(dumpfile)
213
+ @newset=TraceableSet.load_from_marshal(dumpfile)
214
+
215
+ @set.inspect.gsub(/0x[0-9a-z]+/, "x").should==@newset.inspect.gsub(/0x[0-9a-z]+/, "x")
216
+ end
217
+
218
+
219
+ it "can be dumped to a graphml file" do
220
+ GRAHPHML = "traceable-set.graphml"
221
+ myset=TraceableSet.new
222
+
223
+ t0=Traceable.new
224
+ t0.id="t0"
225
+ myset.add(t0)
226
+
227
+ t1=Traceable.new
228
+ t1.id="t1"
229
+ t1.contributes_to= ["t0"]
230
+ myset.add(t1)
231
+
232
+ t2=Traceable.new
233
+ t2.id="t2"
234
+ t2.contributes_to= ["t0"]
235
+ myset.add(t2)
236
+
237
+ t10= Traceable.new
238
+ t10.id = "t10"
239
+ t10.contributes_to = ["t1", "t2"]
240
+ myset.add(t10)
241
+
242
+ t20= Traceable.new
243
+ t20.id = "t20"
244
+ t20.contributes_to = ["t2", "t1"]
245
+ myset.add(t20)
246
+
247
+ t100 = Traceable.new
248
+ t100.id="t100"
249
+ t100.contributes_to = ["t10"]
250
+ myset.add(t100)
251
+
252
+ t200 = Traceable.new
253
+ t200.id="t200"
254
+ t200.contributes_to = ["t20"]
255
+ myset.add(t200)
256
+
257
+
258
+ observed = myset.to_graphml()
259
+ expected = File.new("#{File.dirname(__FILE__)}/test.graphml").readlines.join
260
+ observed.should==expected
261
+ nil
262
+ end
263
+
264
+
265
+ end
266
+
267
+
268
+ describe Traceable do
269
+
270
+ before :all do
271
+ @x = Traceable.new
272
+ @x.id = "id"
273
+ @x.origin = "origin"
274
+ @x.alternative_id = "alternative_id"
275
+ @x.header_plain = "header_plain"
276
+ @x.header_orig = "\\textt{header_origin}"
277
+ @x.body_plain = "body_plain"
278
+ @x.contributes_to = ["contributes_to"]
279
+ @x.trace_orig = "trace_orig"
280
+ @x.origin = "origin"
281
+ @x.category = "category"
282
+ @x.info = "info"
283
+ end
284
+
285
+
286
+ specify { @x.id.should == "id" }
287
+ specify { @x.origin.should == "origin" }
288
+ specify { @x.alternative_id.should == "alternative_id" }
289
+ specify { @x.header_plain.should == "header_plain" }
290
+ specify { @x.header_orig.should == "\\textt{header_origin}" }
291
+ specify { @x.body_plain.should == "body_plain" }
292
+ specify { @x.contributes_to.should == ["contributes_to"] }
293
+ specify { @x.trace_orig.should == "trace_orig" }
294
+ specify { @x.origin.should == "origin" }
295
+ specify { @x.category.should == "category" }
296
+ specify { @x.info.should == "info" }
297
+
298
+
299
+ end
@@ -0,0 +1,168 @@
1
+ require 'rake'
2
+ require 'tmpdir'
3
+
4
+ wortsammlerbin = "'#{File.expand_path("bin")}'"
5
+ wortsammler = "'#{File.expand_path(File.join("bin", "wortsammler"))}'"
6
+ testprojectdir = "testproject/30_Sources"
7
+
8
+ describe "Wortsammler generic issues" do
9
+
10
+ it "provides a help" do
11
+ result = `#{wortsammler} -h`
12
+ result.should include("Usage: Wortsammler [options]")
13
+ $?.success?.should==true
14
+ end
15
+
16
+ it "can create a new project folder" do
17
+ system "#{wortsammler} -n #{testprojectdir}"
18
+ $?.success?.should==true
19
+
20
+ Dir["#{testprojectdir}/**/*"].should include "#{testprojectdir}/001_Main"
21
+ end
22
+
23
+ it "does not initialize into an existing project folder" do
24
+ tempdir=Dir.mktmpdir
25
+ `#{wortsammler} -n #{tempdir}`
26
+ $?.success?.should==false
27
+ end
28
+ end
29
+
30
+ describe "Wortsammler options validator" do
31
+ it "rejects no processing" do
32
+ system "#{wortsammler} -i."
33
+ $?.success?.should==false
34
+ end
35
+
36
+ it "rejeccts inputs without outputs" do
37
+ system "#{wortsammler} -pi ." do
38
+ $?.success?.should==false
39
+ end
40
+ end
41
+ end
42
+
43
+ describe "Wortsammler beautifier features" do
44
+
45
+ it "beautifies all markdown files in a folder" do
46
+ tempdir=Dir.mktmpdir
47
+ mdtext="#this is headline\n\n lorem ipsum\n\nbla fasel"
48
+
49
+ cycles=10
50
+ cycles.times{|i|
51
+ File.open("#{tempdir}/#{i}.md", "w"){|f|f.puts mdtext}
52
+ }
53
+
54
+ system "#{wortsammler} -bi #{tempdir}"
55
+ $?.success?.should==true
56
+
57
+ cycles.times{|i|
58
+ beautified_result=File.open("#{tempdir}/#{i}.md").readlines.join
59
+ beautified_result.should include("# this is headline")
60
+ }
61
+ end
62
+
63
+
64
+ it "beautifies a single file" do
65
+ tempdir=Dir.mktmpdir
66
+ mdfile="#{tempdir}/single.md"
67
+ mdtext="#this is headline\n\n lorem ipsum\n\nbla fasel"
68
+
69
+ File.open(mdfile, "w"){|f|f.puts mdtext}
70
+ system "#{wortsammler} -bi #{mdfile}"
71
+ $?.success?.should==true
72
+
73
+ beautified_result=File.open(mdfile).readlines.join
74
+ beautified_result.should include("# this is headline")
75
+ end
76
+
77
+ it "beautifies input files in a manifest" do
78
+ FileUtils.cd("testproject/30_Sources/ZSUPP_Tools") {|d|
79
+ manifest="../ZSUPP_Manifests/sample_the-sample-document.yaml"
80
+ cmd= "#{wortsammler} -bm #{manifest}"
81
+ system cmd
82
+ }
83
+ $?.success?.should==true
84
+ end
85
+
86
+ it "claims missing input" do
87
+ system "#{wortsammler} -b"
88
+ $?.success?.should==false
89
+ end
90
+
91
+
92
+ it "claims undefined document path" do
93
+ system "#{wortsammler} -bi this-path-does-not-exist"
94
+ $?.success?.should == false
95
+ end
96
+
97
+ end
98
+
99
+ describe "Wortsammler conversion" do
100
+
101
+ it "converts a single file to output format" do
102
+ tempdir=Dir.mktmpdir
103
+ mdfile="#{tempdir}/single.md"
104
+ mdtext="#this is headline\n\n lorem ipsum\n\nbla fasel"
105
+ File.open(mdfile, "w"){|f| f.puts mdtext}
106
+ system "#{wortsammler} -pi #{mdfile} -o #{tempdir} -f latex:pdf:html:docx"
107
+ $?.success?.should==true
108
+
109
+
110
+ Dir["#{tempdir}/*"].map{|f|File.basename(f)}.should== ["single.docx",
111
+ "single.html",
112
+ "single.latex",
113
+ "single.md",
114
+ "single.pdf"
115
+ ]
116
+ end
117
+
118
+ it "converts all files within a folder output format" do
119
+ tempdir=Dir.mktmpdir
120
+ system "#{wortsammler} -pi . -o #{tempdir} -f latex:pdf:html:docx"
121
+ $?.success?.should==true
122
+
123
+
124
+ Dir["#{tempdir}/*"].map{|f|File.basename(f)}.should== ["main.docx",
125
+ "main.html",
126
+ "main.latex",
127
+ "main.pdf",
128
+ "README.docx",
129
+ "README.html",
130
+ "README.latex",
131
+ "README.pdf"]
132
+
133
+ end
134
+
135
+ it "processes a manifest" do
136
+ FileUtils.cd("testproject/30_Sources/ZSUPP_Tools") {|d|
137
+ manifest="../ZSUPP_Manifests/sample_the-sample-document.yaml"
138
+ cmd= "#{wortsammler} -pm #{manifest}"
139
+ system cmd
140
+ }
141
+ $?.success?.should==true
142
+ end
143
+
144
+ it "investigates the existence of a manifest" do
145
+ manifest="testproject/30_Sources/ZSUPP_Manifests/xxthis-path-does-not-exist.yaml"
146
+ system "#{wortsammler} -m #{manifest}"
147
+ $?.success?.should==false
148
+ end
149
+
150
+ it "extracts the traceables according to a manifest" do
151
+ manifest="testproject/30_Sources/ZSUPP_Manifests/sample_the-sample-document.yaml"
152
+ system "#{wortsammler} -cm #{manifest}"
153
+ $?.success?.should==true
154
+ end
155
+
156
+
157
+ # it "shall run the rake file in the sample document" do
158
+ # FileUtils.cd("testproject/30_Sources/ZSUPP_Tools") {|d|
159
+ # path=ENV['PATH']
160
+ # ENV['PATH']="#{wortsammlerbin}:#{path}"
161
+ # puts ENV['PATH']
162
+ # system 'wortsammler -h'
163
+ # #cmd= "rake sample"
164
+ # #system cmd
165
+ # }
166
+ # $?.success?.should==true
167
+ # end
168
+ end