Skip to content

Commit 767066d

Browse files
JanWielemakerclaude
andcommitted
TEST: read_term/3 blob(resolve) matching on the blob address
A zipper writes the address of the blob data and is thus found on the address; a stream writes the address of its handle and takes the fallback. Either way the text must match exactly. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017dv8qG8JrSfiHguZaFbLAW
1 parent c4e4fcf commit 767066d

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

tests/core/test_blob.pl

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,63 @@
200200
),
201201
close(S)).
202202

203+
% A zipper writes the address of the
204+
% blob data, so it is found on that
205+
% address rather than by writing all
206+
% zippers. A stream (above) writes
207+
% the address of its handle and thus
208+
% takes the fallback.
209+
zipper(File, Zipper) :-
210+
tmp_file(zip, File),
211+
zip_open(File, write, Zipper, []).
212+
213+
close_zipper(File, Zipper) :-
214+
zip_close(Zipper),
215+
delete_file(File).
216+
217+
retype(Text, Type, NewText) :- % <zipper>(0x1) --> <Type>(0x1)
218+
once(sub_atom(Text, Before, _, _, '(')),
219+
sub_atom(Text, Before, _, 0, Args),
220+
format(atom(NewText), '<~w>~w', [Type, Args]).
221+
222+
add_arg(Text, NewText) :- % <zipper>(0x1) --> <zipper>(0x1,x)
223+
sub_atom(Text, 0, _, 1, Head),
224+
format(atom(NewText), '~w,x)', [Head]).
225+
226+
test(address, Z == Z2) :-
227+
setup_call_cleanup(
228+
zipper(File, Z),
229+
( written(Z, Text),
230+
read_resolve(Text, Z2)
231+
),
232+
close_zipper(File, Z)).
233+
234+
% The address only selects the
235+
% candidate: the blob must write
236+
% exactly as it was read.
237+
test(address_other_type, Type == no_such_blob_type) :-
238+
setup_call_cleanup(
239+
zipper(File, Z),
240+
( written(Z, Text),
241+
retype(Text, no_such_blob_type, Text2),
242+
read_resolve(Text2, B),
243+
blob(B, Type)
244+
),
245+
close_zipper(File, Z)).
246+
test(address_other_args) :-
247+
setup_call_cleanup(
248+
zipper(File, Z),
249+
( written(Z, Text),
250+
add_arg(Text, Text2),
251+
read_resolve(Text2, B),
252+
blob(B, zipper),
253+
B \== Z
254+
),
255+
close_zipper(File, Z)).
256+
test(null_address, Type == zipper) :-
257+
read_resolve('<zipper>(0x0)', B),
258+
blob(B, Type).
259+
203260
:- end_tests(blob_resolve).
204261

205262
:- begin_tests(blob_syntax).

0 commit comments

Comments
 (0)