blob: da79cd1817abe95e53dba99a1e8502bedd0261a4 [file] [log] [blame]
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. 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' show Future;
import 'dart:convert' show utf8;
import 'dart:io';
import 'package:collection/collection.dart';
import 'package:path/path.dart' as p;
import 'package:test/test.dart';
import 'package:test_descriptor/test_descriptor.dart';
import 'package:yaml/yaml.dart';
import '../descriptor.dart';
class YamlDescriptor extends FileDescriptor {
final String _contents;
YamlDescriptor(String name, this._contents) : super.protected(name);
Future<String> read() async => _contents;
Stream<List<int>> readAsBytes() =>
Future validate([String parent]) async {
var fullPath = p.join(parent ?? sandbox, name);
if (!await File(fullPath).exists()) {
fail("File not found: '$fullPath'.");
var bytes = await File(fullPath).readAsBytes();
final actualContentsText = utf8.decode(bytes);
final actual = loadYaml(actualContentsText);
final expected = loadYaml(_contents);
if (!DeepCollectionEquality().equals(expected, actual)) {
fail('Expected $expected, found: $actual');