Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# True Changelog

## 9.1.0 UNRELEASED

- BREAKING: Remove the `$inspect` option from assertions,
since Sass has improved comparisons and changed inspection.

## 9.1.0-alpha.0 (07/01/25)

- FEATURE: Do not fail on non-standard at-rules (switch to postcss for css
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@
"eslint-plugin-simple-import-sort": "^12.1.1",
"globals": "^16.5.0",
"jest": "^30.2.0",
"mocha": "^11.7.4",
"mocha": "^11.7.5",
"npm-run-all": "^4.1.5",
"sass": "1.90.0",
"sass-embedded": "1.90.0",
"sass": "^1.93.3",
"sass-embedded": "^1.93.3",
"sassdoc": "^2.7.4",
"sassdoc-theme-herman": "^6.0.2",
"stylelint": "^16.25.0",
Expand Down
30 changes: 6 additions & 24 deletions sass/assert/_values.scss
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@
/// @param {string} $description [null] -
/// Description of the assertion being tested
/// (a `null` of `false` value generates a default description)
/// @param {bool} $inspect [false] -
/// Optionally compare inspected values
/// (useful for comparing CSS output rather than Sass values)
///
/// @example scss -
/// @use 'sass:math';
Expand All @@ -102,20 +99,14 @@
/// math.div(8, 2), 4,
/// 'You can optionally describe the assertion...');
/// }
@mixin assert-equal($assert, $expected, $description: null, $inspect: false) {
@mixin assert-equal($assert, $expected, $description: null) {
@include utils.setup('assert-equal', $description);

@if $inspect {
$assert: meta.inspect($assert);
$expected: meta.inspect($expected);
}

@include utils.result($assert, $expected);
}

/// @alias assert-equal
@mixin is-equal($assert, $expected, $description: null, $inspect: false) {
@include assert-equal($assert, $expected, $description, $inspect);
@mixin is-equal($assert, $expected, $description: null) {
@include assert-equal($assert, $expected, $description);
}

// Assert UnEqual
Expand All @@ -133,28 +124,19 @@
/// @param {string} $description [null] -
/// Description of the assertion being tested.
/// A `null` of `false` value generates a default description.
/// @param {bool} $inspect [false] -
/// Optionally compare inspected values
/// (useful for comparing CSS output rather than Sass values)
///
/// @example scss -
/// @include true.test('Strings and numbers are not the same') {
/// @include true.assert-unequal(
/// 1em,
/// '1em');
/// }
@mixin assert-unequal($assert, $expected, $description: null, $inspect: false) {
@mixin assert-unequal($assert, $expected, $description: null) {
@include utils.setup('assert-unequal', $description);

@if $inspect {
$assert: meta.inspect($assert);
$expected: meta.inspect($expected);
}

@include utils.result($assert, $expected, 'unequal');
}

/// @alias assert-unequal
@mixin not-equal($assert, $expected, $description: null, $inspect: false) {
@include assert-unequal($assert, $expected, $description, $inspect);
@mixin not-equal($assert, $expected, $description: null) {
@include assert-unequal($assert, $expected, $description);
}
46 changes: 17 additions & 29 deletions sass/data/_details.scss
Original file line number Diff line number Diff line change
Expand Up @@ -103,49 +103,37 @@
$two-type: meta.type-of($two);
$note: null;
$pre: '- Details: ';
$inspect: '(set `$inspect: true` to compare output values)';

// Type
@if ($one-type != $two-type) {
$message: 'variable types do not match';

@return $pre + $message;
}

// List Separators
@if ($one-type == 'list') and ($two-type == 'list') {
@if $one-type == 'list' {
@if (list.join((), $one, comma) == list.join((), $two, comma)) {
$message: 'list-separators do not match';
$note: $pre + $message;

@return $pre + $message;
}
}

// String Quotes
@if ($one-type == 'string') and ($two-type == 'string') {
@if $one-type == 'string' {
@if (string.unquote($one) == string.unquote($two)) {
$message: 'string quotations do not match';
$note: $pre + $message;
}
}

$one: if(($one-type == 'string'), string.unquote($one), $one);
$two: if(($two-type == 'string'), string.unquote($two), $two);

@if (meta.inspect($one) == meta.inspect($two)) {
// Type
@if ($one-type != $two-type) {
$message: 'variable types do not match';
$note: $pre + $message + ' ' + $inspect;
@return $pre + $message;
}
}

// Rounding
$number: ($one-type == 'number') and ($two-type == 'number');
$color: ($one-type == 'color') and ($two-type == 'color');
@if list.index(('number', 'color'), $one-type) {
$message: '#{$one-type}s may need to be rounded before comparison';

@if ($number or $color) {
$type: if($number, 'numbers', 'colors');
$message: '#{$type} may need to be rounded before comparison';
$note: $pre + $message + ' ' + $inspect;
}

// Catch-All (I think this may not be currently possible)
@if (not $note) {
$note: $pre + $inspect;
}
@return $pre + $message;
}

@return $note;
@return $pre;
}
36 changes: 16 additions & 20 deletions test/css/test.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 5 additions & 19 deletions test/scss/assert/_values.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,34 +50,20 @@
}

@include it('Adding floats') {
@include assert-equal(0.1 + 0.2, 0.3, $inspect: true);
@include assert-equal(0.1 + 0.2, 0.3);
Comment thread
jgerigmeyer marked this conversation as resolved.
}

@include it('Rounded numbers with $inspect') {
@include assert-equal(math.div(1, 3), 0.3333333333, $inspect: true);
@include it('Rounded numbers') {
@include assert-equal(math.div(1, 3), 0.3333333333333333);
}

@include it('Rounded colors with $inspect') {
@include it('Rounded colors') {
$origin: #246;
$expected: rgb(53.125, 106.25, 159.375);

@include assert-equal(
color.adjust($origin, $lightness: 15%),
$expected,
$inspect: true
);
}

@include it('Mismatched types with $inspect') {
@include assert-unequal(
string.unquote('1rem'),
1rem,
'normally unequal'
);
@include assert-equal(
string.unquote('1rem'),
1rem,
$inspect: true
);
}

Expand All @@ -97,7 +83,7 @@
@include assert-unequal(string.unquote('1rem'), 1rem);
}

@include it('Mismatched units no longer needs $inspect') {
@include it('Mismatched units') {
@include assert-unequal(1, 1rem);
}

Expand Down
22 changes: 14 additions & 8 deletions test/scss/data/_details.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
@include assert {
@include output(false) {
@include context.context('assert', '[assert-equal] Test Assertion');
@include details.fail-details(math.div(1, 3), 0.3333333333, not 'terminal');
@include details.fail-details(math.div(1, 3), 0.333, not 'terminal');
@include context.context-pop;
}

@include expect(false) {
/* ✖ FAILED: [assert-equal] Test Assertion */
/* - Output: [number] 0.3333333333 */
/* - Expected: [number] 0.3333333333 */
/* - Details: numbers may need to be rounded before comparison (set `$inspect: true` to compare output values) */
/* - Output: [number] 0.3333333333333333 */
/* - Expected: [number] 0.333 */
/* - Details: numbers may need to be rounded before comparison */
/* - Module: Fail Details */
/* - Test: Compiles full failure details */
}
Expand Down Expand Up @@ -78,7 +78,7 @@
// EdgeFail Notes
@include describe('Edgefail Notes') {
@include it('Type mismatch') {
$message: '- Details: variable types do not match (set `$inspect: true` to compare output values)';
$message: '- Details: variable types do not match';

@include assert-equal(details.edgefail-notes(1em, '1em'), $message);

Expand All @@ -103,9 +103,12 @@
}

@include it('Number Rounding') {
$message: '- Details: numbers may need to be rounded before comparison (set `$inspect: true` to compare output values)';
$message: '- Details: numbers may need to be rounded before comparison';

@include assert-equal(details.edgefail-notes(math.div(1, 3), 0.3333333333), $message);
@include assert-equal(
details.edgefail-notes(math.div(1, 3), 0.3),
$message
);
}

@include it('List Separators') {
Expand All @@ -114,6 +117,9 @@
$space: list.join((), 'one', space);
$comma: list.join((), 'one', comma);

@include assert-equal(details.edgefail-notes($space, $comma), $message);
@include assert-equal(
details.edgefail-notes($space, $comma),
$message
);
}
}
Loading