module scheme import arena fn crs_check(condition bool, message string) { if !condition { panic(message) } } fn test_raw_initial_cohorts_use_anchor_identity_even_when_contents_are_equal() { mut a := &CustomRawAnchor{} mut b := &CustomRawAnchor{} x := custom_initial_raw_point(a, 0) or { panic(err.msg()) } y := custom_initial_raw_point(b, 0) or { panic(err.msg()) } crs_check(!x.same_origin(y), 'distinct unresolved initial anchors aliased') a.resolve(integer(100)) or { panic(err.msg()) } b.resolve(integer(100)) or { panic(err.msg()) } crs_check(!x.same_origin(y), 'distinct resolved initial anchors aliased') crs_check(x.same(x) && y.same(y), 'same anchor identity lost') } fn test_raw_symbolic_coordinates_prove_relative_identity_without_inventing_absolute_positions() { mut cohorts := CustomRawCohorts{} first := cohorts.next() second := CustomRawPoint{ ...first, offset: 2 } third := cohorts.next() crs_check(second.same_origin(first) && second.delta(first) == 2, 'same-publication offsets') crs_check(!third.same_origin(first) && !third.same(first), 'different publications aliased') retreated := second.retreat(1) or { panic(err.msg()) } crs_check(retreated.delta(first) == 1, 'symbolic retreat') for point in [first, second, third, retreated] { if _ := point.absolute() { panic('cohort ID became an absolute source position') } } mut anchor := cohorts.anchor if _ := anchor.resolve(integer(0)) { panic('symbolic origin was resolved as position zero') } if _ := custom_initial_raw_point(anchor, 0) { panic('symbolic anchor accepted as initial resolvable origin') } mut ordinary := &CustomRawAnchor{} if _ := custom_symbolic_raw_point(ordinary, 1, 0) { panic('ordinary initial anchor accepted as symbolic') } ordinary.resolve(integer(100)) or { panic(err.msg()) } resolved := custom_initial_raw_point(ordinary, 2) or { panic(err.msg()) } crs_check((resolved.absolute() or { panic(err.msg()) }).whole() == 102, 'ordinary origin resolution changed') } fn test_raw_symbolic_cohort_counter_rotation_keeps_old_captures_distinct() { mut cohorts := CustomRawCohorts{} old := cohorts.next() cohorts.serial = u64(max_i64) - 1 last := cohorts.next() crs_check(last.origin.whole() == max_i64 && voidptr(last.initial) == voidptr(old.initial), 'last inline ID') rotated := cohorts.next() crs_check(rotated.origin.whole() == 1 && voidptr(rotated.initial) != voidptr(old.initial), 'cohort anchor did not rotate') crs_check(!rotated.same_origin(old), 'old captured ID aliased after rotation') crs_check(old.same(old) && !old.same(last), 'older captures changed') if _ := rotated.absolute() { panic('rotated symbolic origin materialized') } } fn test_raw_symbolic_map_distinguishes_unread_and_unobserved_ignored_tail_from_physical_cursor() { mut cohorts := CustomRawCohorts{} publication := cohorts.next() physical := CustomRawPoint{ ...publication, offset: 2 } mut history := TranscodedBoundaries[CustomRawPoint]{} history.reset(publication) history.append(1, CustomRawPoint{ ...publication, offset: 1 }) visible := history.at(1) or { panic(err.msg()) } crs_check(!visible.same(physical), 'unread raw suffix lost') if _ := visible.absolute() { panic('unknown absolute rewind target invented') } history.append(1, physical) crs_check((history.at(2) or { panic(err.msg()) }).same(physical), 'consumed input cannot prove no rewind needed') // Ignored suffix advances the decoder physically, but does not move the // last visible endpoint until an error or EOF is actually observed. history.reset(publication) history.append(1, CustomRawPoint{ ...publication, offset: 1 }) crs_check(!(history.at(1) or { panic(err.msg()) }).same(physical), 'ignored suffix committed before observation') history.commit(physical) crs_check((history.at(1) or { panic(err.msg()) }).same(physical), 'observed EOF did not commit symbolic frontier') } fn test_raw_symbolic_publications_do_not_allocate_per_callback_after_warmup() { mut region := arena.new() region.push() defer { region.pop() region.free() } mut cohorts := CustomRawCohorts{} first := cohorts.next() before := region.used() for _ in 0 .. 10000 { point := cohorts.next() crs_check(!point.same_origin(first) && voidptr(point.initial) == voidptr(first.initial), 'symbolic publication identity') } crs_check(region.used() == before, 'per-callback symbolic allocation') }