@@ -97,22 +97,6 @@ void main() {
97
97
await expectLater (process.outbound, emits (isSuccess (equals ("a{b:3px}" ))));
98
98
await process.kill ();
99
99
});
100
-
101
- test ("expanded mode when nested mode is passed" , () async {
102
- process.inbound.add (compileString ("a {b: 1px + 2px}" ,
103
- style: InboundMessage_CompileRequest_OutputStyle .NESTED ));
104
- await expectLater (
105
- process.outbound, emits (isSuccess (equals ("a {\n b: 3px;\n }" ))));
106
- await process.kill ();
107
- });
108
-
109
- test ("expanded mode when compact mode is passed" , () async {
110
- process.inbound.add (compileString ("a {b: 1px + 2px}" ,
111
- style: InboundMessage_CompileRequest_OutputStyle .COMPACT ));
112
- await expectLater (
113
- process.outbound, emits (isSuccess (equals ("a {\n b: 3px;\n }" ))));
114
- await process.kill ();
115
- });
116
100
});
117
101
118
102
test ("doesn't include a source map by default" , () async {
@@ -145,31 +129,74 @@ void main() {
145
129
});
146
130
147
131
group ("emits a log event" , () {
148
- test ("for a @debug rule" , () async {
149
- process.inbound.add (compileString ("a {@debug hello}" ));
132
+ group ("for a @debug rule" , () {
133
+ test ("with correct fields" , () async {
134
+ process.inbound.add (compileString ("a {@debug hello}" ));
135
+
136
+ var logEvent = getLogEvent (await process.outbound.next);
137
+ expect (logEvent.compilationId, equals (0 ));
138
+ expect (logEvent.type, equals (OutboundMessage_LogEvent_Type .DEBUG ));
139
+ expect (logEvent.message, equals ("hello" ));
140
+ expect (logEvent.span.text, equals ("@debug hello" ));
141
+ expect (logEvent.span.start, equals (location (3 , 0 , 3 )));
142
+ expect (logEvent.span.end, equals (location (15 , 0 , 15 )));
143
+ expect (logEvent.span.context, equals ("a {@debug hello}" ));
144
+ expect (logEvent.stackTrace, isEmpty);
145
+ expect (logEvent.formatted, equals ('-:1 DEBUG: hello\n ' ));
146
+ await process.kill ();
147
+ });
150
148
151
- var logEvent = getLogEvent (await process.outbound.next);
152
- expect (logEvent.compilationId, equals (0 ));
153
- expect (logEvent.type, equals (OutboundMessage_LogEvent_Type .DEBUG ));
154
- expect (logEvent.message, equals ("hello" ));
155
- expect (logEvent.span.text, equals ("@debug hello" ));
156
- expect (logEvent.span.start, equals (location (3 , 0 , 3 )));
157
- expect (logEvent.span.end, equals (location (15 , 0 , 15 )));
158
- expect (logEvent.span.context, equals ("a {@debug hello}" ));
159
- expect (logEvent.stackTrace, isEmpty);
160
- await process.kill ();
149
+ test ("formatted with terminal colors" , () async {
150
+ process.inbound
151
+ .add (compileString ("a {@debug hello}" , alertColor: true ));
152
+ var logEvent = getLogEvent (await process.outbound.next);
153
+ expect (
154
+ logEvent.formatted, equals ('-:1 \u 001b[1mDebug\u 001b[0m: hello\n ' ));
155
+ await process.kill ();
156
+ });
161
157
});
162
158
163
- test ("for a @warn rule" , () async {
164
- process.inbound.add (compileString ("a {@warn hello}" ));
159
+ group ("for a @warn rule" , () {
160
+ test ("with correct fields" , () async {
161
+ process.inbound.add (compileString ("a {@warn hello}" ));
165
162
166
- var logEvent = getLogEvent (await process.outbound.next);
167
- expect (logEvent.compilationId, equals (0 ));
168
- expect (logEvent.type, equals (OutboundMessage_LogEvent_Type .WARNING ));
169
- expect (logEvent.message, equals ("hello" ));
170
- expect (logEvent.span, equals (SourceSpan ()));
171
- expect (logEvent.stackTrace, equals ("- 1:4 root stylesheet\n " ));
172
- await process.kill ();
163
+ var logEvent = getLogEvent (await process.outbound.next);
164
+ expect (logEvent.compilationId, equals (0 ));
165
+ expect (logEvent.type, equals (OutboundMessage_LogEvent_Type .WARNING ));
166
+ expect (logEvent.message, equals ("hello" ));
167
+ expect (logEvent.span, equals (SourceSpan ()));
168
+ expect (logEvent.stackTrace, equals ("- 1:4 root stylesheet\n " ));
169
+ expect (
170
+ logEvent.formatted,
171
+ equals ('WARNING: hello\n '
172
+ ' - 1:4 root stylesheet\n ' ));
173
+ await process.kill ();
174
+ });
175
+
176
+ test ("formatted with terminal colors" , () async {
177
+ process.inbound.add (compileString ("a {@warn hello}" , alertColor: true ));
178
+ var logEvent = getLogEvent (await process.outbound.next);
179
+ expect (
180
+ logEvent.formatted,
181
+ equals ('\x 1B[33m\x 1B[1mWarning\x 1B[0m: hello\n '
182
+ ' - 1:4 root stylesheet\n ' ));
183
+ await process.kill ();
184
+ });
185
+
186
+ test ("encoded in ASCII" , () async {
187
+ process.inbound
188
+ .add (compileString ("a {@debug a && b}" , alertAscii: true ));
189
+ var logEvent = getLogEvent (await process.outbound.next);
190
+ expect (
191
+ logEvent.formatted,
192
+ equals ('WARNING on line 1, column 13: \n '
193
+ 'In Sass, "&&" means two copies of the parent selector. You probably want to use "and" instead.\n '
194
+ ' ,\n '
195
+ '1 | a {@debug a && b}\n '
196
+ ' | ^^\n '
197
+ ' \'\n ' ));
198
+ await process.kill ();
199
+ });
173
200
});
174
201
175
202
test ("for a parse-time deprecation warning" , () async {
343
370
expect (failure.stackTrace, equals ("- 1:11 root stylesheet\n " ));
344
371
await process.kill ();
345
372
});
373
+
374
+ group ("and provides a formatted" , () {
375
+ test ("message" , () async {
376
+ process.inbound.add (compileString ("a {b: 1px + 1em}" ));
377
+
378
+ var failure = getCompileFailure (await process.outbound.next);
379
+ expect (
380
+ failure.formatted,
381
+ equals ('Error: 1px and 1em have incompatible units.\n '
382
+ ' ╷\n '
383
+ '1 │ a {b: 1px + 1em}\n '
384
+ ' │ ^^^^^^^^^\n '
385
+ ' ╵\n '
386
+ ' - 1:7 root stylesheet' ));
387
+ await process.kill ();
388
+ });
389
+
390
+ test ("message with terminal colors" , () async {
391
+ process.inbound
392
+ .add (compileString ("a {b: 1px + 1em}" , alertColor: true ));
393
+
394
+ var failure = getCompileFailure (await process.outbound.next);
395
+ expect (
396
+ failure.formatted,
397
+ equals ('Error: 1px and 1em have incompatible units.\n '
398
+ '\x 1B[34m ╷\x 1B[0m\n '
399
+ '\x 1B[34m1 │\x 1B[0m a {b: \x 1B[31m1px + 1em\x 1B[0m}\n '
400
+ '\x 1B[34m │\x 1B[0m \x 1B[31m ^^^^^^^^^\x 1B[0m\n '
401
+ '\x 1B[34m ╵\x 1B[0m\n '
402
+ ' - 1:7 root stylesheet' ));
403
+ await process.kill ();
404
+ });
405
+
406
+ test ("message with ASCII encoding" , () async {
407
+ process.inbound
408
+ .add (compileString ("a {b: 1px + 1em}" , alertAscii: true ));
409
+
410
+ var failure = getCompileFailure (await process.outbound.next);
411
+ expect (
412
+ failure.formatted,
413
+ equals ('Error: 1px and 1em have incompatible units.\n '
414
+ ' ,\n '
415
+ '1 | a {b: 1px + 1em}\n '
416
+ ' | ^^^^^^^^^\n '
417
+ ' \'\n '
418
+ ' - 1:7 root stylesheet' ));
419
+ await process.kill ();
420
+ });
421
+ });
346
422
});
347
423
}
0 commit comments