Skip to content

Commit

Permalink
Update ffi tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Dec 11, 2024
1 parent 455c052 commit c47874f
Show file tree
Hide file tree
Showing 25 changed files with 130 additions and 161 deletions.
2 changes: 1 addition & 1 deletion ffi/dart/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ environment:
dependencies:
ffi: ^2.0.0
native_assets_cli: ^0.4.2
meta: ^1.12.0
meta: ^1.16.0

dev_dependencies:
lints: ^3.0.0
Expand Down
8 changes: 4 additions & 4 deletions ffi/dart/test/icu_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void main() {
});

test('LocaleFallbacker', () {
final iterator = LocaleFallbacker(DataProvider.compiled())
final iterator = LocaleFallbacker()
.forConfig(LocaleFallbackConfig(priority: LocaleFallbackPriority.region))
.fallbackForLocale(Locale.fromString('de-CH-u-ca-japanese'));
expect(iterator.moveNext(), true);
Expand All @@ -24,17 +24,17 @@ void main() {
Rune a = 'a'.runes.first;
Rune emoji = '💡'.runes.first;

final emojiSet = CodePointSetData.emoji(DataProvider.compiled());
final emojiSet = CodePointSetData.emoji();
expect(emojiSet.contains(a), false);
expect(emojiSet.contains(emoji), true);

Rune upperA = CaseMapper(DataProvider.compiled()).simpleUppercase(a);
Rune upperA = CaseMapper().simpleUppercase(a);
expect(String.fromCharCode(upperA), 'A');
});

test('ListFormatter', () {
final formatter = ListFormatter.andWithLength(
DataProvider.compiled(), Locale.fromString('es'), ListLength.wide);
Locale.fromString('es'), ListLength.wide);
final list = ['España', 'Francia', 'Suiza', 'Italia'];

expect(formatter.format(list), 'España, Francia, Suiza e Italia');
Expand Down
19 changes: 11 additions & 8 deletions tutorials/c-tiny/fixeddecimal/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions tutorials/c-tiny/segmenter/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions tutorials/c-tiny/segmenter/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@
#include <stdio.h>

int main(int argc, char *argv[]) {
icu4x_LineSegmenter_create_auto_mv1_result segmenter_result = icu4x_LineSegmenter_create_auto_mv1();
if (!segmenter_result.is_ok) {
printf("Failed to create icu4x_LineSegmenter_mv1\n");
return 1;
}
LineSegmenter* segmenter = segmenter_result.ok;
LineSegmenter* segmenter = icu4x_LineSegmenter_create_auto_mv1();


char output[40];
DiplomatWrite write = diplomat_simple_write(output, 40);
Expand Down
19 changes: 11 additions & 8 deletions tutorials/c/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions tutorials/c/fixeddecimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ int main() {
return 1;
}
Locale* locale = locale_result.ok;
DataProvider* provider = icu4x_DataProvider_compiled_mv1();

SignedFixedDecimal* decimal = icu4x_SignedFixedDecimal_from_uint64_mv1(1000007);

FixedDecimalGroupingStrategy_option o = {.ok = FixedDecimalGroupingStrategy_Auto, .is_ok = true};

icu4x_FixedDecimalFormatter_create_with_grouping_strategy_mv1_result fdf_result =
icu4x_FixedDecimalFormatter_create_with_grouping_strategy_mv1(provider, locale, o);
icu4x_FixedDecimalFormatter_create_with_grouping_strategy_mv1(locale, o);
if (!fdf_result.is_ok) {
printf("Failed to create FixedDecimalFormatter\n");
return 1;
Expand Down Expand Up @@ -103,7 +102,6 @@ int main() {
icu4x_SignedFixedDecimal_destroy_mv1(decimal);
icu4x_FixedDecimalFormatter_destroy_mv1(fdf);
icu4x_Locale_destroy_mv1(locale);
icu4x_DataProvider_destroy_mv1(provider);

return 0;
}
17 changes: 4 additions & 13 deletions tutorials/c/locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,19 +241,10 @@ int main() {
icu4x_Locale_destroy_mv1(locale);

// Create a LocaleCanonicalizer and LocaleExpander.
DataProvider* provider = icu4x_DataProvider_compiled_mv1();
icu4x_LocaleCanonicalizer_create_mv1_result result2 = icu4x_LocaleCanonicalizer_create_mv1(provider);
if (!result2.is_ok) {
printf("Could not construct Locale Canonicalizer");
return 1;
}
LocaleCanonicalizer* lc = result2.ok;
icu4x_LocaleExpander_create_mv1_result result3 = icu4x_LocaleExpander_create_mv1(provider);
if (!result3.is_ok) {
printf("Could not construct Locale Canonicalizer");
return 1;
}
LocaleExpander* le = result3.ok;
LocaleCanonicalizer* lc = icu4x_LocaleCanonicalizer_create_mv1();

LocaleExpander* le = icu4x_LocaleExpander_create_mv1();


// Test maximize.
write = diplomat_simple_write(output, 40);
Expand Down
4 changes: 1 addition & 3 deletions tutorials/c/pluralrules.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ int main() {
return 1;
}
Locale* locale = locale_result.ok;
DataProvider* provider = icu4x_DataProvider_compiled_mv1();
icu4x_PluralRules_create_cardinal_mv1_result plural_result = icu4x_PluralRules_create_cardinal_mv1(provider, locale);
icu4x_PluralRules_create_cardinal_mv1_result plural_result = icu4x_PluralRules_create_cardinal_mv1(locale);
if (!plural_result.is_ok) {
printf("Failed to create PluralRules\n");
return 1;
Expand Down Expand Up @@ -68,7 +67,6 @@ int main() {
printf("Plural Category %d (should be %d)\n", (int)cat2, (int)PluralCategory_Many);

icu4x_PluralRules_destroy_mv1(rules);
icu4x_DataProvider_destroy_mv1(provider);
icu4x_Locale_destroy_mv1(locale);

if (!categories.zero) { return 1; }
Expand Down
19 changes: 11 additions & 8 deletions tutorials/cpp/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions tutorials/cpp/bidi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

#include <icu4x/DataProvider.hpp>
#include <icu4x/Bidi.hpp>
#include <icu4x/Logger.hpp>

Expand All @@ -11,8 +10,7 @@
using namespace icu4x;

int main() {
std::unique_ptr<DataProvider> dp = DataProvider::compiled();
std::unique_ptr<Bidi> bidi = Bidi::create(*dp.get()).ok().value();
std::unique_ptr<Bidi> bidi = Bidi::create();

// Written char-by-char to avoid messing up certain text editors.
std::string_view str =
Expand Down
4 changes: 1 addition & 3 deletions tutorials/cpp/casemapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include <icu4x/CaseMapper.hpp>
#include <icu4x/Logger.hpp>
#include <icu4x/DataProvider.hpp>
#include <icu4x/CodePointSetBuilder.hpp>
#include <icu4x/TitlecaseOptionsV1.hpp>

Expand All @@ -17,9 +16,8 @@ int main() {
std::unique_ptr<Locale> und = Locale::from_string("und").ok().value();
std::unique_ptr<Locale> greek = Locale::from_string("el").ok().value();
std::unique_ptr<Locale> turkish = Locale::from_string("tr").ok().value();
std::unique_ptr<DataProvider> dp = DataProvider::compiled();

std::unique_ptr<CaseMapper> cm = CaseMapper::create(*dp.get()).ok().value();
std::unique_ptr<CaseMapper> cm = CaseMapper::create();

TitlecaseOptionsV1 tc_options = TitlecaseOptionsV1::default_options();

Expand Down
Loading

0 comments on commit c47874f

Please sign in to comment.