45
45
stderr=subprocess.PIPE)
47
47
cword = len(words) + cword
48
input = '%s\n' % self.script
49
input += ('COMP_WORDS=( %s )\n' %
50
' '.join(["'"+w.replace("'", "'\\''")+"'" for w in words]))
51
input += 'COMP_CWORD=%d\n' % cword
52
input += '%s\n' % getattr(self, 'script_name', '_brz')
53
input += 'echo ${#COMPREPLY[*]}\n'
54
input += "IFS=$'\\n'\n"
55
input += 'echo "${COMPREPLY[*]}"\n'
48
encoding = osutils.get_user_encoding()
49
input = b'%s\n' % self.script.encode(encoding)
50
input += (b'COMP_WORDS=( %s )\n' %
51
b' '.join([b"'"+w.replace("'", "'\\''").encode(encoding)+b"'" for w in words]))
52
input += b'COMP_CWORD=%d\n' % cword
53
input += b'%s\n' % getattr(self, 'script_name', '_brz').encode(encoding)
54
input += b'echo ${#COMPREPLY[*]}\n'
55
input += b"IFS=$'\\n'\n"
56
input += b'echo "${COMPREPLY[*]}"\n'
56
57
(out, err) = proc.communicate(input)
58
59
raise AssertionError('Unexpected error message:\n%s' % err)
59
self.assertEqual('', err, 'No messages to standard error')
60
self.assertEqual(b'', err, 'No messages to standard error')
61
62
#print >>sys.stdout, '---\n%s\n---\n%s\n---\n' % (input, out)
62
lines = out.split('\n')
63
lines = out.split(b'\n')
63
64
nlines = int(lines[0])
65
self.assertEqual('', lines[-1], 'Newline at end')
66
self.assertEqual(b'', lines[-1], 'Newline at end')
67
if nlines == 0 and len(lines) == 1 and lines[0] == '':
68
if nlines == 0 and len(lines) == 1 and lines[0] == b'':
69
70
self.assertEqual(nlines, len(lines), 'No newlines in generated words')
70
self.completion_result = set(lines)
71
self.completion_result = {l.decode(encoding) for l in lines}
71
72
return self.completion_result
73
74
def assertCompletionEquals(self, *words):
166
167
def test_revspec_tag_all(self):
167
168
self.requireFeature(features.sed_feature)
168
169
wt = self.make_branch_and_tree('.', format='dirstate-tags')
169
wt.branch.tags.set_tag('tag1', 'null:')
170
wt.branch.tags.set_tag('tag2', 'null:')
171
wt.branch.tags.set_tag('3tag', 'null:')
170
wt.branch.tags.set_tag('tag1', b'null:')
171
wt.branch.tags.set_tag('tag2', b'null:')
172
wt.branch.tags.set_tag('3tag', b'null:')
172
173
self.complete(['brz', 'log', '-r', 'tag', ':'])
173
174
self.assertCompletionEquals('tag1', 'tag2', '3tag')
175
176
def test_revspec_tag_prefix(self):
176
177
self.requireFeature(features.sed_feature)
177
178
wt = self.make_branch_and_tree('.', format='dirstate-tags')
178
wt.branch.tags.set_tag('tag1', 'null:')
179
wt.branch.tags.set_tag('tag2', 'null:')
180
wt.branch.tags.set_tag('3tag', 'null:')
179
wt.branch.tags.set_tag('tag1', b'null:')
180
wt.branch.tags.set_tag('tag2', b'null:')
181
wt.branch.tags.set_tag('3tag', b'null:')
181
182
self.complete(['brz', 'log', '-r', 'tag', ':', 't'])
182
183
self.assertCompletionEquals('tag1', 'tag2')
184
185
def test_revspec_tag_spaces(self):
185
186
self.requireFeature(features.sed_feature)
186
187
wt = self.make_branch_and_tree('.', format='dirstate-tags')
187
wt.branch.tags.set_tag('tag with spaces', 'null:')
188
wt.branch.tags.set_tag('tag with spaces', b'null:')
188
189
self.complete(['brz', 'log', '-r', 'tag', ':', 't'])
189
190
self.assertCompletionEquals(r'tag\ with\ spaces')
190
191
self.complete(['brz', 'log', '-r', '"tag:t'])
195
196
def test_revspec_tag_endrange(self):
196
197
self.requireFeature(features.sed_feature)
197
198
wt = self.make_branch_and_tree('.', format='dirstate-tags')
198
wt.branch.tags.set_tag('tag1', 'null:')
199
wt.branch.tags.set_tag('tag2', 'null:')
199
wt.branch.tags.set_tag('tag1', b'null:')
200
wt.branch.tags.set_tag('tag2', b'null:')
200
201
self.complete(['brz', 'log', '-r', '3..tag', ':', 't'])
201
202
self.assertCompletionEquals('tag1', 'tag2')
202
203
self.complete(['brz', 'log', '-r', '"3..tag:t'])