File tree Expand file tree Collapse file tree
test/clojure/test_clojure Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -965,7 +965,8 @@ else if(coll instanceof RandomAccess) {
965965 }
966966 else if (coll instanceof Matcher ) {
967967 Matcher m = (Matcher ) coll ;
968- if (n < m .groupCount ())
968+ int groups = m .groupCount ();
969+ if (groups > 0 && n <= m .groupCount ())
969970 return m .group (n );
970971 return notFound ;
971972 }
Original file line number Diff line number Diff line change 348348; Regex Support
349349; re-matcher re-find re-matches re-groups re-seq
350350
351+ (deftest test-regex-matcher
352+ (let [matcher (re-matcher #"(\d {2})/(\d {2})/(\d {4})" " 12/02/1975" )]
353+ (is (= [" 12/02/1975" " 12" " 02" " 1975" ] (re-find matcher)))
354+ (is (= [" 12/02/1975" " 12" " 02" " 1975" ] (re-groups matcher)))
355+ (is (= " 12/02/1975" (nth matcher 0 ) (nth matcher 0 :foo )))
356+ (is (= " 12" (nth matcher 1 ) (nth matcher 1 :foo )))
357+ (is (= " 02" (nth matcher 2 ) (nth matcher 2 :foo )))
358+ (is (= " 1975" (nth matcher 3 ) (nth matcher 3 :foo )))
359+ (is (thrown? IndexOutOfBoundsException (nth matcher -1 )))
360+ (is (= :foo (nth matcher -1 :foo )))
361+ (is (thrown? IndexOutOfBoundsException (nth matcher 4 )))
362+ (is (= :foo (nth matcher 4 :foo )))))
363+
351364; update
352365
353366(deftest test-update
You can’t perform that action at this time.
0 commit comments