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.

FileNameMatcherTest.java 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  1. /*
  2. * Copyright (C) 2008, Florian Koeberle <florianskarten@web.de>
  3. * Copyright (C) 2008, Florian Köberle <florianskarten@web.de>
  4. * and other copyright owners as documented in the project's IP log.
  5. *
  6. * This program and the accompanying materials are made available
  7. * under the terms of the Eclipse Distribution License v1.0 which
  8. * accompanies this distribution, is reproduced below, and is
  9. * available at http://www.eclipse.org/org/documents/edl-v10.php
  10. *
  11. * All rights reserved.
  12. *
  13. * Redistribution and use in source and binary forms, with or
  14. * without modification, are permitted provided that the following
  15. * conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright
  18. * notice, this list of conditions and the following disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials provided
  23. * with the distribution.
  24. *
  25. * - Neither the name of the Eclipse Foundation, Inc. nor the
  26. * names of its contributors may be used to endorse or promote
  27. * products derived from this software without specific prior
  28. * written permission.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  31. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  32. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  33. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  34. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  35. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  36. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  37. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  38. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  39. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  40. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  42. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  43. */
  44. package org.eclipse.jgit.fnmatch;
  45. import static org.junit.Assert.assertEquals;
  46. import static org.junit.Assert.assertTrue;
  47. import static org.junit.Assert.fail;
  48. import org.eclipse.jgit.errors.InvalidPatternException;
  49. import org.junit.Test;
  50. public class FileNameMatcherTest {
  51. private void assertMatch(final String pattern, final String input,
  52. final boolean matchExpected, final boolean appendCanMatchExpected)
  53. throws InvalidPatternException {
  54. final FileNameMatcher matcher = new FileNameMatcher(pattern, null);
  55. matcher.append(input);
  56. assertEquals(matchExpected, matcher.isMatch());
  57. assertEquals(appendCanMatchExpected, matcher.canAppendMatch());
  58. }
  59. private void assertFileNameMatch(final String pattern, final String input,
  60. final char excludedCharacter, final boolean matchExpected,
  61. final boolean appendCanMatchExpected)
  62. throws InvalidPatternException {
  63. final FileNameMatcher matcher = new FileNameMatcher(pattern,
  64. new Character(excludedCharacter));
  65. matcher.append(input);
  66. assertEquals(matchExpected, matcher.isMatch());
  67. assertEquals(appendCanMatchExpected, matcher.canAppendMatch());
  68. }
  69. @Test
  70. public void testVerySimplePatternCase0() throws Exception {
  71. assertMatch("", "", true, false);
  72. }
  73. @Test
  74. public void testVerySimplePatternCase1() throws Exception {
  75. assertMatch("ab", "a", false, true);
  76. }
  77. @Test
  78. public void testVerySimplePatternCase2() throws Exception {
  79. assertMatch("ab", "ab", true, false);
  80. }
  81. @Test
  82. public void testVerySimplePatternCase3() throws Exception {
  83. assertMatch("ab", "ac", false, false);
  84. }
  85. @Test
  86. public void testVerySimplePatternCase4() throws Exception {
  87. assertMatch("ab", "abc", false, false);
  88. }
  89. @Test
  90. public void testVerySimpleWirdcardCase0() throws Exception {
  91. assertMatch("?", "a", true, false);
  92. }
  93. @Test
  94. public void testVerySimpleWildCardCase1() throws Exception {
  95. assertMatch("??", "a", false, true);
  96. }
  97. @Test
  98. public void testVerySimpleWildCardCase2() throws Exception {
  99. assertMatch("??", "ab", true, false);
  100. }
  101. @Test
  102. public void testVerySimpleWildCardCase3() throws Exception {
  103. assertMatch("??", "abc", false, false);
  104. }
  105. @Test
  106. public void testVerySimpleStarCase0() throws Exception {
  107. assertMatch("*", "", true, true);
  108. }
  109. @Test
  110. public void testVerySimpleStarCase1() throws Exception {
  111. assertMatch("*", "a", true, true);
  112. }
  113. @Test
  114. public void testVerySimpleStarCase2() throws Exception {
  115. assertMatch("*", "ab", true, true);
  116. }
  117. @Test
  118. public void testSimpleStarCase0() throws Exception {
  119. assertMatch("a*b", "a", false, true);
  120. }
  121. @Test
  122. public void testSimpleStarCase1() throws Exception {
  123. assertMatch("a*c", "ac", true, true);
  124. }
  125. @Test
  126. public void testSimpleStarCase2() throws Exception {
  127. assertMatch("a*c", "ab", false, true);
  128. }
  129. @Test
  130. public void testSimpleStarCase3() throws Exception {
  131. assertMatch("a*c", "abc", true, true);
  132. }
  133. @Test
  134. public void testManySolutionsCase0() throws Exception {
  135. assertMatch("a*a*a", "aaa", true, true);
  136. }
  137. @Test
  138. public void testManySolutionsCase1() throws Exception {
  139. assertMatch("a*a*a", "aaaa", true, true);
  140. }
  141. @Test
  142. public void testManySolutionsCase2() throws Exception {
  143. assertMatch("a*a*a", "ababa", true, true);
  144. }
  145. @Test
  146. public void testManySolutionsCase3() throws Exception {
  147. assertMatch("a*a*a", "aaaaaaaa", true, true);
  148. }
  149. @Test
  150. public void testManySolutionsCase4() throws Exception {
  151. assertMatch("a*a*a", "aaaaaaab", false, true);
  152. }
  153. @Test
  154. public void testVerySimpleGroupCase0() throws Exception {
  155. assertMatch("[ab]", "a", true, false);
  156. }
  157. @Test
  158. public void testVerySimpleGroupCase1() throws Exception {
  159. assertMatch("[ab]", "b", true, false);
  160. }
  161. @Test
  162. public void testVerySimpleGroupCase2() throws Exception {
  163. assertMatch("[ab]", "ab", false, false);
  164. }
  165. @Test
  166. public void testVerySimpleGroupRangeCase0() throws Exception {
  167. assertMatch("[b-d]", "a", false, false);
  168. }
  169. @Test
  170. public void testVerySimpleGroupRangeCase1() throws Exception {
  171. assertMatch("[b-d]", "b", true, false);
  172. }
  173. @Test
  174. public void testVerySimpleGroupRangeCase2() throws Exception {
  175. assertMatch("[b-d]", "c", true, false);
  176. }
  177. @Test
  178. public void testVerySimpleGroupRangeCase3() throws Exception {
  179. assertMatch("[b-d]", "d", true, false);
  180. }
  181. @Test
  182. public void testVerySimpleGroupRangeCase4() throws Exception {
  183. assertMatch("[b-d]", "e", false, false);
  184. }
  185. @Test
  186. public void testVerySimpleGroupRangeCase5() throws Exception {
  187. assertMatch("[b-d]", "-", false, false);
  188. }
  189. @Test
  190. public void testTwoGroupsCase0() throws Exception {
  191. assertMatch("[b-d][ab]", "bb", true, false);
  192. }
  193. @Test
  194. public void testTwoGroupsCase1() throws Exception {
  195. assertMatch("[b-d][ab]", "ca", true, false);
  196. }
  197. @Test
  198. public void testTwoGroupsCase2() throws Exception {
  199. assertMatch("[b-d][ab]", "fa", false, false);
  200. }
  201. @Test
  202. public void testTwoGroupsCase3() throws Exception {
  203. assertMatch("[b-d][ab]", "bc", false, false);
  204. }
  205. @Test
  206. public void testTwoRangesInOneGroupCase0() throws Exception {
  207. assertMatch("[b-ce-e]", "a", false, false);
  208. }
  209. @Test
  210. public void testTwoRangesInOneGroupCase1() throws Exception {
  211. assertMatch("[b-ce-e]", "b", true, false);
  212. }
  213. @Test
  214. public void testTwoRangesInOneGroupCase2() throws Exception {
  215. assertMatch("[b-ce-e]", "c", true, false);
  216. }
  217. @Test
  218. public void testTwoRangesInOneGroupCase3() throws Exception {
  219. assertMatch("[b-ce-e]", "d", false, false);
  220. }
  221. @Test
  222. public void testTwoRangesInOneGroupCase4() throws Exception {
  223. assertMatch("[b-ce-e]", "e", true, false);
  224. }
  225. @Test
  226. public void testTwoRangesInOneGroupCase5() throws Exception {
  227. assertMatch("[b-ce-e]", "f", false, false);
  228. }
  229. @Test
  230. public void testIncompleteRangesInOneGroupCase0() throws Exception {
  231. assertMatch("a[b-]", "ab", true, false);
  232. }
  233. @Test
  234. public void testIncompleteRangesInOneGroupCase1() throws Exception {
  235. assertMatch("a[b-]", "ac", false, false);
  236. }
  237. @Test
  238. public void testIncompleteRangesInOneGroupCase2() throws Exception {
  239. assertMatch("a[b-]", "a-", true, false);
  240. }
  241. @Test
  242. public void testCombinedRangesInOneGroupCase0() throws Exception {
  243. assertMatch("[a-c-e]", "b", true, false);
  244. }
  245. /**
  246. * The c belongs to the range a-c. "-e" is no valid range so d should not
  247. * match.
  248. *
  249. * @throws Exception
  250. * for some reasons
  251. */
  252. @Test
  253. public void testCombinedRangesInOneGroupCase1() throws Exception {
  254. assertMatch("[a-c-e]", "d", false, false);
  255. }
  256. @Test
  257. public void testCombinedRangesInOneGroupCase2() throws Exception {
  258. assertMatch("[a-c-e]", "e", true, false);
  259. }
  260. @Test
  261. public void testInversedGroupCase0() throws Exception {
  262. assertMatch("[!b-c]", "a", true, false);
  263. }
  264. @Test
  265. public void testInversedGroupCase1() throws Exception {
  266. assertMatch("[!b-c]", "b", false, false);
  267. }
  268. @Test
  269. public void testInversedGroupCase2() throws Exception {
  270. assertMatch("[!b-c]", "c", false, false);
  271. }
  272. @Test
  273. public void testInversedGroupCase3() throws Exception {
  274. assertMatch("[!b-c]", "d", true, false);
  275. }
  276. @Test
  277. public void testAlphaGroupCase0() throws Exception {
  278. assertMatch("[[:alpha:]]", "d", true, false);
  279. }
  280. @Test
  281. public void testAlphaGroupCase1() throws Exception {
  282. assertMatch("[[:alpha:]]", ":", false, false);
  283. }
  284. @Test
  285. public void testAlphaGroupCase2() throws Exception {
  286. // \u00f6 = 'o' with dots on it
  287. assertMatch("[[:alpha:]]", "\u00f6", true, false);
  288. }
  289. @Test
  290. public void test2AlphaGroupsCase0() throws Exception {
  291. // \u00f6 = 'o' with dots on it
  292. assertMatch("[[:alpha:]][[:alpha:]]", "a\u00f6", true, false);
  293. assertMatch("[[:alpha:]][[:alpha:]]", "a1", false, false);
  294. }
  295. @Test
  296. public void testAlnumGroupCase0() throws Exception {
  297. assertMatch("[[:alnum:]]", "a", true, false);
  298. }
  299. @Test
  300. public void testAlnumGroupCase1() throws Exception {
  301. assertMatch("[[:alnum:]]", "1", true, false);
  302. }
  303. @Test
  304. public void testAlnumGroupCase2() throws Exception {
  305. assertMatch("[[:alnum:]]", ":", false, false);
  306. }
  307. @Test
  308. public void testBlankGroupCase0() throws Exception {
  309. assertMatch("[[:blank:]]", " ", true, false);
  310. }
  311. @Test
  312. public void testBlankGroupCase1() throws Exception {
  313. assertMatch("[[:blank:]]", "\t", true, false);
  314. }
  315. @Test
  316. public void testBlankGroupCase2() throws Exception {
  317. assertMatch("[[:blank:]]", "\r", false, false);
  318. }
  319. @Test
  320. public void testBlankGroupCase3() throws Exception {
  321. assertMatch("[[:blank:]]", "\n", false, false);
  322. }
  323. @Test
  324. public void testBlankGroupCase4() throws Exception {
  325. assertMatch("[[:blank:]]", "a", false, false);
  326. }
  327. @Test
  328. public void testCntrlGroupCase0() throws Exception {
  329. assertMatch("[[:cntrl:]]", "a", false, false);
  330. }
  331. @Test
  332. public void testCntrlGroupCase1() throws Exception {
  333. assertMatch("[[:cntrl:]]", String.valueOf((char) 7), true, false);
  334. }
  335. @Test
  336. public void testDigitGroupCase0() throws Exception {
  337. assertMatch("[[:digit:]]", "0", true, false);
  338. }
  339. @Test
  340. public void testDigitGroupCase1() throws Exception {
  341. assertMatch("[[:digit:]]", "5", true, false);
  342. }
  343. @Test
  344. public void testDigitGroupCase2() throws Exception {
  345. assertMatch("[[:digit:]]", "9", true, false);
  346. }
  347. @Test
  348. public void testDigitGroupCase3() throws Exception {
  349. // \u06f9 = EXTENDED ARABIC-INDIC DIGIT NINE
  350. assertMatch("[[:digit:]]", "\u06f9", true, false);
  351. }
  352. @Test
  353. public void testDigitGroupCase4() throws Exception {
  354. assertMatch("[[:digit:]]", "a", false, false);
  355. }
  356. @Test
  357. public void testDigitGroupCase5() throws Exception {
  358. assertMatch("[[:digit:]]", "]", false, false);
  359. }
  360. @Test
  361. public void testGraphGroupCase0() throws Exception {
  362. assertMatch("[[:graph:]]", "]", true, false);
  363. }
  364. @Test
  365. public void testGraphGroupCase1() throws Exception {
  366. assertMatch("[[:graph:]]", "a", true, false);
  367. }
  368. @Test
  369. public void testGraphGroupCase2() throws Exception {
  370. assertMatch("[[:graph:]]", ".", true, false);
  371. }
  372. @Test
  373. public void testGraphGroupCase3() throws Exception {
  374. assertMatch("[[:graph:]]", "0", true, false);
  375. }
  376. @Test
  377. public void testGraphGroupCase4() throws Exception {
  378. assertMatch("[[:graph:]]", " ", false, false);
  379. }
  380. @Test
  381. public void testGraphGroupCase5() throws Exception {
  382. // \u00f6 = 'o' with dots on it
  383. assertMatch("[[:graph:]]", "\u00f6", true, false);
  384. }
  385. @Test
  386. public void testLowerGroupCase0() throws Exception {
  387. assertMatch("[[:lower:]]", "a", true, false);
  388. }
  389. @Test
  390. public void testLowerGroupCase1() throws Exception {
  391. assertMatch("[[:lower:]]", "h", true, false);
  392. }
  393. @Test
  394. public void testLowerGroupCase2() throws Exception {
  395. assertMatch("[[:lower:]]", "A", false, false);
  396. }
  397. @Test
  398. public void testLowerGroupCase3() throws Exception {
  399. assertMatch("[[:lower:]]", "H", false, false);
  400. }
  401. @Test
  402. public void testLowerGroupCase4() throws Exception {
  403. // \u00e4 = small 'a' with dots on it
  404. assertMatch("[[:lower:]]", "\u00e4", true, false);
  405. }
  406. @Test
  407. public void testLowerGroupCase5() throws Exception {
  408. assertMatch("[[:lower:]]", ".", false, false);
  409. }
  410. @Test
  411. public void testPrintGroupCase0() throws Exception {
  412. assertMatch("[[:print:]]", "]", true, false);
  413. }
  414. @Test
  415. public void testPrintGroupCase1() throws Exception {
  416. assertMatch("[[:print:]]", "a", true, false);
  417. }
  418. @Test
  419. public void testPrintGroupCase2() throws Exception {
  420. assertMatch("[[:print:]]", ".", true, false);
  421. }
  422. @Test
  423. public void testPrintGroupCase3() throws Exception {
  424. assertMatch("[[:print:]]", "0", true, false);
  425. }
  426. @Test
  427. public void testPrintGroupCase4() throws Exception {
  428. assertMatch("[[:print:]]", " ", true, false);
  429. }
  430. @Test
  431. public void testPrintGroupCase5() throws Exception {
  432. // \u00f6 = 'o' with dots on it
  433. assertMatch("[[:print:]]", "\u00f6", true, false);
  434. }
  435. @Test
  436. public void testPunctGroupCase0() throws Exception {
  437. assertMatch("[[:punct:]]", ".", true, false);
  438. }
  439. @Test
  440. public void testPunctGroupCase1() throws Exception {
  441. assertMatch("[[:punct:]]", "@", true, false);
  442. }
  443. @Test
  444. public void testPunctGroupCase2() throws Exception {
  445. assertMatch("[[:punct:]]", " ", false, false);
  446. }
  447. @Test
  448. public void testPunctGroupCase3() throws Exception {
  449. assertMatch("[[:punct:]]", "a", false, false);
  450. }
  451. @Test
  452. public void testSpaceGroupCase0() throws Exception {
  453. assertMatch("[[:space:]]", " ", true, false);
  454. }
  455. @Test
  456. public void testSpaceGroupCase1() throws Exception {
  457. assertMatch("[[:space:]]", "\t", true, false);
  458. }
  459. @Test
  460. public void testSpaceGroupCase2() throws Exception {
  461. assertMatch("[[:space:]]", "\r", true, false);
  462. }
  463. @Test
  464. public void testSpaceGroupCase3() throws Exception {
  465. assertMatch("[[:space:]]", "\n", true, false);
  466. }
  467. @Test
  468. public void testSpaceGroupCase4() throws Exception {
  469. assertMatch("[[:space:]]", "a", false, false);
  470. }
  471. @Test
  472. public void testUpperGroupCase0() throws Exception {
  473. assertMatch("[[:upper:]]", "a", false, false);
  474. }
  475. @Test
  476. public void testUpperGroupCase1() throws Exception {
  477. assertMatch("[[:upper:]]", "h", false, false);
  478. }
  479. @Test
  480. public void testUpperGroupCase2() throws Exception {
  481. assertMatch("[[:upper:]]", "A", true, false);
  482. }
  483. @Test
  484. public void testUpperGroupCase3() throws Exception {
  485. assertMatch("[[:upper:]]", "H", true, false);
  486. }
  487. @Test
  488. public void testUpperGroupCase4() throws Exception {
  489. // \u00c4 = 'A' with dots on it
  490. assertMatch("[[:upper:]]", "\u00c4", true, false);
  491. }
  492. @Test
  493. public void testUpperGroupCase5() throws Exception {
  494. assertMatch("[[:upper:]]", ".", false, false);
  495. }
  496. @Test
  497. public void testXDigitGroupCase0() throws Exception {
  498. assertMatch("[[:xdigit:]]", "a", true, false);
  499. }
  500. @Test
  501. public void testXDigitGroupCase1() throws Exception {
  502. assertMatch("[[:xdigit:]]", "d", true, false);
  503. }
  504. @Test
  505. public void testXDigitGroupCase2() throws Exception {
  506. assertMatch("[[:xdigit:]]", "f", true, false);
  507. }
  508. @Test
  509. public void testXDigitGroupCase3() throws Exception {
  510. assertMatch("[[:xdigit:]]", "0", true, false);
  511. }
  512. @Test
  513. public void testXDigitGroupCase4() throws Exception {
  514. assertMatch("[[:xdigit:]]", "5", true, false);
  515. }
  516. @Test
  517. public void testXDigitGroupCase5() throws Exception {
  518. assertMatch("[[:xdigit:]]", "9", true, false);
  519. }
  520. @Test
  521. public void testXDigitGroupCase6() throws Exception {
  522. assertMatch("[[:xdigit:]]", "۹", false, false);
  523. }
  524. @Test
  525. public void testXDigitGroupCase7() throws Exception {
  526. assertMatch("[[:xdigit:]]", ".", false, false);
  527. }
  528. @Test
  529. public void testWordroupCase0() throws Exception {
  530. assertMatch("[[:word:]]", "g", true, false);
  531. }
  532. @Test
  533. public void testWordroupCase1() throws Exception {
  534. // \u00f6 = 'o' with dots on it
  535. assertMatch("[[:word:]]", "\u00f6", true, false);
  536. }
  537. @Test
  538. public void testWordroupCase2() throws Exception {
  539. assertMatch("[[:word:]]", "5", true, false);
  540. }
  541. @Test
  542. public void testWordroupCase3() throws Exception {
  543. assertMatch("[[:word:]]", "_", true, false);
  544. }
  545. @Test
  546. public void testWordroupCase4() throws Exception {
  547. assertMatch("[[:word:]]", " ", false, false);
  548. }
  549. @Test
  550. public void testWordroupCase5() throws Exception {
  551. assertMatch("[[:word:]]", ".", false, false);
  552. }
  553. @Test
  554. public void testMixedGroupCase0() throws Exception {
  555. assertMatch("[A[:lower:]C3-5]", "A", true, false);
  556. }
  557. @Test
  558. public void testMixedGroupCase1() throws Exception {
  559. assertMatch("[A[:lower:]C3-5]", "C", true, false);
  560. }
  561. @Test
  562. public void testMixedGroupCase2() throws Exception {
  563. assertMatch("[A[:lower:]C3-5]", "e", true, false);
  564. }
  565. @Test
  566. public void testMixedGroupCase3() throws Exception {
  567. assertMatch("[A[:lower:]C3-5]", "3", true, false);
  568. }
  569. @Test
  570. public void testMixedGroupCase4() throws Exception {
  571. assertMatch("[A[:lower:]C3-5]", "4", true, false);
  572. }
  573. @Test
  574. public void testMixedGroupCase5() throws Exception {
  575. assertMatch("[A[:lower:]C3-5]", "5", true, false);
  576. }
  577. @Test
  578. public void testMixedGroupCase6() throws Exception {
  579. assertMatch("[A[:lower:]C3-5]", "B", false, false);
  580. }
  581. @Test
  582. public void testMixedGroupCase7() throws Exception {
  583. assertMatch("[A[:lower:]C3-5]", "2", false, false);
  584. }
  585. @Test
  586. public void testMixedGroupCase8() throws Exception {
  587. assertMatch("[A[:lower:]C3-5]", "6", false, false);
  588. }
  589. @Test
  590. public void testMixedGroupCase9() throws Exception {
  591. assertMatch("[A[:lower:]C3-5]", ".", false, false);
  592. }
  593. @Test
  594. public void testSpecialGroupCase0() throws Exception {
  595. assertMatch("[[]", "[", true, false);
  596. }
  597. @Test
  598. public void testSpecialGroupCase1() throws Exception {
  599. assertMatch("[]]", "]", true, false);
  600. }
  601. @Test
  602. public void testSpecialGroupCase2() throws Exception {
  603. assertMatch("[]a]", "]", true, false);
  604. }
  605. @Test
  606. public void testSpecialGroupCase3() throws Exception {
  607. assertMatch("[a[]", "[", true, false);
  608. }
  609. @Test
  610. public void testSpecialGroupCase4() throws Exception {
  611. assertMatch("[a[]", "a", true, false);
  612. }
  613. @Test
  614. public void testSpecialGroupCase5() throws Exception {
  615. assertMatch("[!]]", "]", false, false);
  616. }
  617. @Test
  618. public void testSpecialGroupCase6() throws Exception {
  619. assertMatch("[!]]", "x", true, false);
  620. }
  621. @Test
  622. public void testSpecialGroupCase7() throws Exception {
  623. assertMatch("[:]]", ":]", true, false);
  624. }
  625. @Test
  626. public void testSpecialGroupCase8() throws Exception {
  627. assertMatch("[:]]", ":", false, true);
  628. }
  629. @Test
  630. public void testSpecialGroupCase9() throws Exception {
  631. try {
  632. assertMatch("[[:]", ":", true, true);
  633. fail("InvalidPatternException expected");
  634. } catch (InvalidPatternException e) {
  635. // expected
  636. }
  637. }
  638. @Test
  639. public void testUnsupportedGroupCase0() throws Exception {
  640. try {
  641. assertMatch("[[=a=]]", "b", false, false);
  642. fail("InvalidPatternException expected");
  643. } catch (InvalidPatternException e) {
  644. assertTrue(e.getMessage().contains("[=a=]"));
  645. }
  646. }
  647. @Test
  648. public void testUnsupportedGroupCase1() throws Exception {
  649. try {
  650. assertMatch("[[.a.]]", "b", false, false);
  651. fail("InvalidPatternException expected");
  652. } catch (InvalidPatternException e) {
  653. assertTrue(e.getMessage().contains("[.a.]"));
  654. }
  655. }
  656. @Test
  657. public void testFilePathSimpleCase() throws Exception {
  658. assertFileNameMatch("a/b", "a/b", '/', true, false);
  659. }
  660. @Test
  661. public void testFilePathCase0() throws Exception {
  662. assertFileNameMatch("a*b", "a/b", '/', false, false);
  663. }
  664. @Test
  665. public void testFilePathCase1() throws Exception {
  666. assertFileNameMatch("a?b", "a/b", '/', false, false);
  667. }
  668. @Test
  669. public void testFilePathCase2() throws Exception {
  670. assertFileNameMatch("a*b", "a\\b", '\\', false, false);
  671. }
  672. @Test
  673. public void testFilePathCase3() throws Exception {
  674. assertFileNameMatch("a?b", "a\\b", '\\', false, false);
  675. }
  676. @Test
  677. public void testReset() throws Exception {
  678. final String pattern = "helloworld";
  679. final FileNameMatcher matcher = new FileNameMatcher(pattern, null);
  680. matcher.append("helloworld");
  681. assertEquals(true, matcher.isMatch());
  682. assertEquals(false, matcher.canAppendMatch());
  683. matcher.reset();
  684. matcher.append("hello");
  685. assertEquals(false, matcher.isMatch());
  686. assertEquals(true, matcher.canAppendMatch());
  687. matcher.append("world");
  688. assertEquals(true, matcher.isMatch());
  689. assertEquals(false, matcher.canAppendMatch());
  690. matcher.append("to much");
  691. assertEquals(false, matcher.isMatch());
  692. assertEquals(false, matcher.canAppendMatch());
  693. matcher.reset();
  694. matcher.append("helloworld");
  695. assertEquals(true, matcher.isMatch());
  696. assertEquals(false, matcher.canAppendMatch());
  697. }
  698. @Test
  699. public void testCreateMatcherForSuffix() throws Exception {
  700. final String pattern = "helloworld";
  701. final FileNameMatcher matcher = new FileNameMatcher(pattern, null);
  702. matcher.append("hello");
  703. final FileNameMatcher childMatcher = matcher.createMatcherForSuffix();
  704. assertEquals(false, matcher.isMatch());
  705. assertEquals(true, matcher.canAppendMatch());
  706. assertEquals(false, childMatcher.isMatch());
  707. assertEquals(true, childMatcher.canAppendMatch());
  708. matcher.append("world");
  709. assertEquals(true, matcher.isMatch());
  710. assertEquals(false, matcher.canAppendMatch());
  711. assertEquals(false, childMatcher.isMatch());
  712. assertEquals(true, childMatcher.canAppendMatch());
  713. childMatcher.append("world");
  714. assertEquals(true, matcher.isMatch());
  715. assertEquals(false, matcher.canAppendMatch());
  716. assertEquals(true, childMatcher.isMatch());
  717. assertEquals(false, childMatcher.canAppendMatch());
  718. childMatcher.reset();
  719. assertEquals(true, matcher.isMatch());
  720. assertEquals(false, matcher.canAppendMatch());
  721. assertEquals(false, childMatcher.isMatch());
  722. assertEquals(true, childMatcher.canAppendMatch());
  723. childMatcher.append("world");
  724. assertEquals(true, matcher.isMatch());
  725. assertEquals(false, matcher.canAppendMatch());
  726. assertEquals(true, childMatcher.isMatch());
  727. assertEquals(false, childMatcher.canAppendMatch());
  728. }
  729. @Test
  730. public void testCopyConstructor() throws Exception {
  731. final String pattern = "helloworld";
  732. final FileNameMatcher matcher = new FileNameMatcher(pattern, null);
  733. matcher.append("hello");
  734. final FileNameMatcher copy = new FileNameMatcher(matcher);
  735. assertEquals(false, matcher.isMatch());
  736. assertEquals(true, matcher.canAppendMatch());
  737. assertEquals(false, copy.isMatch());
  738. assertEquals(true, copy.canAppendMatch());
  739. matcher.append("world");
  740. assertEquals(true, matcher.isMatch());
  741. assertEquals(false, matcher.canAppendMatch());
  742. assertEquals(false, copy.isMatch());
  743. assertEquals(true, copy.canAppendMatch());
  744. copy.append("world");
  745. assertEquals(true, matcher.isMatch());
  746. assertEquals(false, matcher.canAppendMatch());
  747. assertEquals(true, copy.isMatch());
  748. assertEquals(false, copy.canAppendMatch());
  749. copy.reset();
  750. assertEquals(true, matcher.isMatch());
  751. assertEquals(false, matcher.canAppendMatch());
  752. assertEquals(false, copy.isMatch());
  753. assertEquals(true, copy.canAppendMatch());
  754. copy.append("helloworld");
  755. assertEquals(true, matcher.isMatch());
  756. assertEquals(false, matcher.canAppendMatch());
  757. assertEquals(true, copy.isMatch());
  758. assertEquals(false, copy.canAppendMatch());
  759. }
  760. }