From 70f02f6ebf7f833d0daeb2f9155b84005ac1ca43 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 11 Dec 2024 16:45:56 -0800 Subject: [PATCH] Add tests for trailing commas after parameters and arguments --- spec/callable/arguments.hrx | 250 +++++++++++++++++++++++++++++++++-- spec/callable/parameters.hrx | 219 ++++++++++++++++++++++++++++++ 2 files changed, 455 insertions(+), 14 deletions(-) create mode 100644 spec/callable/parameters.hrx diff --git a/spec/callable/arguments.hrx b/spec/callable/arguments.hrx index 01a9cca1a..2f384ce7b 100644 --- a/spec/callable/arguments.hrx +++ b/spec/callable/arguments.hrx @@ -1,3 +1,125 @@ +<===> mixin/_utils.scss +@use 'sass:meta'; + +@mixin a($args...) { + b { + positional: meta.inspect($args); + named: meta.inspect(meta.keywords($args)); + } +} + +<===> +================================================================================ +<===> mixin/trailing_comma/positional/input.scss +@use 'callable/arguments/mixin/utils'; +@include utils.a(1, ); + +<===> mixin/trailing_comma/positional/output.css +b { + positional: (1,); + named: (); +} + +<===> +================================================================================ +<===> mixin/trailing_comma/named/alone/input.scss +@use 'callable/arguments/mixin/utils'; +@include utils.a($c: 1, ); + +<===> mixin/trailing_comma/named/alone/output.css +b { + positional: (); + named: (c: 1); +} + +<===> +================================================================================ +<===> mixin/trailing_comma/named/after_positional/input.scss +@use 'callable/arguments/mixin/utils'; +@include utils.a(1, $c: 2, ); + +<===> mixin/trailing_comma/named/after_positional/output.css +b { + positional: (1,); + named: (c: 2); +} + +<===> +================================================================================ +<===> mixin/trailing_comma/rest/alone/input.scss +@use 'callable/arguments/mixin/utils'; +@include utils.a(1..., ); + +<===> mixin/trailing_comma/rest/alone/output.css +b { + positional: (1,); + named: (); +} + +<===> +================================================================================ +<===> mixin/trailing_comma/rest/after_positional/input.scss +@use 'callable/arguments/mixin/utils'; +@include utils.a(1, 2..., ); + +<===> mixin/trailing_comma/rest/after_positional/output.css +b { + positional: 1, 2; + named: (); +} + +<===> +================================================================================ +<===> mixin/trailing_comma/rest/after_named/input.scss +@use 'callable/arguments/mixin/utils'; +@include utils.a($c: 1, 2..., ); + +<===> mixin/trailing_comma/rest/after_named/output.css +b { + positional: (2,); + named: (c: 1); +} + +<===> +================================================================================ +<===> mixin/trailing_comma/rest/after_both/input.scss +@use 'callable/arguments/mixin/utils'; +@include utils.a(1, $c: 2, 3..., ); + +<===> mixin/trailing_comma/rest/after_both/output.css +b { + positional: 1, 3; + named: (c: 2); +} + +<===> +================================================================================ +<===> mixin/trailing_comma/keyword_rest/input.scss +@use 'callable/arguments/mixin/utils'; +@include utils.a(1..., (c: 2)..., ); + +<===> mixin/trailing_comma/keyword_rest/output.css +b { + positional: (1,); + named: (c: 2); +} + +<===> +================================================================================ +<===> mixin/error/comma_only/input.scss +@use 'callable/arguments/mixin/utils'; +@include utils.a( , ); + +<===> mixin/error/comma_only/error +Error: expected ")". + , +2 | @include utils.a( , ); + | ^ + ' + input.scss 2:19 root stylesheet + +<===> +================================================================================ <===> mixin/error/positional_after_named/input.scss @mixin a($b, $c) {} @@ -41,6 +163,120 @@ Error: Duplicate argument. ' input.scss 3:21 root stylesheet +<===> +================================================================================ +<===> function/_utils.scss +@use 'sass:meta'; + +@function a($args...) { + @return meta.inspect(( + positional: $args, + named: meta.keywords($args), + )); +} + +<===> +================================================================================ +<===> function/trailing_comma/positional/input.scss +@use 'callable/arguments/function/utils'; +a {b: utils.a(1, )} + +<===> function/trailing_comma/positional/output.css +a { + b: (positional: ((1,)), named: ()); +} + +<===> +================================================================================ +<===> function/trailing_comma/named/alone/input.scss +@use 'callable/arguments/function/utils'; +a {b: utils.a($c: 1, )} + +<===> function/trailing_comma/named/alone/output.css +a { + b: (positional: (()), named: (c: 1)); +} + +<===> +================================================================================ +<===> function/trailing_comma/named/after_positional/input.scss +@use 'callable/arguments/function/utils'; +a {b: utils.a(1, $c: 2, )} + +<===> function/trailing_comma/named/after_positional/output.css +a { + b: (positional: ((1,)), named: (c: 2)); +} + +<===> +================================================================================ +<===> function/trailing_comma/rest/alone/input.scss +@use 'callable/arguments/function/utils'; +a {b: utils.a(1..., )} + +<===> function/trailing_comma/rest/alone/output.css +a { + b: (positional: ((1,)), named: ()); +} + +<===> +================================================================================ +<===> function/trailing_comma/rest/after_positional/input.scss +@use 'callable/arguments/function/utils'; +a {b: utils.a(1, 2..., )} + +<===> function/trailing_comma/rest/after_positional/output.css +a { + b: (positional: (1, 2), named: ()); +} + +<===> +================================================================================ +<===> function/trailing_comma/rest/after_named/input.scss +@use 'callable/arguments/function/utils'; +a {b: utils.a($c: 1, 2..., )} + +<===> function/trailing_comma/rest/after_named/output.css +a { + b: (positional: ((2,)), named: (c: 1)); +} + +<===> +================================================================================ +<===> function/trailing_comma/rest/after_both/input.scss +@use 'callable/arguments/function/utils'; +a {b: utils.a(1, $c: 2, 3..., )} + +<===> function/trailing_comma/rest/after_both/output.css +a { + b: (positional: (1, 3), named: (c: 2)); +} + +<===> +================================================================================ +<===> function/trailing_comma/keyword_rest/input.scss +@use 'callable/arguments/function/utils'; +a {b: utils.a(1..., (c: 2)..., )} + +<===> function/trailing_comma/keyword_rest/output.css +a { + b: (positional: ((1,)), named: (c: 2)); +} + +<===> +================================================================================ +<===> function/error/comma_only/input.scss +@use 'callable/arguments/function/utils'; +a {b: utils.a( , )}; + +<===> function/error/comma_only/error +Error: expected ")". + , +2 | a {b: utils.a( , )}; + | ^ + ' + input.scss 2:16 root stylesheet + <===> ================================================================================ <===> function/error/positional_after_named/input.scss @@ -95,17 +331,3 @@ Error: expected ")". | ^ ' input.sass 5:8 root stylesheet - -<===> -================================================================================ -<===> function/arguments/sass/input.sass -@function a($b, $c) - @return d - -e - f: a(g, h) - -<===> function/arguments/sass/output.css -e { - f: d; -} diff --git a/spec/callable/parameters.hrx b/spec/callable/parameters.hrx new file mode 100644 index 000000000..7dc84b478 --- /dev/null +++ b/spec/callable/parameters.hrx @@ -0,0 +1,219 @@ +<===> mixin/trailing_comma/no_default/input.scss +@mixin a($b, ) { + c: $b; +} + +d {@include a(1)} + +<===> mixin/trailing_comma/no_default/output.css +d { + c: 1; +} + +<===> +================================================================================ +<===> mixin/trailing_comma/default/alone/input.scss +@mixin a($b: 1, ) { + c: $b; +} + +d {@include a} + +<===> mixin/trailing_comma/default/alone/output.css +d { + c: 1; +} + +<===> +================================================================================ +<===> mixin/trailing_comma/default/after_no_default/input.scss +@mixin a($b, $c: 1, ) { + d: $c; +} + +e {@include a(2)} + +<===> mixin/trailing_comma/default/after_no_default/output.css +e { + d: 1; +} + +<===> +================================================================================ +<===> mixin/trailing_comma/rest/alone/input.scss +@mixin a($b..., ) { + c: $b; +} + +d {@include a(1)} + +<===> mixin/trailing_comma/rest/alone/output.css +d { + c: 1; +} + +<===> +================================================================================ +<===> mixin/trailing_comma/rest/after_no_default/input.scss +@mixin a($b, $c..., ) { + d: $c; +} + +e {@include a(1, 2)} + +<===> mixin/trailing_comma/rest/after_no_default/output.css +e { + d: 2; +} + +<===> +================================================================================ +<===> mixin/trailing_comma/rest/after_default/input.scss +@mixin a($b: 1, $c..., ) { + d: $c; +} + +e {@include a(2, 3)} + +<===> mixin/trailing_comma/rest/after_default/output.css +e { + d: 3; +} + +<===> +================================================================================ +<===> mixin/trailing_comma/rest/after_both/input.scss +@mixin a($b, $c: 1, $d..., ) { + d: $d; +} + +e {@include a(2, 3, 4)} + +<===> mixin/trailing_comma/rest/after_both/output.css +e { + d: 4; +} + +<===> +================================================================================ +<===> mixin/error/comma_only/input.scss +@mixin a( , ) {} + +<===> mixin/error/comma_only/error +Error: expected ")". + , +1 | @mixin a( , ) {} + | ^ + ' + input.scss 1:11 root stylesheet + +<===> +================================================================================ +<===> function/trailing_comma/no_default/input.scss +@function a($b, ) { + @return $b; +} + +c {d: a(e)} + +<===> function/trailing_comma/no_default/output.css +c { + d: e; +} + +<===> +================================================================================ +<===> function/trailing_comma/default/alone/input.scss +@function a($b: 1, ) { + @return $b; +} + +c {d: a()} + +<===> function/trailing_comma/default/alone/output.css +c { + d: 1; +} + +<===> +================================================================================ +<===> function/trailing_comma/default/after_no_default/input.scss +@function a($b, $c: 1, ) { + @return $c; +} + +d {e: a(2)} + +<===> function/trailing_comma/default/after_no_default/output.css +d { + e: 1; +} + +<===> +================================================================================ +<===> function/trailing_comma/rest/alone/input.scss +@function a($b..., ) { + @return $b; +} + +c {d: a(1)} + +<===> function/trailing_comma/rest/alone/output.css +c { + d: 1; +} + +<===> +================================================================================ +<===> function/trailing_comma/rest/after_no_default/input.scss +@function a($b, $c..., ) { + @return $c; +} + +d {e: a(1, 2)} + +<===> function/trailing_comma/rest/after_no_default/output.css +d { + e: 2; +} + +<===> +================================================================================ +<===> function/trailing_comma/rest/after_default/input.scss +@function a($b: 1, $c..., ) { + @return $c; +} + +d {e: a(2, 3)} + +<===> function/trailing_comma/rest/after_default/output.css +d { + e: 3; +} + +<===> +================================================================================ +<===> function/trailing_comma/rest/after_both/input.scss +@function a($b, $c: 1, $d..., ) { + @return $d; +} + +e {f: a(2, 3, 4)} + +<===> function/trailing_comma/rest/after_both/output.css +e { + f: 4; +} + +<===> +================================================================================ +<===> function/error/comma_only/input.scss +@function a( , ) {} + +<===> function/error/comma_only/error +Error: expected ")". + , +1 | @function a( , ) {} + | ^ + ' + input.scss 1:14 root stylesheet