github的一些开源项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

624 lines
7.9 KiB

  1. # This file tests the auxiliary pattern conversion features of the PCRE2
  2. # library, in non-UTF mode.
  3. #forbid_utf
  4. #newline_default lf any anycrlf
  5. # -------- Tests of glob conversion --------
  6. # Set the glob separator explicitly so that different OS defaults are not a
  7. # problem. Then test various errors.
  8. #pattern convert=glob,convert_glob_escape=\,convert_glob_separator=/
  9. /abc/posix
  10. ** The convert and posix modifiers are mutually exclusive
  11. # Separator must be / \ or .
  12. /a*b/convert_glob_separator=%
  13. ** Invalid glob separator '%'
  14. # Can't have separator in a class
  15. "[ab/cd]"
  16. (?s)\A[ab/cd](?<!/)\z
  17. "[,-/]"
  18. (?s)\A[,-/](?<!/)\z
  19. /[ab/
  20. ** Pattern conversion error at offset 3: missing terminating ] for character class
  21. # Length check
  22. /abc/convert_length=11
  23. ** Pattern conversion error at offset 3: no more memory
  24. /abc/convert_length=12
  25. (?s)\Aabc\z
  26. # Now some actual tests
  27. /a?b[]xy]*c/
  28. (?s)\Aa[^/]b[\]xy](*COMMIT)[^/]*?c\z
  29. azb]1234c
  30. 0: azb]1234c
  31. # Tests from the gitwildmatch list, with some additions
  32. /foo/
  33. (?s)\Afoo\z
  34. foo
  35. 0: foo
  36. /= Expect no match
  37. No match
  38. bar
  39. No match
  40. //
  41. (?s)\A\z
  42. \
  43. 0:
  44. /???/
  45. (?s)\A[^/][^/][^/]\z
  46. foo
  47. 0: foo
  48. \= Expect no match
  49. foobar
  50. No match
  51. /*/
  52. (?s)\A[^/]*+\z
  53. foo
  54. 0: foo
  55. \
  56. 0:
  57. /f*/
  58. (?s)\Af(*COMMIT)[^/]*+\z
  59. foo
  60. 0: foo
  61. f
  62. 0: f
  63. /*f/
  64. (?s)\A[^/]*?f\z
  65. oof
  66. 0: oof
  67. \= Expect no match
  68. foo
  69. No match
  70. /*foo*/
  71. (?s)\A[^/]*?foo(*COMMIT)[^/]*+\z
  72. foo
  73. 0: foo
  74. food
  75. 0: food
  76. aprilfool
  77. 0: aprilfool
  78. /*ob*a*r*/
  79. (?s)\A[^/]*?ob(*COMMIT)[^/]*?a(*COMMIT)[^/]*?r(*COMMIT)[^/]*+\z
  80. foobar
  81. 0: foobar
  82. /*ab/
  83. (?s)\A[^/]*?ab\z
  84. aaaaaaabababab
  85. 0: aaaaaaabababab
  86. /foo\*/
  87. (?s)\Afoo\*\z
  88. foo*
  89. 0: foo*
  90. /foo\*bar/
  91. (?s)\Afoo\*bar\z
  92. \= Expect no match
  93. foobar
  94. No match
  95. /f\\oo/
  96. (?s)\Af\\oo\z
  97. f\\oo
  98. 0: f\oo
  99. /*[al]?/
  100. (?s)\A[^/]*?[al][^/]\z
  101. ball
  102. 0: ball
  103. /[ten]/
  104. (?s)\A[ten]\z
  105. \= Expect no match
  106. ten
  107. No match
  108. /t[a-g]n/
  109. (?s)\At[a-g]n\z
  110. ten
  111. 0: ten
  112. /a[]]b/
  113. (?s)\Aa[\]]b\z
  114. a]b
  115. 0: a]b
  116. /a[]a-]b/
  117. (?s)\Aa[\]a\-]b\z
  118. /a[]-]b/
  119. (?s)\Aa[\]\-]b\z
  120. a-b
  121. 0: a-b
  122. a]b
  123. 0: a]b
  124. \= Expect no match
  125. aab
  126. No match
  127. /a[]a-z]b/
  128. (?s)\Aa[\]a-z]b\z
  129. aab
  130. 0: aab
  131. /]/
  132. (?s)\A\]\z
  133. ]
  134. 0: ]
  135. /t[!a-g]n/
  136. (?s)\At[^/a-g]n\z
  137. ton
  138. 0: ton
  139. \= Expect no match
  140. ten
  141. No match
  142. '[[:alpha:]][[:digit:]][[:upper:]]'
  143. (?s)\A[[:alpha:]][[:digit:]][[:upper:]]\z
  144. a1B
  145. 0: a1B
  146. '[[:digit:][:upper:][:space:]]'
  147. (?s)\A[[:digit:][:upper:][:space:]]\z
  148. A
  149. 0: A
  150. 1
  151. 0: 1
  152. \ \=
  153. 0:
  154. \= Expect no match
  155. a
  156. No match
  157. .
  158. No match
  159. '[a-c[:digit:]x-z]'
  160. (?s)\A[a-c[:digit:]x-z]\z
  161. 5
  162. 0: 5
  163. b
  164. 0: b
  165. y
  166. 0: y
  167. \= Expect no match
  168. q
  169. No match
  170. # End of gitwildmatch tests
  171. /*.j?g/
  172. (?s)\A[^/]*?\.j[^/]g\z
  173. pic01.jpg
  174. 0: pic01.jpg
  175. .jpg
  176. 0: .jpg
  177. pic02.jxg
  178. 0: pic02.jxg
  179. \= Expect no match
  180. pic03.j/g
  181. No match
  182. /A[+-0]B/
  183. (?s)\AA[+-0](?<!/)B\z
  184. A+B
  185. 0: A+B
  186. A.B
  187. 0: A.B
  188. A0B
  189. 0: A0B
  190. \= Expect no match
  191. A/B
  192. No match
  193. /*x?z/
  194. (?s)\A[^/]*?x[^/]z\z
  195. abc.xyz
  196. 0: abc.xyz
  197. \= Expect no match
  198. .xyz
  199. 0: .xyz
  200. /?x?z/
  201. (?s)\A[^/]x[^/]z\z
  202. axyz
  203. 0: axyz
  204. \= Expect no match
  205. .xyz
  206. 0: .xyz
  207. "[,-0]x?z"
  208. (?s)\A[,-0](?<!/)x[^/]z\z
  209. ,xyz
  210. 0: ,xyz
  211. \= Expect no match
  212. /xyz
  213. No match
  214. .xyz
  215. 0: .xyz
  216. ".x*"
  217. (?s)\A\.x(*COMMIT)[^/]*+\z
  218. .xabc
  219. 0: .xabc
  220. /a[--0]z/
  221. (?s)\Aa[\--0](?<!/)z\z
  222. a-z
  223. 0: a-z
  224. a.z
  225. 0: a.z
  226. a0z
  227. 0: a0z
  228. \= Expect no match
  229. a/z
  230. No match
  231. a1z
  232. No match
  233. /<[a-c-d]>/
  234. (?s)\A<[a-c\-d]>\z
  235. <a>
  236. 0: <a>
  237. <b>
  238. 0: <b>
  239. <c>
  240. 0: <c>
  241. <d>
  242. 0: <d>
  243. <->
  244. 0: <->
  245. /a[[:digit:].]z/
  246. (?s)\Aa[[:digit:].]z\z
  247. a1z
  248. 0: a1z
  249. a.z
  250. 0: a.z
  251. \= Expect no match
  252. a:z
  253. No match
  254. /a[[:digit].]z/
  255. (?s)\Aa[\[:digit]\.\]z\z
  256. a[.]z
  257. 0: a[.]z
  258. a:.]z
  259. 0: a:.]z
  260. ad.]z
  261. 0: ad.]z
  262. /<[[:a[:digit:]b]>/
  263. (?s)\A<[\[:a[:digit:]b]>\z
  264. <[>
  265. 0: <[>
  266. <:>
  267. 0: <:>
  268. <a>
  269. 0: <a>
  270. <9>
  271. 0: <9>
  272. <b>
  273. 0: <b>
  274. \= Expect no match
  275. <d>
  276. No match
  277. /a*b/convert_glob_separator=\
  278. (?s)\Aa(*COMMIT)[^\\]*?b\z
  279. /a*b/convert_glob_separator=.
  280. (?s)\Aa(*COMMIT)[^\.]*?b\z
  281. /a*b/convert_glob_separator=/
  282. (?s)\Aa(*COMMIT)[^/]*?b\z
  283. # Non control character checking
  284. /A\B\\C\D/
  285. (?s)\AAB\\CD\z
  286. /\\{}\?\*+\[\]()|.^$/
  287. (?s)\A\\\{\}\?\*\+\[\]\(\)\|\.\^\$\z
  288. /*a*\/*b*/
  289. (?s)\A[^/]*?a(*COMMIT)[^/]*?/(*COMMIT)[^/]*?b(*COMMIT)[^/]*+\z
  290. /?a?\/?b?/
  291. (?s)\A[^/]a[^/]/[^/]b[^/]\z
  292. /[a\\b\c][]][-][\]\-]/
  293. (?s)\A[a\\bc][\]][\-][\]\-]\z
  294. /[^a\\b\c][!]][!-][^\]\-]/
  295. (?s)\A[^/a\\bc][^/\]][^/\-][^/\]\-]\z
  296. /[[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:word:][:xdigit:]]/
  297. (?s)\A[[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:word:][:xdigit:]](?<!/)\z
  298. "[/-/]"
  299. (?s)\A[/-/](?<!/)\z
  300. /[-----]/
  301. (?s)\A[\--\-\-\-]\z
  302. /[------]/
  303. (?s)\A[\--\-\--\-]\z
  304. /[!------]/
  305. (?s)\A[^/\--\-\--\-]\z
  306. /[[:alpha:]-a]/
  307. (?s)\A[[:alpha:]\-a]\z
  308. /[[:alpha:]][[:punct:]][[:ascii:]]/
  309. (?s)\A[[:alpha:]][[:punct:]](?<!/)[[:ascii:]](?<!/)\z
  310. /[a-[:alpha:]]/
  311. ** Pattern conversion error at offset 4: invalid syntax
  312. /[[:alpha:/
  313. ** Pattern conversion error at offset 9: missing terminating ] for character class
  314. /[[:alpha:]/
  315. ** Pattern conversion error at offset 10: missing terminating ] for character class
  316. /[[:alphaa:]]/
  317. (?s)\A[\[:alphaa:]\]\z
  318. /[[:xdigi:]]/
  319. (?s)\A[\[:xdigi:]\]\z
  320. /[[:xdigit::]]/
  321. (?s)\A[\[:xdigit::]\]\z
  322. /****/
  323. (?s)
  324. /**\/abc/
  325. (?s)(?:\A|/)abc\z
  326. abc
  327. 0: abc
  328. x/abc
  329. 0: /abc
  330. xabc
  331. No match
  332. /abc\/**/
  333. (?s)\Aabc/
  334. /abc\/**\/abc/
  335. (?s)\Aabc/(*COMMIT)(?:.*?/)??abc\z
  336. /**\/*a*b*g*n*t/
  337. (?s)(?:\A|/)(?>[^/]*?a)(?>[^/]*?b)(?>[^/]*?g)(?>[^/]*?n)(?>[^/]*?t\z)
  338. abcd/abcdefg/abcdefghijk/abcdefghijklmnop.txt
  339. 0: /abcdefghijklmnop.txt
  340. /**\/*a*\/**/
  341. (?s)(?:\A|/)(?>[^/]*?a)(?>[^/]*?/)
  342. xx/xx/xx/xax/xx/xb
  343. 0: /xax/
  344. /**\/*a*/
  345. (?s)(?:\A|/)(?>[^/]*?a)(?>[^/]*+\z)
  346. xx/xx/xx/xax
  347. 0: /xax
  348. xx/xx/xx/xax/xx
  349. No match
  350. /**\/*a*\/**\/*b*/
  351. (?s)(?:\A|/)(?>[^/]*?a)(?>[^/]*?/)(*COMMIT)(?:.*?/)??(?>[^/]*?b)(?>[^/]*+\z)
  352. xx/xx/xx/xax/xx/xb
  353. 0: /xax/xx/xb
  354. xx/xx/xx/xax/xx/x
  355. No match
  356. "**a"convert=glob
  357. (?s)a\z
  358. a
  359. 0: a
  360. c/b/a
  361. 0: a
  362. c/b/aaa
  363. 0: a
  364. "a**/b"convert=glob
  365. (?s)\Aa(*COMMIT).*?/b\z
  366. a/b
  367. 0: a/b
  368. ab
  369. No match
  370. "a/**b"convert=glob
  371. (?s)\Aa/(*COMMIT).*?b\z
  372. a/b
  373. 0: a/b
  374. ab
  375. No match
  376. #pattern convert=glob:glob_no_starstar
  377. /***/
  378. (?s)\A[^/]*+\z
  379. /**a**/
  380. (?s)\A[^/]*?a(*COMMIT)[^/]*+\z
  381. #pattern convert=unset
  382. #pattern convert=glob:glob_no_wild_separator
  383. /*/
  384. (?s)
  385. /*a*/
  386. (?s)a
  387. /**a**/
  388. (?s)a
  389. /a*b/
  390. (?s)\Aa(*COMMIT).*?b\z
  391. /*a*b*/
  392. (?s)a(*COMMIT).*?b
  393. /??a??/
  394. (?s)\A..a..\z
  395. #pattern convert=unset
  396. #pattern convert=glob,convert_glob_escape=0
  397. /a\b\cd/
  398. (?s)\Aa\\b\\cd\z
  399. /**\/a/
  400. (?s)\\/a\z
  401. /a`*b/convert_glob_escape=`
  402. (?s)\Aa\*b\z
  403. /a`*b/convert_glob_escape=0
  404. (?s)\Aa`(*COMMIT)[^/]*?b\z
  405. /a`*b/convert_glob_escape=x
  406. ** Invalid glob escape 'x'
  407. # -------- Tests of extended POSIX conversion --------
  408. #pattern convert=unset:posix_extended
  409. /<[[:a[:digit:]b]>/
  410. (*NUL)<[[:a[:digit:]b]>
  411. <[>
  412. 0: <[>
  413. <:>
  414. 0: <:>
  415. <a>
  416. 0: <a>
  417. <9>
  418. 0: <9>
  419. <b>
  420. 0: <b>
  421. \= Expect no match
  422. <d>
  423. No match
  424. /a+\1b\\c|d[ab\c]/
  425. (*NUL)a+1b\\c|d[ab\\c]
  426. /<[]bc]>/
  427. (*NUL)<[]bc]>
  428. <]>
  429. 0: <]>
  430. <b>
  431. 0: <b>
  432. <c>
  433. 0: <c>
  434. /<[^]bc]>/
  435. (*NUL)<[^]bc]>
  436. <.>
  437. 0: <.>
  438. \= Expect no match
  439. <]>
  440. No match
  441. <b>
  442. No match
  443. /(a)\1b/
  444. (*NUL)(a)1b
  445. a1b
  446. 0: a1b
  447. 1: a
  448. \= Expect no match
  449. aab
  450. No match
  451. /(ab)c)d]/
  452. (*NUL)(ab)c\)d\]
  453. Xabc)d]Y
  454. 0: abc)d]
  455. 1: ab
  456. /a***b/
  457. (*NUL)a*b
  458. # -------- Tests of basic POSIX conversion --------
  459. #pattern convert=unset:posix_basic
  460. /a*b+c\+[def](ab)\(cd\)/
  461. (*NUL)a*b\+c\+[def]\(ab\)(cd)
  462. /\(a\)\1b/
  463. (*NUL)(a)\1b
  464. aab
  465. 0: aab
  466. 1: a
  467. \= Expect no match
  468. a1b
  469. No match
  470. /how.to how\.to/
  471. (*NUL)how.to how\.to
  472. how\nto how.to
  473. 0: how\x0ato how.to
  474. \= Expect no match
  475. how\x{0}to how.to
  476. No match
  477. /^how to \^how to/
  478. (*NUL)^how to \^how to
  479. /^*abc/
  480. (*NUL)^\*abc
  481. /*abc/
  482. (*NUL)\*abc
  483. X*abcY
  484. 0: *abc
  485. /**abc/
  486. (*NUL)\**abc
  487. XabcY
  488. 0: abc
  489. X*abcY
  490. 0: *abc
  491. X**abcY
  492. 0: **abc
  493. /*ab\(*cd\)/
  494. (*NUL)\*ab(\*cd)
  495. /^b\(c^d\)\(^e^f\)/
  496. (*NUL)^b(c\^d)(^e\^f)
  497. /a***b/
  498. (*NUL)a*b
  499. # End of testinput24