-
Notifications
You must be signed in to change notification settings - Fork 347
/
list_test.dart
161 lines (136 loc) · 5.31 KB
/
list_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// 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.
// TODO(nweiz): Remove this ignore and add explicit type arguments once we
// support only Dart SDKs >= 2.15.
// ignore_for_file: inference_failure_on_function_invocation
@TestOn('node')
@Tags(['node'])
import 'dart:js_util';
import 'package:js/js.dart';
import 'package:test/test.dart';
import '../api.dart';
import '../utils.dart';
import 'utils.dart';
void main() {
group("an argument list", () {
late NodeSassList args;
setUp(() {
renderSync(RenderOptions(
data: "a {b: foo(1, 'a', blue)}",
functions: jsify({
r"foo($args...)": allowInterop(expectAsync1((NodeSassList args_) {
args = args_;
return sass.types.Null.NULL;
}))
})));
});
test("is instanceof List", () {
expect(args, isJSInstanceOf(sass.types.List));
});
test("provides access to the list attributes", () {
expect(args.getLength(), equals(3));
expect(args.getSeparator(), isTrue);
expect(args.getValue(0), isJSInstanceOf(sass.types.Number));
expect(args.getValue(1), isJSInstanceOf(sass.types.String));
expect(args.getValue(2), isJSInstanceOf(sass.types.Color));
});
test("has a useful .constructor.name", () {
expect(args.constructor.name, equals("sass.types.List"));
});
});
group("a list", () {
group("from a parameter", () {
late NodeSassList list;
setUp(() {
list = parseValue<NodeSassList>("1, 'a', blue");
});
test("is instanceof List", () {
expect(list, isJSInstanceOf(sass.types.List));
});
test("provides access to its length", () {
expect(list.getLength(), equals(3));
});
test("provides access to its contents", () {
expect(list.getValue(0), isJSInstanceOf(sass.types.Number));
expect(list.getValue(1), isJSInstanceOf(sass.types.String));
expect(list.getValue(2), isJSInstanceOf(sass.types.Color));
});
test("provides access to the separator type", () {
expect(list.getSeparator(), isTrue);
expect(parseValue<NodeSassList>("1 2 3").getSeparator(), isFalse);
});
test("throws on invalid indices", () {
expect(() => list.getValue(-1), throwsA(anything));
expect(() => list.getValue(4), throwsA(anything));
});
test("values can be set without affecting the underlying list", () {
expect(
renderSync(RenderOptions(
data: r"a {$list: 1 2 3; b: foo($list); c: $list}",
functions: jsify({
r"foo($list)": allowInterop(expectAsync1((NodeSassList list) {
list.setValue(1, sass.types.Null.NULL);
expect(list.getValue(1), equals(sass.types.Null.NULL));
return list;
}))
}))),
equalsIgnoringWhitespace("a { b: 1 3; c: 1 2 3; }"));
});
test("the separator can be set without affecting the underlying list",
() {
expect(
renderSync(RenderOptions(
data: r"a {$list: 1 2 3; b: foo($list); c: $list}",
functions: jsify({
r"foo($list)": allowInterop(expectAsync1((NodeSassList list) {
list.setSeparator(true);
expect(list.getSeparator(), isTrue);
return list;
}))
}))),
equalsIgnoringWhitespace("a { b: 1, 2, 3; c: 1 2 3; }"));
});
test(
"lists with undefined separators are reported as having space "
"separators", () {
expect(parseValue<NodeSassList>("()").getSeparator(), isFalse);
expect(
parseValue<NodeSassList>("join((), 1px)").getSeparator(), isFalse);
});
test("has a useful .constructor.name", () {
expect(list.constructor.name, equals("sass.types.List"));
});
});
group("from a constructor", () {
test("is a list with the given length", () {
var list = callConstructor(sass.types.List, [3]);
expect(list, isJSInstanceOf(sass.types.List));
expect(list.getLength(), equals(3));
});
test("is populated with nulls", () {
var list = callConstructor(sass.types.List, [3]);
expect(list.getValue(0), equals(sass.types.Null.NULL));
expect(list.getValue(1), equals(sass.types.Null.NULL));
expect(list.getValue(2), equals(sass.types.Null.NULL));
});
test("can have its values set", () {
var list = callConstructor(sass.types.List, [3]);
list.setValue(1, sass.types.Boolean.TRUE);
expect(list.getValue(1), equals(sass.types.Boolean.TRUE));
});
test("defaults to comma-separated", () {
var list = callConstructor(sass.types.List, [3]);
expect(list.getSeparator(), isTrue);
});
test("can be space-separated", () {
var list = callConstructor(sass.types.List, [3, false]);
expect(list.getSeparator(), isFalse);
});
test("has a useful .constructor.name", () {
expect(callConstructor(sass.types.List, [3]).constructor.name,
equals("sass.types.List"));
});
});
});
}