blob: a5a7444f91f77f44de19b32b8433d21ecb2fdb70 [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:test/test.dart';
import 'package:lib.schemas.dart/entity_codec.dart';
void main() {
group('EntityCodec<T> streaming transform', () {
final EntityCodec<BasicExample> codec = EntityCodec<BasicExample>(
type: 'com.example.basic',
encode: (BasicExample value) => value.name,
decode: (String data) => BasicExample(data),
);
test('stream.transform(codec)', () async {
List<String> list = <String>['foo', 'bar', 'baz'];
Stream<String> stream = Stream<String>.fromIterable(list);
List<String> results = await stream
.transform(codec.decoder)
.map((BasicExample e) => e.name)
.toList();
expect(results.length, equals(list.length));
});
});
}
class BasicExample {
final String name;
BasicExample(this.name);
}