Skip to content

Commit

Permalink
Tests for label shorthands
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomocavalieri committed Jul 25, 2024
1 parent f8a6614 commit 9a66875
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 7 deletions.
19 changes: 19 additions & 0 deletions test/corpus/constants.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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))))))
23 changes: 23 additions & 0 deletions test/corpus/custom_types.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)))))))
28 changes: 28 additions & 0 deletions test/corpus/destructuring.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)))))))
17 changes: 17 additions & 0 deletions test/corpus/functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)))))
12 changes: 10 additions & 2 deletions test/highlight/destructuring.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
7 changes: 7 additions & 0 deletions test/highlight/functions.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,10 @@ fn let_assert_test() {
// <- keyword
// ^ keyword
}

fn punned_call_arg_test() {
wibble(arg:, arg2:)
// ^ function
// ^ property
// ^ property
}
18 changes: 13 additions & 5 deletions test/highlight/records.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 9a66875

Please sign in to comment.