2115
2112
state._validate)
2116
2113
self.assertContainsRe(str(e),
2117
2114
'file a-id is absent in row')
2117
class TestCmpByDirs(TestCase):
2119
def get_cmp_by_dirs(self):
2120
"""Get a specific implementation of cmp_by_dirs."""
2121
return dirstate.py_cmp_by_dirs
2123
def assertPositive(self, val):
2124
"""Assert that val is greater than 0."""
2125
self.assertTrue(val > 0, 'expected a positive value, but got %s' % val)
2127
def assertNegative(self, val):
2128
"""Assert that val is less than 0."""
2129
self.assertTrue(val < 0, 'expected a negative value, but got %s' % val)
2131
def assertCmpByDirs(self, expected, str1, str2):
2132
"""Compare the two strings, in both directions.
2134
:param expected: The expected comparison value. -1 means str1 comes
2135
first, 0 means they are equal, 1 means str2 comes first
2136
:param str1: string to compare
2137
:param str2: string to compare
2139
cmp_by_dirs = self.get_cmp_by_dirs()
2141
self.assertEqual(str1, str2)
2142
self.assertEqual(0, cmp_by_dirs(str1, str2))
2143
self.assertEqual(0, cmp_by_dirs(str2, str1))
2145
self.assertPositive(cmp_by_dirs(str1, str2))
2146
self.assertNegative(cmp_by_dirs(str2, str1))
2148
self.assertNegative(cmp_by_dirs(str1, str2))
2149
self.assertPositive(cmp_by_dirs(str2, str1))
2151
def test_cmp_empty(self):
2152
"""Compare against the empty string."""
2153
self.assertCmpByDirs(0, '', '')
2154
self.assertCmpByDirs(1, 'a', '')
2155
self.assertCmpByDirs(1, 'ab', '')
2156
self.assertCmpByDirs(1, 'abc', '')
2157
self.assertCmpByDirs(1, 'abcd', '')
2158
self.assertCmpByDirs(1, 'abcde', '')
2159
self.assertCmpByDirs(1, 'abcdef', '')
2160
self.assertCmpByDirs(1, 'abcdefg', '')
2161
self.assertCmpByDirs(1, 'abcdefgh', '')
2162
self.assertCmpByDirs(1, 'abcdefghi', '')
2163
self.assertCmpByDirs(1, 'test/ing/a/path/', '')
2165
def test_cmp_same_str(self):
2166
"""Compare the same string"""
2167
self.assertCmpByDirs(0, 'a', 'a')
2168
self.assertCmpByDirs(0, 'ab', 'ab')
2169
self.assertCmpByDirs(0, 'abc', 'abc')
2170
self.assertCmpByDirs(0, 'abcd', 'abcd')
2171
self.assertCmpByDirs(0, 'abcde', 'abcde')
2172
self.assertCmpByDirs(0, 'abcdef', 'abcdef')
2173
self.assertCmpByDirs(0, 'abcdefg', 'abcdefg')
2174
self.assertCmpByDirs(0, 'abcdefgh', 'abcdefgh')
2175
self.assertCmpByDirs(0, 'abcdefghi', 'abcdefghi')
2176
self.assertCmpByDirs(0, 'testing a long string', 'testing a long string')
2177
self.assertCmpByDirs(0, 'x'*10000, 'x'*10000)
2178
self.assertCmpByDirs(0, 'a/b', 'a/b')
2179
self.assertCmpByDirs(0, 'a/b/c', 'a/b/c')
2180
self.assertCmpByDirs(0, 'a/b/c/d', 'a/b/c/d')
2181
self.assertCmpByDirs(0, 'a/b/c/d/e', 'a/b/c/d/e')
2183
def test_simple_paths(self):
2184
"""Compare strings that act like normal string comparison"""
2185
self.assertCmpByDirs(-1, 'a', 'b')
2186
self.assertCmpByDirs(-1, 'aa', 'ab')
2187
self.assertCmpByDirs(-1, 'ab', 'bb')
2188
self.assertCmpByDirs(-1, 'aaa', 'aab')
2189
self.assertCmpByDirs(-1, 'aab', 'abb')
2190
self.assertCmpByDirs(-1, 'abb', 'bbb')
2191
self.assertCmpByDirs(-1, 'aaaa', 'aaab')
2192
self.assertCmpByDirs(-1, 'aaab', 'aabb')
2193
self.assertCmpByDirs(-1, 'aabb', 'abbb')
2194
self.assertCmpByDirs(-1, 'abbb', 'bbbb')
2195
self.assertCmpByDirs(-1, 'aaaaa', 'aaaab')
2196
self.assertCmpByDirs(-1, 'a/a', 'a/b')
2197
self.assertCmpByDirs(-1, 'a/b', 'b/b')
2198
self.assertCmpByDirs(-1, 'a/a/a', 'a/a/b')
2199
self.assertCmpByDirs(-1, 'a/a/b', 'a/b/b')
2200
self.assertCmpByDirs(-1, 'a/b/b', 'b/b/b')
2201
self.assertCmpByDirs(-1, 'a/a/a/a', 'a/a/a/b')
2202
self.assertCmpByDirs(-1, 'a/a/a/b', 'a/a/b/b')
2203
self.assertCmpByDirs(-1, 'a/a/b/b', 'a/b/b/b')
2204
self.assertCmpByDirs(-1, 'a/b/b/b', 'b/b/b/b')
2205
self.assertCmpByDirs(-1, 'a/a/a/a/a', 'a/a/a/a/b')
2207
def test_tricky_paths(self):
2208
self.assertCmpByDirs(1, 'ab/cd/ef', 'ab/cc/ef')
2209
self.assertCmpByDirs(1, 'ab/cd/ef', 'ab/c/ef')
2210
self.assertCmpByDirs(-1, 'ab/cd/ef', 'ab/cd-ef')
2211
self.assertCmpByDirs(-1, 'ab/cd', 'ab/cd-')
2212
self.assertCmpByDirs(-1, 'ab/cd', 'ab-cd')