| Index: tests/html/js_test.dart
|
| diff --git a/tests/html/js_test.dart b/tests/html/js_test.dart
|
| index c7d53f312e8f83eaaeddcb38dd5ab77bc3ad0c62..23f03cd6809a9ba6e19e5f1344dde320a8579fd3 100644
|
| --- a/tests/html/js_test.dart
|
| +++ b/tests/html/js_test.dart
|
| @@ -450,6 +450,137 @@ main() {
|
| */
|
| });
|
|
|
| + group('JsArray', () {
|
| +
|
| + test('new JsArray()', () {
|
| + var array = new JsArray();
|
| + var arrayType = context['Array'];
|
| + expect(array.instanceof(arrayType), true);
|
| + expect(array, []);
|
| + // basic check that it behaves like a List
|
| + array.addAll([1, 2, 3]);
|
| + expect(array, [1, 2, 3]);
|
| + });
|
| +
|
| + test('new JsArray.from()', () {
|
| + var array = new JsArray.from([1, 2, 3]);
|
| + var arrayType = context['Array'];
|
| + expect(array.instanceof(arrayType), true);
|
| + expect(array, [1, 2, 3]);
|
| + });
|
| +
|
| + test('get Array from JS', () {
|
| + context['a'] = [1, 2, 3];
|
| + var a = context['a'];
|
| + expect(a is JsArray, true);
|
| + expect(a, [1, 2, 3]);
|
| + context.deleteProperty('a');
|
| + });
|
| +
|
| + test('[]', () {
|
| + var array = new JsArray.from([1, 2]);
|
| + expect(array[0], 1);
|
| + expect(array[1], 2);
|
| + expect(() => array[-1], throwsA(isRangeError));
|
| + expect(() => array[2], throwsA(isRangeError));
|
| + });
|
| +
|
| + test('[]=', () {
|
| + var array = new JsArray.from([1, 2]);
|
| + array[0] = 'd';
|
| + array[1] = 'e';
|
| + expect(array, ['d', 'e']);
|
| + expect(() => array[-1] = 3, throwsA(isRangeError));
|
| + expect(() => array[2] = 3, throwsA(isRangeError));
|
| + });
|
| +
|
| + test('length', () {
|
| + var array = new JsArray.from([1, 2, 3]);
|
| + expect(array.length, 3);
|
| + array.add(4);
|
| + expect(array.length, 4);
|
| + array.length = 2;
|
| + expect(array, [1, 2]);
|
| + array.length = 3;
|
| + expect(array, [1, 2, null]);
|
| + });
|
| +
|
| + test('add', () {
|
| + var array = new JsArray();
|
| + array.add('a');
|
| + expect(array, ['a']);
|
| + array.add('b');
|
| + expect(array, ['a', 'b']);
|
| + });
|
| +
|
| + test('addAll', () {
|
| + var array = new JsArray();
|
| + array.addAll(['a', 'b']);
|
| + expect(array, ['a', 'b']);
|
| + // make sure addAll can handle Iterables
|
| + array.addAll(new Set.from(['c']));
|
| + expect(array, ['a', 'b', 'c']);
|
| + });
|
| +
|
| + test('insert', () {
|
| + var array = new JsArray.from([]);
|
| + array.insert(0, 'b');
|
| + expect(array, ['b']);
|
| + array.insert(0, 'a');
|
| + expect(array, ['a', 'b']);
|
| + array.insert(2, 'c');
|
| + expect(array, ['a', 'b', 'c']);
|
| + expect(() => array.insert(4, 'e'), throwsA(isRangeError));
|
| + expect(() => array.insert(-1, 'e'), throwsA(isRangeError));
|
| + });
|
| +
|
| + test('removeAt', () {
|
| + var array = new JsArray.from(['a', 'b', 'c']);
|
| + expect(array.removeAt(1), 'b');
|
| + expect(array, ['a', 'c']);
|
| + expect(() => array.removeAt(2), throwsA(isRangeError));
|
| + expect(() => array.removeAt(-1), throwsA(isRangeError));
|
| + });
|
| +
|
| + test('removeLast', () {
|
| + var array = new JsArray.from(['a', 'b', 'c']);
|
| + expect(array.removeLast(), 'c');
|
| + expect(array, ['a', 'b']);
|
| + array.length = 0;
|
| + expect(() => array.removeLast(), throwsA(isRangeError));
|
| + });
|
| +
|
| + test('removeRange', () {
|
| + var array = new JsArray.from(['a', 'b', 'c', 'd']);
|
| + array.removeRange(1, 3);
|
| + expect(array, ['a', 'd']);
|
| + expect(() => array.removeRange(-1, 2), throwsA(isRangeError));
|
| + expect(() => array.removeRange(0, 3), throwsA(isRangeError));
|
| + expect(() => array.removeRange(2, 1), throwsA(isRangeError));
|
| + });
|
| +
|
| + test('setRange', () {
|
| + var array = new JsArray.from(['a', 'b', 'c', 'd']);
|
| + array.setRange(1, 3, ['e', 'f']);
|
| + expect(array, ['a', 'e', 'f', 'd']);
|
| + array.setRange(3, 4, ['g', 'h', 'i'], 1);
|
| + expect(array, ['a', 'e', 'f', 'h']);
|
| + });
|
| +
|
| + test('sort', () {
|
| + var array = new JsArray.from(['c', 'a', 'b']);
|
| + array.sort();
|
| + expect(array, ['a', 'b', 'c']);
|
| + });
|
| +
|
| + test('sort with a Comparator', () {
|
| + var array = new JsArray.from(['c', 'a', 'b']);
|
| + array.sort((a, b) => -(a.compareTo(b)));
|
| + expect(array, ['c', 'b', 'a']);
|
| + });
|
| +
|
| + });
|
| +
|
| group('JsObject.fromBrowserObject()', () {
|
|
|
| test('Nodes are proxied', () {
|
|
|