forked from gleam-lang/gleam
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguards.rs
More file actions
135 lines (126 loc) · 2.12 KB
/
Copy pathguards.rs
File metadata and controls
135 lines (126 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023 The Gleam contributors
use crate::assert_format;
#[test]
fn field_access() {
assert_format!(
r#"pub fn main() {
case x {
_ if a.b -> 1
_ -> 0
}
}
"#
);
}
#[test]
fn nested_field_access() {
assert_format!(
r#"pub fn main() {
case x {
_ if a.b.c.d -> 1
_ -> 0
}
}
"#
);
}
#[test]
fn operators_in_guard() {
assert_format!(
r#"pub fn main() {
case list.map(codepoints, string.utf_codepoint_to_int) {
[drive, colon, slash]
if { slash == 47 || slash == 92 }
&& colon == 58
&& drive >= 65
&& drive <= 90
|| drive >= 97
&& drive <= 122
-> {
1
|> 2
}
}
}
"#
);
}
#[test]
fn commented_operators_in_guard() {
assert_format!(
r#"pub fn main() {
case list.map(codepoints, string.utf_codepoint_to_int) {
[drive, colon, slash]
if { slash == 47 || slash == 92 }
&& colon == 58
// Hello
&& drive >= 65
&& drive <= 90
// This is a comment
|| drive >= 97
// And another one
&& drive <= 122
-> {
1
|> 2
}
}
}
"#
);
}
#[test]
fn a_comment_before_a_guard_doesnt_force_it_to_break() {
assert_format!(
r#"pub fn main() {
case wibble {
// Apparently this comment breaks everything
_ if wobble -> Ok(state.newest)
}
}
"#
);
}
#[test]
fn long_guard_with_alternative_patterns() {
assert_format!(
r#"pub fn main() {
case wibble {
Wibble(first_one)
| Wibble(another_one)
| Wibble(
this_is_extra_long_to_go_over_the_line_limit,
this_gets_broken_as_well,
)
if True
-> Ok(wibble)
}
}
"#
);
}
#[test]
fn guard_block_is_not_removed_even_if_redundant() {
assert_format!(
r#"pub fn main() {
case todo {
_ if { True && True } && True -> 1
_ -> 2
}
}
"#
);
}
#[test]
fn nested_guard_block_is_not_removed_even_if_redundant() {
assert_format!(
r#"pub fn main() {
case todo {
_ if { True && { True && False } } && True -> 1
_ -> 2
}
}
"#
);
}