addon-sdk/source/test/test-list.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     4 'use strict';
     6 const { List, addListItem, removeListItem } = require('sdk/util/list');
     7 const { Class } = require('sdk/core/heritage');
     9 exports.testList = function(assert) {
    10   let list = List();
    11   addListItem(list, 1);
    13   for (let key in list) {
    14     assert.equal(key, 0, 'key is correct');
    15     assert.equal(list[key], 1, 'value is correct');
    16   }
    18   let count = 0;
    19   for each (let ele in list) {
    20     assert.equal(ele, 1, 'ele is correct');
    21     assert.equal(++count, 1, 'count is correct');
    22   }
    24   count = 0;
    25   for (let ele of list) {
    26     assert.equal(ele, 1, 'ele is correct');
    27     assert.equal(++count, 1, 'count is correct');
    28   }
    30   removeListItem(list, 1);
    31   assert.equal(list.length, 0, 'remove worked');
    32 };
    34 exports.testImplementsList = function(assert) {
    35   let List2 = Class({
    36     implements: [List],
    37     initialize: function() {
    38       List.prototype.initialize.apply(this, [0, 1, 2]);
    39     }
    40   });
    41   let list2 = List2();
    42   let count = 0;
    44   for each (let ele in list2) {
    45     assert.equal(ele, count++, 'ele is correct');
    46   }
    48   count = 0;
    49   for (let ele of list2) {
    50     assert.equal(ele, count++, 'ele is correct');
    51   }
    53   addListItem(list2, 3);
    54   assert.equal(list2.length, 4, '3 was added');
    55   assert.equal(list2[list2.length-1], 3, '3 was added');
    56 }
    58 require('sdk/test').run(exports);

mercurial