Skip to content

Commit

Permalink
Fix all pre-commit
Browse files Browse the repository at this point in the history
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
  • Loading branch information
gabrieldemarmiesse committed May 12, 2024
1 parent fe2adb6 commit f27b43a
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
12 changes: 12 additions & 0 deletions stdlib/src/os/env.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ fn setenv(name: String, value: String, overwrite: Bool = True) -> Bool:


fn getenv(name: String) -> String:
"""Returns the value of the given environment variable.
Constraints:
The function only works on macOS or Linux and returns an empty string
otherwise. The default is an empty string.
Args:
name: The name of the environment variable.
Returns:
The value of the environment variable.
"""
return getenv(name, "")


Expand Down
5 changes: 5 additions & 0 deletions stdlib/src/os/os.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ struct _DirHandle:
# listdir
# ===----------------------------------------------------------------------=== #
fn listdir() raises -> List[String]:
"""Gets the list of entries contained in the empty path.
Returns:
Returns the list of entries in the path provided.
"""
return listdir("")


Expand Down
92 changes: 92 additions & 0 deletions stdlib/src/testing/testing.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ fn _assert_error[T: Stringable](msg: T, loc: _SourceLocation) -> String:

@always_inline
fn assert_true(val: Bool) raises:
"""Asserts that the input value is True. If it is not then an
Error is raised.
Args:
val: The value to assert to be True.
Raises:
An Error with the provided message if assert fails and `None` otherwise.
"""
if not val:
raise _assert_error(
"condition was unexpectedly False", __call_location()
Expand All @@ -97,6 +106,15 @@ fn assert_true(val: Bool, msg: String) raises:

@always_inline
fn assert_false(val: Bool) raises:
"""Asserts that the input value is False. If it is not then an Error is
raised.
Args:
val: The value to assert to be False.
Raises:
An Error with the provided message if assert fails and `None` otherwise.
"""
if val:
raise _assert_error(
"condition was unexpectedly True", __call_location()
Expand Down Expand Up @@ -128,6 +146,19 @@ trait Testable(EqualityComparable, Stringable):

@always_inline
fn assert_equal[T: Testable](lhs: T, rhs: T) raises:
"""Asserts that the input values are equal. If it is not then an Error
is raised.
Parameters:
T: A Testable type.
Args:
lhs: The lhs of the equality.
rhs: The rhs of the equality.
Raises:
An Error with the provided message if assert fails and `None` otherwise.
"""
if lhs != rhs:
raise _assert_equal_error(str(lhs), str(rhs), "", __call_location())

Expand All @@ -154,6 +185,16 @@ fn assert_equal[T: Testable](lhs: T, rhs: T, msg: String) raises:

@always_inline
fn assert_equal(lhs: String, rhs: String) raises:
"""Asserts that the input values are equal. If it is not then an Error
is raised.
Args:
lhs: The lhs of the equality.
rhs: The rhs of the equality.
Raises:
An Error with the provided message if assert fails and `None` otherwise.
"""
assert_equal(lhs, rhs, "")


Expand All @@ -179,6 +220,20 @@ fn assert_equal(lhs: String, rhs: String, msg: String) raises:
fn assert_equal[
type: DType, size: Int
](lhs: SIMD[type, size], rhs: SIMD[type, size]) raises:
"""Asserts that the input values are equal. If it is not then an
Error is raised.
Parameters:
type: The dtype of the left- and right-hand-side SIMD vectors.
size: The width of the left- and right-hand-side SIMD vectors.
Args:
lhs: The lhs of the equality.
rhs: The rhs of the equality.
Raises:
An Error with the provided message if assert fails and `None` otherwise.
"""
assert_equal(lhs, rhs, "")


Expand Down Expand Up @@ -209,6 +264,19 @@ fn assert_equal[

@always_inline("nodebug")
fn assert_not_equal[T: Testable](lhs: T, rhs: T) raises:
"""Asserts that the input values are not equal. If it is not then an
Error is raised.
Parameters:
T: A Testable type.
Args:
lhs: The lhs of the inequality.
rhs: The rhs of the inequality.
Raises:
An Error with the provided message if assert fails and `None` otherwise.
"""
assert_not_equal(lhs, rhs, "")


Expand Down Expand Up @@ -236,6 +304,16 @@ fn assert_not_equal[T: Testable](lhs: T, rhs: T, msg: String) raises:

@always_inline("nodebug")
fn assert_not_equal(lhs: String, rhs: String) raises:
"""Asserts that the input values are not equal. If it is not then an
an Error is raised.
Args:
lhs: The lhs of the inequality.
rhs: The rhs of the inequality.
Raises:
An Error with the provided message if assert fails and `None` otherwise.
"""
assert_not_equal(lhs, rhs, "")


Expand All @@ -260,6 +338,20 @@ fn assert_not_equal(lhs: String, rhs: String, msg: String) raises:
fn assert_not_equal[
type: DType, size: Int
](lhs: SIMD[type, size], rhs: SIMD[type, size]) raises:
"""Asserts that the input values are not equal. If it is not then an
Error is raised.
Parameters:
type: The dtype of the left- and right-hand-side SIMD vectors.
size: The width of the left- and right-hand-side SIMD vectors.
Args:
lhs: The lhs of the inequality.
rhs: The rhs of the inequality.
Raises:
An Error with the provided message if assert fails and `None` otherwise.
"""
assert_not_equal(lhs, rhs, "")


Expand Down
1 change: 1 addition & 0 deletions stdlib/test/builtin/test_hash.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def test_hash_string_struct():
assert_not_equal(hash(a), hash(c))
assert_not_equal(hash(b), hash(c))


def main():
test_hash_byte_array()
test_hash_simd()
Expand Down

0 comments on commit f27b43a

Please sign in to comment.