michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: 'use strict'; michael@0: michael@0: const { List, addListItem, removeListItem } = require('sdk/util/list'); michael@0: const { Class } = require('sdk/core/heritage'); michael@0: michael@0: exports.testList = function(assert) { michael@0: let list = List(); michael@0: addListItem(list, 1); michael@0: michael@0: for (let key in list) { michael@0: assert.equal(key, 0, 'key is correct'); michael@0: assert.equal(list[key], 1, 'value is correct'); michael@0: } michael@0: michael@0: let count = 0; michael@0: for each (let ele in list) { michael@0: assert.equal(ele, 1, 'ele is correct'); michael@0: assert.equal(++count, 1, 'count is correct'); michael@0: } michael@0: michael@0: count = 0; michael@0: for (let ele of list) { michael@0: assert.equal(ele, 1, 'ele is correct'); michael@0: assert.equal(++count, 1, 'count is correct'); michael@0: } michael@0: michael@0: removeListItem(list, 1); michael@0: assert.equal(list.length, 0, 'remove worked'); michael@0: }; michael@0: michael@0: exports.testImplementsList = function(assert) { michael@0: let List2 = Class({ michael@0: implements: [List], michael@0: initialize: function() { michael@0: List.prototype.initialize.apply(this, [0, 1, 2]); michael@0: } michael@0: }); michael@0: let list2 = List2(); michael@0: let count = 0; michael@0: michael@0: for each (let ele in list2) { michael@0: assert.equal(ele, count++, 'ele is correct'); michael@0: } michael@0: michael@0: count = 0; michael@0: for (let ele of list2) { michael@0: assert.equal(ele, count++, 'ele is correct'); michael@0: } michael@0: michael@0: addListItem(list2, 3); michael@0: assert.equal(list2.length, 4, '3 was added'); michael@0: assert.equal(list2[list2.length-1], 3, '3 was added'); michael@0: } michael@0: michael@0: require('sdk/test').run(exports);