Skip to content

Commit 31b4075

Browse files
authored
use shorter ? syntax (#152)
1 parent 78e9ae4 commit 31b4075

File tree

7 files changed

+41
-41
lines changed

7 files changed

+41
-41
lines changed

ci/check_all_exposed_funs_tested.roc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ main! = |_args|
2222
# Check if ripgrep is installed
2323
_ = Cmd.exec!("rg", ["--version"])?
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!(

examples/todos.roc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ exec_transaction! = |{ begin_stmt, rollback_stmt, end_stmt }, transaction!|
161161
bindings: [],
162162
},
163163
)
164-
? |err| FailedToBeginTransaction(err)
164+
? FailedToBeginTransaction
165165

166166
end_transaction! = |res|
167167
when res is
@@ -172,7 +172,7 @@ exec_transaction! = |{ begin_stmt, rollback_stmt, end_stmt }, transaction!|
172172
bindings: [],
173173
},
174174
)
175-
? |err| FailedToEndTransaction(err)
175+
? FailedToEndTransaction
176176

177177
Ok(v)
178178

@@ -190,7 +190,7 @@ exec_transaction! = |{ begin_stmt, rollback_stmt, end_stmt }, transaction!|
190190
bindings: [],
191191
},
192192
)
193-
? |err| FailedToRollbackTransaction(err)
193+
? FailedToRollbackTransaction
194194

195195
Err(e)
196196

tests/dir-test.roc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ test_dir_create! = |{}|
5050

5151
# Test creating a single directory
5252
test_dir_name = "test_dir_create"
53-
Dir.create!(test_dir_name) ? |err| DirCreateFailed(err)
53+
Dir.create!(test_dir_name) ? DirCreateFailed
5454

5555
# Verify directory exists using ls
5656
ls_output =
@@ -301,7 +301,7 @@ cleanup_test_dirs! = |dirs_requirement|
301301
302302
when dirs_requirement is
303303
DirsNeedToExist ->
304-
delete_result ? |err| DirDeletionFailed(err)
304+
delete_result ? DirDeletionFailed
305305
DirsMaybeExist ->
306306
Ok({})?
307307

tests/file.roc

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

233-
test_file_exists = File.exists!(filename) ? |err| FileExistsCheckFailed(err)
233+
test_file_exists = File.exists!(filename) ? FileExistsCheckFailed
234234

235235
if test_file_exists then
236236
Stdout.line!("✓ File.exists! returns true for a file that exists")?
@@ -240,7 +240,7 @@ test_file_exists! = |{}|
240240
# Test that a file that does not exist returns false
241241
File.delete!(filename)?
242242
243-
test_file_exists_after_delete = File.exists!(filename) ? |err| FileExistsCheckAfterDeleteFailed(err)
243+
test_file_exists_after_delete = File.exists!(filename) ? FileExistsCheckAfterDeleteFailed
244244
245245
if test_file_exists_after_delete then
246246
Stderr.line!("File.exists! returned true for a file that does not exist")?
@@ -300,7 +300,7 @@ cleanup_test_files! = |files_requirement|
300300
301301
when files_requirement is
302302
FilesNeedToExist ->
303-
delete_result ? |err| FileDeletionFailed(err)
303+
delete_result ? FileDeletionFailed
304304
FilesMaybeExist ->
305305
Ok({})?
306306

tests/path-test.roc

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ test_file_operations! = |{}|
160160
# Verify file exists before deletion
161161
_ = Cmd.exec!("test", ["-e", "test_to_delete.txt"])?
162162
163-
Path.delete!(delete_path) ? |err| DeleteFailed(err)
163+
Path.delete!(delete_path) ? DeleteFailed
164164
165165
# Verify file is gone after deletion
166166
exists_after_res = Cmd.exec!("test", ["-e", "test_to_delete.txt"])
@@ -342,7 +342,7 @@ test_path_rename! = |{}|
342342
new_path = Path.from_str("test_path_rename_new.txt")
343343
test_file_content = "Content for rename test."
344344

345-
Path.write_utf8!(test_file_content, original_path) ? |err| WriteOriginalFailed(err)
345+
Path.write_utf8!(test_file_content, original_path) ? WriteOriginalFailed
346346

347347
# Rename the file
348348
when Path.rename!(original_path, new_path) is
@@ -357,12 +357,12 @@ test_path_rename! = |{}|
357357
else
358358
Stdout.line!("Original file no longer exists")?
359359
360-
new_file_exists = Path.is_file!(new_path) ? |err| NewIsFileFailed(err)
360+
new_file_exists = Path.is_file!(new_path) ? NewIsFileFailed
361361
362362
if new_file_exists then
363363
Stdout.line!("Renamed file exists")?
364364
365-
content = Path.read_utf8!(new_path) ? |err| NewFileReadFailed(err)
365+
content = Path.read_utf8!(new_path) ? NewFileReadFailed
366366
367367
if content == test_file_content then
368368
Stdout.line!("Renamed file has correct content")
@@ -382,7 +382,7 @@ test_path_exists! = |{}|
382382
filename = Path.from_str("test_path_exists.txt")
383383
Path.write_utf8!("This file exists", filename)?
384384
385-
file_exists = Path.exists!(filename) ? |err| PathExistsCheckFailed(err)
385+
file_exists = Path.exists!(filename) ? PathExistsCheckFailed
386386
387387
if file_exists then
388388
Stdout.line!("Path.exists! returns true for a file that exists")?
@@ -392,7 +392,7 @@ test_path_exists! = |{}|
392392
# Test that a file that does not exist returns false
393393
Path.delete!(filename)?
394394
395-
file_exists_after_delete = Path.exists!(filename) ? |err| PathExistsCheckAfterDeleteFailed(err)
395+
file_exists_after_delete = Path.exists!(filename) ? PathExistsCheckAfterDeleteFailed
396396
397397
if file_exists_after_delete then
398398
Stderr.line!("Path.exists! returned true for a file that does not exist")?
@@ -422,23 +422,23 @@ test_is_sym_link! = |{}|
422422
ln_dir_result = Cmd.new("ln") |> Cmd.args(["-s", "test_directory", "test_symlink_to_dir"]) |> Cmd.exec_output!()
423423
424424
# Test is_sym_link on regular file
425-
regular_is_symlink = Path.is_sym_link!(regular_file) ? |err| RegularFileSymlinkCheckFailed(err)
425+
regular_is_symlink = Path.is_sym_link!(regular_file) ? RegularFileSymlinkCheckFailed
426426
427427
# Test is_sym_link on directory
428-
dir_is_symlink = Path.is_sym_link!(test_dir) ? |err| DirSymlinkCheckFailed(err)
428+
dir_is_symlink = Path.is_sym_link!(test_dir) ? DirSymlinkCheckFailed
429429
430430
# Test is_sym_link on symbolic links (if creation succeeded)
431431
file_link_is_symlink =
432432
when ln_file_result is
433433
Ok(_) ->
434-
Path.is_sym_link!(link_to_file) ? |err| FileLinkSymlinkCheckFailed(err)
434+
Path.is_sym_link!(link_to_file) ? FileLinkSymlinkCheckFailed
435435
Err(_) ->
436436
Bool.false
437437
438438
dir_link_is_symlink =
439439
when ln_dir_result is
440440
Ok(_) ->
441-
Path.is_sym_link!(link_to_dir) ? |err| DirLinkSymlinkCheckFailed(err)
441+
Path.is_sym_link!(link_to_dir) ? DirLinkSymlinkCheckFailed
442442
Err(_) ->
443443
Bool.false
444444
@@ -480,16 +480,16 @@ test_path_type! = |{}|
480480
ln_result = Cmd.new("ln") |> Cmd.args(["-s", "test_type_file.txt", "test_type_symlink.txt"]) |> Cmd.exec_output!()
481481
482482
# Test type on regular file
483-
file_type = Path.type!(regular_file) ? |err| FileTypeCheckFailed(err)
483+
file_type = Path.type!(regular_file) ? FileTypeCheckFailed
484484
485485
# Test type on directory
486-
dir_type = Path.type!(test_dir) ? |err| DirTypeCheckFailed(err)
486+
dir_type = Path.type!(test_dir) ? DirTypeCheckFailed
487487
488488
# Test type on symbolic link (if creation succeeded)
489489
symlink_type =
490490
when ln_result is
491491
Ok(_) ->
492-
Path.type!(symlink_path) ? |err| SymlinkTypeCheckFailed(err)
492+
Path.type!(symlink_path) ? SymlinkTypeCheckFailed
493493
Err(_) ->
494494
IsFile
495495
@@ -542,7 +542,7 @@ cleanup_test_files! = |files_requirement|
542542
543543
when files_requirement is
544544
FilesNeedToExist ->
545-
delete_result ? |err| PathDeletionFailed(err)
545+
delete_result ? PathDeletionFailed
546546
FilesMaybeExist ->
547547
Ok({})?
548548

tests/sqlite-test.roc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ run_tests! = |{}|
5252
col_nullable_f64: Sqlite.nullable_f64("col_nullable_f64"),
5353
col_nullable_f32: Sqlite.nullable_f32("col_nullable_f32"),
5454
},
55-
}) ? |err| QuerManyFailed(err)
55+
}) ? QuerManyFailed
5656

5757
rows_texts_str =
5858
all_rows
@@ -68,7 +68,7 @@ run_tests! = |{}|
6868
query: "SELECT COUNT(*) as \"count\" FROM test;",
6969
bindings: [],
7070
row: Sqlite.u64("count"),
71-
}) ? |err| QueryCountFailed(err)
71+
}) ? QueryCountFailed
7272

7373

7474
Stdout.line!("Row count: ${Num.to_str(count)}")?
@@ -78,13 +78,13 @@ run_tests! = |{}|
7878
prepared_count_query = Sqlite.prepare!({
7979
path: db_path,
8080
query: "SELECT COUNT(*) as \"count\" FROM test;",
81-
}) ? |err| PrepareFailed(err)
81+
}) ? PrepareFailed
8282

8383
count_prepared = Sqlite.query_prepared!({
8484
stmt: prepared_count_query,
8585
bindings: [],
8686
row: Sqlite.u64("count"),
87-
}) ? |err| QueryPreparedFailed(err)
87+
}) ? QueryPreparedFailed
8888

8989

9090
Stdout.line!("Row count (prepared): ${Num.to_str(count_prepared)}")?
@@ -94,31 +94,31 @@ run_tests! = |{}|
9494
prepared_update = Sqlite.prepare!({
9595
path: db_path,
9696
query: "UPDATE test SET col_text = :col_text WHERE id = :id;",
97-
}) ? |err| PreparedUpdateFailed(err)
97+
}) ? PreparedUpdateFailed
9898

9999
Sqlite.execute_prepared!({
100100
stmt: prepared_update,
101101
bindings: [
102102
{ name: ":id", value: Integer(1) },
103103
{ name: ":col_text", value: String("Updated text 1") },
104104
],
105-
}) ? |err| ExecutePreparedFailed(err)
105+
}) ? ExecutePreparedFailed
106106

107107
Sqlite.execute_prepared!({
108108
stmt: prepared_update,
109109
bindings: [
110110
{ name: ":id", value: Integer(2) },
111111
{ name: ":col_text", value: String("Updated text 2") },
112112
],
113-
}) ? |err| ExecutePrepared2Failed(err)
113+
}) ? ExecutePrepared2Failed
114114

115115
# Check if the updates were successful
116116
updated_rows = Sqlite.query_many!({
117117
path: db_path,
118118
query: "SELECT COL_TEXT FROM test;",
119119
bindings: [],
120120
rows: Sqlite.str("col_text"),
121-
}) ? |err| QueryUpdatedRowsFailed(err)
121+
}) ? QueryUpdatedRowsFailed
122122

123123
Stdout.line!("Updated rows: ${Inspect.to_str(updated_rows)}")?
124124

@@ -129,15 +129,15 @@ run_tests! = |{}|
129129
{ name: ":id", value: Integer(1) },
130130
{ name: ":col_text", value: String("example text") },
131131
],
132-
}) ? |err| ExecutePrepared3Failed(err)
132+
}) ? ExecutePrepared3Failed
133133

134134
Sqlite.execute_prepared!({
135135
stmt: prepared_update,
136136
bindings: [
137137
{ name: ":id", value: Integer(2) },
138138
{ name: ":col_text", value: String("sample text") },
139139
],
140-
}) ? |err| ExecutePrepared4Failed(err)
140+
}) ? ExecutePrepared4Failed
141141

142142
# Test tagged_value
143143
tagged_value_test = Sqlite.query_many!({
@@ -146,7 +146,7 @@ run_tests! = |{}|
146146
bindings: [],
147147
# This uses the record builder syntax: https://www.roc-lang.org/examples/RecordBuilder/README.html
148148
rows: Sqlite.tagged_value("col_text"),
149-
}) ? |err| QueryMany2Failed(err)
149+
}) ? QueryMany2Failed
150150

151151
Stdout.line!("Tagged value test: ${Inspect.to_str(tagged_value_test)}")?
152152

tests/tcp.roc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ test_tcp_functions! = |stream|
6464
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
6565
Tcp.write!(stream, do_not_read_bytes)?
6666

67-
nineteen_bytes = Tcp.read_up_to!(stream, 19) ? |err| FailedReadUpTo(err)
68-
nineteen_bytes_as_str = Str.from_utf8(nineteen_bytes) ? |err| ReadUpToFromUtf8(err)
67+
nineteen_bytes = Tcp.read_up_to!(stream, 19) ? FailedReadUpTo
68+
nineteen_bytes_as_str = Str.from_utf8(nineteen_bytes) ? ReadUpToFromUtf8
6969

7070
Stdout.line!(
7171
"""
@@ -77,8 +77,8 @@ test_tcp_functions! = |stream|
7777
)?
7878
Tcp.write_utf8!(stream, "BC")?
7979

80-
three_bytes = Tcp.read_exactly!(stream, 3) ? |err| FailedReadExactly(err)
81-
three_bytes_as_str = Str.from_utf8(three_bytes) ? |err| ReadExactlyFromUtf8(err)
80+
three_bytes = Tcp.read_exactly!(stream, 3) ? FailedReadExactly
81+
three_bytes_as_str = Str.from_utf8(three_bytes) ? ReadExactlyFromUtf8
8282

8383
Stdout.line!(
8484
"""
@@ -90,8 +90,8 @@ test_tcp_functions! = |stream|
9090
)?
9191
Tcp.write_utf8!(stream, "Line1\nLine2\n")?
9292

93-
bytes_until = Tcp.read_until!(stream, '\n') ? |err| FailedReadUntil(err)
94-
bytes_until_as_str = Str.from_utf8(bytes_until) ? |err| ReadUntilFromUtf8(err)
93+
bytes_until = Tcp.read_until!(stream, '\n') ? FailedReadUntil
94+
bytes_until_as_str = Str.from_utf8(bytes_until) ? ReadUntilFromUtf8
9595

9696
Stdout.line!("Tcp.read_until yielded: '${bytes_until_as_str}'\n")?
9797

0 commit comments

Comments
 (0)