Skip to content

Commit

Permalink
fix: run-function-with-params should handle maps
Browse files Browse the repository at this point in the history
  • Loading branch information
jackw committed Aug 27, 2020
1 parent 11f9e6e commit e95071f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/internal/_run-function-with-params.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
$input: append(tail($function), $input);
}
@if function-exists($fn) {
@return call(get-function($fn), $input...);
@if type-of($input) == 'map' {
@return call(get-function($fn), $input);
} @else {
@return call(get-function($fn), $input...);
}
} @else {
@return $input;
}
Expand Down
32 changes: 30 additions & 2 deletions test/internal/_run-function-with-params.spec.scss
Original file line number Diff line number Diff line change
@@ -1,23 +1,51 @@
@import 'true';
@import '../../src/internal/run-function-with-params';

@function _sass-fire-run-func-params-spec-darken($percent, $color) {
@function _run-func-params-spec-darken($percent, $color) {
@return darken($color, $percent);
}

@function _run-func-params-spec-darken-map($percent, $map) {
@return darken(map-get($map, 'value'), $percent);
}

@function _run-func-params-spec-x-gt-100($o) {
@if type-of($o) == 'map' {
@return map-get($o, 'x') > 100;
}
@return false;
}

@include describe('run-function-with-params [function]') {
@include it('calls a function with the params passed to it') {
@include assert-equal(_run-function-with-params(abs, -20), 20);
@include assert-true(
_run-function-with-params(
_run-func-params-spec-x-gt-100,
(
x: 200,
)
)
);
}

@include it('calls a function passing in the params supplied') {
@include assert-equal(
_run-function-with-params(
(_sass-fire-run-func-params-spec-darken 20%),
(_run-func-params-spec-darken 20%),
#963e7e
),
#4e2041
);
@include assert-equal(
_run-function-with-params(
(_run-func-params-spec-darken-map 40%),
(
'value': #c30c30,
)
),
#030001
);
}

@include it("returns the input if the function doesn't exist") {
Expand Down

0 comments on commit e95071f

Please sign in to comment.