From 9a66875ae1a8f6dfdd846a1bcf975e12d88595c8 Mon Sep 17 00:00:00 2001 From: Giacomo Cavalieri Date: Thu, 25 Jul 2024 15:48:57 +0200 Subject: [PATCH] Tests for label shorthands --- test/corpus/constants.txt | 19 +++++++++++++++++++ test/corpus/custom_types.txt | 23 +++++++++++++++++++++++ test/corpus/destructuring.txt | 28 ++++++++++++++++++++++++++++ test/corpus/functions.txt | 17 +++++++++++++++++ test/highlight/destructuring.gleam | 12 ++++++++++-- test/highlight/functions.gleam | 7 +++++++ test/highlight/records.gleam | 18 +++++++++++++----- 7 files changed, 117 insertions(+), 7 deletions(-) diff --git a/test/corpus/constants.txt b/test/corpus/constants.txt index e1aa858f3..1fdde8572 100644 --- a/test/corpus/constants.txt +++ b/test/corpus/constants.txt @@ -444,3 +444,22 @@ const a = -100.001e-1_230 (constant (identifier) (float))) + +================================================================================ +Constant with shorthand labels +================================================================================ + +const b = Wibble(arg:, arg:) + +-------------------------------------------------------------------------------- + +(source_file + (constant + (identifier) + (record + (constructor_name) + (arguments + (argument + (label)) + (argument + (label)))))) diff --git a/test/corpus/custom_types.txt b/test/corpus/custom_types.txt index a70a35fdb..4d0cc9ea0 100644 --- a/test/corpus/custom_types.txt +++ b/test/corpus/custom_types.txt @@ -247,3 +247,26 @@ pub opaque type Animal(name, cuteness) { label: (label) value: (type name: (type_identifier)))))))) + +================================================================================ +Record update with shorthand labels +================================================================================ + +Wibble(..wibble, arg:, arg:, arg: todo as "no shorthand") + +-------------------------------------------------------------------------------- + +(source_file + (record_update + (constructor_name) + (identifier) + (record_update_arguments + (record_update_argument + (label)) + (record_update_argument + (label)) + (record_update_argument + (label) + (todo + (string + (quoted_content))))))) diff --git a/test/corpus/destructuring.txt b/test/corpus/destructuring.txt index f1c64dd7c..2312a6ac1 100644 --- a/test/corpus/destructuring.txt +++ b/test/corpus/destructuring.txt @@ -48,3 +48,31 @@ pub fn main() { (argument (string (quoted_content))))))))))) + +================================================================================ +Pattern with label shorthand +================================================================================ + +pub fn main() { + let Wibble(arg1:, arg2:) = todo as "a" +} + +-------------------------------------------------------------------------------- + +(source_file + (function + (visibility_modifier) + (identifier) + (function_parameters) + (function_body + (let + (record_pattern + (constructor_name) + (record_pattern_arguments + (record_pattern_argument + (label)) + (record_pattern_argument + (label)))) + (todo + (string + (quoted_content))))))) diff --git a/test/corpus/functions.txt b/test/corpus/functions.txt index 2e26a545b..8315bba9a 100644 --- a/test/corpus/functions.txt +++ b/test/corpus/functions.txt @@ -1070,3 +1070,20 @@ io.println("// hello world!\n") value: (string (quoted_content) (escape_sequence)))))) + +================================================================================ +Call with label shorthand +================================================================================ + +wibble(arg1:, arg2:) + +-------------------------------------------------------------------------------- + +(source_file + (function_call + (identifier) + (arguments + (argument + (label)) + (argument + (label))))) diff --git a/test/highlight/destructuring.gleam b/test/highlight/destructuring.gleam index 7c6c597b1..d7b673745 100644 --- a/test/highlight/destructuring.gleam +++ b/test/highlight/destructuring.gleam @@ -2,8 +2,8 @@ fn case_case(x: Option(String)) { // ^ variable.parameter // ^ type case #(x, x) { - // ^ variable.parameter - // ^ variable.parameter + // ^ variable.parameter + // ^ variable.parameter #(None, None) -> None // ^ constructor // ^ constructor @@ -22,3 +22,11 @@ fn case_case(x: Option(String)) { z.foo() // <- module } + +fn shorthand_label_pattern_arg() { + case todo { + Wibble(arg1:, arg2:) -> todo + // ^ property + // ^ property + } +} diff --git a/test/highlight/functions.gleam b/test/highlight/functions.gleam index 73366548a..728cabe18 100644 --- a/test/highlight/functions.gleam +++ b/test/highlight/functions.gleam @@ -114,3 +114,10 @@ fn let_assert_test() { // <- keyword // ^ keyword } + +fn punned_call_arg_test() { + wibble(arg:, arg2:) + // ^ function + // ^ property + // ^ property +} diff --git a/test/highlight/records.gleam b/test/highlight/records.gleam index bf9a77ecf..4cf8c9a5e 100644 --- a/test/highlight/records.gleam +++ b/test/highlight/records.gleam @@ -13,8 +13,16 @@ pub fn new(name: String) { // ^ variable.parameter } -let config = Config() -config.connection.host -// ^ variable -// ^ property -// ^ property +pub fn access() { + let config = Config() + config.connection.host + // ^ variable + // ^ property + // ^ property +} + +pub fn record_update_shorthand_label() { + User(..user, name:) + // ^ constructor + // ^ property +}