Permalink
Browse files

fix incorrect translation between Writer.write() and StringBuilder.ap…

…pend() APIs re: length vs. end idx, fixes NREPL-38
  • Loading branch information...
1 parent 2d92207 commit b9e930a1bfbd9616644aa6f0112769cc233cc61e @cemerick cemerick committed Jan 13, 2013
@@ -35,7 +35,8 @@
(cond
(number? x) (.append buf (char x))
(not off) (.append buf x)
- (instance? CharSequence x) (.append buf ^CharSequence x off len)
+ ; the CharSequence overload of append takes an *end* idx, not length!
+ (instance? CharSequence x) (.append buf ^CharSequence x off (+ len off))
:else (.append buf ^chars x off len))
(when (<= *out-limit* (.length buf))
(.flush ^Writer this))))
@@ -37,8 +37,8 @@ public void append(CharSequence s) {
sb.append(s);
}
- public void append(char[] s, int start, int end) {
- sb.append(s, start, end);
+ public void append(char[] s, int start, int len) {
+ sb.append(s, start, len);
}
public void append(char[] s) {
@@ -98,6 +98,7 @@
(.write (.toCharArray "ef") 0 2)
(.write "gh" 0 2)
(.write (.toCharArray "ij"))
+ (.write " klm" 5 1)
(.write 32)
.flush)
(with-open [out (java.io.PrintWriter. w)]
@@ -106,7 +107,7 @@
(prn #{})
(flush)))
- (is (= ["println\n" "abcdefghij " "\n#{}\n"]
+ (is (= ["println\n" "abcdefghijm " "\n#{}\n"]
(->> (repl/response-seq local 0)
(map :out))))))
@@ -118,6 +118,16 @@
(map :out)
(remove nil?)))))
+(def-repl-test session-*out*-writer-length-translation
+ (when (<= 4 (:minor *clojure-version*))
+ (is (= "#inst \"2013-02-11T12:13:44.000+00:00\"\n"
+ (-> (repl-eval session
+ (code (println (doto
+ (java.util.GregorianCalendar. 2013 1 11 12 13 44)
+ (.setTimeZone (java.util.TimeZone/getTimeZone "GMT"))))))
+ combine-responses
+ :out)))))
+
(def-repl-test streaming-out-without-explicit-flushing
(is (= ["(0 1 "
"2 3 4"

0 comments on commit b9e930a

Please sign in to comment.