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.
|
|
|
|
|
2023-05-19 22:22:44 +02:00
|
|
|
@TestOn('vm')
|
|
|
|
|
2018-01-13 02:08:53 +01:00
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
|
|
|
import 'package:sass/sass.dart';
|
|
|
|
|
|
|
|
import 'utils.dart';
|
|
|
|
|
2019-11-06 01:28:26 +01:00
|
|
|
void main() {
|
2018-01-13 02:08:53 +01:00
|
|
|
group("a function value", () {
|
2021-03-17 03:25:39 +01:00
|
|
|
late SassFunction value;
|
2018-01-13 02:08:53 +01:00
|
|
|
setUp(() => value = parseValue("get-function('red')") as SassFunction);
|
|
|
|
|
|
|
|
test("has a callable with the given name", () {
|
|
|
|
expect(value.callable.name, equals("red"));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("is a function", () {
|
|
|
|
expect(value.assertFunction(), equals(value));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("equals the same function", () {
|
|
|
|
expect(value, equalsWithHash(parseValue("get-function('red')")));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("isn't any other type", () {
|
|
|
|
expect(value.assertBoolean, throwsSassScriptException);
|
|
|
|
expect(value.assertColor, throwsSassScriptException);
|
|
|
|
expect(value.assertMap, throwsSassScriptException);
|
2020-09-16 01:23:01 +02:00
|
|
|
expect(value.tryMap(), isNull);
|
2018-01-13 02:08:53 +01:00
|
|
|
expect(value.assertNumber, throwsSassScriptException);
|
|
|
|
expect(value.assertString, throwsSassScriptException);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("can return a new function", () {
|
|
|
|
var css = compileString("a {b: call(foo(), 12)}", functions: [
|
2018-11-16 00:16:24 +01:00
|
|
|
Callable("foo", "", (_) {
|
|
|
|
return SassFunction(Callable("bar", r"$arg",
|
|
|
|
(arguments) => SassNumber(arguments[0].assertNumber().value + 1)));
|
2018-01-13 02:08:53 +01:00
|
|
|
})
|
|
|
|
]);
|
|
|
|
|
|
|
|
expect(css, equalsIgnoringWhitespace("a { b: 13; }"));
|
|
|
|
});
|
|
|
|
}
|