1
# Copyright (C) 2005 by Canonical Ltd
1
# Copyright (C) 2005, 2006, 2008, 2009, 2011 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
"""Test that various operations work in a non-ASCII environment."""
23
23
from bzrlib import osutils
24
24
from bzrlib.osutils import pathjoin
25
25
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
26
from bzrlib.workingtree import WorkingTree
29
28
class NonAsciiTest(TestCaseWithTransport):
36
35
except UnicodeEncodeError:
37
36
raise TestSkipped("filesystem can't accomodate nonascii names")
39
file(pathjoin(br_dir, "a"), "w").write("hello")
38
with file(pathjoin(br_dir, "a"), "w") as f: f.write("hello")
40
39
wt.add(["a"], ["a-id"])
46
45
a_dots_d = u'a\u0308'
47
46
z_umlat_c = u'\u017d'
48
47
z_umlat_d = u'Z\u030c'
48
squared_c = u'\xbc' # This gets mapped to '2' if we use NFK[CD]
50
quarter_c = u'\xb2' # Gets mapped to u'1\u20444' (1/4) if we use NFK[CD]
51
54
class TestNormalization(TestCase):
52
55
"""Verify that we have our normalizations correct."""
54
57
def test_normalize(self):
55
self.assertEqual(a_circle_d, normalize('NFKD', a_circle_c))
56
self.assertEqual(a_circle_c, normalize('NFKC', a_circle_d))
57
self.assertEqual(a_dots_d, normalize('NFKD', a_dots_c))
58
self.assertEqual(a_dots_c, normalize('NFKC', a_dots_d))
59
self.assertEqual(z_umlat_d, normalize('NFKD', z_umlat_c))
60
self.assertEqual(z_umlat_c, normalize('NFKC', z_umlat_d))
58
self.assertEqual(a_circle_d, normalize('NFD', a_circle_c))
59
self.assertEqual(a_circle_c, normalize('NFC', a_circle_d))
60
self.assertEqual(a_dots_d, normalize('NFD', a_dots_c))
61
self.assertEqual(a_dots_c, normalize('NFC', a_dots_d))
62
self.assertEqual(z_umlat_d, normalize('NFD', z_umlat_c))
63
self.assertEqual(z_umlat_c, normalize('NFC', z_umlat_d))
64
self.assertEqual(squared_d, normalize('NFC', squared_c))
65
self.assertEqual(squared_c, normalize('NFD', squared_d))
66
self.assertEqual(quarter_d, normalize('NFC', quarter_c))
67
self.assertEqual(quarter_c, normalize('NFD', quarter_d))
63
70
class NormalizedFilename(TestCaseWithTransport):
74
81
self.assertEqual((a_dots_c, True), anf(a_dots_d))
75
82
self.assertEqual((z_umlat_c, True), anf(z_umlat_c))
76
83
self.assertEqual((z_umlat_c, True), anf(z_umlat_d))
84
self.assertEqual((squared_c, True), anf(squared_c))
85
self.assertEqual((squared_c, True), anf(squared_d))
86
self.assertEqual((quarter_c, True), anf(quarter_c))
87
self.assertEqual((quarter_c, True), anf(quarter_d))
78
89
def test__inaccessible_normalized_filename(self):
79
90
inf = osutils._inaccessible_normalized_filename
86
97
self.assertEqual((a_dots_c, False), inf(a_dots_d))
87
98
self.assertEqual((z_umlat_c, True), inf(z_umlat_c))
88
99
self.assertEqual((z_umlat_c, False), inf(z_umlat_d))
100
self.assertEqual((squared_c, True), inf(squared_c))
101
self.assertEqual((squared_c, True), inf(squared_d))
102
self.assertEqual((quarter_c, True), inf(quarter_c))
103
self.assertEqual((quarter_c, True), inf(quarter_d))
90
105
def test_functions(self):
91
106
if osutils.normalizes_filenames():
115
130
self.assertEqual(expected, present)
117
132
def test_access_normalized(self):
118
# We should always be able to access files created with
133
# We should always be able to access files created with
119
134
# normalized filenames
120
135
# With FAT32 and certain encodings on win32
121
136
# a_circle_c and a_dots_c actually map to the same file
122
137
# adding a suffix kicks in the 'preserving but insensitive'
123
138
# route, and maintains the right files
124
files = [a_circle_c+'.1', a_dots_c+'.2', z_umlat_c+'.3']
139
files = [a_circle_c+'.1', a_dots_c+'.2', z_umlat_c+'.3',
140
squared_c+'.4', quarter_c+'.5']
126
self.build_tree(files)
142
self.build_tree(files, line_endings='native')
127
143
except UnicodeError:
128
144
raise TestSkipped("filesystem cannot create unicode files")
143
159
actual = f.read()
146
self.assertEqual(shouldbe, actual,
147
'contents of %s is incorrect: %r != %r'
162
self.assertEqual(shouldbe, actual,
163
'contents of %r is incorrect: %r != %r'
148
164
% (path, shouldbe, actual))
150
166
def test_access_non_normalized(self):