1" Tests for regexp with backslash and other special characters inside []
2" Also test backslash for hex/octal numbered character.
3
4function RunSTest(value, calls, expected)
5  new
6  call feedkeys("i" . a:value, "mx")
7  exec a:calls
8  call assert_equal(a:expected, getline(1), printf("wrong result for %s", a:calls))
9  quit!
10endfunction
11
12function RunXTest(value, search_exp, expected)
13  new
14  call feedkeys("i" . a:value, "mx")
15  call feedkeys("gg" . a:search_exp . "\nx", "mx")
16  call assert_equal(a:expected, getline(1), printf("wrong result for %s", a:search_exp))
17  quit!
18endfunction
19
20
21function Test_x_search()
22  let res = "test text test text"
23  call RunXTest("test \\text test text", "/[\\x]", res)
24  call RunXTest("test \ttext test text", "/[\\t\\]]", res)
25  call RunXTest("test text ]test text", "/[]y]", res)
26  call RunXTest("test ]text test text", "/[\\]]", res)
27  call RunXTest("test text te^st text", "/[y^]", res)
28  call RunXTest("test te$xt test text", "/[$y]", res)
29  call RunXTest("test taext test text", "/[\\x61]", res)
30  call RunXTest("test tbext test text","/[\\x60-\\x64]", res)
31  call RunXTest("test 5text test text","/[\\x785]", res)
32  call RunXTest("testc text test text","/[\\o143]", res)
33  call RunXTest("tesdt text test text","/[\\o140-\\o144]", res)
34  call RunXTest("test7 text test text", "/[\\o417]", res)
35  call RunXTest("test text tBest text", "/\\%x42", res)
36  call RunXTest("test text teCst text", "/\\%o103", res)
37  call RunXTest("test text \<C-V>x00test text", "/[\\x00]", res)
38endfunction
39
40function Test_s_search()
41  let res = "test text test text"
42  call RunSTest("test te\<C-V>x00xt t\<C-V>x04est t\<C-V>x10ext", "s/[\\x00-\\x10]//g", res)
43  call RunSTest("test \\xyztext test text", "s/[\\x-z]\\+//", res)
44  call RunSTest("test text tev\\uyst text", "s/[\\u-z]\\{2,}//", res)
45  call RunSTest("xx aaaaa xx a", "s/\\(a\\)\\+//", "xx  xx a")
46  call RunSTest("xx aaaaa xx a", "s/\\(a*\\)\\+//", "xx aaaaa xx a")
47  call RunSTest("xx aaaaa xx a", "s/\\(a*\\)*//", "xx aaaaa xx a")
48  call RunSTest("xx aaaaa xx", "s/\\(a\\)\\{2,3}/A/", "xx Aaa xx")
49  call RunSTest("xx aaaaa xx", "s/\\(a\\)\\{-2,3}/A/", "xx Aaaa xx")
50  call RunSTest("xx aaa12aa xx", "s/\\(a\\)*\\(12\\)\\@>/A/", "xx Aaa xx")
51  call RunSTest("xx foobar xbar xx", "s/\\(foo\\)\\@<!bar/A/", "xx foobar xA xx")
52  call RunSTest("xx an file xx", "s/\\(an\\_s\\+\\)\\@<=file/A/", "xx an A xx")
53  call RunSTest("x= 9;", "s/^\\(\\h\\w*\\%(->\\|\\.\\)\\=\\)\\+=/XX/", "XX 9;")
54  call RunSTest("hh= 77;", "s/^\\(\\h\\w*\\%(->\\|\\.\\)\\=\\)\\+=/YY/", "YY 77;")
55  call RunSTest(" aaa ", "s/aaa/xyz/", " xyz ")
56  call RunSTest(" xyz", "s/~/bcd/", " bcd")
57  call RunSTest(" bcdbcdbcd", "s/~\\+/BB/", " BB")
58endfunction
59