Skip to content

Commit

Permalink
Add ctest
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Mar 16, 2021
1 parent 1c8e410 commit 7a8deb3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions components/capi/ctest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a.out
25 changes: 25 additions & 0 deletions components/capi/ctest/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This file is part of ICU4X. For terms of use, please see the file
# called LICENSE at the top level of the ICU4X source tree
# (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

.DEFAULT_GOAL := test
.PHONY: build test

ALL_HEADERS := $(wildcard ../include/*.h)
ALL_RUST := $(wildcard ../src/*.rs)

$(ALL_RUST):

$(ALL_HEADERS):


../../../target/debug/libicu_capi.a: $(ALL_RUST)
cargo build

a.out: ../../../target/debug/libicu_capi.a $(ALL_HEADERS)
gcc test.c ../../../target/debug/libicu_capi.a -ldl -lpthread -lm

build: a.out

test: build
./a.out
40 changes: 40 additions & 0 deletions components/capi/ctest/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

#include "../include/pluralrules.h"
#include <string.h>
#include <stdio.h>

const char* path = "../../../resources/testdata/data/json/";
int main() {
Locale* locale = locale_create("ar", 2);
CreateDataProviderResult result = fs_data_provider_create(path, strlen(path));
if (!result.success) {
printf("Failed to create FsDataProvider\n");
return 1;
}
ErasedDataProvider provider = result.provider;
CreatePluralRulesResult plural_result = plural_rules_create(locale, &provider, PluralRuleType_Cardinal);
if (!plural_result.success) {
printf("Failed to create PluralRules\n");
return 1;
}
PluralRules* rules = plural_result.rules;

PluralOperands op;
op.i = 3;

PluralCategory cat = plural_rules_select(rules, &op);

printf("Plural Category %d (should be %d)\n", (int)cat, (int)PluralCategory_Few);

plural_rules_destroy(rules);
erased_data_provider_destroy(provider);
locale_destroy(locale);

if (cat != PluralCategory_Few) {
return 1;
}
return 0;
}

0 comments on commit 7a8deb3

Please sign in to comment.