From 5a951d1b938a8680fbb211a2174c30afbba4cf53 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Mon, 9 Feb 2015 17:30:31 -0800 Subject: [PATCH] pull in latest iojs buffer tests --- bin/download-node-tests.js | 2 +- test/node-test-buffer-ascii.js | 21 ---------- test/node-test-buffer-big.js | 21 ---------- test/node-test-buffer-concat.js | 21 ---------- test/node-test-buffer-inspect.js | 21 ---------- test/node-test-buffer-iterator.js | 64 +++++++++++++++++++++++++++++++ test/node-test-buffer-slice.js | 21 ---------- test/node-test-buffer.js | 28 ++++---------- 8 files changed, 72 insertions(+), 127 deletions(-) create mode 100644 test/node-test-buffer-iterator.js diff --git a/bin/download-node-tests.js b/bin/download-node-tests.js index 0b21e39..241816b 100755 --- a/bin/download-node-tests.js +++ b/bin/download-node-tests.js @@ -56,7 +56,7 @@ function testfixer (filename) { } // comment out require('common') - line = line.replace(/^(var common = require.*)/, '// $1') + line = line.replace(/(var common = require.*)/, '// $1') // require browser buffer line = line.replace(/(.*)require\('buffer'\)(.*)/, '$1require(\'../\')$2') diff --git a/test/node-test-buffer-ascii.js b/test/node-test-buffer-ascii.js index 983841b..e3d918c 100644 --- a/test/node-test-buffer-ascii.js +++ b/test/node-test-buffer-ascii.js @@ -1,26 +1,5 @@ var Buffer = require('../').Buffer if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - // var common = require('../common'); var assert = require('assert'); diff --git a/test/node-test-buffer-big.js b/test/node-test-buffer-big.js index 36ad13a..a5558d5 100644 --- a/test/node-test-buffer-big.js +++ b/test/node-test-buffer-big.js @@ -1,26 +1,5 @@ var Buffer = require('../').Buffer if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - // var common = require('../common'); var assert = require('assert'); diff --git a/test/node-test-buffer-concat.js b/test/node-test-buffer-concat.js index 28860a9..d68b135 100644 --- a/test/node-test-buffer-concat.js +++ b/test/node-test-buffer-concat.js @@ -1,26 +1,5 @@ var Buffer = require('../').Buffer if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - // var common = require('../common'); var assert = require('assert'); diff --git a/test/node-test-buffer-inspect.js b/test/node-test-buffer-inspect.js index c79bac9..c35d416 100644 --- a/test/node-test-buffer-inspect.js +++ b/test/node-test-buffer-inspect.js @@ -1,26 +1,5 @@ var Buffer = require('../').Buffer if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - // var common = require('../common'); var assert = require('assert'); diff --git a/test/node-test-buffer-iterator.js b/test/node-test-buffer-iterator.js new file mode 100644 index 0000000..61399ad --- /dev/null +++ b/test/node-test-buffer-iterator.js @@ -0,0 +1,64 @@ +var Buffer = require('../').Buffer +if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false +// var common = require('../common'); +var assert = require('assert'); + +var buffer = new Buffer([1, 2, 3, 4, 5]); +var arr; +var b; + +// buffers should be iterable + +arr = []; + +for (b of buffer) + arr.push(b); + +assert.deepEqual(arr, [1, 2, 3, 4, 5]); + + +// buffer iterators should be iterable + +arr = []; + +for (b of buffer[Symbol.iterator]()) + arr.push(b); + +assert.deepEqual(arr, [1, 2, 3, 4, 5]); + + +// buffer#values() should return iterator for values + +arr = []; + +for (b of buffer.values()) + arr.push(b); + +assert.deepEqual(arr, [1, 2, 3, 4, 5]); + + +// buffer#keys() should return iterator for keys + +arr = []; + +for (b of buffer.keys()) + arr.push(b); + +assert.deepEqual(arr, [0, 1, 2, 3, 4]); + + +// buffer#entries() should return iterator for entries + +arr = []; + +for (var b of buffer.entries()) + arr.push(b); + +assert.deepEqual(arr, [ + [0, 1], + [1, 2], + [2, 3], + [3, 4], + [4, 5] +]); + diff --git a/test/node-test-buffer-slice.js b/test/node-test-buffer-slice.js index d12a4e6..ebef86e 100644 --- a/test/node-test-buffer-slice.js +++ b/test/node-test-buffer-slice.js @@ -1,26 +1,5 @@ var Buffer = require('../').Buffer if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - // var common = require('../common'); var assert = require('assert'); diff --git a/test/node-test-buffer.js b/test/node-test-buffer.js index 06fe9c7..ab4535d 100644 --- a/test/node-test-buffer.js +++ b/test/node-test-buffer.js @@ -1,26 +1,5 @@ var Buffer = require('../').Buffer if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - // var common = require('../common'); var assert = require('assert'); @@ -1151,11 +1130,14 @@ assert.equal(b.compare(c), -1); assert.equal(c.compare(d), 1); assert.equal(d.compare(b), 1); assert.equal(b.compare(d), -1); +assert.equal(b.compare(b), 0); assert.equal(Buffer.compare(b, c), -1); assert.equal(Buffer.compare(c, d), 1); assert.equal(Buffer.compare(d, b), 1); assert.equal(Buffer.compare(b, d), -1); +assert.equal(Buffer.compare(c, c), 0); + assert.throws(function() { var b = new Buffer(1); @@ -1181,8 +1163,12 @@ var e = new Buffer(6).fill('abcdef'); assert.ok(b.equals(c)); assert.ok(!c.equals(d)); assert.ok(!d.equals(e)); +assert.ok(d.equals(d)); assert.throws(function() { var b = new Buffer(1); b.equals('abc'); }); + +// Regression test for https://github.com/iojs/io.js/issues/649. +assert.throws(function() { Buffer(1422561062959).toString('utf8'); }); -- 2.34.1