1 | package org.armedbear.lisp; |
---|
2 | |
---|
3 | import java.util.List; |
---|
4 | import java.text.MessageFormat; |
---|
5 | import org.junit.After; |
---|
6 | import org.junit.AfterClass; |
---|
7 | import org.junit.Before; |
---|
8 | import org.junit.BeforeClass; |
---|
9 | import org.junit.Test; |
---|
10 | import static org.junit.Assert.*; |
---|
11 | |
---|
12 | public class JarPathnameTest |
---|
13 | { |
---|
14 | @Test |
---|
15 | public void enumerate1() { |
---|
16 | String s = "jar:jar:file:/a/foo.jar!/b/baz.abcl!/path/c.lisp"; |
---|
17 | List<String> r = JarPathname.enumerate(s); |
---|
18 | assertTrue("3 results", r.size() == 3); |
---|
19 | String parts[] = { |
---|
20 | "file:/a/foo.jar", |
---|
21 | "b/baz.abcl!/", |
---|
22 | "/path/c.lisp" |
---|
23 | }; |
---|
24 | for (int i = 0; i < parts.length; i++) { |
---|
25 | assertTrue(parts[i], r.get(i).equals(parts[i])); |
---|
26 | } |
---|
27 | } |
---|
28 | |
---|
29 | @Test |
---|
30 | public void enumerate2() { |
---|
31 | String s = "jar:jar:file:/a/foo.jar!/b/baz.abcl!/"; |
---|
32 | List<String> r = JarPathname.enumerate(s); |
---|
33 | assertTrue("2 results", r.size() == 2); |
---|
34 | String parts[] = { |
---|
35 | "file:/a/foo.jar", |
---|
36 | "b/baz.abcl!/" |
---|
37 | }; |
---|
38 | for (int i = 0; i < parts.length; i++) { |
---|
39 | assertTrue(parts[i], r.get(i).equals(parts[i])); |
---|
40 | } |
---|
41 | } |
---|
42 | |
---|
43 | @Test |
---|
44 | public void enumerate3() { |
---|
45 | String s = "jar:jar:https://example.com/a/foo.jar!/b/baz.abcl!/path/c.lisp"; |
---|
46 | List<String> r = JarPathname.enumerate(s); |
---|
47 | assertTrue("3 results", r.size() == 3); |
---|
48 | String parts[] = { |
---|
49 | "https://example.com/a/foo.jar", |
---|
50 | "b/baz.abcl!/", |
---|
51 | "/path/c.lisp" |
---|
52 | }; |
---|
53 | for (int i = 0; i < parts.length; i++) { |
---|
54 | assertTrue(parts[i], r.get(i).equals(parts[i])); |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | @Test |
---|
59 | public void enumerate4() { |
---|
60 | String s = "jar:jar:jar:file:/a/foo.jar!/b/baz.abcl!/log4j.jar!/MF/manifest.mf"; |
---|
61 | List<String> r = JarPathname.enumerate(s); |
---|
62 | assertTrue("4 results", r.size() == 4); |
---|
63 | String parts[] = { |
---|
64 | "file:/a/foo.jar", |
---|
65 | "b/baz.abcl!/", |
---|
66 | "log4j.jar!/", |
---|
67 | "/MF/manifest.mf" |
---|
68 | }; |
---|
69 | for (int i = 0; i < parts.length; i++) { |
---|
70 | assertTrue(parts[i], r.get(i).equals(parts[i])); |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | @Test |
---|
75 | public void roundTrips() { |
---|
76 | String namestrings[] = { |
---|
77 | "jar:file:///foo.jar!/", |
---|
78 | "jar:jar:file:///foo.jar!/baz.abcl!/", |
---|
79 | "jar:jar:file:///foo.jar!/baz.abcl!/__loader__._", |
---|
80 | "jar:jar:jar:file:///a/b/foo.jar!/c/baz.zip!/log4j.jar!/MF/manifest.mf", |
---|
81 | "jar:https://abcl.org/releases/1.7.1/abcl-contrib.jar!/" |
---|
82 | }; |
---|
83 | |
---|
84 | for (String namestring : namestrings) { |
---|
85 | Pathname result = (Pathname) Pathname.create(namestring); |
---|
86 | String resultingNamestring = result.getNamestring(); |
---|
87 | String message = MessageFormat.format("Namestring \"{0}\" failed to roundtrip", namestring); |
---|
88 | assertTrue(message, |
---|
89 | namestring.equals(resultingNamestring)); |
---|
90 | } |
---|
91 | } |
---|
92 | |
---|
93 | @Test |
---|
94 | public void invalidNamestrings() { |
---|
95 | String namestrings[] = { |
---|
96 | "jar:file:foo.jar!/", |
---|
97 | "jar:file:foo.jar!/baz.abcl!/", |
---|
98 | "jar:jar:file:foo.jar!/baz.abcl!/__loader__._", |
---|
99 | "jar:file:foo.jar!/baz.abcl!/__loader__._", |
---|
100 | "jar:jar:file:foo.jar!/baz.abcl!/", |
---|
101 | "jar:jar:jar:file:a/b/foo.jar!/c/baz.zip!/log4j.jar!/MF/manifest.mf" |
---|
102 | }; |
---|
103 | |
---|
104 | // JUnit 4.12 (which is what is available in Netbeans 12) doesn't |
---|
105 | // have an assertion about throwing an error. |
---|
106 | for (String namestring : namestrings) { |
---|
107 | try { |
---|
108 | Pathname.create(namestring); |
---|
109 | } catch (Throwable t) { |
---|
110 | String message = MessageFormat.format("Namestring \"{0}\" is invalid throwing: {1}", |
---|
111 | namestring, |
---|
112 | t.getCause()); |
---|
113 | assertTrue(message, true); |
---|
114 | } |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | @Test |
---|
119 | public void makePathname() { |
---|
120 | String urlString = "https://abcl.org/releases/1.7.1/abcl-contrib.jar"; |
---|
121 | URLPathname urlPathname = URLPathname.create(urlString); |
---|
122 | LispObject args[] = {Keyword.DEVICE, Lisp.list(urlPathname)}; |
---|
123 | LispObject result = Symbol.MAKE_PATHNAME.execute(args); |
---|
124 | assertTrue("MAKE-PATHNAME created instance of a JAR-PATHNAME", result instanceof JarPathname); |
---|
125 | String expectedNamestring |
---|
126 | = MessageFormat.format("jar:{0}!/", urlString); |
---|
127 | String resultingNamestring |
---|
128 | = ((JarPathname)result).getNamestring(); |
---|
129 | assertTrue(MessageFormat.format("Namestring '{0}' is '{1}'", expectedNamestring, resultingNamestring), |
---|
130 | expectedNamestring.equals(resultingNamestring)); |
---|
131 | } |
---|
132 | |
---|
133 | } |
---|