2018-01-13 02:08:53 +01: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.
|
|
|
|
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
|
|
|
import 'package:sass/sass.dart';
|
|
|
|
import 'package:sass/src/exception.dart';
|
|
|
|
|
|
|
|
/// Parses [source] by way of a function call.
|
|
|
|
Value parseValue(String source) {
|
2021-03-17 03:25:39 +01:00
|
|
|
late Value value;
|
2019-06-02 19:29:06 +02:00
|
|
|
compileString("""
|
|
|
|
@use "sass:list";
|
2021-09-07 21:25:08 +02:00
|
|
|
@use "sass:math";
|
2019-06-02 19:29:06 +02:00
|
|
|
|
|
|
|
a {b: foo(($source))}
|
|
|
|
""", functions: [
|
2018-11-16 00:16:24 +01:00
|
|
|
Callable("foo", r"$arg", expectAsync1((arguments) {
|
2018-01-13 02:08:53 +01:00
|
|
|
expect(arguments, hasLength(1));
|
|
|
|
value = arguments.first;
|
|
|
|
return sassNull;
|
|
|
|
}))
|
|
|
|
]);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A matcher that asserts that a function throws a [SassScriptException].
|
|
|
|
final throwsSassScriptException =
|
2018-06-15 22:58:13 +02:00
|
|
|
throwsA(const TypeMatcher<SassScriptException>());
|
2018-01-13 02:08:53 +01:00
|
|
|
|
|
|
|
/// Like [equals], but asserts that the hash codes of the values are the same as
|
|
|
|
/// well.
|
2021-03-17 04:51:32 +01:00
|
|
|
Matcher equalsWithHash(Object expected) => predicate((actual) {
|
2018-01-13 02:08:53 +01:00
|
|
|
expect(actual, equals(expected));
|
|
|
|
expect(actual.hashCode, equals(expected.hashCode),
|
|
|
|
reason: "Expected $actual's hash code to equal $expected's.");
|
|
|
|
return true;
|
|
|
|
});
|