test_delimited_read.js (859B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 const StreamUtils = require("resource://devtools/shared/transport/stream-utils.js"); 6 7 const StringInputStream = Components.Constructor( 8 "@mozilla.org/io/string-input-stream;1", 9 "nsIStringInputStream", 10 "setByteStringData" 11 ); 12 13 function run_test() { 14 add_task(async function () { 15 await test_delimited_read("0123:", "0123:"); 16 await test_delimited_read("0123:4567:", "0123:"); 17 await test_delimited_read("012345678901:", "0123456789"); 18 await test_delimited_read("0123/0123", "0123/0123"); 19 }); 20 21 run_next_test(); 22 } 23 24 /*** Tests ***/ 25 26 function test_delimited_read(input, expected) { 27 input = new StringInputStream(input); 28 const result = StreamUtils.delimitedRead(input, ":", 10); 29 Assert.equal(result, expected); 30 }