Add tests for formatParse
With one currently failing so you know they're worth it.weechat-hashes
parent
326bc5163d
commit
3cf064a531
|
@ -1,4 +1,5 @@
|
||||||
*.o
|
*.o
|
||||||
|
*.t
|
||||||
chatte
|
chatte
|
||||||
chroot.tar
|
chroot.tar
|
||||||
root
|
root
|
||||||
|
|
16
Makefile
16
Makefile
|
@ -24,15 +24,25 @@ OBJS += term.o
|
||||||
OBJS += ui.o
|
OBJS += ui.o
|
||||||
OBJS += url.o
|
OBJS += url.o
|
||||||
|
|
||||||
|
TESTS += format.t
|
||||||
|
|
||||||
all: tags chatte
|
all: tags chatte
|
||||||
|
|
||||||
|
tags: *.h *.c
|
||||||
|
ctags -w *.h *.c
|
||||||
|
|
||||||
chatte: $(OBJS)
|
chatte: $(OBJS)
|
||||||
$(CC) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $@
|
$(CC) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $@
|
||||||
|
|
||||||
$(OBJS): chat.h
|
$(OBJS): chat.h
|
||||||
|
|
||||||
tags: *.h *.c
|
test: $(TESTS)
|
||||||
ctags -w *.h *.c
|
$(TESTS:%=./%;)
|
||||||
|
|
||||||
|
.SUFFIXES: .t
|
||||||
|
|
||||||
|
.c.t:
|
||||||
|
$(CC) $(CFLAGS) -DTEST $(LDFLAGS) $< $(LDLIBS) -o $@
|
||||||
|
|
||||||
install: chatte chatte.1
|
install: chatte chatte.1
|
||||||
install -d $(PREFIX)/bin $(MANPATH)/man1
|
install -d $(PREFIX)/bin $(MANPATH)/man1
|
||||||
|
@ -77,4 +87,4 @@ chroot.tar: chatte chatte.1 man.sh
|
||||||
tar -c -f chroot.tar -C root bin etc home lib libexec usr
|
tar -c -f chroot.tar -C root bin etc home lib libexec usr
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf tags chatte $(OBJS) root chroot.tar
|
rm -rf tags chatte $(OBJS) $(TESTS) root chroot.tar
|
||||||
|
|
63
format.c
63
format.c
|
@ -117,3 +117,66 @@ bool formatParse(struct Format *format, const wchar_t *split) {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TEST
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
static bool testColor(
|
||||||
|
const wchar_t *str, enum IRCColor fg, enum IRCColor bg, size_t index
|
||||||
|
) {
|
||||||
|
struct Format format = { .str = str };
|
||||||
|
formatReset(&format);
|
||||||
|
if (!formatParse(&format, NULL)) return false;
|
||||||
|
if (format.fg != fg) return false;
|
||||||
|
if (format.bg != bg) return false;
|
||||||
|
return (format.str == &str[index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool testSplit(const wchar_t *str, size_t index) {
|
||||||
|
struct Format format = { .str = str };
|
||||||
|
formatReset(&format);
|
||||||
|
bool split = false;
|
||||||
|
while (formatParse(&format, &str[index])) {
|
||||||
|
if (format.split && split) return false;
|
||||||
|
if (format.split) split = true;
|
||||||
|
}
|
||||||
|
return split;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool testSplits(const wchar_t *str) {
|
||||||
|
for (size_t i = 0; i <= wcslen(str); ++i) {
|
||||||
|
if (!testSplit(str, i)) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
assert(testColor(L"\003a", IRCDefault, IRCDefault, 1));
|
||||||
|
assert(testColor(L"\003,a", IRCDefault, IRCDefault, 1));
|
||||||
|
assert(testColor(L"\003,1", IRCDefault, IRCDefault, 1));
|
||||||
|
assert(testColor(L"\0031a", IRCBlack, IRCDefault, 2));
|
||||||
|
assert(testColor(L"\0031,a", IRCBlack, IRCDefault, 2));
|
||||||
|
assert(testColor(L"\00312a", IRCLightBlue, IRCDefault, 3));
|
||||||
|
assert(testColor(L"\00312,a", IRCLightBlue, IRCDefault, 3));
|
||||||
|
assert(testColor(L"\003123", IRCLightBlue, IRCDefault, 3));
|
||||||
|
assert(testColor(L"\0031,1a", IRCBlack, IRCBlack, 4));
|
||||||
|
assert(testColor(L"\0031,12a", IRCBlack, IRCLightBlue, 5));
|
||||||
|
assert(testColor(L"\0031,123", IRCBlack, IRCLightBlue, 5));
|
||||||
|
assert(testColor(L"\00312,1a", IRCLightBlue, IRCBlack, 5));
|
||||||
|
assert(testColor(L"\00312,12a", IRCLightBlue, IRCLightBlue, 6));
|
||||||
|
assert(testColor(L"\00312,123", IRCLightBlue, IRCLightBlue, 6));
|
||||||
|
|
||||||
|
assert(testColor(L"\00316,16a", IRCDefault, IRCDefault, 6));
|
||||||
|
assert(testColor(L"\00399,99a", IRCDefault, IRCDefault, 6));
|
||||||
|
|
||||||
|
assert(testSplits(L"ab"));
|
||||||
|
assert(testSplits(L"\002ab"));
|
||||||
|
assert(testSplits(L"a\002b"));
|
||||||
|
assert(testSplits(L"a\002\003b"));
|
||||||
|
assert(testSplits(L"a\0031b"));
|
||||||
|
assert(testSplits(L"a\00312b"));
|
||||||
|
assert(testSplits(L"a\00312,1b"));
|
||||||
|
assert(testSplits(L"a\00312,12b"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue