From 52b31846e442da6d2243defe39cd988568dd93ba Mon Sep 17 00:00:00 2001 From: Joel Croteau Date: Wed, 19 Feb 2014 23:18:31 -0800 Subject: Formatting fix and add test --- AUTHORS | 1 + src/library.js | 24 ++++++++++++------------ tests/test_core.py | 4 ++++ tests/test_locale.c | 24 ++++++++++++++++++++++++ tests/test_locale.out | 12 ++++++++++++ 5 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 tests/test_locale.c create mode 100644 tests/test_locale.out diff --git a/AUTHORS b/AUTHORS index 39f41407..6c6b3f27 100644 --- a/AUTHORS +++ b/AUTHORS @@ -125,3 +125,4 @@ a license to everyone to use it as detailed in LICENSE.) * Sami Vaarala * Jack A. Arrington * Richard Janicek +* Joel Croteau diff --git a/src/library.js b/src/library.js index 9f5a7dd7..340384e7 100644 --- a/src/library.js +++ b/src/library.js @@ -6444,18 +6444,18 @@ LibraryManager.library = { var me = _localeconv; if (!me.ret) { // These are defaults from the "C" locale - me.ret = allocate( - [allocate(intArrayFromString('.'), 'i8', ALLOC_NORMAL),0,0,0, // decimal_point - allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),0,0,0, // thousands_sep - allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),0,0,0, // grouping - allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),0,0,0, // int_curr_symbol - allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),0,0,0, // currency_symbol - allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),0,0,0, // mon_decimal_point - allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),0,0,0, // mon_thousands_sep - allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),0,0,0, // mon_grouping - allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),0,0,0, // positive_sign - allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),0,0,0], // negative_sign - 'i8*', ALLOC_NORMAL); // Allocate strings in lconv, still don't allocate chars + me.ret = allocate([ + allocate(intArrayFromString('.'), 'i8', ALLOC_NORMAL),0,0,0, // decimal_point + allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),0,0,0, // thousands_sep + allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),0,0,0, // grouping + allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),0,0,0, // int_curr_symbol + allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),0,0,0, // currency_symbol + allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),0,0,0, // mon_decimal_point + allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),0,0,0, // mon_thousands_sep + allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),0,0,0, // mon_grouping + allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),0,0,0, // positive_sign + allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),0,0,0 // negative_sign + ], 'i8*', ALLOC_NORMAL); // Allocate strings in lconv, still don't allocate chars } return me.ret; }, diff --git a/tests/test_core.py b/tests/test_core.py index e598655d..1a22bab3 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -6402,6 +6402,10 @@ def process(filename): if os.environ.get('EMCC_FAST_COMPILER') != '1': return self.skip('this test will not pass in the old compiler') self.do_run(open(path_from_root('tests', 'test_minmax.c')).read(), 'NAN != NAN\nSuccess!') + def test_locale(self): + if self.emcc_args is None: return self.skip('needs emcc') + self.do_run_from_file(path_from_root('tests', 'test_locale.c'), path_from_root('tests', 'test_locale.out')) + # Generate tests for everything def make_run(fullname, name=-1, compiler=-1, embetter=0, quantum_size=0, typed_arrays=0, emcc_args=None, env=None): diff --git a/tests/test_locale.c b/tests/test_locale.c new file mode 100644 index 00000000..4aba30db --- /dev/null +++ b/tests/test_locale.c @@ -0,0 +1,24 @@ +#include +#include + +int main() +{ + // Test basic functions from classic locale. + struct lconv* locale = localeconv(); + + printf("Testing locale information.\n"); + printf("Decimal point: %s\n", locale->decimal_point); + printf("Thousands separator: %s\n", locale->thousands_sep); + printf("Grouping: %s\n", locale->grouping); + printf("International currency symbol: %s\n", locale->int_curr_symbol); + printf("Currency symbol: %s\n", locale->currency_symbol); + printf("Money decimal point: %s\n", locale->mon_decimal_point); + printf("Money thousands separator: %s\n", locale->mon_thousands_sep); + printf("Money Grouping: %s\n", locale->mon_grouping); + printf("Positive sign: %s\n", locale->positive_sign); + printf("Negative sign: %s\n", locale->negative_sign); + + // If no runtime errors, assume the test passed. + printf("Locale tests passed.\n"); + return 0; +} diff --git a/tests/test_locale.out b/tests/test_locale.out new file mode 100644 index 00000000..7e8740fb --- /dev/null +++ b/tests/test_locale.out @@ -0,0 +1,12 @@ +Testing locale information. +Decimal point: . +Thousands separator: +Grouping: +International currency symbol: +Currency symbol: +Money decimal point: +Money thousands separator: +Money Grouping: +Positive sign: +Negative sign: +Locale tests passed. -- cgit v1.2.3-18-g5258