1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
|
$TESTING = true
require 'rubygems'
require 'minitest/autorun'
require 'zentest_mapping' unless defined? $ZENTEST
class Dummy
attr_accessor :inherited_methods
include ZenTestMapping
end
class TestZentestMapping < Minitest::Test
def setup
@tester = Dummy.new
end
def util_simple_setup
klasses = {
"Something" => {
"method1" => true,
"method1!" => true,
"method1=" => true,
"method1?" => true,
"attrib" => true,
"attrib=" => true,
"equal?" => true,
"self.method3" => true,
"self.[]" => true,
},
}
test_klasses = {
"TestSomething" => {
"test_class_method4" => true,
"test_method2" => true,
"setup" => true,
"teardown" => true,
"test_class_index" => true,
},
}
@tester.inherited_methods = test_klasses.merge(klasses)
@generated_code = "
require 'test/unit' unless defined? $ZENTEST and $ZENTEST
class Something
def self.method4(*args)
raise NotImplementedError, 'Need to write self.method4'
end
def method2(*args)
raise NotImplementedError, 'Need to write method2'
end
end
class TestSomething < Test::Unit::TestCase
def test_class_method3
raise NotImplementedError, 'Need to write test_class_method3'
end
def test_attrib
raise NotImplementedError, 'Need to write test_attrib'
end
def test_attrib_equals
raise NotImplementedError, 'Need to write test_attrib_equals'
end
def test_equal_eh
raise NotImplementedError, 'Need to write test_equal_eh'
end
def test_method1
raise NotImplementedError, 'Need to write test_method1'
end
def test_method1_bang
raise NotImplementedError, 'Need to write test_method1_bang'
end
def test_method1_eh
raise NotImplementedError, 'Need to write test_method1_eh'
end
def test_method1_equals
raise NotImplementedError, 'Need to write test_method1_equals'
end
end
# Number of errors detected: 10
"
end
def test_normal_to_test
self.util_simple_setup
assert_equal("test_method1", @tester.normal_to_test("method1"))
assert_equal("test_method1_bang", @tester.normal_to_test("method1!"))
assert_equal("test_method1_eh", @tester.normal_to_test("method1?"))
assert_equal("test_method1_equals", @tester.normal_to_test("method1="))
end
def test_normal_to_test_cls
self.util_simple_setup
assert_equal("test_class_method1",
@tester.normal_to_test("self.method1"))
assert_equal("test_class_method1_bang",
@tester.normal_to_test("self.method1!"))
assert_equal("test_class_method1_eh",
@tester.normal_to_test("self.method1?"))
assert_equal("test_class_method1_equals",
@tester.normal_to_test("self.method1="))
end
def test_normal_to_test_operators
self.util_simple_setup
assert_equal("test_and", @tester.normal_to_test("&"))
assert_equal("test_bang", @tester.normal_to_test("!"))
assert_equal("test_carat", @tester.normal_to_test("^"))
assert_equal("test_div", @tester.normal_to_test("/"))
assert_equal("test_equalstilde", @tester.normal_to_test("=~"))
assert_equal("test_minus", @tester.normal_to_test("-"))
assert_equal("test_or", @tester.normal_to_test("|"))
assert_equal("test_percent", @tester.normal_to_test("%"))
assert_equal("test_plus", @tester.normal_to_test("+"))
assert_equal("test_tilde", @tester.normal_to_test("~"))
end
def test_normal_to_test_overlap
self.util_simple_setup
assert_equal("test_equals2", @tester.normal_to_test("=="))
assert_equal("test_equals3", @tester.normal_to_test("==="))
assert_equal("test_ge", @tester.normal_to_test(">="))
assert_equal("test_gt", @tester.normal_to_test(">"))
assert_equal("test_gt2", @tester.normal_to_test(">>"))
assert_equal("test_index", @tester.normal_to_test("[]"))
assert_equal("test_index_equals", @tester.normal_to_test("[]="))
assert_equal("test_lt", @tester.normal_to_test("<"))
assert_equal("test_lt2", @tester.normal_to_test("<\<"))
assert_equal("test_lte", @tester.normal_to_test("<="))
assert_equal("test_method", @tester.normal_to_test("method"))
assert_equal("test_method_equals", @tester.normal_to_test("method="))
assert_equal("test_spaceship", @tester.normal_to_test("<=>"))
assert_equal("test_times", @tester.normal_to_test("*"))
assert_equal("test_times2", @tester.normal_to_test("**"))
assert_equal("test_unary_minus", @tester.normal_to_test("-@"))
assert_equal("test_unary_plus", @tester.normal_to_test("+@"))
assert_equal("test_class_index", @tester.normal_to_test("self.[]"))
end
def test_test_to_normal
self.util_simple_setup
assert_equal("method1!",
@tester.test_to_normal("test_method1_bang", "Something"))
assert_equal("method1",
@tester.test_to_normal("test_method1", "Something"))
assert_equal("method1=",
@tester.test_to_normal("test_method1_equals", "Something"))
assert_equal("method1?",
@tester.test_to_normal("test_method1_eh", "Something"))
end
def test_test_to_normal_cls
self.util_simple_setup
assert_equal("self.method1",
@tester.test_to_normal("test_class_method1"))
assert_equal("self.method1!",
@tester.test_to_normal("test_class_method1_bang"))
assert_equal("self.method1?",
@tester.test_to_normal("test_class_method1_eh"))
assert_equal("self.method1=",
@tester.test_to_normal("test_class_method1_equals"))
assert_equal("self.[]",
@tester.test_to_normal("test_class_index"))
end
def test_test_to_normal_extended
self.util_simple_setup
assert_equal("equal?",
@tester.test_to_normal("test_equal_eh_extension",
"Something"))
assert_equal("equal?",
@tester.test_to_normal("test_equal_eh_extension_again",
"Something"))
assert_equal("method1",
@tester.test_to_normal("test_method1_extension",
"Something"))
assert_equal("method1",
@tester.test_to_normal("test_method1_extension_again",
"Something"))
end
def test_test_to_normal_mapped
self.util_simple_setup
assert_equal("*", @tester.test_to_normal("test_times"))
assert_equal("*", @tester.test_to_normal("test_times_ext"))
assert_equal("==", @tester.test_to_normal("test_equals2"))
assert_equal("==", @tester.test_to_normal("test_equals2_ext"))
assert_equal("===", @tester.test_to_normal("test_equals3"))
assert_equal("===", @tester.test_to_normal("test_equals3_ext"))
assert_equal("[]", @tester.test_to_normal("test_index"))
assert_equal("[]", @tester.test_to_normal("test_index_ext"))
assert_equal("[]=", @tester.test_to_normal("test_index_equals"))
assert_equal("[]=", @tester.test_to_normal("test_index_equals_ext"))
end
def test_test_to_normal_operators
self.util_simple_setup
assert_equal("&", @tester.test_to_normal("test_and"))
assert_equal("!", @tester.test_to_normal("test_bang"))
assert_equal("^", @tester.test_to_normal("test_carat"))
assert_equal("/", @tester.test_to_normal("test_div"))
assert_equal("=~", @tester.test_to_normal("test_equalstilde"))
assert_equal("-", @tester.test_to_normal("test_minus"))
assert_equal("|", @tester.test_to_normal("test_or"))
assert_equal("%", @tester.test_to_normal("test_percent"))
assert_equal("+", @tester.test_to_normal("test_plus"))
assert_equal("~", @tester.test_to_normal("test_tilde"))
end
def test_test_to_normal_overlap
self.util_simple_setup
assert_equal("==", @tester.test_to_normal("test_equals2"))
assert_equal("===", @tester.test_to_normal("test_equals3"))
assert_equal(">=", @tester.test_to_normal("test_ge"))
assert_equal(">", @tester.test_to_normal("test_gt"))
assert_equal(">>", @tester.test_to_normal("test_gt2"))
assert_equal("[]", @tester.test_to_normal("test_index"))
assert_equal("[]=", @tester.test_to_normal("test_index_equals"))
assert_equal("<", @tester.test_to_normal("test_lt"))
assert_equal("<\<", @tester.test_to_normal("test_lt2"))
assert_equal("<=", @tester.test_to_normal("test_lte"))
assert_equal("<=>", @tester.test_to_normal("test_spaceship"))
assert_equal("*", @tester.test_to_normal("test_times"))
assert_equal("**", @tester.test_to_normal("test_times2"))
assert_equal("-@", @tester.test_to_normal("test_unary_minus"))
assert_equal("+@", @tester.test_to_normal("test_unary_plus"))
end
def test_to_normal_subset
self.util_simple_setup
assert_equal("get_foo", @tester.test_to_normal("test_get_foo"))
end
end
|