annotate test/org/tmatesoft/hg/test/TestAuxUtilities.java @ 443:072b5f3ed0c8

Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 04 May 2012 17:59:22 +0200
parents 12f668401613
children 7bcfbc255f48
rev   line source
311
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 418
diff changeset
2 * Copyright (c) 2011-2012 TMate Software Ltd
311
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.test;
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
313
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
19 import static org.tmatesoft.hg.repo.HgRepository.TIP;
443
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
20 import static org.tmatesoft.hg.util.Path.CompareResult.*;
313
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
21
322
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
22 import java.io.IOException;
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
23 import java.nio.ByteBuffer;
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
24
311
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import org.junit.Assert;
331
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
26 import org.junit.Ignore;
443
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
27 import org.junit.Rule;
311
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 import org.junit.Test;
322
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
29 import org.tmatesoft.hg.core.HgCatCommand;
312
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
30 import org.tmatesoft.hg.core.Nodeid;
311
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 import org.tmatesoft.hg.internal.ArrayHelper;
443
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
32 import org.tmatesoft.hg.internal.PathScope;
312
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
33 import org.tmatesoft.hg.repo.HgChangelog;
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
34 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset;
327
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
35 import org.tmatesoft.hg.repo.HgDataFile;
313
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
36 import org.tmatesoft.hg.repo.HgManifest;
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
37 import org.tmatesoft.hg.repo.HgManifest.Flags;
331
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
38 import org.tmatesoft.hg.repo.HgRepoConfig;
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
39 import org.tmatesoft.hg.repo.HgRepoConfig.PathsSection;
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
40 import org.tmatesoft.hg.repo.HgRepoConfig.Section;
312
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
41 import org.tmatesoft.hg.repo.HgRepository;
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
42 import org.tmatesoft.hg.util.Adaptable;
322
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
43 import org.tmatesoft.hg.util.ByteChannel;
312
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
44 import org.tmatesoft.hg.util.CancelSupport;
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
45 import org.tmatesoft.hg.util.CancelledException;
331
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
46 import org.tmatesoft.hg.util.Pair;
313
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
47 import org.tmatesoft.hg.util.Path;
311
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 /**
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 *
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 * @author Artem Tikhomirov
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 * @author TMate Software Ltd.
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 */
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 public class TestAuxUtilities {
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55
443
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
56 @Rule
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
57 public ErrorCollectorExt errorCollector = new ErrorCollectorExt();
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
58
311
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 @Test
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 public void testArrayHelper() {
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 String[] initial = {"d", "w", "k", "b", "c", "i", "a", "r", "e", "h" };
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 ArrayHelper ah = new ArrayHelper();
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 String[] result = initial.clone();
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 ah.sort(result);
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 String[] restored = restore(result, ah.getReverse());
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 Assert.assertArrayEquals(initial, restored);
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 //
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 // few elements are on the right place from the very start and do not shift during sort.
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 // make sure for them we've got correct reversed indexes as well
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 initial = new String[] {"d", "h", "c", "b", "k", "i", "a", "r", "e", "w" };
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 ah.sort(result = initial.clone());
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 restored = restore(result, ah.getReverse());
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 Assert.assertArrayEquals(initial, restored);
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 }
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 private static String[] restore(String[] sorted, int[] sortReverse) {
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 String[] rebuilt = new String[sorted.length];
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 for (int i = 0; i < sorted.length; i++) {
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 int indexInOriginal = sortReverse[i];
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 rebuilt[indexInOriginal-1] = sorted[i];
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 }
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 return rebuilt;
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 }
312
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
84
313
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
85 static class CancelImpl implements CancelSupport {
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
86 private boolean shallStop = false;
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
87 public void stop() {
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
88 shallStop = true;
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
89 }
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
90 public void checkCancelled() throws CancelledException {
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
91 if (shallStop) {
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
92 throw new CancelledException();
312
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
93 }
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
94 }
313
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
95 }
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
96
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
97 @Test
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
98 public void testChangelogCancelSupport() throws Exception {
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
99 HgRepository repository = Configuration.get().find("branches-1"); // any repo with more revisions
312
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
100 class InspectorImplementsCancel implements HgChangelog.Inspector, CancelSupport {
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
101 public final int when2stop;
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
102 public int lastVisitet = 0;
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
103 private final CancelImpl cancelImpl = new CancelImpl();
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
104
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
105 public InspectorImplementsCancel(int limit) {
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
106 when2stop = limit;
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
107 }
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
108
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
109 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
110 lastVisitet = revisionNumber;
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
111 if (revisionNumber == when2stop) {
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
112 cancelImpl.stop();
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
113 }
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
114 }
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
115
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
116 public void checkCancelled() throws CancelledException {
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
117 cancelImpl.checkCancelled();
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
118 }
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
119 };
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
120 class InspectorImplementsAdaptable implements HgChangelog.Inspector, Adaptable {
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
121 public final int when2stop;
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
122 public int lastVisitet = 0;
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
123 private final CancelImpl cancelImpl = new CancelImpl();
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
124
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
125 public InspectorImplementsAdaptable(int limit) {
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
126 when2stop = limit;
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
127 }
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
128
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
129 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
130 lastVisitet = revisionNumber;
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
131 if (revisionNumber == when2stop) {
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
132 cancelImpl.stop();
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
133 }
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
134 }
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
135 public <T> T getAdapter(Class<T> adapterClass) {
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
136 if (CancelSupport.class == adapterClass) {
322
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
137 return adapterClass.cast(cancelImpl);
312
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
138 }
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
139 return null;
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
140 }
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
141
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
142 }
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
143 //
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
144 InspectorImplementsCancel insp1;
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
145 repository.getChangelog().all(insp1= new InspectorImplementsCancel(2));
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
146 Assert.assertEquals(insp1.when2stop, insp1.lastVisitet);
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
147 repository.getChangelog().all(insp1 = new InspectorImplementsCancel(12));
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
148 Assert.assertEquals(insp1.when2stop, insp1.lastVisitet);
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
149 //
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
150 InspectorImplementsAdaptable insp2;
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
151 repository.getChangelog().all(insp2= new InspectorImplementsAdaptable(3));
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
152 Assert.assertEquals(insp2.when2stop, insp2.lastVisitet);
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
153 repository.getChangelog().all(insp2 = new InspectorImplementsAdaptable(10));
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
154 Assert.assertEquals(insp2.when2stop, insp2.lastVisitet);
f9f3e9b67ccc Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 311
diff changeset
155 }
313
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
156
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
157 @Test
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
158 public void testManifestCancelSupport() throws Exception {
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
159 HgRepository repository = Configuration.get().find("branches-1"); // any repo with as many revisions as possible
424
6437d261048a Deprecated code removed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 423
diff changeset
160 class InspectorImplementsAdaptable implements HgManifest.Inspector, Adaptable {
313
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
161 public final int when2stop;
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
162 public int lastVisitet = 0;
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
163 private final CancelImpl cancelImpl = new CancelImpl();
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
164
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
165 public InspectorImplementsAdaptable(int limit) {
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
166 when2stop = limit;
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
167 }
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
168
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
169 public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) {
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
170 if (++lastVisitet == when2stop) {
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
171 cancelImpl.stop();
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
172 }
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
173 return true;
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
174 }
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
175
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
176 public boolean end(int manifestRevision) {
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
177 return true;
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
178 }
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
179
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
180 public <T> T getAdapter(Class<T> adapterClass) {
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
181 if (CancelSupport.class == adapterClass) {
322
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
182 return adapterClass.cast(cancelImpl);
313
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
183 }
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
184 return null;
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
185 }
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
186
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
187 public boolean next(Nodeid nid, Path fname, Flags flags) {
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
188 return true;
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
189 }
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
190 }
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
191 InspectorImplementsAdaptable insp1;
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
192 repository.getManifest().walk(0, TIP, insp1= new InspectorImplementsAdaptable(3));
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
193 Assert.assertEquals(insp1.when2stop, insp1.lastVisitet);
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
194 repository.getManifest().walk(0, TIP, insp1 = new InspectorImplementsAdaptable(10));
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
195 Assert.assertEquals(insp1.when2stop, insp1.lastVisitet);
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
196 }
c1e3c18fd2f2 Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 312
diff changeset
197
322
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
198 @Test
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
199 public void testCatCommandCancelSupport() throws Exception {
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
200 HgRepository repository = Configuration.get().find("branches-1"); // any repo
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
201 final HgCatCommand cmd = new HgCatCommand(repository);
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
202 cmd.file(Path.create("file1"));
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
203 cmd.set(new CancelSupport() {
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
204 int i = 0;
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
205 public void checkCancelled() throws CancelledException {
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
206 if (i++ == 2) {
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
207 throw new CancelledException();
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
208 }
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
209 }
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
210 });
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
211 try {
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
212 cmd.execute(new ByteChannel() {
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
213
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
214 public int write(ByteBuffer buffer) throws IOException, CancelledException {
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
215 Assert.fail("Shall not get that far provided cancellation from command's CancelSupport is functional");
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
216 return 0;
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
217 }
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
218 });
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
219 Assert.fail("Command execution shall not fail silently, exception shall propagate");
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
220 } catch (CancelledException ex) {
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
221 // good!
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
222 }
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 313
diff changeset
223 }
327
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
224
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
225 @Test
418
528b6780a8bd A bit of FIXME cleanup (mostly degraded to TODO post 1.0), comments and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 367
diff changeset
226 public void testRevlogInspectors() throws Exception { // TODO move to better place
327
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
227 HgRepository repository = Configuration.get().find("branches-1"); // any repo
431
12f668401613 FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
228 repository.getChangelog().indexWalk(0, TIP, new HgChangelog.RevisionInspector() {
327
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
229
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
230 public void next(int localRevision, Nodeid revision, int linkedRevision) {
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
231 Assert.assertEquals(localRevision, linkedRevision);
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
232 }
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
233 });
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
234 final HgDataFile fileNode = repository.getFileNode("file1");
431
12f668401613 FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
235 fileNode.indexWalk(0, TIP, new HgDataFile.RevisionInspector() {
327
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
236 int i = 0;
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
237
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
238 public void next(int localRevision, Nodeid revision, int linkedRevision) {
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 418
diff changeset
239 Assert.assertEquals(i++, localRevision);
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 418
diff changeset
240 Assert.assertEquals(fileNode.getChangesetRevisionIndex(localRevision), linkedRevision);
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 418
diff changeset
241 Assert.assertEquals(fileNode.getRevision(localRevision), revision);
327
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
242 }
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
243 });
431
12f668401613 FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
244 fileNode.indexWalk(0, TIP, new HgDataFile.ParentInspector() {
327
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
245 int i = 0;
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
246 Nodeid[] all = new Nodeid[fileNode.getRevisionCount()];
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
247
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
248 public void next(int localRevision, Nodeid revision, int parent1, int parent2, Nodeid nidParent1, Nodeid nidParent2) {
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
249 Assert.assertEquals(i++, localRevision);
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
250 all[localRevision] = revision;
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
251 Assert.assertNotNull(revision);
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
252 Assert.assertFalse(localRevision == 0 && (parent1 != -1 || parent2 != -1));
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
253 Assert.assertFalse(localRevision > 0 && parent1 == -1 && parent2 == -1);
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
254 if (parent1 != -1) {
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
255 Assert.assertNotNull(nidParent1);
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
256 // deliberately ==, not asserEquals to ensure same instance
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
257 Assert.assertTrue(nidParent1 == all[parent1]);
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
258 }
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
259 if (parent2 != -1) {
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
260 Assert.assertNotNull(nidParent2);
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
261 Assert.assertTrue(nidParent2 == all[parent2]);
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
262 }
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
263 }
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
264 });
3f09b8c19142 Tests for Revlog.Inspectors
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
265 }
331
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
266
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
267 @Test
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
268 @Ignore("just a dump for now, to compare values visually")
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
269 public void testRepositoryConfig() throws Exception {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
270 HgRepository repo = Configuration.get().own();
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
271 final HgRepoConfig cfg = repo.getConfiguration();
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
272 Assert.assertNotNull(cfg.getPaths());
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
273 Assert.assertNotNull(cfg.getExtensions());
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
274 final Section dne = cfg.getSection("does-not-exist");
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
275 Assert.assertNotNull(dne);
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
276 Assert.assertFalse(dne.exists());
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
277 for (Pair<String, String> p : cfg.getSection("ui")) {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
278 System.out.printf("%s = %s\n", p.first(), p.second());
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
279 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
280 final PathsSection p = cfg.getPaths();
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
281 System.out.printf("Known paths: %d. default: %s(%s), default-push: %s(%s)\n", p.getKeys().size(), p.getDefault(), p.hasDefault(), p.getDefaultPush(), p.hasDefaultPush());
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
282 for (String k : cfg.getPaths().getKeys()) {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
283 System.out.println(k);
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
284 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
285 Assert.assertFalse(p.hasDefault() ^ p.getDefault() != null);
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
286 Assert.assertFalse(p.hasDefaultPush() ^ p.getDefaultPush() != null);
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
287 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
288
363
d9dfa9fe9cec Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
289 @Test
d9dfa9fe9cec Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
290 public void testChangelogExtrasDecode() {
d9dfa9fe9cec Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
291 final String s = "abc\u0123\r\ndef\n\txx\\yy";
d9dfa9fe9cec Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
292 String r = s.replace("\\", "\\\\").replace("\n", "\\n").replace("\r", "\\r").replace("\0", "\\0");
d9dfa9fe9cec Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
293 // System.out.println(r);
d9dfa9fe9cec Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
294 String r2 = r.replace("\\\\", "\\").replace("\\n", "\n").replace("\\r", "\r").replace("\\0", "\00");
d9dfa9fe9cec Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
295 // System.out.println(r2);
d9dfa9fe9cec Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
296 Assert.assertTrue(s.equals(r2));
d9dfa9fe9cec Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
297 }
d9dfa9fe9cec Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
298
443
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
299 @Test
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
300 public void testPathScope() {
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
301 // XXX whether PathScope shall accept paths that are leading towards configured elements
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
302 Path[] scope = new Path[] {
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
303 Path.create("a/"),
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
304 Path.create("b/c"),
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
305 Path.create("d/e/f/")
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
306 };
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
307 //
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
308 // accept specified path, with files and folders below
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
309 PathScope ps1 = new PathScope(true, scope);
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
310 // folders
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
311 errorCollector.assertTrue(ps1.accept(Path.create("a/"))); // == scope[0]
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
312 errorCollector.assertTrue(ps1.accept(Path.create("a/d/"))); // scope[0] is parent and recursiveDir = true
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
313 errorCollector.assertTrue(ps1.accept(Path.create("a/d/e/"))); // scope[0] is parent and recursiveDir = true
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
314 errorCollector.assertTrue(!ps1.accept(Path.create("b/d/"))); // unrelated to any preconfigured
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
315 errorCollector.assertTrue(ps1.accept(Path.create("b/"))); // arg is parent to scope[1]
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
316 errorCollector.assertTrue(ps1.accept(Path.create("d/"))); // arg is parent to scope[2]
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
317 errorCollector.assertTrue(ps1.accept(Path.create("d/e/"))); // arg is parent to scope[2]
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
318 errorCollector.assertTrue(!ps1.accept(Path.create("d/g/"))); // unrelated to any preconfigured
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
319 // files
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
320 errorCollector.assertTrue(ps1.accept(Path.create("a/d"))); // "a/" is parent
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
321 errorCollector.assertTrue(ps1.accept(Path.create("a/d/f"))); // "a/" is still a parent
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
322 errorCollector.assertTrue(ps1.accept(Path.create("b/c"))); // ==
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
323 errorCollector.assertTrue(!ps1.accept(Path.create("b/d"))); // file, !=
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
324 //
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
325 // accept only specified files, folders and their direct children, allow navigate to them from above (FileIterator contract)
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
326 PathScope ps2 = new PathScope(true, false, true, scope);
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
327 // folders
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
328 errorCollector.assertTrue(!ps2.accept(Path.create("a/b/c/"))); // recursiveDirs = false
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
329 errorCollector.assertTrue(ps2.accept(Path.create("b/"))); // arg is parent to scope[1] (IOW, scope[1] is nested under arg)
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
330 errorCollector.assertTrue(ps2.accept(Path.create("d/"))); // scope[2] is nested under arg
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
331 errorCollector.assertTrue(ps2.accept(Path.create("d/e/"))); // scope[2] is nested under arg
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
332 errorCollector.assertTrue(!ps2.accept(Path.create("d/f/")));
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
333 errorCollector.assertTrue(!ps2.accept(Path.create("b/f/")));
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
334 // files
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
335 errorCollector.assertTrue(!ps2.accept(Path.create("a/b/c"))); // file, no exact match
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
336 errorCollector.assertTrue(ps2.accept(Path.create("d/e/f/g"))); // file under scope[2]
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
337 errorCollector.assertTrue(!ps2.accept(Path.create("b/e"))); // unrelated file
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
338
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
339 // matchParentDirs == false
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
340 PathScope ps3 = new PathScope(false, true, true, Path.create("a/b/")); // match any dir/file under a/b/, but not above
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
341 errorCollector.assertTrue(!ps3.accept(Path.create("a/")));
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
342 errorCollector.assertTrue(ps3.accept(Path.create("a/b/c/d")));
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
343 errorCollector.assertTrue(ps3.accept(Path.create("a/b/c")));
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
344 errorCollector.assertTrue(!ps3.accept(Path.create("b/")));
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
345 errorCollector.assertTrue(!ps3.accept(Path.create("d/")));
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
346 errorCollector.assertTrue(!ps3.accept(Path.create("d/e/")));
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
347
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
348 // match nested but not direct dir
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
349 PathScope ps4 = new PathScope(false, true, false, Path.create("a/b/")); // match any dir/file *deep* under a/b/,
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
350 errorCollector.assertTrue(!ps4.accept(Path.create("a/")));
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
351 errorCollector.assertTrue(!ps4.accept(Path.create("a/b/c")));
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
352 errorCollector.assertTrue(ps4.accept(Path.create("a/b/c/d")));
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
353 }
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
354
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
355 @Test
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
356 public void testPathCompareWith() {
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
357 Path p1 = Path.create("a/b/");
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
358 Path p2 = Path.create("a/b/c");
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
359 Path p3 = Path.create("a/b"); // file with the same name as dir
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
360 Path p4 = Path.create("a/b/c/d/");
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
361 Path p5 = Path.create("d/");
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
362
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
363 errorCollector.assertEquals(Same, p1.compareWith(p1));
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
364 errorCollector.assertEquals(Same, p1.compareWith(Path.create(p1.toString())));
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
365 errorCollector.assertEquals(Unrelated, p1.compareWith(null));
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
366 errorCollector.assertEquals(Unrelated, p1.compareWith(p5));
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
367 //
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
368 errorCollector.assertEquals(Parent, p1.compareWith(p4));
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
369 errorCollector.assertEquals(Nested, p4.compareWith(p1));
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
370 errorCollector.assertEquals(ImmediateParent, p1.compareWith(p2));
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
371 errorCollector.assertEquals(ImmediateChild, p2.compareWith(p1));
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
372 //
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
373 errorCollector.assertEquals(Unrelated, p2.compareWith(p3));
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
374 errorCollector.assertEquals(Unrelated, p3.compareWith(p2));
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
375 }
072b5f3ed0c8 Path to tell immediate parent-child relationship; more powerful scope impl; tests for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
376
363
d9dfa9fe9cec Decode escape sequences in changeset extras field
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
377
331
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
378 public static void main(String[] args) throws Exception {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
379 new TestAuxUtilities().testRepositoryConfig();
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 327
diff changeset
380 }
311
b9592e21176a Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
381 }