1904
1912
self.assertContainsRe(out, "^file1.txt~7$", flags=TestGrep._reflags)
1905
1913
self.assertEqual(len(out.splitlines()), 1)
1916
class TestColorGrep(GrepTestBase):
1917
"""Tests for the --color option."""
1918
_rev_sep = color_string('~', fg=FG.BOLD_YELLOW)
1919
_sep = color_string(':', fg=FG.BOLD_CYAN)
1921
def test_color_option(self):
1922
"""Ensure options for color are valid.
1924
out, err = self.run_bzr(['grep', '--color', 'foo', 'bar'], 3)
1925
self.assertEqual(out, '')
1926
self.assertContainsRe(err, 'Valid values for --color are', flags=TestGrep._reflags)
1928
def test_ver_basic_file(self):
1929
"""(versioned) Search for pattern in specfic file.
1932
self.make_branch_and_tree(wd)
1934
lp = 'foo is foobar'
1935
self._mk_versioned_file('file0.txt', line_prefix=lp, total_lines=1)
1937
# prepare colored result
1938
foo = color_string('foo', fg=FG.BOLD_RED)
1939
res = (color_string('file0.txt', fg=FG.MAGENTA)
1940
+ self._rev_sep + '1' + self._sep
1941
+ foo + ' is ' + foo + 'bar1' + '\n')
1943
nres = (color_string('file0.txt', fg=FG.MAGENTA)
1944
+ self._rev_sep + '1' + self._sep + '1' + self._sep
1945
+ foo + ' is ' + foo + 'bar1' + '\n')
1947
out, err = self.run_bzr(['grep', '--color',
1948
'always', '-r', '1', 'foo'])
1949
self.assertEqual(out, res)
1950
self.assertEqual(len(out.splitlines()), 1)
1952
out, err = self.run_bzr(['grep', '-i', '--color',
1953
'always', '-r', '1', 'FOO'])
1954
self.assertEqual(out, res)
1955
self.assertEqual(len(out.splitlines()), 1)
1957
out, err = self.run_bzr(['grep', '--color',
1958
'always', '-r', '1', 'f.o'])
1959
self.assertEqual(out, res)
1960
self.assertEqual(len(out.splitlines()), 1)
1962
out, err = self.run_bzr(['grep', '-i', '--color',
1963
'always', '-r', '1', 'F.O'])
1964
self.assertEqual(out, res)
1965
self.assertEqual(len(out.splitlines()), 1)
1967
out, err = self.run_bzr(['grep', '-n', '--color',
1968
'always', '-r', '1', 'foo'])
1969
self.assertEqual(out, nres)
1970
self.assertEqual(len(out.splitlines()), 1)
1972
out, err = self.run_bzr(['grep', '-n', '-i', '--color',
1973
'always', '-r', '1', 'FOO'])
1974
self.assertEqual(out, nres)
1975
self.assertEqual(len(out.splitlines()), 1)
1977
out, err = self.run_bzr(['grep', '-n', '--color',
1978
'always', '-r', '1', 'f.o'])
1979
self.assertEqual(out, nres)
1980
self.assertEqual(len(out.splitlines()), 1)
1982
out, err = self.run_bzr(['grep', '-n', '-i', '--color',
1983
'always', '-r', '1', 'F.O'])
1984
self.assertEqual(out, nres)
1985
self.assertEqual(len(out.splitlines()), 1)
1987
def test_wtree_basic_file(self):
1988
"""(wtree) Search for pattern in specfic file.
1991
self.make_branch_and_tree(wd)
1993
lp = 'foo is foobar'
1994
self._mk_versioned_file('file0.txt', line_prefix=lp, total_lines=1)
1996
# prepare colored result
1997
foo = color_string('foo', fg=FG.BOLD_RED)
1998
res = (color_string('file0.txt', fg=FG.MAGENTA)
1999
+ self._sep + foo + ' is ' + foo + 'bar1' + '\n')
2001
nres = (color_string('file0.txt', fg=FG.MAGENTA)
2002
+ self._sep + '1' + self._sep
2003
+ foo + ' is ' + foo + 'bar1' + '\n')
2005
out, err = self.run_bzr(['grep', '--color',
2007
self.assertEqual(out, res)
2008
self.assertEqual(len(out.splitlines()), 1)
2010
out, err = self.run_bzr(['grep', '-i', '--color',
2012
self.assertEqual(out, res)
2013
self.assertEqual(len(out.splitlines()), 1)
2015
out, err = self.run_bzr(['grep', '--color',
2017
self.assertEqual(out, res)
2018
self.assertEqual(len(out.splitlines()), 1)
2020
out, err = self.run_bzr(['grep', '-i', '--color',
2022
self.assertEqual(out, res)
2023
self.assertEqual(len(out.splitlines()), 1)
2025
out, err = self.run_bzr(['grep', '-n', '--color',
2027
self.assertEqual(out, nres)
2028
self.assertEqual(len(out.splitlines()), 1)
2030
out, err = self.run_bzr(['grep', '-n', '-i', '--color',
2032
self.assertEqual(out, nres)
2033
self.assertEqual(len(out.splitlines()), 1)
2035
out, err = self.run_bzr(['grep', '-n', '--color',
2037
self.assertEqual(out, nres)
2038
self.assertEqual(len(out.splitlines()), 1)
2040
out, err = self.run_bzr(['grep', '-n', '-i', '--color',
2042
self.assertEqual(out, nres)
2043
self.assertEqual(len(out.splitlines()), 1)