diff --git a/tests/test_functions.cpp b/tests/test_functions.cpp index 0bc645d1..83a9ae96 100644 --- a/tests/test_functions.cpp +++ b/tests/test_functions.cpp @@ -254,6 +254,9 @@ NB_MODULE(test_functions_ext, m) { m.def("test_19", [](nb::int_ i) { return i + nb::int_(123); }); m.def("test_20", [](nb::str s) { return nb::int_(s) + nb::int_(123); }); m.def("test_21", [](nb::int_ i) { return (int) i; }); + m.def("test_21_f", [](nb::float_ f) { return nb::int_(f); }); + m.def("test_21_g", []() { return nb::int_(1.5); }); + m.def("test_21_h", []() { return nb::int_(1e50); }); // Test capsule wrapper m.def("test_22", []() -> void * { return (void*) 1; }); diff --git a/tests/test_functions.py b/tests/test_functions.py index 377ab86e..832657bc 100644 --- a/tests/test_functions.py +++ b/tests/test_functions.py @@ -280,6 +280,13 @@ def test25_int(): assert t.test_19(5) == 128 assert t.test_20("5") == 128 assert t.test_21(5) == 5 + assert t.test_21_f(5.1) == int(5.1) + assert t.test_21_f(1e50) == int(1e50) + assert type(t.test_21_f(0.5)) is int + assert t.test_21_g() == int(1.5) + assert type(t.test_21_g()) is int + assert t.test_21_h() == int(1e50) + assert type(t.test_21_h()) is int assert t.test_19.__doc__ == "test_19(arg: int, /) -> object" diff --git a/tests/test_functions_ext.pyi.ref b/tests/test_functions_ext.pyi.ref index 05d5fe50..3a025ba1 100644 --- a/tests/test_functions_ext.pyi.ref +++ b/tests/test_functions_ext.pyi.ref @@ -120,6 +120,12 @@ def test_20(arg: str, /) -> object: ... def test_21(arg: int, /) -> int: ... +def test_21_f(arg: float, /) -> int: ... + +def test_21_g() -> int: ... + +def test_21_h() -> int: ... + def test_22() -> types.CapsuleType: ... def test_23() -> types.CapsuleType: ...