1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
/*******************************************************************************
* Copyright (c) 2009 Cloudsmith Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Cloudsmith Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.equinox.p2.tests.omniVersion;
import org.eclipse.equinox.p2.metadata.Version;
import junit.framework.TestCase;
/**
* Tests format(n) and format(N)
*
*/
public class FormatNTest extends TestCase {
public void testNonNegative() {
Version v = Version.parseVersion("format(n):1");
assertNotNull(v);
assertEquals(Version.parseVersion("raw:1"), v);
assertNotNull(v = Version.parseVersion("format(n):0"));
assertEquals(Version.parseVersion("raw:0"), v);
try {
Version.parseVersion("format(n):-1");
fail("Uncaught exception: negative number in 'n' format");
} catch (IllegalArgumentException e) {
assertTrue(true);
}
}
public void testNegativeValues() {
Version v = Version.parseVersion("format(N):-1");
assertNotNull(v);
assertEquals(Version.parseVersion("raw:-1"), v);
assertNotNull(v = Version.parseVersion("format(N):1"));
assertEquals(Version.parseVersion("raw:1"), v);
assertNotNull(v = Version.parseVersion("format(N):0"));
assertEquals(Version.parseVersion("raw:0"), v);
}
public void testLeadingZeros() {
Version v = Version.parseVersion("format(n):000001");
assertNotNull(v);
assertEquals(Version.parseVersion("raw:1"), v);
assertNotNull(v = Version.parseVersion("format(N):-000001"));
assertEquals(Version.parseVersion("raw:-1"), v);
}
public void testExact() {
Version v = Version.parseVersion("format(n={2};n={2};):1122");
assertNotNull(v);
assertEquals(Version.parseVersion("raw:11.22"), v);
assertNotNull(v = Version.parseVersion("format(N={4};N={1};):-1234"));
assertEquals(Version.parseVersion("raw:-123.4"), v);
assertNotNull(v = Version.parseVersion("format(N={4};N={3};):-001234"));
assertEquals(Version.parseVersion("raw:-1.234"), v);
try {
v = Version.parseVersion("format(n={2};.;n={2};):1.2");
fail();
} catch (IllegalArgumentException e) {
assertTrue(true);
}
try {
v = Version.parseVersion("format(n={2};.;n={2};):111.2222");
fail();
} catch (IllegalArgumentException e) {
assertTrue(true);
}
}
public void testAtLeast() {
Version v = Version.parseVersion("format(n={2,};.n={2,};):111.22222");
assertNotNull(v);
assertEquals(Version.parseVersion("raw:111.22222"), v);
try {
v = Version.parseVersion("format(n={2,};.;n={2};):111.2");
fail();
} catch (IllegalArgumentException e) {
assertTrue(true);
}
}
public void testAtMost() {
Version v = Version.parseVersion("format(n={2,3};.n={2,3};):111.22");
assertNotNull(v);
assertEquals(Version.parseVersion("raw:111.22"), v);
try {
v = Version.parseVersion("format(n={2,3};.n={2,3};):111.2222");
fail();
} catch (IllegalArgumentException e) {
assertTrue(true);
}
try {
v = Version.parseVersion("format(n={2,3};.n={2,3};):1.222");
fail();
} catch (IllegalArgumentException e) {
assertTrue(true);
}
}
public void testNIsGreedy() {
try {
Version.parseVersion("format(nn):1010");
fail();
} catch (IllegalArgumentException e) {
assertTrue(true);
}
}
}
|