summaryrefslogtreecommitdiff
path: root/test/utf8.c
blob: 5d75cb65d6740d011119f0bbd4a0b3980140038c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <assert.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "matching.h"
#include "tap.h"

void is_single_match(enum matching_algorithm algorithm, const char *pattern, const char *str, const char *message)
{
	int32_t res = match_words(algorithm, pattern, str);
	tap_isnt(res, INT32_MIN, message);
}

void isnt_single_match(enum matching_algorithm algorithm, const char *pattern, const char *str, const char *message)
{
	int32_t res = match_words(algorithm, pattern, str);
	tap_is(res, INT32_MIN, message);
}

void is_match(const char *pattern, const char *str, const char *message)
{
	is_single_match(MATCHING_ALGORITHM_NORMAL, pattern, str, message);
	is_single_match(MATCHING_ALGORITHM_PREFIX, pattern, str, message);
	is_single_match(MATCHING_ALGORITHM_FUZZY, pattern, str, message);
}

void isnt_match(const char *pattern, const char *str, const char *message)
{
	isnt_single_match(MATCHING_ALGORITHM_NORMAL, pattern, str, message);
	isnt_single_match(MATCHING_ALGORITHM_PREFIX, pattern, str, message);
	isnt_single_match(MATCHING_ALGORITHM_FUZZY, 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_single_match(MATCHING_ALGORITHM_NORMAL, "ạ", "aọ", "Decomposed diacritics, character mismatch");
	tap_todo("Needs composed character comparison");
	isnt_single_match(MATCHING_ALGORITHM_FUZZY, "ạ", "aọ", "Decomposed diacritics, character mismatch");

	tap_plan();

	return EXIT_SUCCESS;
}