2018-04-26 01:12:37 +02:00
|
|
|
// Copyright 2018 Google Inc. Use of this source code is governed by an
|
|
|
|
// MIT-style license that can be found in the LICENSE file or at
|
|
|
|
// https://opensource.org/licenses/MIT.
|
|
|
|
|
2018-06-15 22:42:36 +02:00
|
|
|
import 'dart:convert';
|
2018-04-28 01:57:37 +02:00
|
|
|
|
2020-09-08 18:23:46 +02:00
|
|
|
import 'package:path/path.dart' as p;
|
2018-04-26 01:12:37 +02:00
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
2018-04-28 01:57:37 +02:00
|
|
|
import 'package:sass/src/io.dart';
|
|
|
|
|
2018-04-26 01:12:37 +02:00
|
|
|
/// A regular expression for matching the URL in a source map comment.
|
2018-11-16 00:16:24 +01:00
|
|
|
final _sourceMapCommentRegExp = RegExp(r"/\*# sourceMappingURL=(.*) \*/\s*$");
|
2018-04-26 01:12:37 +02:00
|
|
|
|
2018-04-28 01:57:37 +02:00
|
|
|
/// Returns a [Future] that waits long enough for modification times to be
|
|
|
|
/// different.
|
|
|
|
///
|
|
|
|
/// Windows (or at least Appveyor) seems to require a more coarse-grained time
|
|
|
|
/// than Unixes.
|
2019-05-31 17:01:49 +02:00
|
|
|
Future<void> get tick =>
|
2018-11-16 00:16:24 +01:00
|
|
|
Future.delayed(Duration(milliseconds: isWindows ? 1000 : 50));
|
2018-04-28 01:57:37 +02:00
|
|
|
|
2018-04-26 01:12:37 +02:00
|
|
|
/// Loads and decodes the source map embedded as a `data:` URI in [css].
|
|
|
|
///
|
|
|
|
/// Throws a [TestFailure] if [css] doesn't have such a source map.
|
2021-04-09 22:19:35 +02:00
|
|
|
Map<String, dynamic> embeddedSourceMap(String css) {
|
2018-04-26 01:12:37 +02:00
|
|
|
expect(css, matches(_sourceMapCommentRegExp));
|
|
|
|
|
2021-03-17 03:25:39 +01:00
|
|
|
var match = _sourceMapCommentRegExp.firstMatch(css)!;
|
|
|
|
var data = Uri.parse(match[1]!).data!;
|
2018-04-26 01:12:37 +02:00
|
|
|
expect(data.mimeType, equals("application/json"));
|
2021-04-09 22:19:35 +02:00
|
|
|
return jsonDecode(data.contentAsString()) as Map<String, dynamic>;
|
2018-04-26 01:12:37 +02:00
|
|
|
}
|
2020-09-08 18:23:46 +02:00
|
|
|
|
2021-03-17 04:51:32 +01:00
|
|
|
/// Returns a function with one argument that fails the test if it's ever
|
|
|
|
/// called.
|
|
|
|
Never Function(Object? arg) get expectNever1 =>
|
|
|
|
expectAsync1((_) => throw '', count: 0);
|
|
|
|
|
2020-09-08 18:23:46 +02:00
|
|
|
// Like `p.prettyUri()`, but for a non-URL path.
|
|
|
|
String prettyPath(String path) => p.prettyUri(p.toUri(path));
|