knut_tools 0.1.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/lib/knut_tools.rb +45 -0
- data/lib/knut_tools/catch_output.rb +173 -0
- data/lib/knut_tools/file__END__.rb +88 -0
- data/lib/knut_tools/file_winlink.rb +52 -0
- data/lib/knut_tools/rake/gempackager.rb +551 -0
- data/lib/knut_tools/rake/testtask.rb +67 -0
- data/lib/knut_tools/required_what.rb +78 -0
- data/lib/knut_tools/yaml.rb +131 -0
- data/readme.html +63 -0
- data/readme.txt +47 -0
- data/unittest/test_file__END__.rb +77 -0
- data/unittest/test_file_winlink.rb +35 -0
- data/unittest/test_gempackager.rb +195 -0
- data/unittest/test_rake_testtask.rb +105 -0
- data/unittest/test_required_what.rb +72 -0
- data/unittest/test_yaml.rb +144 -0
- data/unittest/testdata/dummy_test.rb +3 -0
- data/unittest/testdata/hello_world.rb +8 -0
- metadata +112 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
$:.unshift('../lib') if $0 == __FILE__
|
4
|
+
require "knut_tools/file_winlink.rb"
|
5
|
+
require "knut_tools/catch_output"
|
6
|
+
|
7
|
+
|
8
|
+
class Test_shortcut < Test::Unit::TestCase
|
9
|
+
def setup()
|
10
|
+
@tmpdir = 'tmp_testdata'
|
11
|
+
@linkname = "#{@tmpdir}/link4test.lnk"
|
12
|
+
Dir.mkdir(@tmpdir) unless File.exist?(@tmpdir)
|
13
|
+
end
|
14
|
+
def teardown
|
15
|
+
File.delete(@linkname) if File.exist?(@linkname)
|
16
|
+
Dir.delete(@tmpdir)
|
17
|
+
end
|
18
|
+
#Check behaviour with unexisting files.
|
19
|
+
def test_exceptions()
|
20
|
+
assert_raise(Errno::ENOENT){mk_link( 'no_existing', 'xx.lnk') }
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_create()
|
24
|
+
|
25
|
+
#Clear old testcases.
|
26
|
+
File.delete(@linkname) if File.exist?(@linkname)
|
27
|
+
|
28
|
+
assert_equal(false, File.exist?(@linkname))
|
29
|
+
Frame_catch_output.catch_stdout{
|
30
|
+
mk_link( __FILE__, @linkname, "This is a link to #{__FILE__}")
|
31
|
+
}
|
32
|
+
assert_equal(true, File.exist?(@linkname))
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,195 @@
|
|
1
|
+
$:.unshift('../lib') if $0 == __FILE__
|
2
|
+
require 'test/unit'
|
3
|
+
require 'knut_tools/rake/gempackager.rb'
|
4
|
+
require 'knut_tools/catch_output'
|
5
|
+
|
6
|
+
class Test_Gem_packer < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_create()
|
9
|
+
gemdef = Gem_packer.new('test', '0.1.0')
|
10
|
+
assert_kind_of(Gem_packer, gemdef)
|
11
|
+
assert_kind_of(Gem::Specification, gemdef.spec)
|
12
|
+
assert_equal('0.1.0', gemdef.spec.version.to_s)
|
13
|
+
assert_equal(gemdef.version, gemdef.spec.version.to_s)
|
14
|
+
|
15
|
+
assert_raise(ArgumentError){ Gem_packer.new('test', '0.1.0', :xx=>:c)}
|
16
|
+
assert_raise(ArgumentError){ Gem_packer.new('test', '0.1.0', 1 )}
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_create_block()
|
21
|
+
gemdef = Gem_packer.new('test', '0.1.0'){|gemdef, spec|
|
22
|
+
assert_kind_of(Gem_packer, gemdef)
|
23
|
+
assert_kind_of(Gem::Specification, spec)
|
24
|
+
}
|
25
|
+
end
|
26
|
+
def test_version()
|
27
|
+
gemdef = Gem_packer.new('test_version', '0.1.0')
|
28
|
+
gemdef.versions << '0.1.0'
|
29
|
+
assert_equal('0.1.0', gemdef.spec.version.to_s)
|
30
|
+
assert_equal(gemdef.version, gemdef.spec.version.to_s)
|
31
|
+
|
32
|
+
app = Rake.application
|
33
|
+
assert_nothing_raised(){ app["test_version:check_version"].invoke }
|
34
|
+
|
35
|
+
#force a version error
|
36
|
+
gemdef.spec.version = '1.0.0'
|
37
|
+
app["test_version:check_version"].reenable
|
38
|
+
assert_raise(Gem_packer::VersionError){ app["test_version:check_version"].invoke }
|
39
|
+
|
40
|
+
#
|
41
|
+
gemdef = Gem_packer.new('test_version2', '0.1.0')
|
42
|
+
gemdef.versions << '0.1.1' #Assignment must be done before task is called
|
43
|
+
assert_equal('0.1.0', gemdef.spec.version.to_s)
|
44
|
+
assert_equal(gemdef.version, gemdef.spec.version.to_s)
|
45
|
+
assert_raise(Gem_packer::VersionError){ app["test_version2:check_version"].invoke }
|
46
|
+
|
47
|
+
#~ puts `call rake -f my_rake4gem.rb -T`
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_tasks_generell()
|
51
|
+
app = Rake.application
|
52
|
+
assert_kind_of(Rake::Task, app['default'])
|
53
|
+
assert_kind_of(Rake::Task, app['check_version'])
|
54
|
+
|
55
|
+
assert_kind_of(Array, app['check_version'].prerequisites)
|
56
|
+
|
57
|
+
end
|
58
|
+
def test_tasks()
|
59
|
+
|
60
|
+
app = Rake.application
|
61
|
+
test_name = 'test_tasks' #test gem for this test. Must be uniq for all tests
|
62
|
+
tasks_before = app.tasks #get previous task list
|
63
|
+
|
64
|
+
#No test_tasks exist in advance
|
65
|
+
assert_raise(RuntimeError){app[test_name]}
|
66
|
+
Gem_packer::TASKLIST.each{|task|
|
67
|
+
assert_raise(RuntimeError){app["#{test_name}:#{task}"]}
|
68
|
+
}
|
69
|
+
|
70
|
+
#Build new action -> new tasks
|
71
|
+
gemdef = Gem_packer.new(test_name, '0.1.0')
|
72
|
+
|
73
|
+
#test_tasks exist after gem-definition
|
74
|
+
assert_nothing_raised(RuntimeError){app[test_name]}
|
75
|
+
assert_kind_of(Rake::Task, app[test_name])
|
76
|
+
Gem_packer::TASKLIST.each{|task|
|
77
|
+
assert_nothing_raised('Expected task from Gem_packer::TASKLIST missing'){ app["#{test_name}:#{task}"] }
|
78
|
+
assert_kind_of(Rake::Task, app["#{test_name}:#{task}"])
|
79
|
+
#check 'global' tasks
|
80
|
+
assert_equal(true, app[task].prerequisites.include?("#{test_name}:#{task}"))
|
81
|
+
}
|
82
|
+
|
83
|
+
#Check special tasks
|
84
|
+
assert_equal(true, app[test_name].prerequisites.include?("#{test_name}:default"))
|
85
|
+
assert_equal(["check"], app["#{test_name}:default"].prerequisites)
|
86
|
+
assert_equal(%w{check_version check_gemspec}, app["#{test_name}:check"].prerequisites)
|
87
|
+
|
88
|
+
#All new tasks
|
89
|
+
#~ assert_equal(Gem_packer::TASKLIST.size + 1, (app.tasks - tasks_before).size)
|
90
|
+
assert_equal([test_name] + Gem_packer::TASKLIST.map{|task| "#{test_name}:#{task}"}.sort,
|
91
|
+
(app.tasks - tasks_before).map{|x|x.name}
|
92
|
+
)
|
93
|
+
|
94
|
+
end
|
95
|
+
=begin rdoc
|
96
|
+
This test requires following files to be successfull:
|
97
|
+
testdata/
|
98
|
+
testdata/dummy_test.rb
|
99
|
+
=end
|
100
|
+
def test_test_task()
|
101
|
+
|
102
|
+
app = Rake.application
|
103
|
+
test_name = 'test_test_tasks' #test gem for this test. Must be uniq for all tests
|
104
|
+
gemdef = Gem_packer.new(test_name, '0.1.0')
|
105
|
+
|
106
|
+
#Missing test directory
|
107
|
+
assert_raise(ArgumentError){ gemdef.define_test()}
|
108
|
+
assert_raise(ArgumentError){ gemdef.define_test('not_existing_directory')}
|
109
|
+
|
110
|
+
assert_equal(true, File.exist?('testdata'))
|
111
|
+
#Require path missing
|
112
|
+
assert_raise(ArgumentError){ gemdef.define_test('testdata') }
|
113
|
+
|
114
|
+
#define gem with reachable require path
|
115
|
+
gemdef.spec.require_path = '.'
|
116
|
+
#no test files found
|
117
|
+
assert_raise(ArgumentError){ gemdef.define_test('testdata') }
|
118
|
+
assert_raise(ArgumentError){ gemdef.define_test('testdata', FileList['xxxx']) }
|
119
|
+
|
120
|
+
#Test files available
|
121
|
+
tasks_before = app.tasks
|
122
|
+
assert_nothing_raised{
|
123
|
+
assert_kind_of(Rake::TestTask, gemdef.define_test('testdata', FileList['dummy_test.rb']))
|
124
|
+
}
|
125
|
+
#One more test available
|
126
|
+
assert_equal(["#{test_name}:test"], (app.tasks - tasks_before).map{|x|x.name} )
|
127
|
+
assert_kind_of(Rake::Task, app["#{test_name}:test"])
|
128
|
+
|
129
|
+
end #test_test_task()
|
130
|
+
def test_mk_gem()
|
131
|
+
|
132
|
+
app = Rake.application
|
133
|
+
test_name = 'test_mk_gem' #test gem for this test. Must be uniq for all tests
|
134
|
+
gemdef = Gem_packer.new(test_name, '0.1.0'){|gem,spec|
|
135
|
+
spec.author = 'Author'
|
136
|
+
spec.email = 'Email'
|
137
|
+
spec.homepage = 'http://www.rubypla.net'
|
138
|
+
spec.summary = 'Summary'
|
139
|
+
spec.description = 'Description'
|
140
|
+
spec.rubyforge_project = 'test'
|
141
|
+
}
|
142
|
+
|
143
|
+
assert_equal(false, File.exist?("#{gemdef.spec.full_name}.gem"))
|
144
|
+
Frame_catch_output.catch_stdout{
|
145
|
+
app["#{test_name}:gem"].invoke
|
146
|
+
}
|
147
|
+
assert_equal(true, File.exist?("#{gemdef.spec.full_name}.gem"))
|
148
|
+
|
149
|
+
File.delete("#{gemdef.spec.full_name}.gem")
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_mk_install()
|
153
|
+
#no testcases
|
154
|
+
end #test_mk_install()
|
155
|
+
def test_ftp_rdoc()
|
156
|
+
app = Rake.application
|
157
|
+
test_name = 'test_ftp_rdoc' #test gem for this test. Must be uniq for all tests
|
158
|
+
gemdef = nil
|
159
|
+
Frame_catch_output.catch_stdout{
|
160
|
+
gemdef = Gem_packer.new(test_name, '0.1.0')
|
161
|
+
}
|
162
|
+
assert_kind_of(Rake::Task, app["#{test_name}:ftp_rdoc"] )
|
163
|
+
assert_raise(Gem_packer::BlockError){ app["#{test_name}:ftp_rdoc"].invoke }
|
164
|
+
|
165
|
+
gemdef.public = true #Now it should be possible (but without add_ftp_connection nothing will happen)
|
166
|
+
assert_nothing_raised(Gem_packer::BlockError){ app["#{test_name}:ftp_rdoc"].invoke }
|
167
|
+
|
168
|
+
#no further testcases
|
169
|
+
end #test_mk_push()
|
170
|
+
def test_mk_push()
|
171
|
+
app = Rake.application
|
172
|
+
test_name = 'test_push' #test gem for this test. Must be uniq for all tests
|
173
|
+
gemdef = nil
|
174
|
+
Frame_catch_output.catch_stdout{
|
175
|
+
gemdef = Gem_packer.new(test_name, '0.1.0'){|gem,spec|
|
176
|
+
spec.author = 'Author'
|
177
|
+
spec.email = 'Email'
|
178
|
+
spec.homepage = 'http://www.rubypla.net'
|
179
|
+
spec.summary = 'Summary'
|
180
|
+
spec.description = 'Description'
|
181
|
+
spec.rubyforge_project = 'test'
|
182
|
+
}
|
183
|
+
app["#{test_name}:gem"].invoke #call prerequisite for push
|
184
|
+
}
|
185
|
+
assert_kind_of(Rake::Task, app["#{test_name}:push"] )
|
186
|
+
assert_raise(Gem_packer::BlockError){ app["#{test_name}:push"].invoke }
|
187
|
+
assert_nothing_raised{ File.delete(gemdef.spec.full_name + '.gem') }
|
188
|
+
#not tested. else we "push" the test
|
189
|
+
#~ gemdef.public = true #Now it should be possible
|
190
|
+
#~ assert_nothing_raised(Gem_packer::BlockError){ app["#{test_name}:ftp_rdoc"].invoke }
|
191
|
+
|
192
|
+
#no further testcases
|
193
|
+
end #test_mk_push()
|
194
|
+
|
195
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
$:.unshift('../lib') if $0 == __FILE__
|
2
|
+
|
3
|
+
#~ gem 'rake', '= 0.8.7'
|
4
|
+
#~ gem 'test-unit', '= ???'
|
5
|
+
require 'test/unit'
|
6
|
+
require 'knut_tools/catch_output'
|
7
|
+
require 'knut_tools/rake/testtask.rb'
|
8
|
+
require 'rake/clean'
|
9
|
+
|
10
|
+
=begin
|
11
|
+
C:\Program Files\ruby\lib\ruby\gems\1.8\gems\rake-0.8.7\lib\rake
|
12
|
+
C:\Program Files\Ruby19\lib\ruby\gems\1.9.1\gems\rake-0.8.7\lib\rake
|
13
|
+
|
14
|
+
Problem:
|
15
|
+
Test lesen Datei.
|
16
|
+
Mit Rake::TestTask.new ist kein Verzeichniswechsel m�glich.
|
17
|
+
|
18
|
+
=end
|
19
|
+
|
20
|
+
$testdir = "testdir"
|
21
|
+
$testfile = "my_test.rb"
|
22
|
+
|
23
|
+
#
|
24
|
+
#Build the testfile
|
25
|
+
#
|
26
|
+
desc 'Make the testdata'
|
27
|
+
task :mk_testdata do
|
28
|
+
Dir.mkdir($testdir) unless File.directory?($testdir)
|
29
|
+
File.open('hello_world.txt', 'w'){ |f| f << 'Hello World'}
|
30
|
+
File.open("#{$testdir}/#{$testfile}", 'w'){ |f| f << <<testscript
|
31
|
+
require 'test/unit'
|
32
|
+
|
33
|
+
class Test__xx < Test::Unit::TestCase
|
34
|
+
def test_xx()
|
35
|
+
assert_equal(true, File.exist?('../hello_world.txt'))
|
36
|
+
end #
|
37
|
+
end
|
38
|
+
testscript
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
desc 'Delete the testfiles'
|
43
|
+
CLOBBER.include(['hello_world.txt', $testdir])
|
44
|
+
|
45
|
+
Rake::TestTask.new(:test_ok) do |t|
|
46
|
+
t.dir = $testdir
|
47
|
+
t.test_files = [$testfile].flatten
|
48
|
+
t.verbose = true
|
49
|
+
end
|
50
|
+
=begin
|
51
|
+
This test stopps with a "not found error"
|
52
|
+
Class: <Errno::ENOENT>
|
53
|
+
Message: <"No such file or directory - testdir">
|
54
|
+
=end
|
55
|
+
Rake::TestTask.new(:test_err) do |t|
|
56
|
+
t.test_files = ["#{$testdir}/#{$testfile}"]
|
57
|
+
t.verbose = true
|
58
|
+
end
|
59
|
+
|
60
|
+
task :default => :mk_testdata
|
61
|
+
task :default => :test_ok
|
62
|
+
#~ task :default => :test_err #makes an error
|
63
|
+
task :default => :clobber
|
64
|
+
|
65
|
+
if $0 == __FILE__
|
66
|
+
#~ app = Rake.application
|
67
|
+
#~ app[:default].invoke
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
class Test_testtask < Test::Unit::TestCase
|
72
|
+
def test_rake_testtask_def()
|
73
|
+
assert_equal(true, Rake::TestTask.new.respond_to?(:'dir='))
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_rake_testtask()
|
77
|
+
app = Rake.application
|
78
|
+
app[:mk_testdata].invoke
|
79
|
+
|
80
|
+
|
81
|
+
assert_nothing_raised{ app[:test_ok].invoke }
|
82
|
+
|
83
|
+
|
84
|
+
notify("Frame_catch_output.catch_screen_output does not work as expected with ruby 1.9.1.")
|
85
|
+
stdout, stderr = Frame_catch_output.catch_screen_output{
|
86
|
+
assert_nothing_raised{ app[:test_ok].invoke }
|
87
|
+
}
|
88
|
+
assert_match( %r{Loaded suite .*lib/rake/rake_test_loader
|
89
|
+
Started
|
90
|
+
.
|
91
|
+
Finished in .* seconds.
|
92
|
+
|
93
|
+
1 tests, 1 assertions, 0 failures, 0 errors}, stdout)
|
94
|
+
|
95
|
+
|
96
|
+
Frame_catch_output.catch_screen_output{
|
97
|
+
assert_raise(RuntimeError){ app[:test_err].invoke }
|
98
|
+
}
|
99
|
+
Frame_catch_output.catch_stderr{
|
100
|
+
app[:clobber].invoke
|
101
|
+
}
|
102
|
+
#~ assert_raise(Errno::ENOENT){ app[:test_err].invoke }
|
103
|
+
#~ assert_equal_filecontent( "/test.txt", DUMMYTEXT )
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
This function is only for Ruby 1.8.
|
3
|
+
Ruby 1.9 includes already the full name of the included packages.
|
4
|
+
|
5
|
+
=end
|
6
|
+
if RUBY_VERSION =~ /1.9/
|
7
|
+
puts "Obsolte function for Ruby #{RUBY_VERSION}"
|
8
|
+
exit
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'test/unit'
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
$:.unshift('../lib') if $0 == __FILE__
|
16
|
+
require 'knut_tools/catch_output'
|
17
|
+
require 'knut_tools/required_what'
|
18
|
+
|
19
|
+
|
20
|
+
class Test_required_what < Test::Unit::TestCase
|
21
|
+
def test_system()
|
22
|
+
assert_equal($:, $LOAD_PATH)
|
23
|
+
assert_equal($", $LOADED_FEATURES)
|
24
|
+
assert_equal("global-variable", defined? $LOADED_FEATURES_FULL)
|
25
|
+
#~ assert_equal([], $LOADED_FEATURES_FULL)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_load()
|
29
|
+
|
30
|
+
before = $LOADED_FEATURES.dup
|
31
|
+
before_full = $LOADED_FEATURES_FULL.dup
|
32
|
+
|
33
|
+
Frame_catch_output.catch_stdout{
|
34
|
+
assert_nothing_raised{ require 'testdata/hello_world' }
|
35
|
+
}
|
36
|
+
|
37
|
+
assert_equal(["testdata/hello_world.rb"], $LOADED_FEATURES - before)
|
38
|
+
assert_equal(["./testdata/hello_world.rb"], $LOADED_FEATURES_FULL - before_full)
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_load_again()
|
43
|
+
|
44
|
+
load_result = nil
|
45
|
+
before = $LOADED_FEATURES_FULL.dup
|
46
|
+
|
47
|
+
assert_nothing_raised{
|
48
|
+
load_result = require 'knut_tools/catch_output'
|
49
|
+
}
|
50
|
+
assert_equal( false, load_result)
|
51
|
+
assert_equal([], $LOADED_FEATURES_FULL - before)
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_singleton()
|
56
|
+
|
57
|
+
load_result = nil
|
58
|
+
before = $LOADED_FEATURES_FULL.dup
|
59
|
+
File.open('singleton.rb', 'w'){} unless File.exist?('singleton.rb')
|
60
|
+
|
61
|
+
load_result = require 'singleton.rb'
|
62
|
+
#If called from rakefile, singleton already loaded.
|
63
|
+
if load_result
|
64
|
+
assert_equal("C:/Program Files/ruby/lib/ruby/1.8/singleton.rb", ($LOADED_FEATURES_FULL - before).last)
|
65
|
+
assert_match(%r{Filename conflict in require: singleton.rb: \[.*singleton.rb\", \"./singleton.rb\"\]}, $LOADED_FEATURES_WARN.last )
|
66
|
+
end
|
67
|
+
|
68
|
+
File.delete('singleton.rb')
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
@@ -0,0 +1,144 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'more_unit_test/assert_stdout.rb'
|
3
|
+
|
4
|
+
$: << '../lib' if $0 == __FILE__
|
5
|
+
require 'knut_tools/yaml'
|
6
|
+
|
7
|
+
#~ $expected = File.dirname(__FILE__) + '/tmp_expected'
|
8
|
+
#~ $folder_for_failure = File.dirname(__FILE__) + '/tmp_failure'
|
9
|
+
|
10
|
+
|
11
|
+
class Test_knut_tools_yaml < Test::Unit::TestCase
|
12
|
+
def test_yaml_load_with_warning()
|
13
|
+
assert_stdout_block("!YAML.load: Double Hash-key: a\n"){YAML.load_with_warning(<<-xx
|
14
|
+
a: A
|
15
|
+
a: A
|
16
|
+
xx
|
17
|
+
)}
|
18
|
+
assert_stdout_block("!YAML.load: Double Hash-key: 1\n"){YAML.load_with_warning(<<-xx
|
19
|
+
1: [ eins, one, un, une ]
|
20
|
+
2: [ zwei, two, deux ]
|
21
|
+
3:
|
22
|
+
foo: bar
|
23
|
+
baz: foo
|
24
|
+
1: [ eins ]
|
25
|
+
10: zehn
|
26
|
+
0xA: zehn, aber hex
|
27
|
+
xx
|
28
|
+
)}
|
29
|
+
end #test_yaml_load_with_warning
|
30
|
+
#
|
31
|
+
#Unfortenatly only level 1.
|
32
|
+
#
|
33
|
+
def test_yaml_load_with_warning_2()
|
34
|
+
assert_stdout_block(""){YAML.load_with_warning(<<-xx
|
35
|
+
1:
|
36
|
+
a: A
|
37
|
+
a: A
|
38
|
+
xx
|
39
|
+
)}
|
40
|
+
assert_stdout_block(""){YAML.load_with_warning(<<-xx
|
41
|
+
-
|
42
|
+
a: A
|
43
|
+
a: A
|
44
|
+
xx
|
45
|
+
)}
|
46
|
+
end
|
47
|
+
end #Test_knut_tools
|
48
|
+
|
49
|
+
class Test_knut_tools_yaml_hash < Test::Unit::TestCase
|
50
|
+
|
51
|
+
Hash1 = { 2 => :two, 1 => :one }
|
52
|
+
Hash2 = { 'zwei' => 2, 'eins' => 1 }
|
53
|
+
ListWithHash = [ Hash1, Hash2 ]
|
54
|
+
|
55
|
+
#
|
56
|
+
#Default is "sorted"
|
57
|
+
#
|
58
|
+
def test_hash_default()
|
59
|
+
assert_equal(
|
60
|
+
"--- \n1: :one\n2: :two\n",
|
61
|
+
Hash1.to_yaml
|
62
|
+
)
|
63
|
+
assert_equal(
|
64
|
+
"--- \neins: 1\nzwei: 2\n",
|
65
|
+
Hash2.to_yaml
|
66
|
+
)
|
67
|
+
end #test_hash_default()
|
68
|
+
def test_ListWithHash()
|
69
|
+
assert_equal(
|
70
|
+
"--- \n- 1: :one\n 2: :two\n- eins: 1\n zwei: 2\n",
|
71
|
+
ListWithHash.to_yaml
|
72
|
+
)
|
73
|
+
end #test_ListWithHash()
|
74
|
+
def test_hash_without_hash()
|
75
|
+
assert_nothing_raised{[2,1].to_yaml}
|
76
|
+
assert_nothing_raised{'aaa'.to_yaml}
|
77
|
+
assert_nothing_raised{%w{a b c d e}.to_yaml}
|
78
|
+
end
|
79
|
+
def test_hash_true()
|
80
|
+
assert_equal(
|
81
|
+
"--- \n1: :one\n2: :two\n",
|
82
|
+
Hash1.to_yaml(:SortKeys => true)
|
83
|
+
)
|
84
|
+
assert_equal(
|
85
|
+
"--- \neins: 1\nzwei: 2\n",
|
86
|
+
Hash2.to_yaml(:SortKeys => true)
|
87
|
+
)
|
88
|
+
end
|
89
|
+
#
|
90
|
+
#This result may change. There is no fixed behaviuor
|
91
|
+
#
|
92
|
+
def test_hash_false()
|
93
|
+
#~ assert_equal(
|
94
|
+
#~ "--- \n1: :one\n2: :two\n",
|
95
|
+
#~ Hash1.to_yaml(:SortKeys => false)
|
96
|
+
#~ )
|
97
|
+
#~ assert_equal(
|
98
|
+
#~ "--- \nzwei: 2\neins: 1\n",
|
99
|
+
#~ Hash2.to_yaml(:SortKeys => false),
|
100
|
+
#~ "Result may change"
|
101
|
+
#~ )
|
102
|
+
end
|
103
|
+
def test_hash_symbols()
|
104
|
+
hash_sym = { :b => 'B', :a => 'A' }
|
105
|
+
assert_equal(
|
106
|
+
"--- \n:a: A\n:b: B\n",
|
107
|
+
hash_sym.to_yaml(:SortKeys => true)
|
108
|
+
)
|
109
|
+
#random the same
|
110
|
+
assert_equal(
|
111
|
+
"--- \n:a: A\n:b: B\n",
|
112
|
+
hash_sym.to_yaml(:SortKeys => false)
|
113
|
+
)
|
114
|
+
end
|
115
|
+
def test_hash_symbols()
|
116
|
+
hash_sym_mix = { :b => 'B', 'a' => 'A' }
|
117
|
+
assert_equal(
|
118
|
+
"--- \na: A\n:b: B\n",
|
119
|
+
hash_sym_mix.to_yaml(:SortKeys => true)
|
120
|
+
)
|
121
|
+
#by random the same
|
122
|
+
assert_equal(
|
123
|
+
"--- \na: A\n:b: B\n",
|
124
|
+
hash_sym_mix.to_yaml(:SortKeys => false)
|
125
|
+
)
|
126
|
+
end
|
127
|
+
def test_hash_mix_num()
|
128
|
+
hash_sym_mix = { 2 => 2, 1 => 1, '10' => 10 }
|
129
|
+
assert_equal(
|
130
|
+
"--- \n1: 1\n\"10\": 10\n2: 2\n",
|
131
|
+
hash_sym_mix.to_yaml(:SortKeys => true)
|
132
|
+
)
|
133
|
+
#by random the same
|
134
|
+
#~ assert_equal(
|
135
|
+
#~ "--- \n1: 1\n2: 2\n\"10\": 10\n",
|
136
|
+
#~ hash_sym_mix.to_yaml(:SortKeys => false),
|
137
|
+
#~ "Result may change"
|
138
|
+
#~ )
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
__END__
|
143
|
+
- first item
|
144
|
+
- second item
|