comparison 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
comparison
equal deleted inserted replaced
474:09f2d38ecf26 475:0e34b8f3946a
13 * For information on how to redistribute this software under 13 * For information on how to redistribute this software under
14 * the terms of a license other than GNU General Public License 14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@hg4j.com 15 * contact TMate Software at support@hg4j.com
16 */ 16 */
17 package org.tmatesoft.hg.test; 17 package org.tmatesoft.hg.test;
18
19 import java.util.Iterator;
20 import java.util.NoSuchElementException;
21 import java.util.regex.Matcher;
22 import java.util.regex.Pattern;
18 23
19 /** 24 /**
20 * 25 *
21 * @author Artem Tikhomirov 26 * @author Artem Tikhomirov
22 * @author TMate Software Ltd. 27 * @author TMate Software Ltd.
43 // else no-op 48 // else no-op
44 } 49 }
45 public CharSequence result() { 50 public CharSequence result() {
46 return result; 51 return result;
47 } 52 }
53
54 public Iterable<String> lines() {
55 return lines("(.+)$");
56 }
57 public Iterable<String> lines(String pattern) {
58 final Matcher m = Pattern.compile(pattern, Pattern.MULTILINE).matcher(result);
59 class S implements Iterable<String>, Iterator<String> {
60 public Iterator<String> iterator() {
61 return this;
62 }
63 private boolean next;
64 {
65 next = m.find();
66 }
67
68 public boolean hasNext() {
69 return next;
70 }
71
72 public String next() {
73 if (next) {
74 String rv = m.group();
75 next = m.find();
76 return rv;
77 }
78 throw new NoSuchElementException();
79 }
80
81 public void remove() {
82 throw new UnsupportedOperationException();
83 }
84 };
85 return new S();
86 }
48 } 87 }
49 } 88 }