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.
|
|
|
|
|
|
|
|
@TestOn("vm")
|
|
|
|
|
|
|
|
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 map with contents", () {
|
2021-03-17 03:25:39 +01:00
|
|
|
late SassMap value;
|
2018-01-13 02:08:53 +01:00
|
|
|
setUp(() => value = parseValue("(a: b, c: d)") as SassMap);
|
|
|
|
|
2019-07-03 02:16:46 +02:00
|
|
|
test("has an undecided separator", () {
|
2018-01-13 02:08:53 +01:00
|
|
|
expect(value.separator, equals(ListSeparator.comma));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("returns its contents as a map", () {
|
|
|
|
expect(
|
|
|
|
value.contents,
|
|
|
|
equals({
|
2018-11-16 00:16:24 +01:00
|
|
|
SassString("a", quotes: false): SassString("b", quotes: false),
|
|
|
|
SassString("c", quotes: false): SassString("d", quotes: false)
|
2018-01-13 02:08:53 +01:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("returns its contents as a list", () {
|
|
|
|
expect(
|
|
|
|
value.asList,
|
|
|
|
equals([
|
2018-11-16 00:16:24 +01:00
|
|
|
SassList([
|
|
|
|
SassString("a", quotes: false),
|
|
|
|
SassString("b", quotes: false)
|
2018-02-03 01:47:54 +01:00
|
|
|
], ListSeparator.space),
|
2018-11-16 00:16:24 +01:00
|
|
|
SassList([
|
|
|
|
SassString("c", quotes: false),
|
|
|
|
SassString("d", quotes: false)
|
2018-02-03 01:47:54 +01:00
|
|
|
], ListSeparator.space)
|
2018-01-13 02:08:53 +01:00
|
|
|
]));
|
|
|
|
});
|
|
|
|
|
2018-01-14 22:38:43 +01:00
|
|
|
group("sassIndexToListIndex()", () {
|
|
|
|
test("converts a positive index to a Dart index", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(value.sassIndexToListIndex(SassNumber(1)), equals(0));
|
|
|
|
expect(value.sassIndexToListIndex(SassNumber(2)), equals(1));
|
2018-01-14 22:38:43 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("converts a negative index to a Dart index", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(value.sassIndexToListIndex(SassNumber(-1)), equals(1));
|
|
|
|
expect(value.sassIndexToListIndex(SassNumber(-2)), equals(0));
|
2018-01-14 22:38:43 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("rejects invalid indices", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(() => value.sassIndexToListIndex(SassNumber(0)),
|
2018-01-14 22:38:43 +01:00
|
|
|
throwsSassScriptException);
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(() => value.sassIndexToListIndex(SassNumber(3)),
|
2018-01-14 22:38:43 +01:00
|
|
|
throwsSassScriptException);
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(() => value.sassIndexToListIndex(SassNumber(-3)),
|
2018-01-14 22:38:43 +01:00
|
|
|
throwsSassScriptException);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-01-13 02:08:53 +01:00
|
|
|
test("equals the same map", () {
|
|
|
|
expect(
|
|
|
|
value,
|
2018-11-16 00:16:24 +01:00
|
|
|
equalsWithHash(SassMap({
|
|
|
|
SassString("a", quotes: false): SassString("b", quotes: false),
|
|
|
|
SassString("c", quotes: false): SassString("d", quotes: false)
|
2018-01-13 02:08:53 +01:00
|
|
|
})));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("doesn't equal the equivalent list", () {
|
|
|
|
expect(
|
|
|
|
value,
|
2018-11-16 00:16:24 +01:00
|
|
|
isNot(equals(SassList([
|
|
|
|
SassList([
|
|
|
|
SassString("a", quotes: false),
|
|
|
|
SassString("b", quotes: false)
|
2018-02-03 01:47:54 +01:00
|
|
|
], ListSeparator.space),
|
2018-11-16 00:16:24 +01:00
|
|
|
SassList([
|
|
|
|
SassString("c", quotes: false),
|
|
|
|
SassString("d", quotes: false)
|
2018-02-03 01:47:54 +01:00
|
|
|
], ListSeparator.space)
|
2018-01-13 02:08:53 +01:00
|
|
|
], ListSeparator.comma))));
|
|
|
|
});
|
|
|
|
|
|
|
|
group("doesn't equal a map with", () {
|
|
|
|
test("a different value", () {
|
|
|
|
expect(
|
|
|
|
value,
|
2018-11-16 00:16:24 +01:00
|
|
|
isNot(equals(SassMap({
|
|
|
|
SassString("a", quotes: false): SassString("x", quotes: false),
|
|
|
|
SassString("c", quotes: false): SassString("d", quotes: false)
|
2018-01-13 02:08:53 +01:00
|
|
|
}))));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("a different key", () {
|
|
|
|
expect(
|
|
|
|
value,
|
2018-11-16 00:16:24 +01:00
|
|
|
isNot(equals(SassMap({
|
|
|
|
SassString("a", quotes: false): SassString("b", quotes: false),
|
|
|
|
SassString("x", quotes: false): SassString("d", quotes: false)
|
2018-01-13 02:08:53 +01:00
|
|
|
}))));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("a missing pair", () {
|
|
|
|
expect(
|
|
|
|
value,
|
2018-11-16 00:16:24 +01:00
|
|
|
isNot(equals(SassMap({
|
|
|
|
SassString("a", quotes: false): SassString("b", quotes: false)
|
2018-02-03 01:47:54 +01:00
|
|
|
}))));
|
2018-01-13 02:08:53 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("an additional pair", () {
|
|
|
|
expect(
|
|
|
|
value,
|
2018-11-16 00:16:24 +01:00
|
|
|
isNot(equals(SassMap({
|
|
|
|
SassString("a", quotes: false): SassString("b", quotes: false),
|
|
|
|
SassString("c", quotes: false): SassString("d", quotes: false),
|
|
|
|
SassString("e", quotes: false): SassString("f", quotes: false)
|
2018-01-13 02:08:53 +01:00
|
|
|
}))));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("is a map", () {
|
|
|
|
expect(value.assertMap(), equals(value));
|
2020-09-16 01:23:01 +02:00
|
|
|
expect(value.tryMap(), equals(value));
|
2018-01-13 02:08:53 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("isn't any other type", () {
|
|
|
|
expect(value.assertBoolean, throwsSassScriptException);
|
|
|
|
expect(value.assertColor, throwsSassScriptException);
|
|
|
|
expect(value.assertFunction, throwsSassScriptException);
|
|
|
|
expect(value.assertNumber, throwsSassScriptException);
|
|
|
|
expect(value.assertString, throwsSassScriptException);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
group("an empty map", () {
|
2021-03-17 03:25:39 +01:00
|
|
|
late SassMap value;
|
2018-01-13 02:08:53 +01:00
|
|
|
setUp(() => value = parseValue("map-remove((a: b), a)") as SassMap);
|
|
|
|
|
2019-07-03 02:16:46 +02:00
|
|
|
test("has an undecided separator", () {
|
|
|
|
expect(value.separator, equals(ListSeparator.undecided));
|
2018-01-13 02:08:53 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("returns its contents as a map", () {
|
|
|
|
expect(value.contents, isEmpty);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("returns its contents as a list", () {
|
|
|
|
expect(value.asList, isEmpty);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("equals an empty list", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(value, equalsWithHash(SassList.empty()));
|
2018-01-13 02:08:53 +01:00
|
|
|
});
|
2018-01-14 22:38:43 +01:00
|
|
|
|
|
|
|
test("sassIndexToListIndex() rejects invalid indices", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(() => value.sassIndexToListIndex(SassNumber(0)),
|
2018-01-14 22:38:43 +01:00
|
|
|
throwsSassScriptException);
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(() => value.sassIndexToListIndex(SassNumber(1)),
|
2018-01-14 22:38:43 +01:00
|
|
|
throwsSassScriptException);
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(() => value.sassIndexToListIndex(SassNumber(-1)),
|
2018-01-14 22:38:43 +01:00
|
|
|
throwsSassScriptException);
|
|
|
|
});
|
2018-01-13 02:08:53 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("new SassMap.empty() creates an empty map with default metadata", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(SassMap.empty().contents, isEmpty);
|
2018-01-13 02:08:53 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("new SassMap() creates a map with the given contents", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
var list = SassMap(
|
|
|
|
{SassString("a", quotes: false): SassString("b", quotes: false)});
|
2018-02-03 01:47:54 +01:00
|
|
|
expect(
|
|
|
|
list.contents,
|
2018-11-16 00:16:24 +01:00
|
|
|
equals(
|
|
|
|
{SassString("a", quotes: false): SassString("b", quotes: false)}));
|
2018-01-13 02:08:53 +01:00
|
|
|
});
|
|
|
|
}
|