Skip to content

Commit

Permalink
Add tests for sublistView
Browse files Browse the repository at this point in the history
  • Loading branch information
mgenware committed Aug 25, 2024
1 parent 2c13e8a commit 3ed169c
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions test/bytes_view_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import 'dart:typed_data';

import 'package:random_access_source/random_access_source.dart';
import 'package:test/test.dart';

Future<BytesRASource> _bytesSource() async {
return BytesRASource(Uint8List.sublistView(
Uint8List.fromList([-1, 0, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), 3, 8));
}

void main() {
test('Length', () async {
final src = await _bytesSource();
expect(await src.length(), 5);
await src.close();
});

test('ReadByte', () async {
final src = await _bytesSource();
expect(await src.readByte(), 1);
expect(await src.position(), 1);

expect(await src.readByte(), 2);
expect(await src.position(), 2);

expect(await src.readByte(), 3);
expect(await src.position(), 3);

expect(await src.readByte(), 4);
expect(await src.position(), 4);

expect(await src.readByte(), 5);
expect(await src.position(), 5);

expect(await src.readByte(), -1);
expect(await src.position(), 5);
await src.close();
});

test('Read', () async {
final src = await _bytesSource();
expect(await src.read(2), Uint8List.fromList([1, 2]));
expect(await src.position(), 2);

expect(await src.read(2), Uint8List.fromList([3, 4]));
expect(await src.position(), 4);

expect(await src.read(2), Uint8List.fromList([5]));
expect(await src.position(), 5);

expect(await src.read(2), Uint8List(0));
expect(await src.position(), 5);
await src.close();
});

test('Position', () async {
final src = await _bytesSource();
expect(await src.position(), 0);
await src.setPosition(2);
expect(await src.position(), 2);
expect(await src.readByte(), 3);
await src.close();
});
}

0 comments on commit 3ed169c

Please sign in to comment.