CC = ./acc
INCS = -Iinc/
BINS = bin/tide bin/registrar bin/edit bin/fetch bin/pick
+TEST_BINS = tests/libedit
MAN1 = docs/tide.1
LIBEDIT_OBJS = \
src/lib/x11_gc.o \
src/lib/x11_sel.o
-TEST_BINS = tests/libedit tests/test_tide
-
include config.mk
.PHONY: all docs clean install uninstall test
#define EXPECT_EXIT \
if ((ExitExpected = true, 0 == setjmp(ExitPad)))
-#define QCHECK(desc, prop, ...) \
- CHECK(qcheck(desc, prop, __VA_ARGS__))
-
/* Function Definitions
*****************************************************************************/
#ifdef INCLUDE_DEFS
/**
- QCheck - A minimalistic property based testing framework.
+ QCheck - A minimal property-based testing framework.
Copyright 2019 Michael D. Lowis
#define QASSERT(cond) \
if (!(cond)) return 0
+#define QCHECK(desc, prop, ...) \
+ CHECK(qcheck(desc, prop, __VA_ARGS__))
+
+#ifndef CHECK
+#include <assert.h>
+#define CHECK assert
+#endif
+
static inline QCValue* qcgetval(int nvals, QCValue** vals, int i) {
return vals[i < nvals ? i : nvals-1];
}
#include <stdlib.h>
#include <stdio.h>
-static int Seed = 0, NTrials = 5000;
+static int Seed = 0, NTrials = 1000;
void qcinit(int seed) {
Seed = (seed ? seed : time(NULL));
int passed = 0;
QCResult result;
va_list vals;
+ #pragma omp parallel for
for (int i = 0; i < NTrials; i++) {
va_start(vals, nvals);
result = vqcheck(prop, nvals, vals);
return (IVAL(0) == buf_getc(&TestBuf));
}
+PROPERTY(getc_returns_error) {
+ setup_buffer();
+ buf_putc(&TestBuf, IVAL(0));
+ TestBuf.selection.end = TestBuf.selection.beg = 0;
+ printf("0x%08x\n", buf_getc(&TestBuf));
+ return (0xFFFD == buf_getc(&TestBuf));
+}
+
PROPERTY(gets_returns_puts) {
setup_buffer();
char* input = VAL(0,char*);
return 1;
}
+void show_codepoint(QCValue* val) {
+ char buf[UTF_MAX+1] = {0};
+ utf8encode(buf, val->data[0]);
+ printf("0x%08x (%s)\n", (int)(val->data[0]), buf);
+}
+
QCValue* GenCodepoint(void) {
- return GenLongR(0, 0x10FFFF);
+ long cp = 0;
+ do { cp = qcrandr(32,0x10FFFF); }
+ while (
+ (cp >= 0xD000 && cp <= 0xDFFF) ||
+ (cp >= 0xFDD0 && cp <= 0xFDEF) ||
+ ((cp & 0xFFFE) == 0xFFFE)
+ );
+ return MkLong(cp, show_codepoint);
}
TEST_SUITE(BufferTests) {
TEST(buf should adhere to specific properties) {
QCHECK("getc should return the same printable ascii value inserted with putc",
getc_returns_putc, 1, GenAsciiChar);
-// QCHECK("getc should return the same printable unicode value inserted with putc",
-// getc_returns_putc, 1, GenCodepoint);
QCHECK("gets should return the same printable ascii string inserted with puts",
gets_returns_puts, 1, GenAsciiString);
+ QCHECK("getc should return the same printable unicode value inserted with putc",
+ getc_returns_putc, 1, GenCodepoint);
QCHECK("edit operations should be reversible",
edit_operations_are_reversible, 1, GenAsciiString);
}
+++ /dev/null
-#define TEST
-#include "src/tide.c"
-
-#define INCLUDE_DEFS
-#include "qcheck.h"
-
-/************************************************/
-
-void tide_init(void) {
- if (!ShellCmd[0]) ShellCmd[0] = getenv("SHELL");
- if (!ShellCmd[0]) ShellCmd[0] = "/bin/sh";
- win_init(Bindings);
- view_init(&Regions[TAGS], NULL);
- view_init(&Regions[EDIT], NULL);
- view_putstr(win_view(TAGS), TagString);
- view_resize(win_view(TAGS), 640, 1);
- buf_logclear(win_buf(TAGS));
- win_prop_set("TIDE", "", "tide");
- xupdate(NULL);
-}
-
-/************************************************/
-
-int divisible_by_two(int nvals, QCValue** vals) {
- (void)nvals;
- return ((vals[0]->data[0] % 2) == 0);
-}
-
-int resizing_should_not_crash(int nvals, QCValue** vals) {
-// int pid = fork();
-// /* test the resize event */
-// if (pid == 0) {
-// XEvent e = {0};
-// e.xconfigure.width = vals[0]->data[0];
-// e.xconfigure.height = vals[1]->data[0];
-// tide_init();
-// (X.eventfns[ConfigureNotify])(&X, &e);
-// xupdate(NULL);
-// }
-// switch (fork()) {
-// case 0:
-// tide_init();
-// break;
-// default:
-// /* wait for pid to exit */
-// break;
-// }
- return ((void)vals, (void)nvals, 1);
-}
-
-int main(int argc, char** argv) {
- (void)usage;
-
- qcinit(argc >= 2 ? strtol(argv[1], 0, 0) : 0);
- qcheck("all numbers are divisible by 2", divisible_by_two, 1, GenLong);
-
- return 0;
-}