Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simc committed Sep 3, 2018
1 parent 171edac commit fccfe38
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
7 changes: 3 additions & 4 deletions lib/src/list.dart
Expand Up @@ -77,13 +77,12 @@ class $List<E> extends _$DelegatingList<E> {

/// Creates an unmodifiable list containing all [elements].
///
/// The [Iterator] of [elements] provides the order of the elements.
///
/// An unmodifiable list cannot have its length or elements changed.
/// If the elements are themselves immutable, then the resulting list
/// is also immutable.
factory $List.unmodifiable(Iterable<E> elements) {
return $List(List.unmodifiable(elements));
factory $List.unmodifiable([Iterable<E> elements]) {
var elementsNotNull = elements ?? List();
return $List(List.unmodifiable(elementsNotNull));
}

set lastIndex(int value) => length = value + 1;
Expand Down
37 changes: 32 additions & 5 deletions test/list_test.dart
Expand Up @@ -43,16 +43,40 @@ void main() {
expect($List<int>.generate(5, (i) => i), [0, 1, 2, 3, 4]);
});

test("test List.unmodifiable()", () {
{
expect($List<int>.unmodifiable(), empty);
}
{
var list = $List<int>.unmodifiable([0, 1, 2]);
expect(list, [0, 1, 2]);
expect(() => list[0] = 2, throwsUnsupportedError);
expect(() => list.add(3), throwsUnsupportedError);
expect(() => list.clear(), throwsUnsupportedError);
}
});

test("test lastIndex", () {
expect(empty.lastIndex, -1);
expect($List<int>.withLength(10).lastIndex, 9);
});

test("test second third fourth", () {
var list = $([0, 1, 2, 3]);
expect(list.second, 1);
expect(list.third, 2);
expect(list.fourth, 3);
test("test set second third fourth", () {
{
var list = $([0, 1, 2, 3]);
list.second = 8;
expect(list.second, 8);
}
{
var list = $([0, 1, 2, 3]);
list.third = 5;
expect(list.third, 5);
}
{
var list = $([0, 1, 2, 3]);
list.fourth = 1;
expect(list.fourth, 1);
}
});

test("test get", () {
Expand Down Expand Up @@ -113,6 +137,9 @@ void main() {
var result = elements.dropLast(10);
expect(result, <int>[]);
}
{
expect(() => elements.dropLast(-1), throwsArgumentError);
}
});

test("test dropLastWhile", () {
Expand Down

0 comments on commit fccfe38

Please sign in to comment.