2 * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
3 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
7 * Redistribution and use in source and binary forms, with or
8 * without modification, are permitted provided that the following
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
19 * - Neither the name of the Git Development Community nor the
20 * names of its contributors may be used to endorse or promote
21 * products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
25 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
26 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 package org
.spearce
.jgit
.transport
;
41 import junit
.framework
.TestCase
;
43 import org
.spearce
.jgit
.lib
.Ref
;
45 public class RefSpecTestCase
extends TestCase
{
46 public void testMasterMaster() {
47 final String sn
= "refs/heads/master";
48 final RefSpec rs
= new RefSpec(sn
+ ":" + sn
);
49 assertFalse(rs
.isForceUpdate());
50 assertFalse(rs
.isWildcard());
51 assertEquals(sn
, rs
.getSource());
52 assertEquals(sn
, rs
.getDestination());
53 assertEquals(sn
+ ":" + sn
, rs
.toString());
54 assertEquals(rs
, new RefSpec(rs
.toString()));
56 Ref r
= new Ref(sn
, null);
57 assertTrue(rs
.matchSource(r
));
58 assertTrue(rs
.matchDestination(r
));
59 assertSame(rs
, rs
.expandFromSource(r
));
61 r
= new Ref(sn
+ "-and-more", null);
62 assertFalse(rs
.matchSource(r
));
63 assertFalse(rs
.matchDestination(r
));
66 public void testForceMasterMaster() {
67 final String sn
= "refs/heads/master";
68 final RefSpec rs
= new RefSpec("+" + sn
+ ":" + sn
);
69 assertTrue(rs
.isForceUpdate());
70 assertFalse(rs
.isWildcard());
71 assertEquals(sn
, rs
.getSource());
72 assertEquals(sn
, rs
.getDestination());
73 assertEquals("+" + sn
+ ":" + sn
, rs
.toString());
74 assertEquals(rs
, new RefSpec(rs
.toString()));
76 Ref r
= new Ref(sn
, null);
77 assertTrue(rs
.matchSource(r
));
78 assertTrue(rs
.matchDestination(r
));
79 assertSame(rs
, rs
.expandFromSource(r
));
81 r
= new Ref(sn
+ "-and-more", null);
82 assertFalse(rs
.matchSource(r
));
83 assertFalse(rs
.matchDestination(r
));
86 public void testMaster() {
87 final String sn
= "refs/heads/master";
88 final RefSpec rs
= new RefSpec(sn
);
89 assertFalse(rs
.isForceUpdate());
90 assertFalse(rs
.isWildcard());
91 assertEquals(sn
, rs
.getSource());
92 assertNull(rs
.getDestination());
93 assertEquals(sn
, rs
.toString());
94 assertEquals(rs
, new RefSpec(rs
.toString()));
96 Ref r
= new Ref(sn
, null);
97 assertTrue(rs
.matchSource(r
));
98 assertFalse(rs
.matchDestination(r
));
99 assertSame(rs
, rs
.expandFromSource(r
));
101 r
= new Ref(sn
+ "-and-more", null);
102 assertFalse(rs
.matchSource(r
));
103 assertFalse(rs
.matchDestination(r
));
106 public void testForceMaster() {
107 final String sn
= "refs/heads/master";
108 final RefSpec rs
= new RefSpec("+" + sn
);
109 assertTrue(rs
.isForceUpdate());
110 assertFalse(rs
.isWildcard());
111 assertEquals(sn
, rs
.getSource());
112 assertNull(rs
.getDestination());
113 assertEquals("+" + sn
, rs
.toString());
114 assertEquals(rs
, new RefSpec(rs
.toString()));
116 Ref r
= new Ref(sn
, null);
117 assertTrue(rs
.matchSource(r
));
118 assertFalse(rs
.matchDestination(r
));
119 assertSame(rs
, rs
.expandFromSource(r
));
121 r
= new Ref(sn
+ "-and-more", null);
122 assertFalse(rs
.matchSource(r
));
123 assertFalse(rs
.matchDestination(r
));
126 public void testDeleteMaster() {
127 final String sn
= "refs/heads/master";
128 final RefSpec rs
= new RefSpec(":" + sn
);
129 assertFalse(rs
.isForceUpdate());
130 assertFalse(rs
.isWildcard());
131 assertNull(rs
.getSource());
132 assertEquals(sn
, rs
.getDestination());
133 assertEquals(":" + sn
, rs
.toString());
134 assertEquals(rs
, new RefSpec(rs
.toString()));
136 Ref r
= new Ref(sn
, null);
137 assertFalse(rs
.matchSource(r
));
138 assertTrue(rs
.matchDestination(r
));
139 assertSame(rs
, rs
.expandFromSource(r
));
141 r
= new Ref(sn
+ "-and-more", null);
142 assertFalse(rs
.matchSource(r
));
143 assertFalse(rs
.matchDestination(r
));
146 public void testForceRemotesOrigin() {
147 final String srcn
= "refs/heads/*";
148 final String dstn
= "refs/remotes/origin/*";
149 final RefSpec rs
= new RefSpec("+" + srcn
+ ":" + dstn
);
150 assertTrue(rs
.isForceUpdate());
151 assertTrue(rs
.isWildcard());
152 assertEquals(srcn
, rs
.getSource());
153 assertEquals(dstn
, rs
.getDestination());
154 assertEquals("+" + srcn
+ ":" + dstn
, rs
.toString());
155 assertEquals(rs
, new RefSpec(rs
.toString()));
160 r
= new Ref("refs/heads/master", null);
161 assertTrue(rs
.matchSource(r
));
162 assertFalse(rs
.matchDestination(r
));
163 expanded
= rs
.expandFromSource(r
);
164 assertNotSame(rs
, expanded
);
165 assertTrue(expanded
.isForceUpdate());
166 assertFalse(expanded
.isWildcard());
167 assertEquals(r
.getName(), expanded
.getSource());
168 assertEquals("refs/remotes/origin/master", expanded
.getDestination());
170 r
= new Ref("refs/remotes/origin/next", null);
171 assertFalse(rs
.matchSource(r
));
172 assertTrue(rs
.matchDestination(r
));
174 r
= new Ref("refs/tags/v1.0", null);
175 assertFalse(rs
.matchSource(r
));
176 assertFalse(rs
.matchDestination(r
));
179 public void testCreateEmpty() {
180 final RefSpec rs
= new RefSpec();
181 assertFalse(rs
.isForceUpdate());
182 assertFalse(rs
.isWildcard());
183 assertEquals("HEAD", rs
.getSource());
184 assertNull(rs
.getDestination());
185 assertEquals("HEAD", rs
.toString());
188 public void testSetForceUpdate() {
189 final String s
= "refs/heads/*:refs/remotes/origin/*";
190 final RefSpec a
= new RefSpec(s
);
191 assertFalse(a
.isForceUpdate());
192 RefSpec b
= a
.setForceUpdate(true);
194 assertFalse(a
.isForceUpdate());
195 assertTrue(b
.isForceUpdate());
196 assertEquals(s
, a
.toString());
197 assertEquals("+" + s
, b
.toString());
200 public void testSetSource() {
201 final RefSpec a
= new RefSpec();
202 final RefSpec b
= a
.setSource("refs/heads/master");
204 assertEquals("HEAD", a
.toString());
205 assertEquals("refs/heads/master", b
.toString());
208 public void testSetDestination() {
209 final RefSpec a
= new RefSpec();
210 final RefSpec b
= a
.setDestination("refs/heads/master");
212 assertEquals("HEAD", a
.toString());
213 assertEquals("HEAD:refs/heads/master", b
.toString());
216 public void testSetDestination_SourceNull() {
217 final RefSpec a
= new RefSpec();
220 b
= a
.setDestination("refs/heads/master");
221 b
= b
.setSource(null);
223 assertEquals("HEAD", a
.toString());
224 assertEquals(":refs/heads/master", b
.toString());
227 public void testSetSourceDestination() {
228 final RefSpec a
= new RefSpec();
230 b
= a
.setSourceDestination("refs/heads/*", "refs/remotes/origin/*");
232 assertEquals("HEAD", a
.toString());
233 assertEquals("refs/heads/*:refs/remotes/origin/*", b
.toString());