Skip to content

Commit

Permalink
Adds basic test for TextStream
Browse files Browse the repository at this point in the history
  • Loading branch information
botic committed Jun 24, 2014
1 parent 694a89f commit 21ed145
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions modules/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ exports.MemoryStream = function MemoryStream(binaryOrNumber) {
* @param {Object} options the options object. Supports the following properties:
* <ul><li>charset: string containing the name of the encoding to use.
* Defaults to "utf8".</li>
* <li>newline: string containing the newline character sequence to use.
* Defaults to "\n".</li>
* <li>newline: string containing the newline character sequence to use in
* writeLine() and writeLines(). Defaults to "\n".</li>
* <li>delimiter: string containing the delimiter to use in print().
* Defaults to " ".</li></ul>
* @param {number} buflen optional buffer size. Defaults to 8192.
Expand Down Expand Up @@ -386,7 +386,7 @@ exports.TextStream = function TextStream(io, options, buflen) {
/**
* Reads a line from this stream. If the end of the stream is reached
* before any data is gathered, returns an empty string. Otherwise, returns
* the line including the newline.
* the line including only the newline character. Carriage return will be dropped.
* @returns {String} the next line
*/
this.readLine = function () {
Expand Down Expand Up @@ -457,7 +457,7 @@ exports.TextStream = function TextStream(io, options, buflen) {
};

/**
* Not implemented for TextStraim. Calling this method will raise an error.
* Not implemented for TextStream. Calling this method will raise an error.
*/
this.readInto = function (buffer) {
throw new Error("Not implemented");
Expand Down
14 changes: 14 additions & 0 deletions test/io_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,17 @@ exports.testMemoryStream = function() {
}
assert.deepEqual(m.read(bytes.length), new ByteString());
}

exports.testTextStream = function() {
// Carriage return should be dropped
var input = new java.io.ByteArrayInputStream((new java.lang.String("Hello\r\nWorld!")).getBytes("UTF-8"));
var stream = new TextStream(new Stream(input));
var lines = stream.readLines();

assert.strictEqual(lines[0], "Hello\n");
assert.strictEqual(lines[1], "World!");
};

if (module == require.main) {
require("test").run(exports);
}

0 comments on commit 21ed145

Please sign in to comment.