Skip to content

Commit

Permalink
Merge pull request #11 from savi-lang/add/from-u32
Browse files Browse the repository at this point in the history
Add OSError.from_u32! function.
  • Loading branch information
jemc authored Jun 10, 2024
2 parents f43cf7c + 697290e commit 6dd9eb6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions spec/OSError.Spec.savi
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,12 @@
assert: OSError.eperm.description == "Operation not permitted"
assert: OSError[-1].description == "Unsupported error code for this platform"
assert: OSError[999].description == "Unknown error code 999"

:it "converts a U32 to an error code if it's a valid one"
assert: OSError.from_u32!(0) == OSError.success
assert: OSError.from_u32!(1) == OSError.eperm
assert error: OSError.from_u32!(999)

OSError.each_supported_in_platform -> (error |
assert: OSError.from_u32!(error.u32) == error
)
6 changes: 6 additions & 0 deletions src/OSError.savi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
:fun into_string(out String'ref): @name.into_string(out)
:fun into_string_space: @name.into_string_space

:fun non from_u32!(value U32) OSError
@each_supported_in_platform -> (error |
return error if error.u32 == value
)
error!

// Note: cross-platform numeric codes have been sourced from:
// <http://www.ioplex.com/~miallen/errcmp.html>

Expand Down

0 comments on commit 6dd9eb6

Please sign in to comment.