test(stable-api): add comprehensive edge-case parity tests#737
Merged
Conversation
Covers divergence vectors not exercised by the original suite:
- rstring_len: empty string, embedded NUL mid-string (len=7 not 3),
exact embed/heap boundary (23 vs 24 bytes), binary bytes, multibyte
UTF-8, frozen strings
- rstring_ptr/rstring_end: embedded vs heap, ptr+len == end invariant
- rarray_len/rarray_const_ptr: empty, embed max (3), first heap (4),
large (1000), special VALUE elements, nested arrays
- num2dbl: NaN (custom is_nan check since NaN!=NaN), -0.0 bit-exact
sign preservation, -Inf, negative flonum, subnormal, MIN_POSITIVE
- dbl2num: -0.0 roundtrip sign check, NaN roundtrip, -Inf roundtrip,
negative flonum
- rhash_size: exactly 8 (AR max), exactly 9 (ST threshold), after
delete, string keys, mixed keys, nested values
- rhash_empty_p: after deleting all entries
- encoding_get: BINARY, US-ASCII; UTF-8 vs BINARY differ assertion
- frozen_p: Symbol/Integer/Float (always frozen), nil/true/false,
mutable vs frozen String and Hash
- special_const_p: nil, true, false, fixnum 0, large fixnum, flonum
(immediate), heap Float (not immediate), Bignum, Array
- nil_p: false/0/""/[] all return false
- rb_test: nil/false falsy; 0/""/[]/{} all truthy (Ruby gotcha)
- type_p: correct and wrong type for String, Bignum, Float, Hash
- rbasic_class: String, Hash, Bignum, heap Float
- builtin_type: Bignum, heap Float, Regexp, Class, Module, Struct
- rstring_interned_p: dynamic (false) vs frozen literal (true)
- bignum_positive_p/negative_p: FIXNUM_MAX+1, FIXNUM_MIN-1, 2**128
- num2long/num2ulong: FIXNUM_MAX, FIXNUM_MIN (LP64 only)
d9973f8 to
22279e2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
What's covered
rstring_len"foo\x00bar"→ len=7), embed/heap boundary (23 vs 24 bytes), binary bytes, multibyte UTF-8, frozenrstring_ptr/rstring_endptr + len == endinvariantrarray_len/rarray_const_ptrnum2dblis_nan()—assert_eq!silently passes for NaN), −0.0 bit-exact sign, −Inf, subnormal, MIN_POSITIVEdbl2numrhash_sizeencoding_getfrozen_pspecial_const_pnil_p/rb_test"",[],{}are all truthy — common C/Java gotchatype_pbuiltin_typerstring_interned_pbignum_*num2long/num2ulongTest plan
cargo test -p rb-sys-tests)🤖 Generated with Claude Code