-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Just contains a couple of very simple UTF-8 tests for now.
- Loading branch information
Showing
5 changed files
with
154 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
tests = [ | ||
'utf8' | ||
] | ||
|
||
foreach test_file : tests | ||
t = executable( | ||
test_file, | ||
files(test_file + '.c', 'tap.c'), common_sources, wl_proto_src, wl_proto_headers, | ||
include_directories: ['../src'], | ||
dependencies: [librt, libm, freetype, harfbuzz, cairo, pangocairo, wayland_client, xkbcommon, glib, gio_unix], | ||
install: false | ||
) | ||
|
||
test(test_file, t, protocol: 'tap') | ||
endforeach |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <stdarg.h> | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
static size_t test = 0; | ||
static char *todo = NULL; | ||
|
||
void tap_version(size_t version) | ||
{ | ||
printf("TAP version %zu\n", version); | ||
} | ||
|
||
void tap_plan() | ||
{ | ||
printf("1..%zu\n", test); | ||
} | ||
|
||
void tap_ok(const char *message, ...) | ||
{ | ||
va_list args; | ||
va_start(args, message); | ||
printf("ok %zu - ", ++test); | ||
vprintf(message, args); | ||
if (todo != NULL) { | ||
printf(" # TODO %s", todo); | ||
free(todo); | ||
todo = NULL; | ||
} | ||
printf("\n"); | ||
va_end(args); | ||
} | ||
|
||
void tap_not_ok(const char *message, ...) | ||
{ | ||
va_list args; | ||
va_start(args, message); | ||
printf("not ok %zu - ", ++test); | ||
vprintf(message, args); | ||
if (todo != NULL) { | ||
printf(" # TODO %s", todo); | ||
free(todo); | ||
todo = NULL; | ||
} | ||
printf("\n"); | ||
va_end(args); | ||
} | ||
|
||
void tap_todo(const char *message) | ||
{ | ||
todo = strdup(message); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef TAP_H | ||
#define TAP_H | ||
|
||
#include <stddef.h> | ||
|
||
#define tap_is(a, b, message) ((a) == (b) ? tap_ok((message)) : tap_not_ok((message))) | ||
#define tap_isnt(a, b, message) ((a) != (b) ? tap_ok((message)) : tap_not_ok((message))) | ||
|
||
void tap_version(size_t version); | ||
void tap_plan(void); | ||
void tap_ok(const char *message, ...); | ||
void tap_not_ok(const char *message, ...); | ||
void tap_todo(const char *message); | ||
|
||
#endif /* TAP_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include <assert.h> | ||
#include <locale.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include "fuzzy_match.h" | ||
#include "tap.h" | ||
#include "utf8.h" | ||
|
||
void is_simple_match(const char *pattern, const char *str, const char *message) | ||
{ | ||
int32_t res = fuzzy_match_simple_words(pattern, str); | ||
tap_isnt(res, INT32_MIN, message); | ||
} | ||
|
||
void isnt_simple_match(const char *pattern, const char *str, const char *message) | ||
{ | ||
int32_t res = fuzzy_match_simple_words(pattern, str); | ||
tap_is(res, INT32_MIN, message); | ||
} | ||
|
||
void is_fuzzy_match(const char *pattern, const char *str, const char *message) | ||
{ | ||
int32_t res = fuzzy_match_words(pattern, str); | ||
tap_isnt(res, INT32_MIN, message); | ||
} | ||
|
||
void isnt_fuzzy_match(const char *pattern, const char *str, const char *message) | ||
{ | ||
int32_t res = fuzzy_match_words(pattern, str); | ||
tap_is(res, INT32_MIN, message); | ||
} | ||
|
||
void is_match(const char *pattern, const char *str, const char *message) | ||
{ | ||
is_simple_match(pattern, str, message); | ||
is_fuzzy_match(pattern, str, message); | ||
} | ||
|
||
void isnt_match(const char *pattern, const char *str, const char *message) | ||
{ | ||
isnt_simple_match(pattern, str, message); | ||
isnt_fuzzy_match(pattern, str, message); | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
setlocale(LC_ALL, ""); | ||
|
||
tap_version(14); | ||
|
||
/* Case insensitivity. */ | ||
is_match("o", "O", "Single Latin character, different case"); | ||
is_match("д", "Д", "Single Cyrillic character, different case"); | ||
is_match("ξ", "Ξ", "Single Greek character, different case"); | ||
is_match("o", "ọ", "Single character with decomposed diacritic"); | ||
|
||
/* Combining diacritics. */ | ||
isnt_match("o", "ọ", "Single character with composed diacritic"); | ||
isnt_simple_match("ạ", "aọ", "Decomposed diacritics, character mismatch"); | ||
tap_todo("Needs composed character comparison"); | ||
isnt_fuzzy_match("ạ", "aọ", "Decomposed diacritics, character mismatch"); | ||
|
||
tap_plan(); | ||
|
||
return EXIT_SUCCESS; | ||
} |