forked from sass/dart-sass
/
output_test.dart
92 lines (82 loc) · 3.14 KB
/
output_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
// Copyright 2019 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.
// Almost all CSS output tests should go in sass-spec rather than here. This
// just covers tests that explicitly validate out that's considered too
// implementation-specific to verify in sass-spec.
import 'package:test/test.dart';
import 'package:sass/sass.dart';
void main() {
// Regression test for sass/dart-sass#623. This needs to be tested here
// because sass-spec normalizes CR LF newlines.
group("normalizes newlines in a loud comment", () {
test("in SCSS", () {
expect(compileString("/* foo\r\n * bar */"), equals("/* foo\n * bar */"));
});
test("in Sass", () {
expect(compileString("/*\r\n foo\r\n bar", syntax: Syntax.sass),
equals("/* foo\n * bar */"));
});
});
// Regression test for sass/dart-sass#688. This needs to be tested here
// because it varies between Dart and Node.
group("removes exponential notation", () {
group("for integers", () {
test(">= 1e21", () {
expect(compileString("a {b: 1e21}"),
equalsIgnoringWhitespace("a { b: 1${'0' * 21}; }"));
});
// At time of writing, numbers that are 20 digits or fewer are not printed
// in exponential notation by either Dart or Node, and we rely on that to
// determine when to get rid of the exponent. This test ensures that if that
// ever changes, we know about it.
test("< 1e21", () {
expect(compileString("a {b: 1e20}"),
equalsIgnoringWhitespace("a { b: 1${'0' * 20}; }"));
});
});
group("for floating-point numbers", () {
test(">= 1e21", () {
expect(compileString("a {b: 1.01e21}"),
equalsIgnoringWhitespace("a { b: 101${'0' * 19}; }"));
});
// At time of writing, numbers that are 20 digits or fewer are not printed
// in exponential notation by either Dart or Node, and we rely on that to
// determine when to get rid of the exponent. This test ensures that if that
// ever changes, we know about it.
test("< 1e21", () {
expect(compileString("a {b: 1.01e20}"),
equalsIgnoringWhitespace("a { b: 101${'0' * 18}; }"));
});
});
});
// Regression test for sass/dart-sass#417.
group("preserve trailing loud comments", () {
// No need for "in Sass" cases as it's not possible to have
// trailing loud comments in the Sass syntax.
group("in SCSS", () {
test("after open block", () {
expect(compileString("""
selector { /* please don't move me */
name: value;
}"""), equals("""
selector { /* please don't move me */
name: value;
}"""));
});
test("after declaration", () {
expect(compileString("""
selector {
name: value; /* please don't move me */
}"""), equals("""
selector {
name: value; /* please don't move me */
}"""));
});
test("after top-level statement", () {
expect(compileString("@rule; /* please don't move me */"),
equals("@rule; /* please don't move me */"));
});
});
});
}