unified_matchers 0.1.5.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.
data/AUTHORS ADDED
@@ -0,0 +1,8 @@
1
+ ---
2
+ UnifiedMatchers was written by and with the assistance of:
3
+
4
+ - Nicolas Pouillard <nicolas.pouillard@gmail.com>:
5
+ - Initial design, release manager.
6
+
7
+ - Gaëlle Champarnaud <gaelle.champarnaud@gmail.com>:
8
+ - Development and tests.
data/ChangeLog ADDED
@@ -0,0 +1,233 @@
1
+ 2006-04-30 Gaelle Champarnaud <gallooo@gmail.com>
2
+
3
+ Update to Rslide.
4
+
5
+ * doc/slides.html: Regenerate.
6
+ * doc/documentation.rslide: Make shell_command a class.
7
+
8
+ 2006-04-30 Gaelle Champarnaud <gallooo@gmail.com>
9
+
10
+ Documentation and some improvments.
11
+
12
+ * lib/unified_matchers/matcher_result.rb: Change error message.
13
+ * lib/unified_matchers/matcher_results.rb: New method: first.
14
+ * lib/unified_matchers/unified_matcher.rb,
15
+ * lib/unified_matchers/diff_matcher.rb,
16
+ * lib/unified_matchers/lcs_diff_matcher.rb: Documentation.
17
+ * lib/unified_matchers/gnu_diff_matcher.rb: Documentation, update
18
+ to ObjectiveCommand.
19
+
20
+ 2006-04-30 Gaelle Champarnaud <gallooo@gmail.com>
21
+
22
+ Documentation of UnifiedMatchers.
23
+
24
+ * doc: New.
25
+ * doc/slides.html: New.
26
+ * doc/documentation.rslide: New.
27
+
28
+ 2006-04-03 Gaelle Champarnaud <gallooo@gmail.com>
29
+
30
+ Lazy creation of messages.
31
+
32
+ * lib/unified_matchers/matcher_result.rb: Compute messages.
33
+ * lib/unified_matchers/unified_matcher.rb: Defer messages
34
+ computation.
35
+ * lib/unified_matchers/lcs_diff_matcher.rb: Layout.
36
+
37
+ 2006-04-02 Gaelle Champarnaud <gallooo@gmail.com>
38
+
39
+ Improve messages.
40
+
41
+ * lib/unified_matchers/unified_matcher.rb: Handle messages of
42
+ finals.
43
+ * lib/unified_matchers/assertions.rb: Two new assertions.
44
+ * example/check-commands.rb: Make the output YAML compliant.
45
+
46
+ * lib/unified_matchers/equality_based_matcher.rb,
47
+ * lib/unified_matchers/stream_matcher.rb,
48
+ * lib/unified_matchers/gnu_diff_matcher.rb,
49
+ * lib/unified_matchers/strict_equality_based_matcher.rb,
50
+ * lib/unified_matchers/case_equality_based_matcher.rb,
51
+ * lib/unified_matchers/lcs_diff_matcher.rb: Add template messages
52
+ to rules and finals.
53
+
54
+ 2006-04-02 Gaelle Champarnaud <gallooo@gmail.com>
55
+
56
+ Make the OCmd interaction example works.
57
+
58
+ * test/fixtures/birds.txt: New.
59
+ * test/fixtures/pluralizer: New.
60
+ * test/fixtures/bird.txt: New.
61
+ * example/check-commands.rb: Update.
62
+
63
+ 2006-04-02 Gaelle Champarnaud <gallooo@gmail.com>
64
+
65
+ Improve the message system.
66
+
67
+ * lib/unified_matchers/stream_matcher.rb:
68
+ Update message templates.
69
+ * lib/unified_matchers/matcher_result.rb,
70
+ * lib/unified_matchers/matcher_results.rb,
71
+ * lib/unified_matchers/unified_matcher.rb,
72
+ * lib/unified_matchers/assertions.rb: Handle messages.
73
+
74
+ 2006-04-02 Gaelle Champarnaud <gallooo@gmail.com>
75
+
76
+ Change the matcher result and make some improvments.
77
+
78
+ * lib/unified_matchers/matcher_result_composite.rb: Rename to ...
79
+ * lib/unified_matchers/matcher_results.rb: ... this and adapt.
80
+ * lib/unified_matchers/unified_matcher.rb: Produce now a
81
+ MatcherResults and prevent from a possibly infinite rule
82
+ activation.
83
+ * lib/unified_matchers/lcs_diff_matcher.rb: Update to
84
+ MatcherResults.
85
+
86
+ * lib/unified_matchers/stream_matcher.rb: Add a final rule and
87
+ test it. Start the message handling.
88
+ * lib/unified_matchers/matcher_result.rb: Start the message
89
+ handling and improve an error message.
90
+ * lib/unified_matchers.rb: Make UM a shortcut of UnifiedMatchers.
91
+
92
+ 2006-03-31 Gaelle Champarnaud <gallooo@gmail.com>
93
+
94
+ A new optional argument in a final block.
95
+
96
+ * lib/unified_matchers/unified_matcher.rb: Fix some bugs,
97
+ introduce the matcher as an optional third argument in a final
98
+ block.
99
+ * lib/unified_matchers/case_equality_based_matcher.rb: Test it.
100
+
101
+ 2006-03-24 Gaelle Champarnaud <gallooo@gmail.com>
102
+
103
+ Introduce a new rule system, clearer and more powerful.
104
+
105
+ * lib/unified_matchers/unified_matcher.rb: New implementation.
106
+
107
+ * lib/unified_matchers/equality_based_matcher.rb,
108
+ * lib/unified_matchers/case_equality_based_matcher.rb,
109
+ * lib/unified_matchers/strict_equality_based_matcher.rb:
110
+ Replace 'with' by 'final'.
111
+
112
+ * lib/unified_matchers/stream_matcher.rb:
113
+ Replace 'with' by 'rule' or 'final' and improve a test.
114
+ * lib/unified_matchers/gnu_diff_matcher.rb:
115
+ Replace 'with' by 'rule' or 'final' and use 'delete_final'.
116
+ * lib/unified_matchers/lcs_diff_matcher.rb: Replace 'with' by
117
+ 'rule' or 'final', use 'delete_final' and 'redefine_rule', add a test.
118
+
119
+ * lib/unified_matchers/matcher_result.rb,
120
+ * lib/unified_matchers/assertions.rb: Trailing white spaces.
121
+
122
+ 2006-03-24 Gaelle Champarnaud <gallooo@gmail.com>
123
+
124
+ Add a composite class for matcher results.
125
+
126
+ * lib/unified_matchers/matcher_result_composite.rb: New.
127
+
128
+ 2006-03-12 Gaelle Champarnaud <gallooo@gmail.com>
129
+
130
+ Add a class to handle a matcher result.
131
+
132
+ * lib/unified_matchers/matcher_result.rb: New.
133
+ * lib/unified_matchers/equality_based_matcher.rb,
134
+ * lib/unified_matchers/strict_equality_based_matcher.rb,
135
+ * lib/unified_matchers/case_equality_based_matcher.rb: Update
136
+ tests.
137
+ * lib/unified_matchers/stream_matcher.rb,
138
+ * lib/unified_matchers/gnu_diff_matcher.rb,
139
+ * lib/unified_matchers/lcs_diff_matcher.rb: Update tests and
140
+ values returned by the matchers.
141
+ * lib/unified_matchers/unified_matcher.rb: Change the result of
142
+ the method [].
143
+ * lib/unified_matchers/assertions.rb: Make two new assertions.
144
+
145
+ 2006-03-12 Gaelle Champarnaud <gallooo@gmail.com>
146
+
147
+ Make all the tests pass.
148
+
149
+ * test/unit.yml: Update.
150
+ * lib/unified_matchers/lcs_diff_matcher.rb,
151
+ * lib/unified_matchers/gnu_diff_matcher.rb: Make the names
152
+ consistent.
153
+
154
+ 2006-03-11 Gaelle Champarnaud <gallooo@gmail.com>
155
+
156
+ Minor improvments.
157
+
158
+ * lib/unified_matchers/stream_matcher.rb: Revert the previous
159
+ * change (use match).
160
+ * lib/unified_matchers/gnu_diff_matcher.rb: Improve the Object
161
+ * rule and improve the tests.
162
+ * lib/unified_matchers/unified_matcher.rb: Handle an error case.
163
+ * lib/unified_matchers/lcs_diff_matcher.rb: Add a comment.
164
+ * lib/unified_matchers.rb: Remove a useless line.
165
+
166
+ 2005-10-08 Nicolas Pouillard <ertai@lrde.epita.fr>
167
+
168
+ A simple implementation.
169
+
170
+ * lib/unified_matchers/unified_matcher.rb: This implementation is not
171
+ yet optimizied but respect the previous contract.
172
+
173
+ 2005-10-08 Nicolas Pouillard <ertai@lrde.epita.fr>
174
+
175
+ Improve the contract.
176
+
177
+ * lib/unified_matchers/stream_matcher.rb: Returns a boolean,
178
+ handles StringIO.
179
+ * lib/unified_matchers/gnu_diff_matcher.rb: Makes it really pathname
180
+ based and provides some conversions.
181
+ * lib/unified_matchers/case_equality_based_matcher.rb: .
182
+ * lib/unified_matchers/lcs_diff_matcher.rb: Fix an assertion.
183
+ * lib/unified_matchers.rb: Requires 'diff/lcs' if available, add
184
+ Unified_matchers.{dir,fixtures} class attributes.
185
+ * test/fixtures/my.file: New.
186
+
187
+ 2005-10-08 Nicolas Pouillard <ertai@lrde.epita.fr>
188
+
189
+ More tests.
190
+
191
+ * lib/unified_matchers/stream_matcher.rb: Add tests with a dynamically
192
+ added class.
193
+
194
+ 2005-10-07 Nicolas Pouillard <ertai@lrde.epita.fr>
195
+
196
+ Commit the first contract.
197
+
198
+ * test/unit.yml: New.
199
+ * test/check.yml: New.
200
+ * lib/unified_matchers: New.
201
+ * lib/unified_matchers.rb: New. The main module.
202
+ * lib/unified_matchers/unified_matcher.rb: New.
203
+ Abstract matcher to fix.
204
+ * lib/unified_matchers/strict_equality_based_matcher.rb: New.
205
+ Matchers based on Object#equal?.
206
+ * lib/unified_matchers/equality_based_matcher.rb: New. (==)
207
+ * lib/unified_matchers/case_equality_based_matcher.rb: New. (===)
208
+ * lib/unified_matchers/stream_matcher.rb: New.
209
+ * lib/unified_matchers/diff_matcher.rb: New. Abstract.
210
+ * lib/unified_matchers/gnu_diff_matcher.rb: New.
211
+ Command based diff output.
212
+ * lib/unified_matchers/lcs_diff_matcher.rb: New.
213
+ Will be a LCS::Diff based diff output.
214
+ * lib/unified_matchers/assertions.rb: New.
215
+
216
+ 2005-10-05 Nicolas Pouillard <ertai@lrde.epita.fr>
217
+
218
+ Initial checkin.
219
+
220
+ * lib: New.
221
+ * test: New.
222
+ * test/unit: New.
223
+ * test/pkg: New.
224
+ * test/functional: New.
225
+ * bin: New.
226
+ * vcs: New.
227
+ * vcs/unified_matchers_vcs.rb: New.
228
+ * Rakefile: New.
229
+ * AUTHORS: New.
230
+ * SPEC.yml: New.
231
+ * NEWS: New.
232
+ * README: New.
233
+
data/NEWS ADDED
@@ -0,0 +1,3 @@
1
+ = New 0.1, 2007-01-14:
2
+
3
+ Initial Release.
data/README ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # Author:: The Uttk Team. -*- ruby -*-
2
+ # Copyright:: Copyright (c) 2005, 2006 Uttk team. All rights reserved.
3
+ # License:: Ruby License
4
+ # Revision:: $Id$
5
+
6
+ require 'rubygems'
7
+ require_gem 'core_ex'
8
+ load 'core_ex/rakefile_base.rf'
data/SPEC.gemspec ADDED
@@ -0,0 +1,13 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{unified_matchers}
3
+ s.version = "0.1.5.0"
4
+ s.date = %q{2007-01-14}
5
+ s.summary = %q{UnifiedMatchers}
6
+ s.email = ["nicolas.pouillard@gmail.com", "gaelle.champarnaud@gmail.com"]
7
+ s.homepage = %q{http://api.feydakins.org/unified_matchers}
8
+ s.rubyforge_project = %q{unified_matchers}
9
+ s.description = %q{}
10
+ s.authors = ["Nicolas Pouillard", "Ga\303\253lle Champarnaud"]
11
+ s.files = ["lib/unified_matchers.rb", "lib/unified_matchers/assertions.rb", "lib/unified_matchers/case_equality_based_matcher.rb", "lib/unified_matchers/diff_matcher.rb", "lib/unified_matchers/equality_based_matcher.rb", "lib/unified_matchers/gnu_diff_matcher.rb", "lib/unified_matchers/helpers.rb", "lib/unified_matchers/lcs_diff_matcher.rb", "lib/unified_matchers/matcher_result.rb", "lib/unified_matchers/matcher_results.rb", "lib/unified_matchers/stream_matcher.rb", "lib/unified_matchers/strict_equality_based_matcher.rb", "lib/unified_matchers/unified_matcher.rb", "lib/unified_matchers/version_id.rb", "test/check-pkg-unified_matchers.yml", "test/check.yml", "test/fixtures", "test/functional", "test/pkg", "test/sanity", "test/sanity-suite.yml", "test/unit", "test/unit-suite.yml", "test/fixtures/bird.txt", "test/fixtures/birds.txt", "test/fixtures/my.file", "test/fixtures/pluralizer", "test/sanity/multiple-requires.yml", "test/sanity/single-requires.yml", "AUTHORS", "ChangeLog", "NEWS", "Rakefile", "README", "SPEC.gemspec", "SPEC.yml"]
12
+ s.add_dependency(%q<core_ex>, ["~> 0.6.5"])
13
+ end
data/SPEC.yml ADDED
@@ -0,0 +1,41 @@
1
+ ---
2
+ Author: The Uttk Team
3
+ License: Ruby License
4
+ Revision: '$Id$'
5
+
6
+ version: !feydakins.org,2006/version dev-ruby/unified_matchers-0.1
7
+
8
+ # XXX check also lib/unified_matchers/version_id.rb
9
+
10
+ title: UnifiedMatchers
11
+ summary: UnifiedMatchers
12
+ description: ""
13
+ homepage: http://api.feydakins.org/unified_matchers
14
+ rubyforge_project: ttk
15
+ rubyforge_sub_package_name: unified_matchers
16
+
17
+ root_test_suite: test/check-pkg-unified_matchers.yml
18
+ rdoc_dir: doc/html
19
+ tags_url: svn://svn.feydakins.org/unified_matchers/tags
20
+ trunk_url: svn://svn.feydakins.org/unified_matchers/trunk
21
+ version_id.rb: !path lib/unified_matchers/version_id.rb
22
+
23
+ rdoc_files: !filelist
24
+ - README
25
+ - AUTHORS
26
+ - NEWS
27
+ - lib/**/*.rb
28
+
29
+ pkg_files: !filelist
30
+ - lib/**/*.rb
31
+ - test/**/*
32
+ - bin/**/*
33
+ - '[A-Z]*'
34
+
35
+ dependencies:
36
+ core_ex:
37
+ gem : ~> 0.6.5
38
+ tarball: http://rubyforge.iasi.roedu.net/files/ttk/core_ex-0.6.tar.gz
39
+ vcs : svn://svn.feydakins.org/ruby_ex/trunk/core_ex
40
+
41
+ uttk_version: >= 0.3.6.1
@@ -0,0 +1,38 @@
1
+ # Copyright:: Copyright (c) 2005 Uttk Team. All rights reserved.
2
+ # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
3
+ # License:: Gnu General Public License.
4
+ # Revision:: $Id: /w/fey/um/trunk/lib/unified_matchers/assertions.rb 23258 2006-04-09T09:46:24.223538Z ertai $
5
+
6
+ module UnifiedMatchers
7
+
8
+ module Assertions
9
+
10
+ attr_accessor :matcher
11
+
12
+ def assert_success ref, my
13
+ assert_nothing_raised { @my_matcher_results = matcher[ref, my] }
14
+ assert @my_matcher_results.success?, @my_matcher_results.to_s
15
+ end
16
+
17
+ def assert_failure ref, my
18
+ assert_nothing_raised { @my_matcher_results = matcher[ref, my] }
19
+ assert @my_matcher_results.failure?, @my_matcher_results.to_s
20
+ end
21
+
22
+ def assert_data_kind_of ref, my, aClass
23
+ assert_nothing_raised { @my_matcher_results = matcher[ref, my] }
24
+ @my_matcher_results.each do |r|
25
+ assert_kind_of aClass, r.data, r.to_s
26
+ end
27
+ end
28
+
29
+ def assert_message_equal ref, my, aMessage
30
+ assert_nothing_raised { @my_matcher_results = matcher[ref, my] }
31
+ @my_matcher_results.each do |r|
32
+ assert_equal aMessage, r.message, r.name
33
+ end
34
+ end
35
+
36
+ end # module Assertions
37
+
38
+ end # module UnifiedMatchers
@@ -0,0 +1,66 @@
1
+ # Copyright:: Copyright (c) 2005 Uttk Team. All rights reserved.
2
+ # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
3
+ # License:: Gnu General Public License.
4
+ # Revision:: $Id: /w/fey/um/trunk/lib/unified_matchers/case_equality_based_matcher.rb 23258 2006-04-09T09:46:24.223538Z ertai $
5
+
6
+
7
+ module UnifiedMatchers
8
+
9
+ class CaseEqualityBasedMatcher < UnifiedMatcher
10
+ make Concrete
11
+
12
+ final(Object, Object, :message => '%ref === %my') { |ref, my| ref === my }
13
+
14
+ end # class CaseEqualityBasedMatcher
15
+
16
+
17
+
18
+ test_section __FILE__ do
19
+
20
+ class TestCaseEqualityBasedMatcher < ::Test::Unit::TestCase
21
+ include UnifiedMatchers::Assertions
22
+
23
+ def setup
24
+ self.matcher = CaseEqualityBasedMatcher.new
25
+ end
26
+
27
+ def teardown
28
+ end
29
+
30
+ def test_equality_based_matcher
31
+ assert_success 42, 42
32
+ assert_failure 43, 42
33
+ assert_success '42', '42'
34
+ assert_failure 42, '42'
35
+ assert_failure '43', '42'
36
+ assert_success Integer, 42
37
+ assert_success Float, 42.0
38
+ assert_failure Float, 42
39
+ assert_failure 42, Integer
40
+ assert_success(/42/, '42')
41
+ assert_failure(/42/, 42)
42
+ end
43
+
44
+ class MyMatcher < CaseEqualityBasedMatcher
45
+ attr_accessor :ref, :my
46
+ final(Object, Object) do |ref, my, m|
47
+ m.ref = ref
48
+ m.my = my
49
+ false
50
+ end
51
+ end
52
+
53
+ def test_final_block_with_matcher
54
+ self.matcher = MyMatcher.new
55
+ ref = /42/
56
+ my = "18"
57
+ assert_failure ref, my
58
+ assert_equal ref, matcher.ref
59
+ assert_equal my, matcher.my
60
+ end
61
+
62
+ end # class TestCaseEqualityBasedMatcher
63
+
64
+ end
65
+
66
+ end # module UnifiedMatchers
@@ -0,0 +1,21 @@
1
+ # Copyright:: Copyright (c) 2005 Uttk Team. All rights reserved.
2
+ # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
3
+ # License:: Gnu General Public License.
4
+ # Revision:: $Id: /w/fey/um/trunk/lib/unified_matchers/diff_matcher.rb 23455 2006-05-09T10:59:14.845424Z pouillar $
5
+
6
+ # @DiffMatcher@ inherits from @StreamMatcher@ and is just a common class for
7
+ # any diff-like matchers.
8
+ module UnifiedMatchers
9
+
10
+ class DiffMatcher < StreamMatcher
11
+ # FIXME make Abstract
12
+
13
+ end # class DiffMatcher
14
+
15
+
16
+
17
+ test_section __FILE__ do
18
+
19
+ end
20
+
21
+ end # module UnifiedMatchers
@@ -0,0 +1,42 @@
1
+ # Copyright:: Copyright (c) 2005 Uttk Team. All rights reserved.
2
+ # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
3
+ # License:: Gnu General Public License.
4
+ # Revision:: $Id: /w/fey/um/trunk/lib/unified_matchers/equality_based_matcher.rb 23258 2006-04-09T09:46:24.223538Z ertai $
5
+
6
+
7
+ module UnifiedMatchers
8
+
9
+ class EqualityBasedMatcher < UnifiedMatcher
10
+ make Concrete
11
+
12
+ final(Object, Object, :message => '%ref == %my') { |ref, my| ref == my }
13
+
14
+ end # class EqualityBasedMatcher
15
+
16
+
17
+
18
+ test_section __FILE__ do
19
+
20
+ class TestEqualityBasedMatcher < ::Test::Unit::TestCase
21
+ include UnifiedMatchers::Assertions
22
+
23
+ def setup
24
+ self.matcher = EqualityBasedMatcher.new
25
+ end
26
+
27
+ def teardown
28
+ end
29
+
30
+ def test_equality_based_matcher
31
+ assert_success 42, 42
32
+ assert_failure 42, 43
33
+ assert_success '42', '42'
34
+ assert_failure 42, '42'
35
+ assert_failure '42', '43'
36
+ end
37
+
38
+ end # class TestEqualityBasedMatcher
39
+
40
+ end
41
+
42
+ end # module UnifiedMatchers
@@ -0,0 +1,87 @@
1
+ # Copyright:: Copyright (c) 2005 Uttk Team. All rights reserved.
2
+ # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
3
+ # License:: Gnu General Public License.
4
+ # Revision:: $Id: /w/fey/um/trunk/lib/unified_matchers/gnu_diff_matcher.rb 23455 2006-05-09T10:59:14.845424Z pouillar $
5
+
6
+ core_ex_require 'objective_command'
7
+
8
+ # @GnuDiffMatcher@ inherits from @DiffMatcher@.
9
+ # The final rule, where @ref@ is a string, is removed,
10
+ # and an other is added which allows to compare files contents:
11
+ # it can be applied on two pathnames, and compares the files
12
+ # corresponding to the pathnames (using the command diff of GNU).
13
+ # There are also new intermediate rules, called before
14
+ # the intermediate rule @to_s@ of @StreamMatcher@:
15
+ # list do
16
+ # * if an argument is a String, it is put in a temporary file
17
+ # and the pathname of this file is returned,
18
+ # * if an argument responds to the method to_path, this method is applied.
19
+ # end
20
+ # This class contains two class attributes accessors:
21
+ # list do
22
+ # * diff: by default it is the command diff,
23
+ # * runner: by default it is a system runner.
24
+ # end
25
+ module UnifiedMatchers
26
+
27
+ class GnuDiffMatcher < DiffMatcher
28
+ make Concrete
29
+
30
+ cattr_accessor :runner, :diff
31
+ self.runner = OCmd::Runners::System.new
32
+ self.diff = 'diff'.to_ocmd
33
+
34
+ delete_final String
35
+
36
+ rule :string_to_path, String, :before => :to_s do |s|
37
+ TempPath.new.overwrite s
38
+ end
39
+ rule :to_path
40
+
41
+ final(Pathname, Pathname, :message => 'gnu_diff(%ref, %my)') do |ref, my|
42
+ cmd = diff[ref, my] + %w[ -u --label ref --label my ]
43
+ data = cmd.run(runner)
44
+ [data.status.success?, data]
45
+ end
46
+
47
+ end # class GnuDiffMatcher
48
+
49
+
50
+
51
+ test_section __FILE__ do
52
+
53
+ class TestGnuDiffMatcher < ::Test::Unit::TestCase
54
+ include UnifiedMatchers::Assertions
55
+ include OCmd::Runners::Mockable
56
+
57
+ def setup
58
+ @old_runner = GnuDiffMatcher.runner
59
+ @mock_runner = GnuDiffMatcher.runner =
60
+ OCmd::Runners::System.new.make_mock {}
61
+ self.matcher = GnuDiffMatcher.new
62
+ @my = UnifiedMatchers.fixtures/'my.file'
63
+ end
64
+
65
+ def teardown
66
+ GnuDiffMatcher.runner = @old_runner
67
+ end
68
+
69
+ def test_diff
70
+ assert_success "foo/bar\n", @my
71
+ assert_success "I'm not equal to @my.to_s", @my.to_s
72
+ assert_success(/foo/, @my)
73
+ assert_success @my.open, @my
74
+
75
+ re = /diff .* .* -u --label ref --label my/
76
+ @mock_runner.log.each do |cmd|
77
+ assert_match re, cmd.to_sh
78
+ end
79
+ assert_match @my.to_s, @mock_runner.log.first.to_sh
80
+ assert_equal 3, @mock_runner.log.size
81
+ end
82
+
83
+ end # class TestGnuDiffMatcher
84
+
85
+ end
86
+
87
+ end # module UnifiedMatchers
@@ -0,0 +1,33 @@
1
+ # Copyright:: Copyright (c) 2006 Nicolas Pouillard. All rights reserved.
2
+ # Author:: Nicolas Pouillard <nicolas.pouillard@gmail.com>.
3
+ # License:: Gnu General Public License.
4
+ # Revision:: $Id: /w/fey/um/trunk/lib/unified_matchers/helpers.rb 23238 2006-04-02T17:08:37.115292Z ertai $
5
+
6
+
7
+ module UnifiedMatchers
8
+
9
+ module Helpers
10
+
11
+ class ::Object
12
+
13
+ def inspect_for_unified_matchers
14
+ inspect
15
+ end
16
+
17
+ end # class ::Object
18
+
19
+ class ::Pathname
20
+
21
+ def inspect_for_unified_matchers
22
+ "#{to_s.inspect}.to_path"
23
+ end
24
+
25
+ end # class ::Pathname
26
+
27
+ test_section __FILE__ do
28
+
29
+ end
30
+
31
+ end # module Helpers
32
+
33
+ end # module UnifiedMatchers
@@ -0,0 +1,74 @@
1
+ # Copyright:: Copyright (c) 2005 Uttk Team. All rights reserved.
2
+ # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
3
+ # License:: Gnu General Public License.
4
+ # Revision:: $Id: /w/fey/um/trunk/lib/unified_matchers/lcs_diff_matcher.rb 23455 2006-05-09T10:59:14.845424Z pouillar $
5
+
6
+ # @LcsDiffMatcher@ inherits from @DiffMatcher@.
7
+ # The final rule, where @ref@ is a string, is removed,
8
+ # and an other is added which aims at comparing arrays:
9
+ # its arguments are two arrays, and it compares them with LCS.
10
+ # The intermediate rule @io@ is replaced by:
11
+ # if the object responds to @rewind@ and @readlines@, it is read from the beginning as a string array.
12
+ # A new intermediate rule is also defined:
13
+ # if an argument is a String, it is transformed into an array.
14
+ module UnifiedMatchers
15
+
16
+ class LcsDiffMatcher < DiffMatcher
17
+ make Concrete
18
+
19
+ delete_final String
20
+ redefine_rule(:io, :all => [ :rewind, :readlines ],
21
+ :message => '%x.{rewind ; readlines}') { rewind ; readlines }
22
+ rule(:s_to_a, String, :message => '%x.to_a') { to_a }
23
+
24
+ final(Array, Array, :message => 'Diff::LCS.diff(%ref, %my)') do |ref, my|
25
+ res = Diff::LCS.diff(ref, my)
26
+ [res.empty?, res]
27
+ end
28
+
29
+ end # class LcsDiffMatcher
30
+
31
+
32
+ test_section __FILE__ do
33
+
34
+ class TestLcsDiffMatcher < ::Test::Unit::TestCase
35
+ include UnifiedMatchers::Assertions
36
+
37
+ def setup
38
+ self.matcher = LcsDiffMatcher.new
39
+ @my = UnifiedMatchers.fixtures/'my.file'
40
+ end
41
+
42
+ def teardown
43
+ end
44
+
45
+ # All tests are protected by the following condition, uttk will skip if
46
+ # Diff::LCS is not available.
47
+ if defined? Diff::LCS
48
+ def test_lcs_diff
49
+ assert_success 42, 42
50
+ assert_success '42', '42'
51
+ assert_success @my, @my
52
+ assert_success "foo/bar\n", @my
53
+ assert_data_kind_of 'foo', 'bar', Array
54
+ assert_data_kind_of %w[ a b c d e f ], %w[ a c d h e ], Array
55
+ s = "not Diff::LCS.diff(\"foo\".to_a, 42.to_s.to_a)"
56
+ assert_message_equal 'foo', 42, s
57
+ assert_failure(/baz/, @my)
58
+ assert_success(/foo/, @my)
59
+ end
60
+ end
61
+
62
+ def test_stream_matcher
63
+ self.matcher = StreamMatcher.new
64
+ assert_not_equal(StreamMatcher.order, LcsDiffMatcher.order)
65
+ assert_not_equal(StreamMatcher.ref_triggers, LcsDiffMatcher.ref_triggers)
66
+ assert_data_kind_of 'foo', 'bar', NilClass
67
+ assert_data_kind_of @my, 'bar', NilClass
68
+ end
69
+
70
+ end # class TestLcsDiffMatcher
71
+
72
+ end
73
+
74
+ end # module UnifiedMatchers