Skip to content

Commit df2ea0f

Browse files
authored
use shorter ? syntax (#408)
1 parent 217c34a commit df2ea0f

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

ci/check_all_exposed_funs_tested.roc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ err_s = |err_msg| Err(StrErr(err_msg))
2020
main! : List Arg => Result {} _
2121
main! = |_args|
2222
# Check if ripgrep is installed
23-
_ = Cmd.exec!("rg", ["--version"]) ? |err| RipgrepNotInstalled(err)
23+
_ = Cmd.exec!("rg", ["--version"]) ? RipgrepNotInstalled
2424

25-
cwd = Env.cwd!({}) ? |err| FailedToGetCwd(err)
25+
cwd = Env.cwd!({}) ? FailedToGetCwd
2626
Stdout.line!("Current working directory: ${Path.display(cwd)}")?
2727

2828
path_to_platform_main = "platform/main.roc"
@@ -87,7 +87,7 @@ is_function_unused! = |module_name, function_name|
8787
search_dirs = ["examples", "tests"]
8888
8989
# Check current working directory
90-
cwd = Env.cwd!({}) ? |err| FailedToGetCwd2(err)
90+
cwd = Env.cwd!({}) ? FailedToGetCwd2
9191
9292
# Check if directories exist
9393
List.for_each_try!(

ci/check_cargo_versions_match.roc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ err_exit = |err_msg| Err(Exit(1, "\n❌ ${err_msg}"))
1919

2020
main! : List Arg => Result {} _
2121
main! = |_args|
22-
cwd = Env.cwd!({}) ? |err| FailedToGetCwd(err)
22+
cwd = Env.cwd!({}) ? FailedToGetCwd
2323
Stdout.line!("Current working directory: ${Path.display(cwd)}")?
2424

2525
root_cargo_path = "Cargo.toml"

tests/file.roc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ test_file_exists! = |{}|
221221
filename = "test_exists.txt"
222222
File.write_utf8!("", filename)?
223223

224-
test_file_exists = File.exists!(filename) ? |err| FileExistsCheckFailed(err)
224+
test_file_exists = File.exists!(filename) ? FileExistsCheckFailed
225225

226226
if test_file_exists then
227227
Stdout.line!("✓ File.exists! returns true for a file that exists")?
@@ -231,7 +231,7 @@ test_file_exists! = |{}|
231231
# Test that a file that does not exist returns false
232232
File.delete!(filename)?
233233
234-
test_file_exists_after_delete = File.exists!(filename) ? |err| FileExistsCheckAfterDeleteFailed(err)
234+
test_file_exists_after_delete = File.exists!(filename) ? FileExistsCheckAfterDeleteFailed
235235
236236
if test_file_exists_after_delete then
237237
Stderr.line!("File.exists! returned true for a file that does not exist")?
@@ -261,7 +261,7 @@ cleanup_test_files! = |files_requirement|
261261
262262
when files_requirement is
263263
FilesNeedToExist ->
264-
delete_result ? |err| FileDeletionFailed(err)
264+
delete_result ? FileDeletionFailed
265265
266266
FilesMaybeExist ->
267267
Ok({})?

tests/path-test.roc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ test_file_operations! = |{}|
151151
# Verify file exists before deletion
152152
_ = Cmd.exec!("test", ["-e", "test_to_delete.txt"])?
153153
154-
Path.delete!(delete_path) ? |err| DeleteFailed(err)
154+
Path.delete!(delete_path) ? DeleteFailed
155155
156156
# Verify file is gone after deletion
157157
exists_after_res = Cmd.exec!("test", ["-e", "test_to_delete.txt"])
@@ -331,7 +331,7 @@ test_path_rename! = |{}|
331331
new_path = Path.from_str("test_path_rename_new.txt")
332332
test_file_content = "Content for rename test."
333333

334-
Path.write_utf8!(test_file_content, original_path) ? |err| WriteOriginalFailed(err)
334+
Path.write_utf8!(test_file_content, original_path) ? WriteOriginalFailed
335335

336336
# Rename the file
337337
when Path.rename!(original_path, new_path) is
@@ -346,12 +346,12 @@ test_path_rename! = |{}|
346346
else
347347
Stdout.line!("Original file no longer exists")?
348348
349-
new_file_exists = Path.is_file!(new_path) ? |err| NewIsFileFailed(err)
349+
new_file_exists = Path.is_file!(new_path) ? NewIsFileFailed
350350
351351
if new_file_exists then
352352
Stdout.line!("Renamed file exists")?
353353
354-
content = Path.read_utf8!(new_path) ? |err| NewFileReadFailed(err)
354+
content = Path.read_utf8!(new_path) ? NewFileReadFailed
355355
356356
if content == test_file_content then
357357
Stdout.line!("Renamed file has correct content")
@@ -371,7 +371,7 @@ test_path_exists! = |{}|
371371
filename = Path.from_str("test_path_exists.txt")
372372
Path.write_utf8!("This file exists", filename)?
373373
374-
file_exists = Path.exists!(filename) ? |err| PathExistsCheckFailed(err)
374+
file_exists = Path.exists!(filename) ? PathExistsCheckFailed
375375
376376
if file_exists then
377377
Stdout.line!("Path.exists! returns true for a file that exists")?
@@ -381,7 +381,7 @@ test_path_exists! = |{}|
381381
# Test that a file that does not exist returns false
382382
Path.delete!(filename)?
383383
384-
file_exists_after_delete = Path.exists!(filename) ? |err| PathExistsCheckAfterDeleteFailed(err)
384+
file_exists_after_delete = Path.exists!(filename) ? PathExistsCheckAfterDeleteFailed
385385
386386
if file_exists_after_delete then
387387
Stderr.line!("Path.exists! returned true for a file that does not exist")?
@@ -419,7 +419,7 @@ cleanup_test_files! = |files_requirement|
419419
420420
when files_requirement is
421421
FilesNeedToExist ->
422-
delete_result ? |err| FileDeletionFailed(err)
422+
delete_result ? FileDeletionFailed
423423
FilesMaybeExist ->
424424
Ok({})?
425425

tests/tcp.roc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ test_tcp_functions! = |stream|
5959
do_not_read_bytes = [100, 111, 32, 110, 111, 116, 32, 114, 101, 97, 100, 32, 112, 97, 115, 116, 32, 109, 101, 65] # "do not read past meA" in bytes
6060
Tcp.write!(stream, do_not_read_bytes)?
6161

62-
nineteen_bytes = Tcp.read_up_to!(stream, 19) ? |err| FailedReadUpTo(err)
63-
nineteen_bytes_as_str = Str.from_utf8(nineteen_bytes) ? |err| ReadUpToFromUtf8(err)
62+
nineteen_bytes = Tcp.read_up_to!(stream, 19) ? FailedReadUpTo
63+
nineteen_bytes_as_str = Str.from_utf8(nineteen_bytes) ? ReadUpToFromUtf8
6464

6565
Stdout.line!(
6666
"""
@@ -72,8 +72,8 @@ test_tcp_functions! = |stream|
7272
)?
7373
Tcp.write_utf8!(stream, "BC")?
7474

75-
three_bytes = Tcp.read_exactly!(stream, 3) ? |err| FailedReadExactly(err)
76-
three_bytes_as_str = Str.from_utf8(three_bytes) ? |err| ReadExactlyFromUtf8(err)
75+
three_bytes = Tcp.read_exactly!(stream, 3) ? FailedReadExactly
76+
three_bytes_as_str = Str.from_utf8(three_bytes) ? ReadExactlyFromUtf8
7777

7878
Stdout.line!(
7979
"""
@@ -85,8 +85,8 @@ test_tcp_functions! = |stream|
8585
)?
8686
Tcp.write_utf8!(stream, "Line1\nLine2\n")?
8787

88-
bytes_until = Tcp.read_until!(stream, '\n') ? |err| FailedReadUntil(err)
89-
bytes_until_as_str = Str.from_utf8(bytes_until) ? |err| ReadUntilFromUtf8(err)
88+
bytes_until = Tcp.read_until!(stream, '\n') ? FailedReadUntil
89+
bytes_until_as_str = Str.from_utf8(bytes_until) ? ReadUntilFromUtf8
9090

9191
Stdout.line!("Tcp.read_until yielded: '${bytes_until_as_str}'")?
9292

0 commit comments

Comments
 (0)