From 02a6bde57fc492a82e52b51f5fab20d4f533dbf7 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 22 Dec 2025 06:02:22 +0000 Subject: [PATCH 1/3] Add unit tests for missing eldritch-core methods Added integration tests for: - dict.clear(), dict.pop(), dict.setdefault() - str.rsplit(), str.codepoints(), str.elems() - str.isalnum(), str.isalpha(), str.isdigit(), str.isspace() Verified via `cargo test -p eldritch-core`. --- .../eldritch-core/tests/missing_methods.rs | 157 ++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 implants/lib/eldritchv2/eldritch-core/tests/missing_methods.rs diff --git a/implants/lib/eldritchv2/eldritch-core/tests/missing_methods.rs b/implants/lib/eldritchv2/eldritch-core/tests/missing_methods.rs new file mode 100644 index 000000000..d318a0d11 --- /dev/null +++ b/implants/lib/eldritchv2/eldritch-core/tests/missing_methods.rs @@ -0,0 +1,157 @@ +mod assert; + +#[test] +fn test_dict_missing_methods() { + // Test clear() + assert::pass( + r#" + d = {"a": 1, "b": 2} + d.clear() + assert_eq(len(d), 0) + assert_eq(d, {}) + d.clear() # Should be fine on empty dict + assert_eq(len(d), 0) + "#, + ); + + // Test pop() + assert::pass( + r#" + d = {"a": 1, "b": 2} + val = d.pop("a") + assert_eq(val, 1) + assert_eq(d, {"b": 2}) + + # Pop with default + val = d.pop("z", 999) + assert_eq(val, 999) + assert_eq(d, {"b": 2}) # Should not modify + "#, + ); + + // Test pop() errors + assert::fail( + "d = {}; d.pop('a')", + "KeyError: a" + ); + assert::fail( + "d = {'a': 1}; d.pop()", + "TypeError: pop() takes between 1 and 2 arguments" + ); + + // Test setdefault() + assert::pass( + r#" + d = {"a": 1} + # Existing key + val = d.setdefault("a", 2) + assert_eq(val, 1) + assert_eq(d["a"], 1) + + # New key with default + val = d.setdefault("b", 2) + assert_eq(val, 2) + assert_eq(d["b"], 2) + + # New key without default (should be None) + val = d.setdefault("c") + assert_eq(val, None) + assert_eq(d["c"], None) + "#, + ); +} + +#[test] +fn test_string_missing_methods() { + // Test rsplit() + assert::pass( + r#" + # With explicit delimiter + s = "a,b,c" + l = s.rsplit(",") + assert_eq(l, ["a", "b", "c"]) + + s = "a,b,c" + # Note: current implementation of rsplit ignores maxsplit (arg 2) if passed, + # but the method signature doesn't even accept it currently in the match arm (impl uses args[0] only) + # We just test basic splitting behavior. + + # Default delimiter is space " " in current impl, not whitespace. + s = "a b c" + l = s.rsplit() + assert_eq(l, ["a", "b", "c"]) + "#, + ); + + // Test codepoints() + assert::pass( + r#" + s = "ABC" + l = s.codepoints() + # 65, 66, 67 + assert_eq(l, [65, 66, 67]) + + s = "€" # Euro sign + l = s.codepoints() + assert_eq(l, [8364]) + "#, + ); + + // Test elems() + assert::pass( + r#" + s = "abc" + l = s.elems() + assert_eq(l, ["a", "b", "c"]) + + s = "" + l = s.elems() + assert_eq(l, []) + "#, + ); +} + +#[test] +fn test_string_boolean_checks() { + // isalnum + assert::pass( + r#" + assert("abc".isalnum()) + assert("123".isalnum()) + assert("a1".isalnum()) + assert(not "!".isalnum()) + assert(not "".isalnum()) + "#, + ); + + // isalpha + assert::pass( + r#" + assert("abc".isalpha()) + assert(not "123".isalpha()) + assert(not "a1".isalpha()) + assert(not "".isalpha()) + "#, + ); + + // isdigit + assert::pass( + r#" + assert("123".isdigit()) + assert(not "12.3".isdigit()) + assert(not "a1".isdigit()) + assert(not "".isdigit()) + "#, + ); + + // isspace + assert::pass( + r#" + assert(" ".isspace()) + assert("\t".isspace()) + assert("\n".isspace()) + assert(not " a".isspace()) + assert(not "".isspace()) + "#, + ); +} From 6926a566806e52747fa09c5425c03b49d4e1d789 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 22 Dec 2025 06:19:41 +0000 Subject: [PATCH 2/3] Refactor missing method tests into logical files Moved dictionary tests to `collections.rs` and string tests to `strings.rs`. Deleted the temporary `missing_methods.rs` file. Verified via `cargo test -p eldritch-core`. --- .../eldritch-core/tests/collections.rs | 61 +++++++ .../eldritch-core/tests/missing_methods.rs | 157 ------------------ .../eldritchv2/eldritch-core/tests/strings.rs | 95 +++++++++++ 3 files changed, 156 insertions(+), 157 deletions(-) delete mode 100644 implants/lib/eldritchv2/eldritch-core/tests/missing_methods.rs diff --git a/implants/lib/eldritchv2/eldritch-core/tests/collections.rs b/implants/lib/eldritchv2/eldritch-core/tests/collections.rs index 6683b1b0f..bb1f593d8 100644 --- a/implants/lib/eldritchv2/eldritch-core/tests/collections.rs +++ b/implants/lib/eldritchv2/eldritch-core/tests/collections.rs @@ -112,6 +112,67 @@ fn test_dict_methods() { assert::fail("d={}; d.popitem()", "empty"); } +#[test] +fn test_dict_missing_methods() { + // Test clear() + assert::pass( + r#" + d = {"a": 1, "b": 2} + d.clear() + assert_eq(len(d), 0) + assert_eq(d, {}) + d.clear() # Should be fine on empty dict + assert_eq(len(d), 0) + "#, + ); + + // Test pop() + assert::pass( + r#" + d = {"a": 1, "b": 2} + val = d.pop("a") + assert_eq(val, 1) + assert_eq(d, {"b": 2}) + + # Pop with default + val = d.pop("z", 999) + assert_eq(val, 999) + assert_eq(d, {"b": 2}) # Should not modify + "#, + ); + + // Test pop() errors + assert::fail( + "d = {}; d.pop('a')", + "KeyError: a" + ); + assert::fail( + "d = {'a': 1}; d.pop()", + "TypeError: pop() takes between 1 and 2 arguments" + ); + + // Test setdefault() + assert::pass( + r#" + d = {"a": 1} + # Existing key + val = d.setdefault("a", 2) + assert_eq(val, 1) + assert_eq(d["a"], 1) + + # New key with default + val = d.setdefault("b", 2) + assert_eq(val, 2) + assert_eq(d["b"], 2) + + # New key without default (should be None) + val = d.setdefault("c") + assert_eq(val, None) + assert_eq(d["c"], None) + "#, + ); +} + #[test] fn test_sets() { assert::pass( diff --git a/implants/lib/eldritchv2/eldritch-core/tests/missing_methods.rs b/implants/lib/eldritchv2/eldritch-core/tests/missing_methods.rs deleted file mode 100644 index d318a0d11..000000000 --- a/implants/lib/eldritchv2/eldritch-core/tests/missing_methods.rs +++ /dev/null @@ -1,157 +0,0 @@ -mod assert; - -#[test] -fn test_dict_missing_methods() { - // Test clear() - assert::pass( - r#" - d = {"a": 1, "b": 2} - d.clear() - assert_eq(len(d), 0) - assert_eq(d, {}) - d.clear() # Should be fine on empty dict - assert_eq(len(d), 0) - "#, - ); - - // Test pop() - assert::pass( - r#" - d = {"a": 1, "b": 2} - val = d.pop("a") - assert_eq(val, 1) - assert_eq(d, {"b": 2}) - - # Pop with default - val = d.pop("z", 999) - assert_eq(val, 999) - assert_eq(d, {"b": 2}) # Should not modify - "#, - ); - - // Test pop() errors - assert::fail( - "d = {}; d.pop('a')", - "KeyError: a" - ); - assert::fail( - "d = {'a': 1}; d.pop()", - "TypeError: pop() takes between 1 and 2 arguments" - ); - - // Test setdefault() - assert::pass( - r#" - d = {"a": 1} - # Existing key - val = d.setdefault("a", 2) - assert_eq(val, 1) - assert_eq(d["a"], 1) - - # New key with default - val = d.setdefault("b", 2) - assert_eq(val, 2) - assert_eq(d["b"], 2) - - # New key without default (should be None) - val = d.setdefault("c") - assert_eq(val, None) - assert_eq(d["c"], None) - "#, - ); -} - -#[test] -fn test_string_missing_methods() { - // Test rsplit() - assert::pass( - r#" - # With explicit delimiter - s = "a,b,c" - l = s.rsplit(",") - assert_eq(l, ["a", "b", "c"]) - - s = "a,b,c" - # Note: current implementation of rsplit ignores maxsplit (arg 2) if passed, - # but the method signature doesn't even accept it currently in the match arm (impl uses args[0] only) - # We just test basic splitting behavior. - - # Default delimiter is space " " in current impl, not whitespace. - s = "a b c" - l = s.rsplit() - assert_eq(l, ["a", "b", "c"]) - "#, - ); - - // Test codepoints() - assert::pass( - r#" - s = "ABC" - l = s.codepoints() - # 65, 66, 67 - assert_eq(l, [65, 66, 67]) - - s = "€" # Euro sign - l = s.codepoints() - assert_eq(l, [8364]) - "#, - ); - - // Test elems() - assert::pass( - r#" - s = "abc" - l = s.elems() - assert_eq(l, ["a", "b", "c"]) - - s = "" - l = s.elems() - assert_eq(l, []) - "#, - ); -} - -#[test] -fn test_string_boolean_checks() { - // isalnum - assert::pass( - r#" - assert("abc".isalnum()) - assert("123".isalnum()) - assert("a1".isalnum()) - assert(not "!".isalnum()) - assert(not "".isalnum()) - "#, - ); - - // isalpha - assert::pass( - r#" - assert("abc".isalpha()) - assert(not "123".isalpha()) - assert(not "a1".isalpha()) - assert(not "".isalpha()) - "#, - ); - - // isdigit - assert::pass( - r#" - assert("123".isdigit()) - assert(not "12.3".isdigit()) - assert(not "a1".isdigit()) - assert(not "".isdigit()) - "#, - ); - - // isspace - assert::pass( - r#" - assert(" ".isspace()) - assert("\t".isspace()) - assert("\n".isspace()) - assert(not " a".isspace()) - assert(not "".isspace()) - "#, - ); -} diff --git a/implants/lib/eldritchv2/eldritch-core/tests/strings.rs b/implants/lib/eldritchv2/eldritch-core/tests/strings.rs index 0fdab780e..7bde5a352 100644 --- a/implants/lib/eldritchv2/eldritch-core/tests/strings.rs +++ b/implants/lib/eldritchv2/eldritch-core/tests/strings.rs @@ -11,6 +11,101 @@ fn test_string_literals() { ); } +#[test] +fn test_string_missing_methods() { + // Test rsplit() + assert::pass( + r#" + # With explicit delimiter + s = "a,b,c" + l = s.rsplit(",") + assert_eq(l, ["a", "b", "c"]) + + s = "a,b,c" + # Note: current implementation of rsplit ignores maxsplit (arg 2) if passed, + # but the method signature doesn't even accept it currently in the match arm (impl uses args[0] only) + # We just test basic splitting behavior. + + # Default delimiter is space " " in current impl, not whitespace. + s = "a b c" + l = s.rsplit() + assert_eq(l, ["a", "b", "c"]) + "#, + ); + + // Test codepoints() + assert::pass( + r#" + s = "ABC" + l = s.codepoints() + # 65, 66, 67 + assert_eq(l, [65, 66, 67]) + + s = "€" # Euro sign + l = s.codepoints() + assert_eq(l, [8364]) + "#, + ); + + // Test elems() + assert::pass( + r#" + s = "abc" + l = s.elems() + assert_eq(l, ["a", "b", "c"]) + + s = "" + l = s.elems() + assert_eq(l, []) + "#, + ); +} + +#[test] +fn test_string_boolean_checks() { + // isalnum + assert::pass( + r#" + assert("abc".isalnum()) + assert("123".isalnum()) + assert("a1".isalnum()) + assert(not "!".isalnum()) + assert(not "".isalnum()) + "#, + ); + + // isalpha + assert::pass( + r#" + assert("abc".isalpha()) + assert(not "123".isalpha()) + assert(not "a1".isalpha()) + assert(not "".isalpha()) + "#, + ); + + // isdigit + assert::pass( + r#" + assert("123".isdigit()) + assert(not "12.3".isdigit()) + assert(not "a1".isdigit()) + assert(not "".isdigit()) + "#, + ); + + // isspace + assert::pass( + r#" + assert(" ".isspace()) + assert("\t".isspace()) + assert("\n".isspace()) + assert(not " a".isspace()) + assert(not "".isspace()) + "#, + ); +} + #[test] fn test_f_strings() { assert::pass( From 417c14663aa423df2fdf1755e8703ee5a5adcead Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 22 Dec 2025 06:21:52 +0000 Subject: [PATCH 3/3] Rename missing method tests to be more descriptive Renamed: - `test_dict_missing_methods` -> `test_dict_clear_pop_setdefault` - `test_string_missing_methods` -> `test_string_rsplit_codepoints_elems` - `test_string_boolean_checks` -> `test_string_boolean_predicates` Verified via `cargo test -p eldritch-core`. --- implants/lib/eldritchv2/eldritch-core/tests/collections.rs | 2 +- implants/lib/eldritchv2/eldritch-core/tests/strings.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/implants/lib/eldritchv2/eldritch-core/tests/collections.rs b/implants/lib/eldritchv2/eldritch-core/tests/collections.rs index bb1f593d8..a28e9479e 100644 --- a/implants/lib/eldritchv2/eldritch-core/tests/collections.rs +++ b/implants/lib/eldritchv2/eldritch-core/tests/collections.rs @@ -113,7 +113,7 @@ fn test_dict_methods() { } #[test] -fn test_dict_missing_methods() { +fn test_dict_clear_pop_setdefault() { // Test clear() assert::pass( r#" diff --git a/implants/lib/eldritchv2/eldritch-core/tests/strings.rs b/implants/lib/eldritchv2/eldritch-core/tests/strings.rs index 7bde5a352..1c01f265d 100644 --- a/implants/lib/eldritchv2/eldritch-core/tests/strings.rs +++ b/implants/lib/eldritchv2/eldritch-core/tests/strings.rs @@ -12,7 +12,7 @@ fn test_string_literals() { } #[test] -fn test_string_missing_methods() { +fn test_string_rsplit_codepoints_elems() { // Test rsplit() assert::pass( r#" @@ -62,7 +62,7 @@ fn test_string_missing_methods() { } #[test] -fn test_string_boolean_checks() { +fn test_string_boolean_predicates() { // isalnum assert::pass( r#"