Skip to content

Commit

Permalink
added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jlangch committed Oct 17, 2023
1 parent d059af3 commit 64a2ca5
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,8 @@ else if (Types.isVncJavaObject(args.first(), BufferedWriter.class)) {
return args.first();
}
else if (Types.isVncJavaObject(args.first(), Writer.class)) {
return new VncJavaObject(args.first());
final Writer wr = Coerce.toVncJavaObject(args.first(), Writer.class);
return new VncJavaObject(new BufferedWriter(wr));
}
else {
throw new VncException(String.format(
Expand Down Expand Up @@ -948,10 +949,13 @@ else if (Types.isVncJavaObject(arg, InputStream.class)) {
throw new VncException("Failed to create reader from a :java.io.InputStream", ex);
}
}
else if (Types.isVncJavaObject(arg, BufferedReader.class)) {
return arg;
}
else if (Types.isVncJavaObject(arg, Reader.class)) {
try {
final Reader rd = Coerce.toVncJavaObject(args.first(), Reader.class);
return new VncJavaObject(rd);
return new VncJavaObject(new BufferedReader(rd));
}
catch (VncException ex) {
throw ex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public void test_io_buffered_reader() {
" (io/delete-file-on-exit file) " +
" (io/spit file \"100\n200\" :append false) " +
" (try-with [rd (io/buffered-reader file :encoding :utf-8)] " +
" (pr-str [(read-line rd) (read-line rd)])))) " +
")";
" (pr-str [(read-line rd) (read-line rd)])))) ";

assertEquals("[\"100\" \"200\"]",venice.eval(script));
}
Expand All @@ -60,10 +59,72 @@ public void test_io_buffered_writer() {
" (println wr \"100\") " +
" (println wr \"200\")) " +
" (try-with [rd (io/buffered-reader file :encoding :utf-8)] " +
" (pr-str [(read-line rd) (read-line rd)])))) " +
")";
" (pr-str [(read-line rd) (read-line rd)])))) ";

assertEquals("[\"100\" \"200\"]",venice.eval(script));
}

@Test
public void test_io_string_reader() {
final Venice venice = new Venice();

final String script1 =
"(try-with [rd (io/string-reader \"1234\")] \n" +
" (pr-str [ (read-char rd) \n" +
" (read-char rd) \n" +
" (read-char rd) ])) ";

final String script2 =
"(let [rd (io/string-reader \"1\\n2\\n3\\n4\")] \n" +
" (try-with [br (io/buffered-reader rd)] \n" +
" (pr-str [ (read-line br) \n" +
" (read-line br) \n" +
" (read-line br) ]))) ";

assertEquals("[#\\1 #\\2 #\\3]",venice.eval(script1));
assertEquals("[\"1\" \"2\" \"3\"]",venice.eval(script2));
}

@Test
public void test_io_string_writer() {
final Venice venice = new Venice();

final String script =
"(try-with [sw (io/string-writer)] \n" +
" (print sw 100) \n" +
" (print sw \"-\") \n" +
" (print sw 200) \n" +
" (flush sw) \n" +
" @sw) ";

assertEquals("100-200",venice.eval(script));
}

@Test
public void test_io_read_char() {
final Venice venice = new Venice();

final String script =
"(try-with [rd (io/string-reader \"1234\")] \n" +
" (pr-str [ (io/read-char rd) \n" +
" (io/read-char rd) \n" +
" (io/read-char rd) ])) ";

assertEquals("[#\\1 #\\2 #\\3]",venice.eval(script));
}

@Test
public void test_io_read_line() {
final Venice venice = new Venice();

final String script =
"(let [rd (io/string-reader \"1\\n2\\n3\\n4\")] \n" +
" (try-with [br (io/buffered-reader rd)] \n" +
" (pr-str [ (io/read-line br) \n" +
" (io/read-line br) \n" +
" (io/read-line br) ]))) ";

assertEquals("[\"1\" \"2\" \"3\"]",venice.eval(script));
}

}

0 comments on commit 64a2ca5

Please sign in to comment.