source: branches/1.3.3/abcl/test/src/org/armedbear/lisp/PathnameTest.java

Last change on this file was 14624, checked in by Mark Evenson, 11 years ago

Fix (remaining?) bugs for DIRECTORY.

Fixes Quicklisp, aka the "DIRECTORY no longer works with
:WILD-INFERIORS" problem, q.v. <http://abcl.org/trac/ticket/344>.

DIRECTORY under non-Windows now fills nil DEVICE components with
:UNSPECIFIC, otherwise forms like

(equal (truename "~/.emacs")

(first (directory "~/.emacs")) )

fail (c.f. ANSI test DIRECTORY.[67]).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1package org.armedbear.lisp;
2
3import java.net.MalformedURLException;
4import org.junit.Test;
5import static org.junit.Assert.*;
6import org.junit.runner.JUnitCore;
7
8
9import java.net.URL;
10import java.io.File;
11import java.io.FileWriter;
12import java.io.InputStream;
13import java.io.InputStreamReader;
14import java.io.IOException;
15
16public class PathnameTest
17{
18  public static void main(final String args[]) {
19    JUnitCore.main("org.armedbear.lisp.PathnameTest");
20  }
21
22  @Test
23  public void constructorURL()
24  {
25    URL url = null;
26    try {
27       url = new URL("file:///Users/evenson/work/abcl/build/classes/org/armedbear/lisp/boot.lisp");
28    } catch (MalformedURLException e) {
29        System.out.println(e.getMessage());
30    }
31    Pathname pathname = new Pathname(url);
32    assertNotNull(pathname);
33    assertNotNull(pathname.getNamestring());
34    assertNotNull(pathname.name);
35    assertNotNull(pathname.type);
36    assertNotNull(pathname.directory);
37  }
38 
39  @Test
40  public void getInputStream() throws IOException {
41    File file = File.createTempFile("foo", ".lisp");
42    FileWriter output = new FileWriter(file);
43    String contents = "(defun foo () 42)";
44    output.append(contents);
45    output.close();
46    Pathname pathname = Pathname.makePathname(file);
47    InputStream input = pathname.getInputStream();
48    InputStreamReader reader = new InputStreamReader(input);
49    char[] buffer = new char[1024];
50    StringBuilder result = new StringBuilder();
51    int i;
52    while((i = reader.read(buffer, 0, buffer.length)) != -1) {
53      result.append(buffer, 0, i);
54    }
55    assertEquals(contents, result.toString());
56    input.close();
57    file.delete();
58  }
59
60  @Test
61  public void copyConstructor() {
62      Pathname orig = new Pathname("/a/b/c/d/e/foo.lisp");
63      Pathname copy = new Pathname(orig.getNamestring());
64      assertTrue(orig.getNamestring().equals(copy.getNamestring()));
65  }
66
67  @Test
68  public void mergePathnames1() {
69      Pathname p = new Pathname("a/b/c/d/foo.lisp");
70      Pathname d = new Pathname("/foo/bar/there");
71      Pathname r = Pathname.mergePathnames(p, d);
72      String s = r.getNamestring();
73      assertTrue(s.equals("/foo/bar/a/b/c/d/foo.lisp"));
74  }
75
76  @Test
77  public void mergePathnames2() {
78      Pathname p = new Pathname("/a/b/c/d/foo.lisp");
79      Pathname d = new Pathname("/foo/bar/there");
80      Pathname r = Pathname.mergePathnames(p, d);
81      assertTrue(r.getNamestring().equals("/a/b/c/d/foo.lisp"));
82  }
83
84  @Test
85  public void mergePathnames3() {
86      LispObject args = Lisp.NIL;
87      args = args.push(Keyword.TYPE);
88      args = args.push(new SimpleString("abcl-tmp"));
89      args = args.nreverse();
90      Pathname p = Pathname.makePathname(args);
91      Pathname d = new Pathname("/foo/bar.abcl");
92      Pathname r = Pathname.mergePathnames(p, d);
93      assertTrue(r.getNamestring().equals("/foo/bar.abcl-tmp"));
94  }
95
96  @Test
97  public void mergePathnames4() {
98      Pathname p = new Pathname("jar:file:foo.jar!/bar.abcl");
99      Pathname d = new Pathname("/a/b/c/");
100      Pathname r = Pathname.mergePathnames(p, d);
101      String s = r.getNamestring();
102      assertTrue(s.equals("jar:file:/a/b/c/foo.jar!/bar.abcl"));
103  }
104  @Test 
105  public void constructorFileDirectory() {
106    Pathname p = new Pathname("file://tmp/");
107    assertTrue(p.getNamestring().endsWith("/"));
108  }
109  @Test 
110    public void constructorFileWindowsDevice() {
111    Pathname p = new Pathname("file:c://tmp/");
112    LispObject device = p.getDevice();
113    if (Utilities.isPlatformWindows) {
114      assert(device != Lisp.NIL);
115    }
116  }
117}
Note: See TracBrowser for help on using the repository browser.