diff test/org/tmatesoft/hg/test/OutputParser.java @ 475:0e34b8f3946a

Tests for MqManager
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 12 Jul 2012 16:57:40 +0200
parents df5009d67be2
children e74580e24feb
line wrap: on
line diff
--- a/test/org/tmatesoft/hg/test/OutputParser.java	Thu Jul 12 15:36:21 2012 +0200
+++ b/test/org/tmatesoft/hg/test/OutputParser.java	Thu Jul 12 16:57:40 2012 +0200
@@ -16,6 +16,11 @@
  */
 package org.tmatesoft.hg.test;
 
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 /**
  *
  * @author Artem Tikhomirov
@@ -45,5 +50,39 @@
 		public CharSequence result() {
 			return result;
 		}
+
+		public Iterable<String> lines() {
+			return lines("(.+)$");
+		}
+		public Iterable<String> lines(String pattern) {
+			final Matcher m = Pattern.compile(pattern, Pattern.MULTILINE).matcher(result);
+			class S implements Iterable<String>, Iterator<String> {
+				public Iterator<String> iterator() {
+					return this;
+				}
+				private boolean next;
+				{
+					next = m.find();
+				}
+
+				public boolean hasNext() {
+					return next;
+				}
+
+				public String next() {
+					if (next) {
+						String rv = m.group();
+						next = m.find();
+						return rv;
+					}
+					throw new NoSuchElementException();
+				}
+
+				public void remove() {
+					throw new UnsupportedOperationException();
+				}
+			};
+			return new S();
+		}
 	}
 }