vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 315f69e604e5d33b113c8cd971dcd872999da53b
parent b2608da7db1a17b26a1ba094882b1ae9343b2caa
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Wed, 13 May 2020 10:11:02 +0200

test/core: add basic save/load tests involving links

Diffstat:
Mcore/text-test.c | 22++++++++++++++++++++++
1 file changed, 22 insertions(+), 0 deletions(-)

diff --git a/core/text-test.c b/core/text-test.c @@ -96,6 +96,7 @@ int main(int argc, char *argv[]) { skip_if(TIS_INTERPRETER, 2, "I/O related") { const char *filename = "data"; + unlink(filename); enum TextLoadMethod load_method[] = { TEXT_LOAD_AUTO, @@ -142,6 +143,27 @@ int main(int argc, char *argv[]) { ok(txt && compare(txt, buf), "Verify save (method %zu)", i); text_free(txt); } + + int (*creation[])(const char*, const char*) = { symlink, link }; + const char *names[] = { "symlink", "hardlink" }; + + for (size_t i = 0; i < LENGTH(names); i++) { + const char *linkname = names[i]; + unlink(linkname); + ok(creation[i](filename, linkname) == 0, "%s creation", names[i]); + + snprintf(buf, sizeof buf, "%s\n", names[i]); + txt = text_load(NULL); + ok(txt && insert(txt, 0, buf) && compare(txt, buf), "Preparing %s content", names[i]); + ok(txt && text_save(txt, linkname), "Text save %s", names[i]); + text_free(txt); + + txt = text_load(linkname); + ok(txt && compare(txt, buf), "Load %s", names[i]); + + ok(txt && !text_save_method(txt, linkname, TEXT_SAVE_ATOMIC), "Text save %s atomic", names[i]); + text_free(txt); + } } txt = text_load(NULL);