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-15 00:39:00 +01:00
|
|
|
group("an unquoted ASCII string", () {
|
2018-01-13 02:08:53 +01:00
|
|
|
SassString value;
|
|
|
|
setUp(() => value = parseValue("foobar") as SassString);
|
|
|
|
|
|
|
|
test("has the correct text", () {
|
|
|
|
expect(value.text, equals("foobar"));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("has no quotes", () {
|
|
|
|
expect(value.hasQuotes, isFalse);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("equals the same string", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(value, equalsWithHash(SassString("foobar", quotes: false)));
|
|
|
|
expect(value, equalsWithHash(SassString("foobar", quotes: true)));
|
2018-01-13 02:08:53 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("is a string", () {
|
|
|
|
expect(value.assertString(), equals(value));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("isn't any other type", () {
|
|
|
|
expect(value.assertBoolean, throwsSassScriptException);
|
|
|
|
expect(value.assertColor, throwsSassScriptException);
|
|
|
|
expect(value.assertFunction, 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);
|
|
|
|
});
|
2018-01-15 00:39:00 +01:00
|
|
|
|
|
|
|
test("sassLength returns the length", () {
|
|
|
|
expect(value.sassLength, equals(6));
|
|
|
|
});
|
|
|
|
|
|
|
|
group("sassIndexToStringIndex()", () {
|
|
|
|
test("converts a positive index to a Dart index", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(value.sassIndexToStringIndex(SassNumber(1)), equals(0));
|
|
|
|
expect(value.sassIndexToStringIndex(SassNumber(2)), equals(1));
|
|
|
|
expect(value.sassIndexToStringIndex(SassNumber(3)), equals(2));
|
|
|
|
expect(value.sassIndexToStringIndex(SassNumber(4)), equals(3));
|
|
|
|
expect(value.sassIndexToStringIndex(SassNumber(5)), equals(4));
|
|
|
|
expect(value.sassIndexToStringIndex(SassNumber(6)), equals(5));
|
2018-01-15 00:39:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("converts a negative index to a Dart index", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(value.sassIndexToStringIndex(SassNumber(-1)), equals(5));
|
|
|
|
expect(value.sassIndexToStringIndex(SassNumber(-2)), equals(4));
|
|
|
|
expect(value.sassIndexToStringIndex(SassNumber(-3)), equals(3));
|
|
|
|
expect(value.sassIndexToStringIndex(SassNumber(-4)), equals(2));
|
|
|
|
expect(value.sassIndexToStringIndex(SassNumber(-5)), equals(1));
|
|
|
|
expect(value.sassIndexToStringIndex(SassNumber(-6)), equals(0));
|
2018-01-15 00:39:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("rejects a non-number", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(() => value.sassIndexToStringIndex(SassString("foo")),
|
2018-01-15 00:39:00 +01:00
|
|
|
throwsSassScriptException);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("rejects a non-integer", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(() => value.sassIndexToStringIndex(SassNumber(1.1)),
|
2018-01-15 00:39:00 +01:00
|
|
|
throwsSassScriptException);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("rejects invalid indices", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(() => value.sassIndexToStringIndex(SassNumber(0)),
|
2018-01-15 00:39:00 +01:00
|
|
|
throwsSassScriptException);
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(() => value.sassIndexToStringIndex(SassNumber(7)),
|
2018-01-15 00:39:00 +01:00
|
|
|
throwsSassScriptException);
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(() => value.sassIndexToStringIndex(SassNumber(-7)),
|
2018-01-15 00:39:00 +01:00
|
|
|
throwsSassScriptException);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
group("sassIndexToRuneIndex()", () {
|
|
|
|
test("converts a positive index to a Dart index", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(value.sassIndexToRuneIndex(SassNumber(1)), equals(0));
|
|
|
|
expect(value.sassIndexToRuneIndex(SassNumber(2)), equals(1));
|
|
|
|
expect(value.sassIndexToRuneIndex(SassNumber(3)), equals(2));
|
|
|
|
expect(value.sassIndexToRuneIndex(SassNumber(4)), equals(3));
|
|
|
|
expect(value.sassIndexToRuneIndex(SassNumber(5)), equals(4));
|
|
|
|
expect(value.sassIndexToRuneIndex(SassNumber(6)), equals(5));
|
2018-01-15 00:39:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("converts a negative index to a Dart index", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(value.sassIndexToRuneIndex(SassNumber(-1)), equals(5));
|
|
|
|
expect(value.sassIndexToRuneIndex(SassNumber(-2)), equals(4));
|
|
|
|
expect(value.sassIndexToRuneIndex(SassNumber(-3)), equals(3));
|
|
|
|
expect(value.sassIndexToRuneIndex(SassNumber(-4)), equals(2));
|
|
|
|
expect(value.sassIndexToRuneIndex(SassNumber(-5)), equals(1));
|
|
|
|
expect(value.sassIndexToRuneIndex(SassNumber(-6)), equals(0));
|
2018-01-15 00:39:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("rejects a non-number", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(() => value.sassIndexToRuneIndex(SassString("foo")),
|
2018-01-15 00:39:00 +01:00
|
|
|
throwsSassScriptException);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("rejects a non-integer", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(() => value.sassIndexToRuneIndex(SassNumber(1.1)),
|
2018-01-15 00:39:00 +01:00
|
|
|
throwsSassScriptException);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("rejects invalid indices", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(() => value.sassIndexToRuneIndex(SassNumber(0)),
|
2018-01-15 00:39:00 +01:00
|
|
|
throwsSassScriptException);
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(() => value.sassIndexToRuneIndex(SassNumber(7)),
|
2018-01-15 00:39:00 +01:00
|
|
|
throwsSassScriptException);
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(() => value.sassIndexToRuneIndex(SassNumber(-7)),
|
2018-01-15 00:39:00 +01:00
|
|
|
throwsSassScriptException);
|
|
|
|
});
|
|
|
|
});
|
2018-01-13 02:08:53 +01:00
|
|
|
});
|
|
|
|
|
2018-01-15 00:39:00 +01:00
|
|
|
group("a quoted ASCII string", () {
|
2018-01-13 02:08:53 +01:00
|
|
|
SassString value;
|
|
|
|
setUp(() => value = parseValue('"foobar"') as SassString);
|
|
|
|
|
|
|
|
test("has the correct text", () {
|
|
|
|
expect(value.text, equals("foobar"));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("has quotes", () {
|
|
|
|
expect(value.hasQuotes, isTrue);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("equals the same string", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(value, equalsWithHash(SassString("foobar", quotes: false)));
|
|
|
|
expect(value, equalsWithHash(SassString("foobar", quotes: true)));
|
2018-01-13 02:08:53 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-01-15 00:39:00 +01:00
|
|
|
group("an unquoted Unicde", () {
|
|
|
|
SassString value;
|
|
|
|
setUp(() => value = parseValue("a👭b👬c") as SassString);
|
|
|
|
|
|
|
|
test("sassLength returns the length", () {
|
|
|
|
expect(value.sassLength, equals(5));
|
|
|
|
});
|
|
|
|
|
|
|
|
group("sassIndexToStringIndex()", () {
|
|
|
|
test("converts a positive index to a Dart index", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(value.sassIndexToStringIndex(SassNumber(1)), equals(0));
|
|
|
|
expect(value.sassIndexToStringIndex(SassNumber(2)), equals(1));
|
|
|
|
expect(value.sassIndexToStringIndex(SassNumber(3)), equals(3));
|
|
|
|
expect(value.sassIndexToStringIndex(SassNumber(4)), equals(4));
|
|
|
|
expect(value.sassIndexToStringIndex(SassNumber(5)), equals(6));
|
2018-01-15 00:39:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("converts a negative index to a Dart index", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(value.sassIndexToStringIndex(SassNumber(-1)), equals(6));
|
|
|
|
expect(value.sassIndexToStringIndex(SassNumber(-2)), equals(4));
|
|
|
|
expect(value.sassIndexToStringIndex(SassNumber(-3)), equals(3));
|
|
|
|
expect(value.sassIndexToStringIndex(SassNumber(-4)), equals(1));
|
|
|
|
expect(value.sassIndexToStringIndex(SassNumber(-5)), equals(0));
|
2018-01-15 00:39:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("rejects invalid indices", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(() => value.sassIndexToStringIndex(SassNumber(0)),
|
2018-01-15 00:39:00 +01:00
|
|
|
throwsSassScriptException);
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(() => value.sassIndexToStringIndex(SassNumber(6)),
|
2018-01-15 00:39:00 +01:00
|
|
|
throwsSassScriptException);
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(() => value.sassIndexToStringIndex(SassNumber(-6)),
|
2018-01-15 00:39:00 +01:00
|
|
|
throwsSassScriptException);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
group("sassIndexToRuneIndex()", () {
|
|
|
|
test("converts a positive index to a Dart index", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(value.sassIndexToRuneIndex(SassNumber(1)), equals(0));
|
|
|
|
expect(value.sassIndexToRuneIndex(SassNumber(2)), equals(1));
|
|
|
|
expect(value.sassIndexToRuneIndex(SassNumber(3)), equals(2));
|
|
|
|
expect(value.sassIndexToRuneIndex(SassNumber(4)), equals(3));
|
|
|
|
expect(value.sassIndexToRuneIndex(SassNumber(5)), equals(4));
|
2018-01-15 00:39:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("converts a negative index to a Dart index", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(value.sassIndexToRuneIndex(SassNumber(-1)), equals(4));
|
|
|
|
expect(value.sassIndexToRuneIndex(SassNumber(-2)), equals(3));
|
|
|
|
expect(value.sassIndexToRuneIndex(SassNumber(-3)), equals(2));
|
|
|
|
expect(value.sassIndexToRuneIndex(SassNumber(-4)), equals(1));
|
|
|
|
expect(value.sassIndexToRuneIndex(SassNumber(-5)), equals(0));
|
2018-01-15 00:39:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("rejects invalid indices", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(() => value.sassIndexToRuneIndex(SassNumber(0)),
|
2018-01-15 00:39:00 +01:00
|
|
|
throwsSassScriptException);
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(() => value.sassIndexToRuneIndex(SassNumber(6)),
|
2018-01-15 00:39:00 +01:00
|
|
|
throwsSassScriptException);
|
2018-11-16 00:16:24 +01:00
|
|
|
expect(() => value.sassIndexToRuneIndex(SassNumber(-6)),
|
2018-01-15 00:39:00 +01:00
|
|
|
throwsSassScriptException);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-01-13 02:08:53 +01:00
|
|
|
group("new SassString.empty()", () {
|
|
|
|
test("creates an empty unquoted string", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
var string = SassString.empty(quotes: false);
|
2018-01-13 02:08:53 +01:00
|
|
|
expect(string.text, isEmpty);
|
|
|
|
expect(string.hasQuotes, isFalse);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("creates an empty quoted string", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
var string = SassString.empty(quotes: true);
|
2018-01-13 02:08:53 +01:00
|
|
|
expect(string.text, isEmpty);
|
|
|
|
expect(string.hasQuotes, isTrue);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
group("new SassString()", () {
|
|
|
|
test("creates an unquoted string with the given text", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
var string = SassString("a b c", quotes: false);
|
2018-01-13 02:08:53 +01:00
|
|
|
expect(string.text, equals("a b c"));
|
|
|
|
expect(string.hasQuotes, isFalse);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("creates a quoted string with the given text", () {
|
2018-11-16 00:16:24 +01:00
|
|
|
var string = SassString("a b c", quotes: true);
|
2018-01-13 02:08:53 +01:00
|
|
|
expect(string.text, equals("a b c"));
|
|
|
|
expect(string.hasQuotes, isTrue);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|