diff --git a/packages/common/src/i18n/locale_data_api.ts b/packages/common/src/i18n/locale_data_api.ts index 072add5903..7c8ab3c5c9 100644 --- a/packages/common/src/i18n/locale_data_api.ts +++ b/packages/common/src/i18n/locale_data_api.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {ɵLocaleDataIndex as LocaleDataIndex, ɵfindLocaleData as findLocaleData, ɵgetLocalePluralCase} from '@angular/core'; +import {ɵLocaleDataIndex, ɵfindLocaleData, ɵgetLocalePluralCase} from '@angular/core'; import {CURRENCIES_EN, CurrenciesSymbols} from './currencies'; import {CurrencyIndex, ExtraLocaleDataIndex} from './locale_data'; @@ -217,7 +217,7 @@ export enum WeekDay { * @publicApi */ export function getLocaleId(locale: string): string { - return findLocaleData(locale)[LocaleDataIndex.LocaleId]; + return ɵfindLocaleData(locale)[ɵLocaleDataIndex.LocaleId]; } /** @@ -233,10 +233,10 @@ export function getLocaleId(locale: string): string { */ export function getLocaleDayPeriods( locale: string, formStyle: FormStyle, width: TranslationWidth): [string, string] { - const data = findLocaleData(locale); + const data = ɵfindLocaleData(locale); const amPmData = <[ string, string - ][][]>[data[LocaleDataIndex.DayPeriodsFormat], data[LocaleDataIndex.DayPeriodsStandalone]]; + ][][]>[data[ɵLocaleDataIndex.DayPeriodsFormat], data[ɵLocaleDataIndex.DayPeriodsStandalone]]; const amPm = getLastDefinedValue(amPmData, formStyle); return getLastDefinedValue(amPm, width); } @@ -255,9 +255,9 @@ export function getLocaleDayPeriods( */ export function getLocaleDayNames( locale: string, formStyle: FormStyle, width: TranslationWidth): string[] { - const data = findLocaleData(locale); + const data = ɵfindLocaleData(locale); const daysData = - [data[LocaleDataIndex.DaysFormat], data[LocaleDataIndex.DaysStandalone]]; + [data[ɵLocaleDataIndex.DaysFormat], data[ɵLocaleDataIndex.DaysStandalone]]; const days = getLastDefinedValue(daysData, formStyle); return getLastDefinedValue(days, width); } @@ -276,9 +276,9 @@ export function getLocaleDayNames( */ export function getLocaleMonthNames( locale: string, formStyle: FormStyle, width: TranslationWidth): string[] { - const data = findLocaleData(locale); + const data = ɵfindLocaleData(locale); const monthsData = - [data[LocaleDataIndex.MonthsFormat], data[LocaleDataIndex.MonthsStandalone]]; + [data[ɵLocaleDataIndex.MonthsFormat], data[ɵLocaleDataIndex.MonthsStandalone]]; const months = getLastDefinedValue(monthsData, formStyle); return getLastDefinedValue(months, width); } @@ -296,8 +296,8 @@ export function getLocaleMonthNames( * @publicApi */ export function getLocaleEraNames(locale: string, width: TranslationWidth): [string, string] { - const data = findLocaleData(locale); - const erasData = <[string, string][]>data[LocaleDataIndex.Eras]; + const data = ɵfindLocaleData(locale); + const erasData = <[string, string][]>data[ɵLocaleDataIndex.Eras]; return getLastDefinedValue(erasData, width); } @@ -313,8 +313,8 @@ export function getLocaleEraNames(locale: string, width: TranslationWidth): [str * @publicApi */ export function getLocaleFirstDayOfWeek(locale: string): WeekDay { - const data = findLocaleData(locale); - return data[LocaleDataIndex.FirstDayOfWeek]; + const data = ɵfindLocaleData(locale); + return data[ɵLocaleDataIndex.FirstDayOfWeek]; } /** @@ -327,8 +327,8 @@ export function getLocaleFirstDayOfWeek(locale: string): WeekDay { * @publicApi */ export function getLocaleWeekEndRange(locale: string): [WeekDay, WeekDay] { - const data = findLocaleData(locale); - return data[LocaleDataIndex.WeekendRange]; + const data = ɵfindLocaleData(locale); + return data[ɵLocaleDataIndex.WeekendRange]; } /** @@ -343,8 +343,8 @@ export function getLocaleWeekEndRange(locale: string): [WeekDay, WeekDay] { * @publicApi */ export function getLocaleDateFormat(locale: string, width: FormatWidth): string { - const data = findLocaleData(locale); - return getLastDefinedValue(data[LocaleDataIndex.DateFormat], width); + const data = ɵfindLocaleData(locale); + return getLastDefinedValue(data[ɵLocaleDataIndex.DateFormat], width); } /** @@ -359,8 +359,8 @@ export function getLocaleDateFormat(locale: string, width: FormatWidth): string * @publicApi */ export function getLocaleTimeFormat(locale: string, width: FormatWidth): string { - const data = findLocaleData(locale); - return getLastDefinedValue(data[LocaleDataIndex.TimeFormat], width); + const data = ɵfindLocaleData(locale); + return getLastDefinedValue(data[ɵLocaleDataIndex.TimeFormat], width); } /** @@ -375,8 +375,8 @@ export function getLocaleTimeFormat(locale: string, width: FormatWidth): string * @publicApi */ export function getLocaleDateTimeFormat(locale: string, width: FormatWidth): string { - const data = findLocaleData(locale); - const dateTimeFormatData = data[LocaleDataIndex.DateTimeFormat]; + const data = ɵfindLocaleData(locale); + const dateTimeFormatData = data[ɵLocaleDataIndex.DateTimeFormat]; return getLastDefinedValue(dateTimeFormatData, width); } @@ -391,13 +391,13 @@ export function getLocaleDateTimeFormat(locale: string, width: FormatWidth): str * @publicApi */ export function getLocaleNumberSymbol(locale: string, symbol: NumberSymbol): string { - const data = findLocaleData(locale); - const res = data[LocaleDataIndex.NumberSymbols][symbol]; + const data = ɵfindLocaleData(locale); + const res = data[ɵLocaleDataIndex.NumberSymbols][symbol]; if (typeof res === 'undefined') { if (symbol === NumberSymbol.CurrencyDecimal) { - return data[LocaleDataIndex.NumberSymbols][NumberSymbol.Decimal]; + return data[ɵLocaleDataIndex.NumberSymbols][NumberSymbol.Decimal]; } else if (symbol === NumberSymbol.CurrencyGroup) { - return data[LocaleDataIndex.NumberSymbols][NumberSymbol.Group]; + return data[ɵLocaleDataIndex.NumberSymbols][NumberSymbol.Group]; } } return res; @@ -439,8 +439,8 @@ export function getLocaleNumberSymbol(locale: string, symbol: NumberSymbol): str * @publicApi */ export function getLocaleNumberFormat(locale: string, type: NumberFormatStyle): string { - const data = findLocaleData(locale); - return data[LocaleDataIndex.NumberFormats][type]; + const data = ɵfindLocaleData(locale); + return data[ɵLocaleDataIndex.NumberFormats][type]; } /** @@ -455,8 +455,8 @@ export function getLocaleNumberFormat(locale: string, type: NumberFormatStyle): * @publicApi */ export function getLocaleCurrencySymbol(locale: string): string|null { - const data = findLocaleData(locale); - return data[LocaleDataIndex.CurrencySymbol] || null; + const data = ɵfindLocaleData(locale); + return data[ɵLocaleDataIndex.CurrencySymbol] || null; } /** @@ -470,8 +470,8 @@ export function getLocaleCurrencySymbol(locale: string): string|null { * @publicApi */ export function getLocaleCurrencyName(locale: string): string|null { - const data = findLocaleData(locale); - return data[LocaleDataIndex.CurrencyName] || null; + const data = ɵfindLocaleData(locale); + return data[ɵLocaleDataIndex.CurrencyName] || null; } /** @@ -481,8 +481,8 @@ export function getLocaleCurrencyName(locale: string): string|null { * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) */ function getLocaleCurrencies(locale: string): {[code: string]: CurrenciesSymbols} { - const data = findLocaleData(locale); - return data[LocaleDataIndex.Currencies]; + const data = ɵfindLocaleData(locale); + return data[ɵLocaleDataIndex.Currencies]; } /** @@ -493,9 +493,9 @@ export const getLocalePluralCase: (locale: string) => ((value: number) => Plural ɵgetLocalePluralCase; function checkFullData(data: any) { - if (!data[LocaleDataIndex.ExtraData]) { + if (!data[ɵLocaleDataIndex.ExtraData]) { throw new Error( - `Missing extra locale data for the locale "${data[LocaleDataIndex.LocaleId]}". Use "registerLocaleData" to load new data. See the "I18n guide" on angular.io to know more.`); + `Missing extra locale data for the locale "${data[ɵLocaleDataIndex.LocaleId]}". Use "registerLocaleData" to load new data. See the "I18n guide" on angular.io to know more.`); } } @@ -522,9 +522,9 @@ function checkFullData(data: any) { * @publicApi */ export function getLocaleExtraDayPeriodRules(locale: string): (Time | [Time, Time])[] { - const data = findLocaleData(locale); + const data = ɵfindLocaleData(locale); checkFullData(data); - const rules = data[LocaleDataIndex.ExtraData][ExtraLocaleDataIndex.ExtraDayPeriodsRules] || []; + const rules = data[ɵLocaleDataIndex.ExtraData][ExtraLocaleDataIndex.ExtraDayPeriodsRules] || []; return rules.map((rule: string | [string, string]) => { if (typeof rule === 'string') { return extractTime(rule); @@ -552,11 +552,11 @@ export function getLocaleExtraDayPeriodRules(locale: string): (Time | [Time, Tim */ export function getLocaleExtraDayPeriods( locale: string, formStyle: FormStyle, width: TranslationWidth): string[] { - const data = findLocaleData(locale); + const data = ɵfindLocaleData(locale); checkFullData(data); const dayPeriodsData = [ - data[LocaleDataIndex.ExtraData][ExtraLocaleDataIndex.ExtraDayPeriodFormats], - data[LocaleDataIndex.ExtraData][ExtraLocaleDataIndex.ExtraDayPeriodStandalone] + data[ɵLocaleDataIndex.ExtraData][ExtraLocaleDataIndex.ExtraDayPeriodFormats], + data[ɵLocaleDataIndex.ExtraData][ExtraLocaleDataIndex.ExtraDayPeriodStandalone] ]; const dayPeriods = getLastDefinedValue(dayPeriodsData, formStyle) || []; return getLastDefinedValue(dayPeriods, width) || []; diff --git a/packages/common/test/i18n/format_date_spec.ts b/packages/common/test/i18n/format_date_spec.ts index 085f81375a..6da8c504c7 100644 --- a/packages/common/test/i18n/format_date_spec.ts +++ b/packages/common/test/i18n/format_date_spec.ts @@ -15,7 +15,7 @@ import localeHu from '@angular/common/locales/hu'; import localeSr from '@angular/common/locales/sr'; import localeTh from '@angular/common/locales/th'; import {isDate, toDate, formatDate} from '@angular/common/src/i18n/format_date'; -import {ɵDEFAULT_LOCALE_ID as DEFAULT_LOCALE_ID} from '@angular/core'; +import {ɵDEFAULT_LOCALE_ID} from '@angular/core'; describe('Format date', () => { describe('toDate', () => { @@ -52,7 +52,8 @@ describe('Format date', () => { // Check the transformation of a date into a pattern function expectDateFormatAs(date: Date | string, pattern: any, output: string): void { - expect(formatDate(date, pattern, DEFAULT_LOCALE_ID)).toEqual(output, `pattern: "${pattern}"`); + expect(formatDate(date, pattern, ɵDEFAULT_LOCALE_ID)) + .toEqual(output, `pattern: "${pattern}"`); } beforeAll(() => { @@ -209,7 +210,7 @@ describe('Format date', () => { }; Object.keys(dateFixtures).forEach((pattern: string) => { - expect(formatDate(date, pattern, DEFAULT_LOCALE_ID, '+0430')) + expect(formatDate(date, pattern, ɵDEFAULT_LOCALE_ID, '+0430')) .toMatch(dateFixtures[pattern]); }); }); @@ -254,22 +255,22 @@ describe('Format date', () => { }; Object.keys(dateFixtures).forEach((pattern: string) => { - expect(formatDate(date, pattern, DEFAULT_LOCALE_ID)).toMatch(dateFixtures[pattern]); + expect(formatDate(date, pattern, ɵDEFAULT_LOCALE_ID)).toMatch(dateFixtures[pattern]); }); }); it('should format invalid in IE ISO date', - () => expect(formatDate('2017-01-11T12:00:00.014-0500', defaultFormat, DEFAULT_LOCALE_ID)) + () => expect(formatDate('2017-01-11T12:00:00.014-0500', defaultFormat, ɵDEFAULT_LOCALE_ID)) .toEqual('Jan 11, 2017')); it('should format invalid in Safari ISO date', - () => expect(formatDate('2017-01-20T12:00:00+0000', defaultFormat, DEFAULT_LOCALE_ID)) + () => expect(formatDate('2017-01-20T12:00:00+0000', defaultFormat, ɵDEFAULT_LOCALE_ID)) .toEqual('Jan 20, 2017')); // https://github.com/angular/angular/issues/9524 // https://github.com/angular/angular/issues/9524 it('should format correctly with iso strings that contain time', - () => expect(formatDate('2017-05-07T22:14:39', 'dd-MM-yyyy HH:mm', DEFAULT_LOCALE_ID)) + () => expect(formatDate('2017-05-07T22:14:39', 'dd-MM-yyyy HH:mm', ɵDEFAULT_LOCALE_ID)) .toMatch(/07-05-2017 \d{2}:\d{2}/)); // https://github.com/angular/angular/issues/21491 @@ -277,22 +278,22 @@ describe('Format date', () => { // this test only works if the timezone is not in UTC // which is the case for BrowserStack when we test Safari if (new Date().getTimezoneOffset() !== 0) { - expect(formatDate('2018-01-11T13:00:00', 'HH', DEFAULT_LOCALE_ID)) - .not.toEqual(formatDate('2018-01-11T13:00:00Z', 'HH', DEFAULT_LOCALE_ID)); + expect(formatDate('2018-01-11T13:00:00', 'HH', ɵDEFAULT_LOCALE_ID)) + .not.toEqual(formatDate('2018-01-11T13:00:00Z', 'HH', ɵDEFAULT_LOCALE_ID)); } }); // https://github.com/angular/angular/issues/16624 // https://github.com/angular/angular/issues/17478 it('should show the correct time when the timezone is fixed', () => { - expect(formatDate('2017-06-13T10:14:39+0000', 'shortTime', DEFAULT_LOCALE_ID, '+0000')) + expect(formatDate('2017-06-13T10:14:39+0000', 'shortTime', ɵDEFAULT_LOCALE_ID, '+0000')) .toEqual('10:14 AM'); - expect(formatDate('2017-06-13T10:14:39+0000', 'h:mm a', DEFAULT_LOCALE_ID, '+0000')) + expect(formatDate('2017-06-13T10:14:39+0000', 'h:mm a', ɵDEFAULT_LOCALE_ID, '+0000')) .toEqual('10:14 AM'); }); it('should remove bidi control characters', - () => expect(formatDate(date, 'MM/dd/yyyy', DEFAULT_LOCALE_ID) !.length).toEqual(10)); + () => expect(formatDate(date, 'MM/dd/yyyy', ɵDEFAULT_LOCALE_ID) !.length).toEqual(10)); it(`should format the date correctly in various locales`, () => { expect(formatDate(date, 'short', 'de')).toEqual('15.06.15, 09:03'); diff --git a/packages/common/test/i18n/format_number_spec.ts b/packages/common/test/i18n/format_number_spec.ts index 9a8bd07b99..faba94d4ea 100644 --- a/packages/common/test/i18n/format_number_spec.ts +++ b/packages/common/test/i18n/format_number_spec.ts @@ -12,7 +12,7 @@ import localeFr from '@angular/common/locales/fr'; import localeAr from '@angular/common/locales/ar'; import {formatCurrency, formatNumber, formatPercent, registerLocaleData} from '@angular/common'; import {describe, expect, it} from '@angular/core/testing/src/testing_internal'; -import {ɵDEFAULT_LOCALE_ID as DEFAULT_LOCALE_ID} from '@angular/core'; +import {ɵDEFAULT_LOCALE_ID} from '@angular/core'; describe('Format number', () => { beforeAll(() => { @@ -25,18 +25,18 @@ describe('Format number', () => { describe('Number', () => { describe('transform', () => { it('should return correct value for numbers', () => { - expect(formatNumber(12345, DEFAULT_LOCALE_ID)).toEqual('12,345'); - expect(formatNumber(123, DEFAULT_LOCALE_ID, '.2')).toEqual('123.00'); - expect(formatNumber(1, DEFAULT_LOCALE_ID, '3.')).toEqual('001'); - expect(formatNumber(1.1, DEFAULT_LOCALE_ID, '3.4-5')).toEqual('001.1000'); - expect(formatNumber(1.123456, DEFAULT_LOCALE_ID, '3.4-5')).toEqual('001.12346'); - expect(formatNumber(1.1234, DEFAULT_LOCALE_ID)).toEqual('1.123'); - expect(formatNumber(1.123456, DEFAULT_LOCALE_ID, '.2')).toEqual('1.123'); - expect(formatNumber(1.123456, DEFAULT_LOCALE_ID, '.4')).toEqual('1.1235'); + expect(formatNumber(12345, ɵDEFAULT_LOCALE_ID)).toEqual('12,345'); + expect(formatNumber(123, ɵDEFAULT_LOCALE_ID, '.2')).toEqual('123.00'); + expect(formatNumber(1, ɵDEFAULT_LOCALE_ID, '3.')).toEqual('001'); + expect(formatNumber(1.1, ɵDEFAULT_LOCALE_ID, '3.4-5')).toEqual('001.1000'); + expect(formatNumber(1.123456, ɵDEFAULT_LOCALE_ID, '3.4-5')).toEqual('001.12346'); + expect(formatNumber(1.1234, ɵDEFAULT_LOCALE_ID)).toEqual('1.123'); + expect(formatNumber(1.123456, ɵDEFAULT_LOCALE_ID, '.2')).toEqual('1.123'); + expect(formatNumber(1.123456, ɵDEFAULT_LOCALE_ID, '.4')).toEqual('1.1235'); }); it('should throw if minFractionDigits is explicitly higher than maxFractionDigits', () => { - expect(() => formatNumber(1.1, DEFAULT_LOCALE_ID, '3.4-2')) + expect(() => formatNumber(1.1, ɵDEFAULT_LOCALE_ID, '3.4-2')) .toThrowError(/is higher than the maximum/); }); }); @@ -50,27 +50,27 @@ describe('Format number', () => { describe('Percent', () => { describe('transform', () => { it('should return correct value for numbers', () => { - expect(formatPercent(1.23, DEFAULT_LOCALE_ID)).toEqual('123%'); - expect(formatPercent(1.2, DEFAULT_LOCALE_ID, '.2')).toEqual('120.00%'); - expect(formatPercent(1.2, DEFAULT_LOCALE_ID, '4.2')).toEqual('0,120.00%'); + expect(formatPercent(1.23, ɵDEFAULT_LOCALE_ID)).toEqual('123%'); + expect(formatPercent(1.2, ɵDEFAULT_LOCALE_ID, '.2')).toEqual('120.00%'); + expect(formatPercent(1.2, ɵDEFAULT_LOCALE_ID, '4.2')).toEqual('0,120.00%'); expect(formatPercent(1.2, 'fr', '4.2')).toEqual('0 120,00 %'); expect(formatPercent(1.2, 'ar', '4.2')).toEqual('0,120.00‎%‎'); // see issue #20136 - expect(formatPercent(0.12345674, DEFAULT_LOCALE_ID, '0.0-10')).toEqual('12.345674%'); - expect(formatPercent(0, DEFAULT_LOCALE_ID, '0.0-10')).toEqual('0%'); - expect(formatPercent(0.00, DEFAULT_LOCALE_ID, '0.0-10')).toEqual('0%'); - expect(formatPercent(1, DEFAULT_LOCALE_ID, '0.0-10')).toEqual('100%'); - expect(formatPercent(0.1, DEFAULT_LOCALE_ID, '0.0-10')).toEqual('10%'); - expect(formatPercent(0.12, DEFAULT_LOCALE_ID, '0.0-10')).toEqual('12%'); - expect(formatPercent(0.123, DEFAULT_LOCALE_ID, '0.0-10')).toEqual('12.3%'); - expect(formatPercent(12.3456, DEFAULT_LOCALE_ID, '0.0-10')).toEqual('1,234.56%'); - expect(formatPercent(12.345600, DEFAULT_LOCALE_ID, '0.0-10')).toEqual('1,234.56%'); - expect(formatPercent(12.345699999, DEFAULT_LOCALE_ID, '0.0-6')).toEqual('1,234.57%'); - expect(formatPercent(12.345699999, DEFAULT_LOCALE_ID, '0.4-6')).toEqual('1,234.5700%'); - expect(formatPercent(100, DEFAULT_LOCALE_ID, '0.4-6')).toEqual('10,000.0000%'); - expect(formatPercent(100, DEFAULT_LOCALE_ID, '0.0-10')).toEqual('10,000%'); - expect(formatPercent(1.5e2, DEFAULT_LOCALE_ID)).toEqual('15,000%'); - expect(formatPercent(1e100, DEFAULT_LOCALE_ID)).toEqual('1E+102%'); + expect(formatPercent(0.12345674, ɵDEFAULT_LOCALE_ID, '0.0-10')).toEqual('12.345674%'); + expect(formatPercent(0, ɵDEFAULT_LOCALE_ID, '0.0-10')).toEqual('0%'); + expect(formatPercent(0.00, ɵDEFAULT_LOCALE_ID, '0.0-10')).toEqual('0%'); + expect(formatPercent(1, ɵDEFAULT_LOCALE_ID, '0.0-10')).toEqual('100%'); + expect(formatPercent(0.1, ɵDEFAULT_LOCALE_ID, '0.0-10')).toEqual('10%'); + expect(formatPercent(0.12, ɵDEFAULT_LOCALE_ID, '0.0-10')).toEqual('12%'); + expect(formatPercent(0.123, ɵDEFAULT_LOCALE_ID, '0.0-10')).toEqual('12.3%'); + expect(formatPercent(12.3456, ɵDEFAULT_LOCALE_ID, '0.0-10')).toEqual('1,234.56%'); + expect(formatPercent(12.345600, ɵDEFAULT_LOCALE_ID, '0.0-10')).toEqual('1,234.56%'); + expect(formatPercent(12.345699999, ɵDEFAULT_LOCALE_ID, '0.0-6')).toEqual('1,234.57%'); + expect(formatPercent(12.345699999, ɵDEFAULT_LOCALE_ID, '0.4-6')).toEqual('1,234.5700%'); + expect(formatPercent(100, ɵDEFAULT_LOCALE_ID, '0.4-6')).toEqual('10,000.0000%'); + expect(formatPercent(100, ɵDEFAULT_LOCALE_ID, '0.0-10')).toEqual('10,000%'); + expect(formatPercent(1.5e2, ɵDEFAULT_LOCALE_ID)).toEqual('15,000%'); + expect(formatPercent(1e100, ɵDEFAULT_LOCALE_ID)).toEqual('1E+102%'); }); }); }); @@ -79,16 +79,16 @@ describe('Format number', () => { const defaultCurrencyCode = 'USD'; describe('transform', () => { it('should return correct value for numbers', () => { - expect(formatCurrency(123, DEFAULT_LOCALE_ID, '$')).toEqual('$123.00'); - expect(formatCurrency(12, DEFAULT_LOCALE_ID, 'EUR', 'EUR', '.1')).toEqual('EUR12.0'); + expect(formatCurrency(123, ɵDEFAULT_LOCALE_ID, '$')).toEqual('$123.00'); + expect(formatCurrency(12, ɵDEFAULT_LOCALE_ID, 'EUR', 'EUR', '.1')).toEqual('EUR12.0'); expect(formatCurrency( - 5.1234, DEFAULT_LOCALE_ID, defaultCurrencyCode, defaultCurrencyCode, '.0-3')) + 5.1234, ɵDEFAULT_LOCALE_ID, defaultCurrencyCode, defaultCurrencyCode, '.0-3')) .toEqual('USD5.123'); - expect(formatCurrency(5.1234, DEFAULT_LOCALE_ID, defaultCurrencyCode)).toEqual('USD5.12'); - expect(formatCurrency(5.1234, DEFAULT_LOCALE_ID, '$')).toEqual('$5.12'); - expect(formatCurrency(5.1234, DEFAULT_LOCALE_ID, 'CA$')).toEqual('CA$5.12'); - expect(formatCurrency(5.1234, DEFAULT_LOCALE_ID, '$')).toEqual('$5.12'); - expect(formatCurrency(5.1234, DEFAULT_LOCALE_ID, '$', defaultCurrencyCode, '5.2-2')) + expect(formatCurrency(5.1234, ɵDEFAULT_LOCALE_ID, defaultCurrencyCode)).toEqual('USD5.12'); + expect(formatCurrency(5.1234, ɵDEFAULT_LOCALE_ID, '$')).toEqual('$5.12'); + expect(formatCurrency(5.1234, ɵDEFAULT_LOCALE_ID, 'CA$')).toEqual('CA$5.12'); + expect(formatCurrency(5.1234, ɵDEFAULT_LOCALE_ID, '$')).toEqual('$5.12'); + expect(formatCurrency(5.1234, ɵDEFAULT_LOCALE_ID, '$', defaultCurrencyCode, '5.2-2')) .toEqual('$00,005.12'); expect(formatCurrency(5.1234, 'fr', '$', defaultCurrencyCode, '5.2-2')) .toEqual('00 005,12 $'); @@ -97,21 +97,22 @@ describe('Format number', () => { it('should support any currency code name', () => { // currency code is unknown, default formatting options will be used - expect(formatCurrency(5.1234, DEFAULT_LOCALE_ID, 'unexisting_ISO_code')) + expect(formatCurrency(5.1234, ɵDEFAULT_LOCALE_ID, 'unexisting_ISO_code')) .toEqual('unexisting_ISO_code5.12'); // currency code is USD, the pipe will format based on USD but will display "Custom name" - expect(formatCurrency(5.1234, DEFAULT_LOCALE_ID, 'Custom name')).toEqual('Custom name5.12'); + expect(formatCurrency(5.1234, ɵDEFAULT_LOCALE_ID, 'Custom name')) + .toEqual('Custom name5.12'); }); it('should round to the default number of digits if no digitsInfo', () => { // IDR has a default number of digits of 0 - expect(formatCurrency(5.1234, DEFAULT_LOCALE_ID, 'IDR', 'IDR')).toEqual('IDR5'); - expect(formatCurrency(5.1234, DEFAULT_LOCALE_ID, 'IDR', 'IDR', '.2')).toEqual('IDR5.12'); - expect(formatCurrency(5.1234, DEFAULT_LOCALE_ID, 'Custom name', 'IDR')) + expect(formatCurrency(5.1234, ɵDEFAULT_LOCALE_ID, 'IDR', 'IDR')).toEqual('IDR5'); + expect(formatCurrency(5.1234, ɵDEFAULT_LOCALE_ID, 'IDR', 'IDR', '.2')).toEqual('IDR5.12'); + expect(formatCurrency(5.1234, ɵDEFAULT_LOCALE_ID, 'Custom name', 'IDR')) .toEqual('Custom name5'); // BHD has a default number of digits of 3 - expect(formatCurrency(5.1234, DEFAULT_LOCALE_ID, 'BHD', 'BHD')).toEqual('BHD5.123'); - expect(formatCurrency(5.1234, DEFAULT_LOCALE_ID, 'BHD', 'BHD', '.1-2')).toEqual('BHD5.12'); + expect(formatCurrency(5.1234, ɵDEFAULT_LOCALE_ID, 'BHD', 'BHD')).toEqual('BHD5.123'); + expect(formatCurrency(5.1234, ɵDEFAULT_LOCALE_ID, 'BHD', 'BHD', '.1-2')).toEqual('BHD5.12'); }); }); }); diff --git a/packages/common/test/i18n/locale_data_api_spec.ts b/packages/common/test/i18n/locale_data_api_spec.ts index 6babf0bd20..ba160ec855 100644 --- a/packages/common/test/i18n/locale_data_api_spec.ts +++ b/packages/common/test/i18n/locale_data_api_spec.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {ɵfindLocaleData as findLocaleData} from '@angular/core'; +import {ɵfindLocaleData} from '@angular/core'; import localeCaESVALENCIA from '@angular/common/locales/ca-ES-VALENCIA'; import localeEn from '@angular/common/locales/en'; import localeFr from '@angular/common/locales/fr'; @@ -32,28 +32,28 @@ import {getCurrencySymbol, getLocaleDateFormat, FormatWidth, getNumberOfCurrency describe('findLocaleData', () => { it('should throw if the LOCALE_DATA for the chosen locale or its parent locale is not available', () => { - expect(() => findLocaleData('pt-AO')) + expect(() => ɵfindLocaleData('pt-AO')) .toThrowError(/Missing locale data for the locale "pt-AO"/); }); it('should return english data if the locale is en-US', - () => { expect(findLocaleData('en-US')).toEqual(localeEn); }); + () => { expect(ɵfindLocaleData('en-US')).toEqual(localeEn); }); it('should return the exact LOCALE_DATA if it is available', - () => { expect(findLocaleData('fr-CA')).toEqual(localeFrCA); }); + () => { expect(ɵfindLocaleData('fr-CA')).toEqual(localeFrCA); }); it('should return the parent LOCALE_DATA if it exists and exact locale is not available', - () => { expect(findLocaleData('fr-BE')).toEqual(localeFr); }); + () => { expect(ɵfindLocaleData('fr-BE')).toEqual(localeFr); }); it(`should find the LOCALE_DATA even if the locale id is badly formatted`, () => { - expect(findLocaleData('ca-ES-VALENCIA')).toEqual(localeCaESVALENCIA); - expect(findLocaleData('CA_es_Valencia')).toEqual(localeCaESVALENCIA); + expect(ɵfindLocaleData('ca-ES-VALENCIA')).toEqual(localeCaESVALENCIA); + expect(ɵfindLocaleData('CA_es_Valencia')).toEqual(localeCaESVALENCIA); }); it(`should find the LOCALE_DATA if the locale id was registered`, () => { - expect(findLocaleData('fake-id')).toEqual(localeFr); - expect(findLocaleData('fake_iD')).toEqual(localeFr); - expect(findLocaleData('fake-id2')).toEqual(localeFrCA); + expect(ɵfindLocaleData('fake-id')).toEqual(localeFr); + expect(ɵfindLocaleData('fake_iD')).toEqual(localeFr); + expect(ɵfindLocaleData('fake-id2')).toEqual(localeFrCA); }); });