annotate 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
rev   line source
61
fac8e7fcc8b0 Simple test framework - capable of parsing Hg cmdline output to compare with Java result
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
410
df5009d67be2 Fixed test to pass in a branch other than default
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 203
diff changeset
2 * Copyright (c) 2011-2012 TMate Software Ltd
66
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
3 *
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
4 * This program is free software; you can redistribute it and/or modify
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
5 * it under the terms of the GNU General Public License as published by
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
6 * the Free Software Foundation; version 2 of the License.
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
7 *
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
8 * This program is distributed in the hope that it will be useful,
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
11 * GNU General Public License for more details.
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
12 *
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
13 * For information on how to redistribute this software under
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
14 * the terms of a license other than GNU General Public License
102
a3a2e5deb320 Updated contact address to support@hg4j.com
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 66
diff changeset
15 * contact TMate Software at support@hg4j.com
61
fac8e7fcc8b0 Simple test framework - capable of parsing Hg cmdline output to compare with Java result
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
66
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
17 package org.tmatesoft.hg.test;
61
fac8e7fcc8b0 Simple test framework - capable of parsing Hg cmdline output to compare with Java result
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
475
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
19 import java.util.Iterator;
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
20 import java.util.NoSuchElementException;
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
21 import java.util.regex.Matcher;
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
22 import java.util.regex.Pattern;
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
23
61
fac8e7fcc8b0 Simple test framework - capable of parsing Hg cmdline output to compare with Java result
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 /**
fac8e7fcc8b0 Simple test framework - capable of parsing Hg cmdline output to compare with Java result
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 *
66
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
26 * @author Artem Tikhomirov
52dc3f4cfc76 Primitive test suite in org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 61
diff changeset
27 * @author TMate Software Ltd.
61
fac8e7fcc8b0 Simple test framework - capable of parsing Hg cmdline output to compare with Java result
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 */
fac8e7fcc8b0 Simple test framework - capable of parsing Hg cmdline output to compare with Java result
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 public interface OutputParser {
fac8e7fcc8b0 Simple test framework - capable of parsing Hg cmdline output to compare with Java result
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30
fac8e7fcc8b0 Simple test framework - capable of parsing Hg cmdline output to compare with Java result
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 public void parse(CharSequence seq);
202
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
32
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
33 public class Stub implements OutputParser {
203
66fd2c73c56f Basic test for HgOutgoingCommand. Handle cases with no outgoing changes in RepositoryComparator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 202
diff changeset
34 private boolean shallDump;
410
df5009d67be2 Fixed test to pass in a branch other than default
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 203
diff changeset
35 private CharSequence result;
df5009d67be2 Fixed test to pass in a branch other than default
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 203
diff changeset
36
203
66fd2c73c56f Basic test for HgOutgoingCommand. Handle cases with no outgoing changes in RepositoryComparator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 202
diff changeset
37 public Stub() {
66fd2c73c56f Basic test for HgOutgoingCommand. Handle cases with no outgoing changes in RepositoryComparator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 202
diff changeset
38 this(false);
66fd2c73c56f Basic test for HgOutgoingCommand. Handle cases with no outgoing changes in RepositoryComparator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 202
diff changeset
39 }
66fd2c73c56f Basic test for HgOutgoingCommand. Handle cases with no outgoing changes in RepositoryComparator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 202
diff changeset
40 public Stub(boolean dump) {
66fd2c73c56f Basic test for HgOutgoingCommand. Handle cases with no outgoing changes in RepositoryComparator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 202
diff changeset
41 shallDump = dump;
66fd2c73c56f Basic test for HgOutgoingCommand. Handle cases with no outgoing changes in RepositoryComparator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 202
diff changeset
42 }
202
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
43 public void parse(CharSequence seq) {
410
df5009d67be2 Fixed test to pass in a branch other than default
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 203
diff changeset
44 result = seq;
203
66fd2c73c56f Basic test for HgOutgoingCommand. Handle cases with no outgoing changes in RepositoryComparator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 202
diff changeset
45 if (shallDump) {
66fd2c73c56f Basic test for HgOutgoingCommand. Handle cases with no outgoing changes in RepositoryComparator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 202
diff changeset
46 System.out.println(seq);
66fd2c73c56f Basic test for HgOutgoingCommand. Handle cases with no outgoing changes in RepositoryComparator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 202
diff changeset
47 }
66fd2c73c56f Basic test for HgOutgoingCommand. Handle cases with no outgoing changes in RepositoryComparator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 202
diff changeset
48 // else no-op
202
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
49 }
410
df5009d67be2 Fixed test to pass in a branch other than default
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 203
diff changeset
50 public CharSequence result() {
df5009d67be2 Fixed test to pass in a branch other than default
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 203
diff changeset
51 return result;
df5009d67be2 Fixed test to pass in a branch other than default
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 203
diff changeset
52 }
475
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
53
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
54 public Iterable<String> lines() {
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
55 return lines("(.+)$");
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
56 }
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
57 public Iterable<String> lines(String pattern) {
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
58 final Matcher m = Pattern.compile(pattern, Pattern.MULTILINE).matcher(result);
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
59 class S implements Iterable<String>, Iterator<String> {
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
60 public Iterator<String> iterator() {
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
61 return this;
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
62 }
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
63 private boolean next;
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
64 {
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
65 next = m.find();
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
66 }
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
67
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
68 public boolean hasNext() {
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
69 return next;
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
70 }
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
71
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
72 public String next() {
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
73 if (next) {
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
74 String rv = m.group();
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
75 next = m.find();
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
76 return rv;
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
77 }
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
78 throw new NoSuchElementException();
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
79 }
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
80
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
81 public void remove() {
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
82 throw new UnsupportedOperationException();
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
83 }
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
84 };
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
85 return new S();
0e34b8f3946a Tests for MqManager
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 410
diff changeset
86 }
202
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
87 }
61
fac8e7fcc8b0 Simple test framework - capable of parsing Hg cmdline output to compare with Java result
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 }