##// END OF EJS Templates
store: add some doctests
Adrian Buehlmann -
r13949:ba43aa1e default
parent child Browse files
Show More
@@ -14,6 +14,14 b' import os, stat'
14 14 # This avoids a collision between a file named foo and a dir named
15 15 # foo.i or foo.d
16 16 def encodedir(path):
17 '''
18 >>> encodedir('data/foo.i')
19 'data/foo.i'
20 >>> encodedir('data/foo.i/bla.i')
21 'data/foo.i.hg/bla.i'
22 >>> encodedir('data/foo.i.hg/bla.i')
23 'data/foo.i.hg.hg/bla.i'
24 '''
17 25 if not path.startswith('data/'):
18 26 return path
19 27 return (path
@@ -22,6 +30,14 b' def encodedir(path):'
22 30 .replace(".d/", ".d.hg/"))
23 31
24 32 def decodedir(path):
33 '''
34 >>> decodedir('data/foo.i')
35 'data/foo.i'
36 >>> decodedir('data/foo.i.hg/bla.i')
37 'data/foo.i/bla.i'
38 >>> decodedir('data/foo.i.hg.hg/bla.i')
39 'data/foo.i.hg/bla.i'
40 '''
25 41 if not path.startswith('data/') or ".hg/" not in path:
26 42 return path
27 43 return (path
@@ -30,6 +46,29 b' def decodedir(path):'
30 46 .replace(".hg.hg/", ".hg/"))
31 47
32 48 def _buildencodefun():
49 '''
50 >>> enc, dec = _buildencodefun()
51
52 >>> enc('nothing/special.txt')
53 'nothing/special.txt'
54 >>> dec('nothing/special.txt')
55 'nothing/special.txt'
56
57 >>> enc('HELLO')
58 '_h_e_l_l_o'
59 >>> dec('_h_e_l_l_o')
60 'HELLO'
61
62 >>> enc('hello:world?')
63 'hello~3aworld~3f'
64 >>> dec('hello~3aworld~3f')
65 'hello:world?'
66
67 >>> enc('the\x07quick\xADshot')
68 'the~07quick~adshot'
69 >>> dec('the~07quick~adshot')
70 'the\\x07quick\\xadshot'
71 '''
33 72 e = '_'
34 73 win_reserved = [ord(x) for x in '\\:*?"<>|']
35 74 cmap = dict([(chr(x), chr(x)) for x in xrange(127)])
@@ -58,6 +97,17 b' def _buildencodefun():'
58 97 encodefilename, decodefilename = _buildencodefun()
59 98
60 99 def _build_lower_encodefun():
100 '''
101 >>> f = _build_lower_encodefun()
102 >>> f('nothing/special.txt')
103 'nothing/special.txt'
104 >>> f('HELLO')
105 'hello'
106 >>> f('hello:world?')
107 'hello~3aworld~3f'
108 >>> f('the\x07quick\xADshot')
109 'the~07quick~adshot'
110 '''
61 111 win_reserved = [ord(x) for x in '\\:*?"<>|']
62 112 cmap = dict([(chr(x), chr(x)) for x in xrange(127)])
63 113 for x in (range(32) + range(126, 256) + win_reserved):
@@ -72,6 +122,23 b' lowerencode = _build_lower_encodefun()'
72 122 com1 com2 com3 com4 com5 com6 com7 com8 com9
73 123 lpt1 lpt2 lpt3 lpt4 lpt5 lpt6 lpt7 lpt8 lpt9'''.split()
74 124 def _auxencode(path, dotencode):
125 '''
126 Encodes filenames containing names reserved by Windows or which end in
127 period or space. Does not touch other single reserved characters c.
128 Specifically, c in '\\:*?"<>|' or ord(c) <= 31 are *not* encoded here.
129 Additionally encodes space or period at the beginning, if dotencode is
130 True.
131 path is assumed to be all lowercase.
132
133 >>> _auxencode('.foo/aux.txt/txt.aux/con/prn/nul/foo.', True)
134 '~2efoo/au~78.txt/txt.aux/co~6e/pr~6e/nu~6c/foo~2e'
135 >>> _auxencode('.com1com2/lpt9.lpt4.lpt1/conprn/foo.', False)
136 '.com1com2/lp~749.lpt4.lpt1/conprn/foo~2e'
137 >>> _auxencode('foo. ', True)
138 'foo.~20'
139 >>> _auxencode(' .foo', True)
140 '~20.foo'
141 '''
75 142 res = []
76 143 for n in path.split('/'):
77 144 if n:
@@ -13,6 +13,9 b' doctest.testmod(mercurial.dagparser, opt'
13 13 import mercurial.match
14 14 doctest.testmod(mercurial.match)
15 15
16 import mercurial.store
17 doctest.testmod(mercurial.store)
18
16 19 import mercurial.url
17 20 doctest.testmod(mercurial.url)
18 21
General Comments 0
You need to be logged in to leave comments. Login now