74
84
self.make_delta, u'not a string', 'a string')
76
86
def test_make_noop_delta(self):
77
ident_delta = self.make_delta(_source_text1, _source_text1)
87
ident_delta = self.make_delta(_text1, _text1)
78
88
self.assertEqual('MM\x90M', ident_delta)
79
ident_delta = self.make_delta(_source_text2, _source_text2)
89
ident_delta = self.make_delta(_text2, _text2)
80
90
self.assertEqual('NN\x90N', ident_delta)
91
ident_delta = self.make_delta(_text3, _text3)
92
self.assertEqual('\x87\x01\x87\x01\x90\x87', ident_delta)
82
94
def test_make_delta(self):
83
delta = self.make_delta(_source_text1, _source_text2)
95
delta = self.make_delta(_text1, _text2)
84
96
self.assertEqual('MN\x90/\x1fdiffer from\nagainst other text\n', delta)
85
delta = self.make_delta(_source_text2, _source_text1)
97
delta = self.make_delta(_text2, _text1)
86
98
self.assertEqual('NM\x90/\x1ebe matched\nagainst other text\n', delta)
99
delta = self.make_delta(_text3, _text1)
100
self.assertEqual('\x87\x01M\x90M', delta)
101
delta = self.make_delta(_text3, _text2)
102
self.assertEqual('\x87\x01N\x90/\x1fdiffer from\nagainst other text\n',
88
105
def test_apply_delta_is_typesafe(self):
89
self.apply_delta(_source_text1, 'MM\x90M')
106
self.apply_delta(_text1, 'MM\x90M')
90
107
self.assertRaises(TypeError,
91
108
self.apply_delta, object(), 'MM\x90M')
92
109
self.assertRaises(TypeError,
93
self.apply_delta, unicode(_source_text1), 'MM\x90M')
94
self.assertRaises(TypeError,
95
self.apply_delta, _source_text1, u'MM\x90M')
96
self.assertRaises(TypeError,
97
self.apply_delta, _source_text1, object())
110
self.apply_delta, unicode(_text1), 'MM\x90M')
111
self.assertRaises(TypeError,
112
self.apply_delta, _text1, u'MM\x90M')
113
self.assertRaises(TypeError,
114
self.apply_delta, _text1, object())
99
116
def test_apply_delta(self):
100
target = self.apply_delta(_source_text1,
117
target = self.apply_delta(_text1,
101
118
'MN\x90/\x1fdiffer from\nagainst other text\n')
102
self.assertEqual(_source_text2, target)
103
target = self.apply_delta(_source_text2,
119
self.assertEqual(_text2, target)
120
target = self.apply_delta(_text2,
104
121
'NM\x90/\x1ebe matched\nagainst other text\n')
105
self.assertEqual(_source_text1, target)
122
self.assertEqual(_text1, target)