Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * WARNING! |
michael@0 | 3 | * |
michael@0 | 4 | * Do not edit this file directly, it is built from the sources at |
michael@0 | 5 | * https://github.com/mozilla/source-map/ |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | Components.utils.import('resource://test/Utils.jsm'); |
michael@0 | 9 | /* -*- Mode: js; js-indent-level: 2; -*- */ |
michael@0 | 10 | /* |
michael@0 | 11 | * Copyright 2011 Mozilla Foundation and contributors |
michael@0 | 12 | * Licensed under the New BSD license. See LICENSE or: |
michael@0 | 13 | * http://opensource.org/licenses/BSD-3-Clause |
michael@0 | 14 | */ |
michael@0 | 15 | define("test/source-map/test-array-set", ["require", "exports", "module"], function (require, exports, module) { |
michael@0 | 16 | |
michael@0 | 17 | var ArraySet = require('source-map/array-set').ArraySet; |
michael@0 | 18 | |
michael@0 | 19 | function makeTestSet() { |
michael@0 | 20 | var set = new ArraySet(); |
michael@0 | 21 | for (var i = 0; i < 100; i++) { |
michael@0 | 22 | set.add(String(i)); |
michael@0 | 23 | } |
michael@0 | 24 | return set; |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | exports['test .has() membership'] = function (assert, util) { |
michael@0 | 28 | var set = makeTestSet(); |
michael@0 | 29 | for (var i = 0; i < 100; i++) { |
michael@0 | 30 | assert.ok(set.has(String(i))); |
michael@0 | 31 | } |
michael@0 | 32 | }; |
michael@0 | 33 | |
michael@0 | 34 | exports['test .indexOf() elements'] = function (assert, util) { |
michael@0 | 35 | var set = makeTestSet(); |
michael@0 | 36 | for (var i = 0; i < 100; i++) { |
michael@0 | 37 | assert.strictEqual(set.indexOf(String(i)), i); |
michael@0 | 38 | } |
michael@0 | 39 | }; |
michael@0 | 40 | |
michael@0 | 41 | exports['test .at() indexing'] = function (assert, util) { |
michael@0 | 42 | var set = makeTestSet(); |
michael@0 | 43 | for (var i = 0; i < 100; i++) { |
michael@0 | 44 | assert.strictEqual(set.at(i), String(i)); |
michael@0 | 45 | } |
michael@0 | 46 | }; |
michael@0 | 47 | |
michael@0 | 48 | exports['test creating from an array'] = function (assert, util) { |
michael@0 | 49 | var set = ArraySet.fromArray(['foo', 'bar', 'baz', 'quux', 'hasOwnProperty']); |
michael@0 | 50 | |
michael@0 | 51 | assert.ok(set.has('foo')); |
michael@0 | 52 | assert.ok(set.has('bar')); |
michael@0 | 53 | assert.ok(set.has('baz')); |
michael@0 | 54 | assert.ok(set.has('quux')); |
michael@0 | 55 | assert.ok(set.has('hasOwnProperty')); |
michael@0 | 56 | |
michael@0 | 57 | assert.strictEqual(set.indexOf('foo'), 0); |
michael@0 | 58 | assert.strictEqual(set.indexOf('bar'), 1); |
michael@0 | 59 | assert.strictEqual(set.indexOf('baz'), 2); |
michael@0 | 60 | assert.strictEqual(set.indexOf('quux'), 3); |
michael@0 | 61 | |
michael@0 | 62 | assert.strictEqual(set.at(0), 'foo'); |
michael@0 | 63 | assert.strictEqual(set.at(1), 'bar'); |
michael@0 | 64 | assert.strictEqual(set.at(2), 'baz'); |
michael@0 | 65 | assert.strictEqual(set.at(3), 'quux'); |
michael@0 | 66 | }; |
michael@0 | 67 | |
michael@0 | 68 | exports['test that you can add __proto__; see github issue #30'] = function (assert, util) { |
michael@0 | 69 | var set = new ArraySet(); |
michael@0 | 70 | set.add('__proto__'); |
michael@0 | 71 | assert.ok(set.has('__proto__')); |
michael@0 | 72 | assert.strictEqual(set.at(0), '__proto__'); |
michael@0 | 73 | assert.strictEqual(set.indexOf('__proto__'), 0); |
michael@0 | 74 | }; |
michael@0 | 75 | |
michael@0 | 76 | exports['test .fromArray() with duplicates'] = function (assert, util) { |
michael@0 | 77 | var set = ArraySet.fromArray(['foo', 'foo']); |
michael@0 | 78 | assert.ok(set.has('foo')); |
michael@0 | 79 | assert.strictEqual(set.at(0), 'foo'); |
michael@0 | 80 | assert.strictEqual(set.indexOf('foo'), 0); |
michael@0 | 81 | assert.strictEqual(set.toArray().length, 1); |
michael@0 | 82 | |
michael@0 | 83 | set = ArraySet.fromArray(['foo', 'foo'], true); |
michael@0 | 84 | assert.ok(set.has('foo')); |
michael@0 | 85 | assert.strictEqual(set.at(0), 'foo'); |
michael@0 | 86 | assert.strictEqual(set.at(1), 'foo'); |
michael@0 | 87 | assert.strictEqual(set.indexOf('foo'), 0); |
michael@0 | 88 | assert.strictEqual(set.toArray().length, 2); |
michael@0 | 89 | }; |
michael@0 | 90 | |
michael@0 | 91 | exports['test .add() with duplicates'] = function (assert, util) { |
michael@0 | 92 | var set = new ArraySet(); |
michael@0 | 93 | set.add('foo'); |
michael@0 | 94 | |
michael@0 | 95 | set.add('foo'); |
michael@0 | 96 | assert.ok(set.has('foo')); |
michael@0 | 97 | assert.strictEqual(set.at(0), 'foo'); |
michael@0 | 98 | assert.strictEqual(set.indexOf('foo'), 0); |
michael@0 | 99 | assert.strictEqual(set.toArray().length, 1); |
michael@0 | 100 | |
michael@0 | 101 | set.add('foo', true); |
michael@0 | 102 | assert.ok(set.has('foo')); |
michael@0 | 103 | assert.strictEqual(set.at(0), 'foo'); |
michael@0 | 104 | assert.strictEqual(set.at(1), 'foo'); |
michael@0 | 105 | assert.strictEqual(set.indexOf('foo'), 0); |
michael@0 | 106 | assert.strictEqual(set.toArray().length, 2); |
michael@0 | 107 | }; |
michael@0 | 108 | |
michael@0 | 109 | }); |
michael@0 | 110 | function run_test() { |
michael@0 | 111 | runSourceMapTests('test/source-map/test-array-set', do_throw); |
michael@0 | 112 | } |