zuzu-rust 0.6.0

Rust implementation of ZuzuScript
Documentation
from test/more import *;

requires_capability( "fs" );

from std/io import Path;

function make_tempfile_path () {
	let file := Path.tempfile();
	let path := file.to_String();
	ok( file.exists(), "tempfile exists while owner is in scope", );
	file.spew_utf8("temporary");
	return path;
}

function make_tempdir_path () {
	let dir := Path.tempdir();
	let path := dir.to_String();
	let child := dir.child("nested").child("payload.txt");
	child.parent().mkdir();
	child.spew_utf8("temporary");
	ok( child.exists(), "tempdir child exists while owner is in scope", );
	return path;
}

function make_tempfile () {
	let file := Path.tempfile();
	file.spew_utf8("temporary");
	return file;
}

function make_tempdir () {
	let dir := Path.tempdir();
	let child := dir.child("nested").child("payload.txt");
	child.parent().mkdir();
	child.spew_utf8("temporary");
	return dir;
}

function make_tempdir_record () {
	let dir := Path.tempdir();
	let child := dir.child("nested").child("payload.txt");
	child.parent().mkdir();
	child.spew_utf8("temporary");
	return {
		dir_obj: dir,
		child_obj: child,
		path: dir.to_String(),
	};
}

function hold_tempdir_record () {
	let record := make_tempdir_record();
	ok(
		record{child_obj}.exists(),
		"returned tempdir in dict is alive while caller keeps the dict",
	);
	return record{path};
}

let tempfile_path := make_tempfile_path();
is(
	(new Path(tempfile_path)).exists(),
	0,
	"tempfile is deleted when owner leaves scope",
);

let tempdir_path := make_tempdir_path();
is(
	(new Path(tempdir_path)).exists(),
	0,
	"tempdir is recursively deleted when owner leaves scope",
);

let returned_file := make_tempfile();
let returned_file_path := returned_file.to_String();
ok(
	returned_file.exists(),
	"returned tempfile is not deleted while caller keeps a reference",
);
returned_file.remove();

let returned_dir := make_tempdir();
let returned_dir_path := returned_dir.to_String();
ok(
	returned_dir.child("nested").child("payload.txt").exists(),
	"returned tempdir is not deleted while caller keeps a reference",
);
returned_dir.remove_tree();

let returned_record_path := hold_tempdir_record();
is(
	(new Path(returned_record_path)).exists(),
	0,
	"returned tempdir in dict is deleted when dict owner leaves scope",
);

done_testing();