From fa60f8e0465b738d6d7c851e37156fdb0cf4714e Mon Sep 17 00:00:00 2001 From: Luke Plant Date: Thu, 9 Aug 2018 11:25:39 +0100 Subject: [PATCH 1/5] Ran everything through elm-format --- src/Intl/Collator.elm | 86 +++--- src/Intl/Currency.elm | 70 +++-- src/Intl/DateTimeFormat.elm | 126 +++++---- src/Intl/Locale.elm | 78 +++-- src/Intl/NumberFormat.elm | 94 ++++--- src/Intl/TimeZone.elm | 29 +- tests/Test/Collator.elm | 246 +++++++++------- tests/Test/Currency.elm | 155 +++++----- tests/Test/DateTimeFormat.elm | 267 ++++++++++-------- tests/Test/Locale.elm | 185 ++++++------ tests/Test/NumberFormat.elm | 515 +++++++++++++++++++--------------- tests/Test/TimeZone.elm | 117 ++++---- 12 files changed, 1083 insertions(+), 885 deletions(-) diff --git a/src/Intl/Collator.elm b/src/Intl/Collator.elm index cb3416b..84b99cf 100644 --- a/src/Intl/Collator.elm +++ b/src/Intl/Collator.elm @@ -1,16 +1,17 @@ -module Intl.Collator exposing - ( Collator - , fromLocale - , fromOptions - , compare - , Options - , Usage(Sort, Search) - , Sensitivity(Base, Accent, Case, Variant) - , CaseFirst(Upper, Lower, Default) - , defaults - , resolvedOptions - , supportedLocalesOf - ) +module Intl.Collator + exposing + ( Collator + , fromLocale + , fromOptions + , compare + , Options + , Usage(Sort, Search) + , Sensitivity(Base, Accent, Case, Variant) + , CaseFirst(Upper, Lower, Default) + , defaults + , resolvedOptions + , supportedLocalesOf + ) {-| A library for comparing strings in a language sensitve way. This module binds to [Intl.Collator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator). @@ -40,7 +41,8 @@ import Intl.Locale exposing (Locale, en) {-| A Collator object, for comparing strings in a language sensitive way. -} -type Collator = Collator +type Collator + = Collator {-| Create a Collator using rules from the specified language @@ -49,7 +51,7 @@ type Collator = Collator -} fromLocale : Locale -> Collator fromLocale = - Native.Intl.Collator.fromLocale + Native.Intl.Collator.fromLocale {-| Create a Collator using rules from the language and other options. @@ -69,7 +71,7 @@ fromLocale = -} fromOptions : Options -> Collator fromOptions = - Native.Intl.Collator.fromOptions + Native.Intl.Collator.fromOptions {-| Compare two Strings according to the sort order of the Collator. @@ -78,26 +80,26 @@ fromOptions = -} compare : Collator -> String -> String -> Order compare = - Native.Intl.Collator.compare + Native.Intl.Collator.compare {-| An Options record, containing the possible settings for a Collator object. -} type alias Options = - { locale: Locale - , usage: Usage - , sensitivity: Sensitivity - , ignorePunctuation: Bool - , numeric: Bool - , caseFirst: CaseFirst - } + { locale : Locale + , usage : Usage + , sensitivity : Sensitivity + , ignorePunctuation : Bool + , numeric : Bool + , caseFirst : CaseFirst + } {-| Whether the comparison is for sorting or for searching for matching strings. -} type Usage - = Sort - | Search + = Sort + | Search {-| Which differences in the strings should lead to non-zero result values. @@ -114,19 +116,19 @@ Possible values are: consideration. Examples: `a ≠ b`, `a ≠ á`, `a ≠ A`. -} type Sensitivity - = Base - | Accent - | Case - | Variant + = Base + | Accent + | Case + | Variant {-| Whether upper case or lower case should sort first, or use the default order for the language. -} type CaseFirst - = Upper - | Lower - | Default + = Upper + | Lower + | Default {-| Returns the default options. This is helpful if you only care to change a @@ -138,13 +140,13 @@ few options. -} defaults : Options defaults = - { locale = en - , usage = Sort - , sensitivity = Variant - , ignorePunctuation = False - , numeric = False - , caseFirst = Default - } + { locale = en + , usage = Sort + , sensitivity = Variant + , ignorePunctuation = False + , numeric = False + , caseFirst = Default + } {-| Returns the locale and collation options computed when the Collator was @@ -157,7 +159,7 @@ created. -} resolvedOptions : Collator -> Options resolvedOptions = - Native.Intl.Collator.resolvedOptions + Native.Intl.Collator.resolvedOptions {-| Returns a list from the provided languages that are supported without having @@ -174,4 +176,4 @@ to fall back to the runtime's default language. -} supportedLocalesOf : List Locale -> List Locale supportedLocalesOf = - Native.Intl.Collator.supportedLocalesOf + Native.Intl.Collator.supportedLocalesOf diff --git a/src/Intl/Currency.elm b/src/Intl/Currency.elm index a2eb9b9..159a733 100644 --- a/src/Intl/Currency.elm +++ b/src/Intl/Currency.elm @@ -1,9 +1,15 @@ -module Intl.Currency exposing - ( Currency - , fromCurrencyCode - , toCurrencyCode - , usd, eur, jpy, gbp, chf, cad - ) +module Intl.Currency + exposing + ( Currency + , fromCurrencyCode + , toCurrencyCode + , usd + , eur + , jpy + , gbp + , chf + , cad + ) {-| A Currency is used to the display numeric data as money. Note that `NumberFormat` does *not* do exchange currency conversion, it only uses the @@ -25,8 +31,8 @@ import String exposing (toUpper) {-| The Currency type holds a valid ISO 4217 currency code. -} -type Currency = - Currency String +type Currency + = Currency String {-| Checks the string as a valid currency code, and returns a currency if it is. @@ -43,10 +49,10 @@ the code you provided. -} fromCurrencyCode : String -> Maybe Currency fromCurrencyCode code = - if contains (regex "^[A-Za-z]{3}$") code then - Just (Currency (toUpper code)) - else - Nothing + if contains (regex "^[A-Za-z]{3}$") code then + Just (Currency (toUpper code)) + else + Nothing {-| Gets the string currency code from a Currency @@ -55,36 +61,48 @@ fromCurrencyCode code = -} toCurrencyCode : Currency -> String toCurrencyCode currency = - case currency of - Currency tag -> tag + case currency of + Currency tag -> + tag -{-| United States Dollar -} +{-| United States Dollar +-} usd : Currency usd = - Currency "USD" + Currency "USD" + -{-| Euro -} +{-| Euro +-} eur : Currency eur = - Currency "EUR" + Currency "EUR" -{-| Japanese Yen -} + +{-| Japanese Yen +-} jpy : Currency jpy = - Currency "JPY" + Currency "JPY" + -{-| Pound Sterling -} +{-| Pound Sterling +-} gbp : Currency gbp = - Currency "GBP" + Currency "GBP" + -{-| Swiss Franc -} +{-| Swiss Franc +-} chf : Currency chf = - Currency "CHF" + Currency "CHF" -{-| Canadian Dollar -} + +{-| Canadian Dollar +-} cad : Currency cad = - Currency "CAD" + Currency "CAD" diff --git a/src/Intl/DateTimeFormat.elm b/src/Intl/DateTimeFormat.elm index d8bae9c..4e87a7f 100644 --- a/src/Intl/DateTimeFormat.elm +++ b/src/Intl/DateTimeFormat.elm @@ -1,17 +1,18 @@ -module Intl.DateTimeFormat exposing - ( DateTimeFormat - , fromLocale - , fromOptions - , format - , Options - , NameStyle(NarrowName, ShortName, LongName, OmitName) - , NumberStyle(NumericNumber, TwoDigitNumber, OmitNumber) - , MonthStyle(NarrowMonth, ShortMonth, LongMonth, NumericMonth, TwoDigitMonth, OmitMonth) - , TimeZoneStyle(ShortTimeZone, LongTimeZone, OmitTimeZone) - , defaults - , resolvedOptions - , supportedLocalesOf - ) +module Intl.DateTimeFormat + exposing + ( DateTimeFormat + , fromLocale + , fromOptions + , format + , Options + , NameStyle(NarrowName, ShortName, LongName, OmitName) + , NumberStyle(NumericNumber, TwoDigitNumber, OmitNumber) + , MonthStyle(NarrowMonth, ShortMonth, LongMonth, NumericMonth, TwoDigitMonth, OmitMonth) + , TimeZoneStyle(ShortTimeZone, LongTimeZone, OmitTimeZone) + , defaults + , resolvedOptions + , supportedLocalesOf + ) {-| A library for formatting dates in a language sensitve way. This module binds to [Intl.DateTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat). @@ -40,7 +41,8 @@ import Date exposing (Date) {-| A DateTimeFormat object, for formatting dates in a language sensitive way. -} -type DateTimeFormat = DateTimeFormat +type DateTimeFormat + = DateTimeFormat {-| Create a DateTimeFormat using rules from the specified language @@ -50,7 +52,7 @@ type DateTimeFormat = DateTimeFormat -} fromLocale : Locale -> DateTimeFormat fromLocale = - Native.Intl.DateTimeFormat.fromLocale + Native.Intl.DateTimeFormat.fromLocale {-| Create a DateTimeFormat using rules from the language and other options. @@ -68,7 +70,7 @@ fromLocale = -} fromOptions : Options -> DateTimeFormat fromOptions = - Native.Intl.DateTimeFormat.fromOptions + Native.Intl.DateTimeFormat.fromOptions {-| Format a Date according to the rules of the DateTimeFormat. @@ -77,62 +79,62 @@ fromOptions = -} format : DateTimeFormat -> Date -> String format = - Native.Intl.DateTimeFormat.format + Native.Intl.DateTimeFormat.format {-| An Options record, containing the possible settings for a DateTimeFormat object. -} type alias Options = - { locale: Locale - , timeZone: Maybe TimeZone - , hour12: Maybe Bool - , weekday: NameStyle - , era: NameStyle - , year: NumberStyle - , month: MonthStyle - , day: NumberStyle - , hour: NumberStyle - , minute: NumberStyle - , second: NumberStyle - , timeZoneName: TimeZoneStyle - } + { locale : Locale + , timeZone : Maybe TimeZone + , hour12 : Maybe Bool + , weekday : NameStyle + , era : NameStyle + , year : NumberStyle + , month : MonthStyle + , day : NumberStyle + , hour : NumberStyle + , minute : NumberStyle + , second : NumberStyle + , timeZoneName : TimeZoneStyle + } {-| Style options for the date parts that can be names. -} type NameStyle - = NarrowName - | ShortName - | LongName - | OmitName + = NarrowName + | ShortName + | LongName + | OmitName {-| Style options for the date parts that can be numbers. -} type NumberStyle - = NumericNumber - | TwoDigitNumber - | OmitNumber + = NumericNumber + | TwoDigitNumber + | OmitNumber {-| Style options for the month. -} type MonthStyle - = NarrowMonth - | ShortMonth - | LongMonth - | NumericMonth - | TwoDigitMonth - | OmitMonth + = NarrowMonth + | ShortMonth + | LongMonth + | NumericMonth + | TwoDigitMonth + | OmitMonth {-| Style options for the timeZoneName. -} type TimeZoneStyle - = ShortTimeZone - | LongTimeZone - | OmitTimeZone + = ShortTimeZone + | LongTimeZone + | OmitTimeZone {-| Returns the default options. This is helpful if you only care to change a @@ -145,19 +147,19 @@ and `day` will be assumed numeric. -} defaults : Options defaults = - { locale = en - , timeZone = Nothing - , hour12 = Nothing - , weekday = OmitName - , era = OmitName - , year = OmitNumber - , month = OmitMonth - , day = OmitNumber - , hour = OmitNumber - , minute = OmitNumber - , second = OmitNumber - , timeZoneName = OmitTimeZone - } + { locale = en + , timeZone = Nothing + , hour12 = Nothing + , weekday = OmitName + , era = OmitName + , year = OmitNumber + , month = OmitMonth + , day = OmitNumber + , hour = OmitNumber + , minute = OmitNumber + , second = OmitNumber + , timeZoneName = OmitTimeZone + } {-| Returns the locale and formatting options computed when the DateTimeFormat @@ -170,7 +172,7 @@ was created. -} resolvedOptions : DateTimeFormat -> Options resolvedOptions = - Native.Intl.DateTimeFormat.resolvedOptions + Native.Intl.DateTimeFormat.resolvedOptions {-| Returns a list from the provided languages that are supported without having @@ -187,4 +189,4 @@ to fall back to the runtime's default language. -} supportedLocalesOf : List Locale -> List Locale supportedLocalesOf = - Native.Intl.DateTimeFormat.supportedLocalesOf + Native.Intl.DateTimeFormat.supportedLocalesOf diff --git a/src/Intl/Locale.elm b/src/Intl/Locale.elm index 07149ca..e3b1d29 100644 --- a/src/Intl/Locale.elm +++ b/src/Intl/Locale.elm @@ -1,9 +1,17 @@ -module Intl.Locale exposing - ( Locale - , fromLanguageTag - , toLanguageTag - , en, zhCN, zhTW, fr, de, it, ja, ko - ) +module Intl.Locale + exposing + ( Locale + , fromLanguageTag + , toLanguageTag + , en + , zhCN + , zhTW + , fr + , de + , it + , ja + , ko + ) {-| A Locale represents a BCP 47 language tag including optional script, region, variant, and extensions. @@ -22,8 +30,8 @@ import Native.Intl.Locale {-| The Locale type holds a valid BCP 47 language tag. -} -type Locale = - Locale String +type Locale + = Locale String {-| Checks the string as a valid language tag, and returns a locale if it is. @@ -40,7 +48,7 @@ returned. -} fromLanguageTag : String -> Maybe Locale fromLanguageTag = - Native.Intl.Locale.fromLanguageTag + Native.Intl.Locale.fromLanguageTag {-| Gets the string language tag from a Locale @@ -49,46 +57,62 @@ fromLanguageTag = -} toLanguageTag : Locale -> String toLanguageTag locale = - case locale of - Locale tag -> tag + case locale of + Locale tag -> + tag -{-| English -} +{-| English +-} en : Locale en = - Locale "en" + Locale "en" + -{-| Simplified Chinese -} +{-| Simplified Chinese +-} zhCN : Locale zhCN = - Locale "zh-CN" + Locale "zh-CN" + -{-| Traditional Chinese -} +{-| Traditional Chinese +-} zhTW : Locale zhTW = - Locale "zh-TW" + Locale "zh-TW" + -{-| French -} +{-| French +-} fr : Locale fr = - Locale "fr" + Locale "fr" + -{-| German -} +{-| German +-} de : Locale de = - Locale "de" + Locale "de" + -{-| Italian -} +{-| Italian +-} it : Locale it = - Locale "it" + Locale "it" + -{-| Japanese -} +{-| Japanese +-} ja : Locale ja = - Locale "ja" + Locale "ja" + -{-| Korean -} +{-| Korean +-} ko : Locale ko = - Locale "ko" + Locale "ko" diff --git a/src/Intl/NumberFormat.elm b/src/Intl/NumberFormat.elm index c70ad7a..007283e 100644 --- a/src/Intl/NumberFormat.elm +++ b/src/Intl/NumberFormat.elm @@ -1,15 +1,16 @@ -module Intl.NumberFormat exposing - ( NumberFormat - , fromLocale - , fromOptions - , format - , Options - , Style(PercentStyle, CurrencyStyle, DecimalStyle) - , CurrencyDisplay(CurrencyCode, CurrencyName, CurrencySymbol) - , defaults - , resolvedOptions - , supportedLocalesOf - ) +module Intl.NumberFormat + exposing + ( NumberFormat + , fromLocale + , fromOptions + , format + , Options + , Style(PercentStyle, CurrencyStyle, DecimalStyle) + , CurrencyDisplay(CurrencyCode, CurrencyName, CurrencySymbol) + , defaults + , resolvedOptions + , supportedLocalesOf + ) {-| A library for formatting numbers in a language sensitve way. This module binds to [Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat). @@ -37,7 +38,8 @@ import Maybe exposing (Maybe) {-| A NumberFormat object, for formatting numbers in a language sensitive way. -} -type NumberFormat = NumberFormat +type NumberFormat + = NumberFormat {-| Create a NumberFormat using rules from the specified language @@ -47,7 +49,7 @@ type NumberFormat = NumberFormat -} fromLocale : Locale -> NumberFormat fromLocale = - Native.Intl.NumberFormat.fromLocale + Native.Intl.NumberFormat.fromLocale {-| Create a NumberFormat using rules from the language and other options. @@ -64,7 +66,7 @@ fromLocale = -} fromOptions : Options -> NumberFormat fromOptions = - Native.Intl.NumberFormat.fromOptions + Native.Intl.NumberFormat.fromOptions {-| Format a number according to the rules of the NumberFormat. @@ -73,7 +75,7 @@ fromOptions = -} format : NumberFormat -> number -> String format = - Native.Intl.NumberFormat.format + Native.Intl.NumberFormat.format {-| An Options record, containing the possible settings for a NumberFormat @@ -86,33 +88,33 @@ least one property from the second group is not `Nothing`, then the first group is ignored. -} type alias Options = - { locale: Locale - , style: Style - , currency: Currency - , currencyDisplay: CurrencyDisplay - , useGrouping: Bool - , minimumIntegerDigits: Maybe Int - , minimumFractionDigits: Maybe Int - , maximumFractionDigits: Maybe Int - , minimumSignificantDigits: Maybe Int - , maximumSignificantDigits: Maybe Int - } + { locale : Locale + , style : Style + , currency : Currency + , currencyDisplay : CurrencyDisplay + , useGrouping : Bool + , minimumIntegerDigits : Maybe Int + , minimumFractionDigits : Maybe Int + , maximumFractionDigits : Maybe Int + , minimumSignificantDigits : Maybe Int + , maximumSignificantDigits : Maybe Int + } {-| Style of the number format. -} type Style - = PercentStyle - | CurrencyStyle - | DecimalStyle + = PercentStyle + | CurrencyStyle + | DecimalStyle {-| How to display the currency information. -} type CurrencyDisplay - = CurrencyCode - | CurrencyName - | CurrencySymbol + = CurrencyCode + | CurrencyName + | CurrencySymbol {-| Returns the default options. This is helpful if you only care to change a @@ -124,17 +126,17 @@ few options. -} defaults : Options defaults = - { locale = en - , style = DecimalStyle - , currency = usd - , currencyDisplay = CurrencySymbol - , useGrouping = True - , minimumIntegerDigits = Nothing - , minimumFractionDigits = Nothing - , maximumFractionDigits = Nothing - , minimumSignificantDigits = Nothing - , maximumSignificantDigits = Nothing - } + { locale = en + , style = DecimalStyle + , currency = usd + , currencyDisplay = CurrencySymbol + , useGrouping = True + , minimumIntegerDigits = Nothing + , minimumFractionDigits = Nothing + , maximumFractionDigits = Nothing + , minimumSignificantDigits = Nothing + , maximumSignificantDigits = Nothing + } {-| Returns the locale and formatting options computed when the NumberFormat @@ -147,7 +149,7 @@ was created. -} resolvedOptions : NumberFormat -> Options resolvedOptions = - Native.Intl.NumberFormat.resolvedOptions + Native.Intl.NumberFormat.resolvedOptions {-| Returns a list from the provided languages that are supported without having @@ -164,4 +166,4 @@ to fall back to the runtime's default language. -} supportedLocalesOf : List Locale -> List Locale supportedLocalesOf = - Native.Intl.NumberFormat.supportedLocalesOf + Native.Intl.NumberFormat.supportedLocalesOf diff --git a/src/Intl/TimeZone.elm b/src/Intl/TimeZone.elm index a55f1a5..c811275 100644 --- a/src/Intl/TimeZone.elm +++ b/src/Intl/TimeZone.elm @@ -1,9 +1,10 @@ -module Intl.TimeZone exposing - ( TimeZone - , fromIANATimeZoneName - , toIANATimeZoneName - , utc - ) +module Intl.TimeZone + exposing + ( TimeZone + , fromIANATimeZoneName + , toIANATimeZoneName + , utc + ) {-| A TimeZone represents a time zone from the IANA database. @@ -22,8 +23,8 @@ import Native.Intl.TimeZone {-| The TimeZone type holds a valid IANA time zone. -} -type TimeZone = - TimeZone String +type TimeZone + = TimeZone String {-| Checks the string as a valid time zone, and returns a TimeZone if it is. @@ -36,7 +37,7 @@ The string is matched in a case-insensitive manner. -} fromIANATimeZoneName : String -> Maybe TimeZone fromIANATimeZoneName = - Native.Intl.TimeZone.fromIANATimeZoneName + Native.Intl.TimeZone.fromIANATimeZoneName {-| Gets the canonicalized string time zone name from a TimeZone. @@ -45,11 +46,13 @@ fromIANATimeZoneName = -} toIANATimeZoneName : TimeZone -> String toIANATimeZoneName timeZone = - case timeZone of - TimeZone name -> name + case timeZone of + TimeZone name -> + name -{-| Coordinated Universal Time -} +{-| Coordinated Universal Time +-} utc : TimeZone utc = - TimeZone "UTC" + TimeZone "UTC" diff --git a/tests/Test/Collator.elm b/tests/Test/Collator.elm index fddaddd..25bf6be 100644 --- a/tests/Test/Collator.elm +++ b/tests/Test/Collator.elm @@ -2,135 +2,173 @@ module Test.Collator exposing (all) import Test exposing (..) import Expect - import Intl.Collator as Collator import Intl.Locale as Locale import List exposing (map, concat, length) import String exposing (startsWith) import Maybe exposing (withDefault) + all : Test all = - let - fromLocaleTests = describe "fromLocale and compare" - ( map - (\locale -> - test (Locale.toLanguageTag locale) <| - \() -> - let - compare = Collator.compare (Collator.fromLocale locale) - in - Expect.equal - [ compare "a" "z", compare "4" "4", compare "c" "a" ] - [ LT, EQ, GT ] - ) - predefinedLocales - ) - fromOptionsTests = describe "fromOptions and resolvedOptions" - ( map - (\options -> - test "options" <| - \() -> - let - resolved = Collator.resolvedOptions (Collator.fromOptions options) - in - Expect.true "Expected resolved options to match options" - ( resolved.usage == options.usage - && resolved.sensitivity == options.sensitivity - && resolved.ignorePunctuation == options.ignorePunctuation - && resolved.numeric == options.numeric - && resolved.caseFirst == options.caseFirst + let + fromLocaleTests = + describe "fromLocale and compare" + (map + (\locale -> + test (Locale.toLanguageTag locale) <| + \() -> + let + compare = + Collator.compare (Collator.fromLocale locale) + in + Expect.equal + [ compare "a" "z", compare "4" "4", compare "c" "a" ] + [ LT, EQ, GT ] + ) + predefinedLocales ) - ) - allOptionCombinations - ) - supportedLocalesOfTests = describe "supportedLocalesOf" - [ test "at least one predefined locale is supported" <| - \() -> - Expect.atLeast 1 - (length (Collator.supportedLocalesOf predefinedLocales)) - , test "not all locales are supported" <| - \() -> - Expect.equal - ( Collator.supportedLocalesOf - [ withDefault Locale.en (Locale.fromLanguageTag "tlh") -- Klingon - , withDefault Locale.en (Locale.fromLanguageTag "qya") -- Elvish - ] - ) - [] - ] - defaultsTests = describe "defaults" - [ test "are valid options" <| - \() -> - Expect.equal - (Collator.resolvedOptions (Collator.fromOptions Collator.defaults)) - Collator.defaults - ] - in - describe "Intl.Collator" - [ fromLocaleTests - , fromOptionsTests - , supportedLocalesOfTests - , defaultsTests - ] + + fromOptionsTests = + describe "fromOptions and resolvedOptions" + (map + (\options -> + test "options" <| + \() -> + let + resolved = + Collator.resolvedOptions (Collator.fromOptions options) + in + Expect.true "Expected resolved options to match options" + (resolved.usage + == options.usage + && resolved.sensitivity + == options.sensitivity + && resolved.ignorePunctuation + == options.ignorePunctuation + && resolved.numeric + == options.numeric + && resolved.caseFirst + == options.caseFirst + ) + ) + allOptionCombinations + ) + + supportedLocalesOfTests = + describe "supportedLocalesOf" + [ test "at least one predefined locale is supported" <| + \() -> + Expect.atLeast 1 + (length (Collator.supportedLocalesOf predefinedLocales)) + , test "not all locales are supported" <| + \() -> + Expect.equal + (Collator.supportedLocalesOf + [ withDefault Locale.en (Locale.fromLanguageTag "tlh") + -- Klingon + , withDefault Locale.en (Locale.fromLanguageTag "qya") + -- Elvish + ] + ) + [] + ] + + defaultsTests = + describe "defaults" + [ test "are valid options" <| + \() -> + Expect.equal + (Collator.resolvedOptions (Collator.fromOptions Collator.defaults)) + Collator.defaults + ] + in + describe "Intl.Collator" + [ fromLocaleTests + , fromOptionsTests + , supportedLocalesOfTests + , defaultsTests + ] predefinedLocales : List Locale.Locale predefinedLocales = - [ Locale.en - , Locale.zhCN - , Locale.zhTW - , Locale.fr - , Locale.de - , Locale.it - , Locale.ja - , Locale.ko - ] + [ Locale.en + , Locale.zhCN + , Locale.zhTW + , Locale.fr + , Locale.de + , Locale.it + , Locale.ja + , Locale.ko + ] + usages : List Collator.Usage usages = - [ Collator.Sort - , Collator.Search - ] + [ Collator.Sort + , Collator.Search + ] + sensitivities : List Collator.Sensitivity sensitivities = - [ Collator.Base - , Collator.Accent - , Collator.Case - , Collator.Variant - ] + [ Collator.Base + , Collator.Accent + , Collator.Case + , Collator.Variant + ] + caseFirsts : List Collator.CaseFirst caseFirsts = - [ Collator.Upper - , Collator.Lower - , Collator.Default - ] + [ Collator.Upper + , Collator.Lower + , Collator.Default + ] + bools = - [ True - , False - ] + [ True + , False + ] + allOptionCombinations : List Collator.Options allOptionCombinations = - predefinedLocales |> map (\locale -> - usages |> map (\usage -> - sensitivities |> map (\sensitivity -> - bools |> map (\ignorePunctuation -> - bools |> map (\numeric -> - caseFirsts |> map (\caseFirst -> - { locale = locale - , usage = usage - , sensitivity = sensitivity - , ignorePunctuation = ignorePunctuation - , numeric = numeric - , caseFirst = caseFirst - } + predefinedLocales + |> map + (\locale -> + usages + |> map + (\usage -> + sensitivities + |> map + (\sensitivity -> + bools + |> map + (\ignorePunctuation -> + bools + |> map + (\numeric -> + caseFirsts + |> map + (\caseFirst -> + { locale = locale + , usage = usage + , sensitivity = sensitivity + , ignorePunctuation = ignorePunctuation + , numeric = numeric + , caseFirst = caseFirst + } + ) + ) + |> List.concat + ) + |> List.concat + ) + |> List.concat + ) + |> List.concat ) - ) |> List.concat - ) |> List.concat - ) |> List.concat - ) |> List.concat - ) |> List.concat + |> List.concat diff --git a/tests/Test/Currency.elm b/tests/Test/Currency.elm index c8c330f..5ad75e8 100644 --- a/tests/Test/Currency.elm +++ b/tests/Test/Currency.elm @@ -3,84 +3,91 @@ module Test.Currency exposing (all) import Test exposing (..) import Fuzz exposing (string) import Expect - import Intl.Currency as Currency import Maybe exposing (..) import String exposing (toUpper) + all : Test all = - let - fromCurrencyCodeTests = describe "fromCurrencyCode" - [ test "empty string" <| - \() -> - Expect.equal (Currency.fromCurrencyCode "") Nothing - , test "invalid characters" <| - \() -> - Expect.equal (Currency.fromCurrencyCode "$@#") Nothing - , test "usd" <| - \() -> - Expect.equal (Currency.fromCurrencyCode "usd") (Just Currency.usd) - , test "EUR" <| - \() -> - Expect.equal (Currency.fromCurrencyCode "EUR") (Just Currency.eur) - , test "jpY" <| - \() -> - Expect.equal (Currency.fromCurrencyCode "jpY") (Just Currency.jpy) - , test "gBp" <| - \() -> - Expect.equal (Currency.fromCurrencyCode "gBp") (Just Currency.gbp) - , test "CHf" <| - \() -> - Expect.equal (Currency.fromCurrencyCode "CHf") (Just Currency.chf) - , test "cAD" <| - \() -> - Expect.equal (Currency.fromCurrencyCode "cAD") (Just Currency.cad) - , test "normalizes capitalization" <| - \() -> - Expect.equal - ( Currency.fromCurrencyCode "xau" - |> withDefault Currency.cad - |> Currency.toCurrencyCode - ) - "XAU" - , fuzz string "doesn't crash on bad inputs" <| - \code -> - case Currency.fromCurrencyCode code of - Nothing -> Expect.pass - Just _ -> Expect.pass - ] + let + fromCurrencyCodeTests = + describe "fromCurrencyCode" + [ test "empty string" <| + \() -> + Expect.equal (Currency.fromCurrencyCode "") Nothing + , test "invalid characters" <| + \() -> + Expect.equal (Currency.fromCurrencyCode "$@#") Nothing + , test "usd" <| + \() -> + Expect.equal (Currency.fromCurrencyCode "usd") (Just Currency.usd) + , test "EUR" <| + \() -> + Expect.equal (Currency.fromCurrencyCode "EUR") (Just Currency.eur) + , test "jpY" <| + \() -> + Expect.equal (Currency.fromCurrencyCode "jpY") (Just Currency.jpy) + , test "gBp" <| + \() -> + Expect.equal (Currency.fromCurrencyCode "gBp") (Just Currency.gbp) + , test "CHf" <| + \() -> + Expect.equal (Currency.fromCurrencyCode "CHf") (Just Currency.chf) + , test "cAD" <| + \() -> + Expect.equal (Currency.fromCurrencyCode "cAD") (Just Currency.cad) + , test "normalizes capitalization" <| + \() -> + Expect.equal + (Currency.fromCurrencyCode "xau" + |> withDefault Currency.cad + |> Currency.toCurrencyCode + ) + "XAU" + , fuzz string "doesn't crash on bad inputs" <| + \code -> + case Currency.fromCurrencyCode code of + Nothing -> + Expect.pass + + Just _ -> + Expect.pass + ] + + toCurrencyCodeTests = + describe "toCurrencyCode" + [ test "usd" <| + \() -> + Expect.equal (Currency.toCurrencyCode Currency.usd) "USD" + , test "eur" <| + \() -> + Expect.equal (Currency.toCurrencyCode Currency.eur) "EUR" + , test "jpy" <| + \() -> + Expect.equal (Currency.toCurrencyCode Currency.jpy) "JPY" + , test "gbp" <| + \() -> + Expect.equal (Currency.toCurrencyCode Currency.gbp) "GBP" + , test "chf" <| + \() -> + Expect.equal (Currency.toCurrencyCode Currency.chf) "CHF" + , test "cad" <| + \() -> + Expect.equal (Currency.toCurrencyCode Currency.cad) "CAD" + , fuzz string "doesn't crash on random Currencies" <| + \code -> + case Currency.fromCurrencyCode code of + Nothing -> + Expect.pass - toCurrencyCodeTests = describe "toCurrencyCode" - [ test "usd" <| - \() -> - Expect.equal (Currency.toCurrencyCode Currency.usd) "USD" - , test "eur" <| - \() -> - Expect.equal (Currency.toCurrencyCode Currency.eur) "EUR" - , test "jpy" <| - \() -> - Expect.equal (Currency.toCurrencyCode Currency.jpy) "JPY" - , test "gbp" <| - \() -> - Expect.equal (Currency.toCurrencyCode Currency.gbp) "GBP" - , test "chf" <| - \() -> - Expect.equal (Currency.toCurrencyCode Currency.chf) "CHF" - , test "cad" <| - \() -> - Expect.equal (Currency.toCurrencyCode Currency.cad) "CAD" - , fuzz string "doesn't crash on random Currencies" <| - \code -> - case Currency.fromCurrencyCode code of - Nothing -> Expect.pass - Just currency -> - Expect.equal - (Currency.toCurrencyCode currency) - (toUpper code) - ] - in - describe "Intl.Currency" - [ fromCurrencyCodeTests - , toCurrencyCodeTests - ] + Just currency -> + Expect.equal + (Currency.toCurrencyCode currency) + (toUpper code) + ] + in + describe "Intl.Currency" + [ fromCurrencyCodeTests + , toCurrencyCodeTests + ] diff --git a/tests/Test/DateTimeFormat.elm b/tests/Test/DateTimeFormat.elm index 569bf48..896c165 100644 --- a/tests/Test/DateTimeFormat.elm +++ b/tests/Test/DateTimeFormat.elm @@ -2,7 +2,6 @@ module Test.DateTimeFormat exposing (all) import Test exposing (..) import Expect - import Intl.DateTimeFormat as DateTimeFormat import Intl.Locale as Locale import Intl.TimeZone exposing (utc) @@ -12,135 +11,163 @@ import Maybe exposing (Maybe(Just), withDefault) import Date import Time exposing (second) + all : Test all = - let - fromLocaleTests = describe "fromLocale and format" - [ test "English" <| - \() -> - let - format = DateTimeFormat.format (DateTimeFormat.fromLocale Locale.en) - in - Expect.equal - (format (Date.fromTime (1482683025 * second))) - "12/25/2016" - ] - fromOptionsTests = describe "fromOptions and resolvedOptions" - ( map - (\options -> - test "options" <| - \() -> - let - resolved = DateTimeFormat.resolvedOptions (DateTimeFormat.fromOptions options) - in - Expect.true "Expected resolved options to not have something match" - ( resolved.weekday == options.weekday - || resolved.era == options.era - || resolved.year == options.year - || resolved.month == options.month - || resolved.day == options.day - || resolved.hour == options.hour - || resolved.minute == options.minute - || resolved.second == options.second - || resolved.timeZoneName == options.timeZoneName + let + fromLocaleTests = + describe "fromLocale and format" + [ test "English" <| + \() -> + let + format = + DateTimeFormat.format (DateTimeFormat.fromLocale Locale.en) + in + Expect.equal + (format (Date.fromTime (1482683025 * second))) + "12/25/2016" + ] + + fromOptionsTests = + describe "fromOptions and resolvedOptions" + (map + (\options -> + test "options" <| + \() -> + let + resolved = + DateTimeFormat.resolvedOptions (DateTimeFormat.fromOptions options) + in + Expect.true "Expected resolved options to not have something match" + (resolved.weekday + == options.weekday + || resolved.era + == options.era + || resolved.year + == options.year + || resolved.month + == options.month + || resolved.day + == options.day + || resolved.hour + == options.hour + || resolved.minute + == options.minute + || resolved.second + == options.second + || resolved.timeZoneName + == options.timeZoneName + ) + ) + optionCombinations ) - ) - optionCombinations - ) - supportedLocalesOfTests = describe "supportedLocalesOf" - [ test "at least one predefined locale is supported" <| - \() -> - Expect.atLeast 1 - (length (DateTimeFormat.supportedLocalesOf predefinedLocales)) - , test "not all locales are supported" <| - \() -> - Expect.equal - ( DateTimeFormat.supportedLocalesOf - [ withDefault Locale.en (Locale.fromLanguageTag "tlh") -- Klingon - , withDefault Locale.en (Locale.fromLanguageTag "qya") -- Elvish - ] - ) - [] - ] - defaultsTests = describe "defaults" - [ test "end up being m/d/y" <| - \() -> - let - resolved = - DateTimeFormat.fromOptions defaults - |> DateTimeFormat.resolvedOptions - in - Expect.true "mdy" - ( resolved.year == DateTimeFormat.NumericNumber - && resolved.month == DateTimeFormat.NumericMonth - && resolved.day == DateTimeFormat.NumericNumber - ) - ] - in - describe "Intl.DateTimeFormat" - [ fromLocaleTests - , fromOptionsTests - , supportedLocalesOfTests - , defaultsTests - ] + + supportedLocalesOfTests = + describe "supportedLocalesOf" + [ test "at least one predefined locale is supported" <| + \() -> + Expect.atLeast 1 + (length (DateTimeFormat.supportedLocalesOf predefinedLocales)) + , test "not all locales are supported" <| + \() -> + Expect.equal + (DateTimeFormat.supportedLocalesOf + [ withDefault Locale.en (Locale.fromLanguageTag "tlh") + -- Klingon + , withDefault Locale.en (Locale.fromLanguageTag "qya") + -- Elvish + ] + ) + [] + ] + + defaultsTests = + describe "defaults" + [ test "end up being m/d/y" <| + \() -> + let + resolved = + DateTimeFormat.fromOptions defaults + |> DateTimeFormat.resolvedOptions + in + Expect.true "mdy" + (resolved.year + == DateTimeFormat.NumericNumber + && resolved.month + == DateTimeFormat.NumericMonth + && resolved.day + == DateTimeFormat.NumericNumber + ) + ] + in + describe "Intl.DateTimeFormat" + [ fromLocaleTests + , fromOptionsTests + , supportedLocalesOfTests + , defaultsTests + ] defaults : DateTimeFormat.Options defaults = - DateTimeFormat.defaults + DateTimeFormat.defaults + predefinedLocales : List Locale.Locale predefinedLocales = - [ Locale.en - , Locale.zhCN - , Locale.zhTW - , Locale.fr - , Locale.de - , Locale.it - , Locale.ja - , Locale.ko - ] + [ Locale.en + , Locale.zhCN + , Locale.zhTW + , Locale.fr + , Locale.de + , Locale.it + , Locale.ja + , Locale.ko + ] + + + +{- A couple commons configurations -} + -{- A couple commons configurations --} optionCombinations : List DateTimeFormat.Options optionCombinations = - [ { defaults - | weekday = DateTimeFormat.LongName - , year = DateTimeFormat.NumericNumber - , month = DateTimeFormat.LongMonth - , day = DateTimeFormat.NumericNumber - , hour = DateTimeFormat.NumericNumber - , minute = DateTimeFormat.TwoDigitNumber - , second = DateTimeFormat.TwoDigitNumber - } - , { defaults - | weekday = DateTimeFormat.NarrowName - , year = DateTimeFormat.NumericNumber - , month = DateTimeFormat.NarrowMonth - , day = DateTimeFormat.NumericNumber - } - , { defaults - | year = DateTimeFormat.NumericNumber - , month = DateTimeFormat.ShortMonth - , day = DateTimeFormat.NumericNumber - } - , { defaults - | year = DateTimeFormat.NumericNumber - , month = DateTimeFormat.LongMonth - } - , { defaults - | month = DateTimeFormat.LongMonth - , day = DateTimeFormat.NumericNumber - } - , { defaults - | hour = DateTimeFormat.NumericNumber - , minute = DateTimeFormat.TwoDigitNumber - , second = DateTimeFormat.TwoDigitNumber - } - , { defaults - | hour12 = Just False - , hour = DateTimeFormat.TwoDigitNumber - , minute = DateTimeFormat.TwoDigitNumber - } - ] + [ { defaults + | weekday = DateTimeFormat.LongName + , year = DateTimeFormat.NumericNumber + , month = DateTimeFormat.LongMonth + , day = DateTimeFormat.NumericNumber + , hour = DateTimeFormat.NumericNumber + , minute = DateTimeFormat.TwoDigitNumber + , second = DateTimeFormat.TwoDigitNumber + } + , { defaults + | weekday = DateTimeFormat.NarrowName + , year = DateTimeFormat.NumericNumber + , month = DateTimeFormat.NarrowMonth + , day = DateTimeFormat.NumericNumber + } + , { defaults + | year = DateTimeFormat.NumericNumber + , month = DateTimeFormat.ShortMonth + , day = DateTimeFormat.NumericNumber + } + , { defaults + | year = DateTimeFormat.NumericNumber + , month = DateTimeFormat.LongMonth + } + , { defaults + | month = DateTimeFormat.LongMonth + , day = DateTimeFormat.NumericNumber + } + , { defaults + | hour = DateTimeFormat.NumericNumber + , minute = DateTimeFormat.TwoDigitNumber + , second = DateTimeFormat.TwoDigitNumber + } + , { defaults + | hour12 = Just False + , hour = DateTimeFormat.TwoDigitNumber + , minute = DateTimeFormat.TwoDigitNumber + } + ] diff --git a/tests/Test/Locale.elm b/tests/Test/Locale.elm index 2d4d479..8815491 100644 --- a/tests/Test/Locale.elm +++ b/tests/Test/Locale.elm @@ -3,99 +3,106 @@ module Test.Locale exposing (all) import Test exposing (..) import Fuzz exposing (string) import Expect - import Intl.Locale as Locale import Maybe exposing (..) import String exposing (toLower) + all : Test all = - let - fromLanguageTagTests = describe "fromLanguageTag" - [ test "empty string" <| - \() -> - Expect.equal (Locale.fromLanguageTag "") Nothing - , test "invalid characters" <| - \() -> - Expect.equal (Locale.fromLanguageTag "$@#") Nothing - , test "en" <| - \() -> - Expect.equal (Locale.fromLanguageTag "en") (Just Locale.en) - , test "zh-CN" <| - \() -> - Expect.equal (Locale.fromLanguageTag "zh-CN") (Just Locale.zhCN) - , test "zh-tw" <| - \() -> - Expect.equal (Locale.fromLanguageTag "zh-tw") (Just Locale.zhTW) - , test "fr" <| - \() -> - Expect.equal (Locale.fromLanguageTag "fr") (Just Locale.fr) - , test "De" <| - \() -> - Expect.equal (Locale.fromLanguageTag "De") (Just Locale.de) - , test "iT" <| - \() -> - Expect.equal (Locale.fromLanguageTag "iT") (Just Locale.it) - , test "ja" <| - \() -> - Expect.equal (Locale.fromLanguageTag "ja") (Just Locale.ja) - , test "ko" <| - \() -> - Expect.equal (Locale.fromLanguageTag "ko") (Just Locale.ko) - , test "en-US" <| - \() -> - Expect.notEqual (Locale.fromLanguageTag "en-US") (Just Locale.en) - , test "normalizes capitalization" <| - \() -> - Expect.equal - ( Locale.fromLanguageTag "ZH-hant-hk" - |> withDefault Locale.en - |> Locale.toLanguageTag - ) - "zh-Hant-HK" - , fuzz string "doesn't crash on bad inputs" <| - \tag -> - case Locale.fromLanguageTag tag of - Nothing -> Expect.pass - Just _ -> Expect.pass - ] + let + fromLanguageTagTests = + describe "fromLanguageTag" + [ test "empty string" <| + \() -> + Expect.equal (Locale.fromLanguageTag "") Nothing + , test "invalid characters" <| + \() -> + Expect.equal (Locale.fromLanguageTag "$@#") Nothing + , test "en" <| + \() -> + Expect.equal (Locale.fromLanguageTag "en") (Just Locale.en) + , test "zh-CN" <| + \() -> + Expect.equal (Locale.fromLanguageTag "zh-CN") (Just Locale.zhCN) + , test "zh-tw" <| + \() -> + Expect.equal (Locale.fromLanguageTag "zh-tw") (Just Locale.zhTW) + , test "fr" <| + \() -> + Expect.equal (Locale.fromLanguageTag "fr") (Just Locale.fr) + , test "De" <| + \() -> + Expect.equal (Locale.fromLanguageTag "De") (Just Locale.de) + , test "iT" <| + \() -> + Expect.equal (Locale.fromLanguageTag "iT") (Just Locale.it) + , test "ja" <| + \() -> + Expect.equal (Locale.fromLanguageTag "ja") (Just Locale.ja) + , test "ko" <| + \() -> + Expect.equal (Locale.fromLanguageTag "ko") (Just Locale.ko) + , test "en-US" <| + \() -> + Expect.notEqual (Locale.fromLanguageTag "en-US") (Just Locale.en) + , test "normalizes capitalization" <| + \() -> + Expect.equal + (Locale.fromLanguageTag "ZH-hant-hk" + |> withDefault Locale.en + |> Locale.toLanguageTag + ) + "zh-Hant-HK" + , fuzz string "doesn't crash on bad inputs" <| + \tag -> + case Locale.fromLanguageTag tag of + Nothing -> + Expect.pass + + Just _ -> + Expect.pass + ] + + toLanguageTagTests = + describe "toLanguageTag" + [ test "en" <| + \() -> + Expect.equal (Locale.toLanguageTag Locale.en) "en" + , test "zh-CN" <| + \() -> + Expect.equal (Locale.toLanguageTag Locale.zhCN) "zh-CN" + , test "zh-TW" <| + \() -> + Expect.equal (Locale.toLanguageTag Locale.zhTW) "zh-TW" + , test "fr" <| + \() -> + Expect.equal (Locale.toLanguageTag Locale.fr) "fr" + , test "de" <| + \() -> + Expect.equal (Locale.toLanguageTag Locale.de) "de" + , test "it" <| + \() -> + Expect.equal (Locale.toLanguageTag Locale.it) "it" + , test "ja" <| + \() -> + Expect.equal (Locale.toLanguageTag Locale.ja) "ja" + , test "ko" <| + \() -> + Expect.equal (Locale.toLanguageTag Locale.ko) "ko" + , fuzz string "doesn't crash on random locales" <| + \tag -> + case Locale.fromLanguageTag tag of + Nothing -> + Expect.pass - toLanguageTagTests = describe "toLanguageTag" - [ test "en" <| - \() -> - Expect.equal (Locale.toLanguageTag Locale.en) "en" - , test "zh-CN" <| - \() -> - Expect.equal (Locale.toLanguageTag Locale.zhCN) "zh-CN" - , test "zh-TW" <| - \() -> - Expect.equal (Locale.toLanguageTag Locale.zhTW) "zh-TW" - , test "fr" <| - \() -> - Expect.equal (Locale.toLanguageTag Locale.fr) "fr" - , test "de" <| - \() -> - Expect.equal (Locale.toLanguageTag Locale.de) "de" - , test "it" <| - \() -> - Expect.equal (Locale.toLanguageTag Locale.it) "it" - , test "ja" <| - \() -> - Expect.equal (Locale.toLanguageTag Locale.ja) "ja" - , test "ko" <| - \() -> - Expect.equal (Locale.toLanguageTag Locale.ko) "ko" - , fuzz string "doesn't crash on random locales" <| - \tag -> - case Locale.fromLanguageTag tag of - Nothing -> Expect.pass - Just locale -> - Expect.equal - (toLower (Locale.toLanguageTag locale)) - (toLower tag) - ] - in - describe "Intl.Locale" - [ fromLanguageTagTests - , toLanguageTagTests - ] + Just locale -> + Expect.equal + (toLower (Locale.toLanguageTag locale)) + (toLower tag) + ] + in + describe "Intl.Locale" + [ fromLanguageTagTests + , toLanguageTagTests + ] diff --git a/tests/Test/NumberFormat.elm b/tests/Test/NumberFormat.elm index 7e7dbdc..94779c2 100644 --- a/tests/Test/NumberFormat.elm +++ b/tests/Test/NumberFormat.elm @@ -2,246 +2,307 @@ module Test.NumberFormat exposing (all) import Test exposing (..) import Expect - import Intl.NumberFormat as NumberFormat import Intl.Locale as Locale import Intl.Currency as Currency import List exposing (map, concat, length) import Maybe exposing (Maybe(Just), withDefault) + all : Test all = - let - fromLocaleTests = describe "fromLocale" - [ test "formats numbers" <| - \() -> - let - format = NumberFormat.format (NumberFormat.fromLocale Locale.en) - in - Expect.equal (format 12345.6789) "12,345.679" - ] - fromOptionsTests = describe "specified options" - [ let - options = - { defaults - | style = NumberFormat.PercentStyle - , maximumSignificantDigits = Just 3 - } - format = NumberFormat.format (NumberFormat.fromOptions options) - resolved = NumberFormat.resolvedOptions (NumberFormat.fromOptions options) - in - describe "percent" - [ test "format" <| - \() -> Expect.equal (format 0.12345) "12.3%" - , test "resolvedOptions" <| - \() -> Expect.equal - resolved.maximumSignificantDigits - options.maximumSignificantDigits - ] - , let - options = - { defaults - | style = NumberFormat.PercentStyle - , minimumFractionDigits = Just 2 - } - format = NumberFormat.format (NumberFormat.fromOptions options) - resolved = NumberFormat.resolvedOptions (NumberFormat.fromOptions options) - in - describe "percent" - [ test "format" <| - \() -> Expect.equal (format 1) "100.00%" - , test "resolvedOptions" <| - \() -> Expect.equal - resolved.minimumFractionDigits - options.minimumFractionDigits - ] - , let - options = - { defaults - | style = NumberFormat.CurrencyStyle - , currency = Currency.cad - , currencyDisplay = NumberFormat.CurrencyCode - , minimumFractionDigits = Just 2 - } - format = NumberFormat.format (NumberFormat.fromOptions options) - resolved = NumberFormat.resolvedOptions (NumberFormat.fromOptions options) - in - describe "dollars" - [ test "format" <| - \() -> Expect.equal (format 42) "CAD42.00" - , test "resolvedOptions" <| - \() -> Expect.equal - resolved.currency - options.currency - ] - , let - options = - { defaults - | style = NumberFormat.CurrencyStyle - , currency = Currency.chf - , currencyDisplay = NumberFormat.CurrencyName - } - format = NumberFormat.format (NumberFormat.fromOptions options) - resolved = NumberFormat.resolvedOptions (NumberFormat.fromOptions options) - in - describe "francs" - [ test "format" <| - \() -> Expect.equal (format 42) "42.00 Swiss francs" - , test "resolvedOptions" <| - \() -> Expect.equal - resolved.currencyDisplay - options.currencyDisplay - ] - , let - options = - { defaults - | style = NumberFormat.CurrencyStyle - , currency = Currency.jpy - , currencyDisplay = NumberFormat.CurrencySymbol - } - format = NumberFormat.format (NumberFormat.fromOptions options) - resolved = NumberFormat.resolvedOptions (NumberFormat.fromOptions options) - in - describe "yen" - [ test "format" <| - \() -> Expect.equal (format 3456) "¥3,456" - , test "resolvedOptions" <| - \() -> Expect.equal - resolved.currencyDisplay - options.currencyDisplay - ] - , let - options = - { defaults - | minimumIntegerDigits = Just 2 - } - format = NumberFormat.format (NumberFormat.fromOptions options) - resolved = NumberFormat.resolvedOptions (NumberFormat.fromOptions options) - in - describe "minimumIntegerDigits" - [ test "format" <| - \() -> Expect.equal (format 0.3456) "00.346" - , test "resolvedOptions" <| - \() -> Expect.equal - resolved.minimumIntegerDigits - options.minimumIntegerDigits - ] - , let - options = - { defaults - | minimumFractionDigits = Just 3 - } - format = NumberFormat.format (NumberFormat.fromOptions options) - resolved = NumberFormat.resolvedOptions (NumberFormat.fromOptions options) - in - describe "minimumFractionDigits" - [ test "format" <| - \() -> Expect.equal (format 2) "2.000" - , test "resolvedOptions" <| - \() -> Expect.equal - resolved.minimumFractionDigits - options.minimumFractionDigits - ] - , let - options = - { defaults - | maximumFractionDigits = Just 1 - } - format = NumberFormat.format (NumberFormat.fromOptions options) - resolved = NumberFormat.resolvedOptions (NumberFormat.fromOptions options) - in - describe "maximumFractionDigits" - [ test "format" <| - \() -> Expect.equal (format 0.1234) "0.1" - , test "resolvedOptions" <| - \() -> Expect.equal - resolved.maximumFractionDigits - options.maximumFractionDigits - ] - , let - options = - { defaults - | minimumSignificantDigits = Just 5 - } - format = NumberFormat.format (NumberFormat.fromOptions options) - resolved = NumberFormat.resolvedOptions (NumberFormat.fromOptions options) - in - describe "minimumSignificantDigits" - [ test "format" <| - \() -> Expect.equal (format 0) "0.0000" - , test "resolvedOptions" <| - \() -> Expect.equal - resolved.minimumSignificantDigits - options.minimumSignificantDigits - ] - , let - options = - { defaults - | maximumSignificantDigits = Just 1 - } - format = NumberFormat.format (NumberFormat.fromOptions options) - resolved = NumberFormat.resolvedOptions (NumberFormat.fromOptions options) - in - describe "maximumSignificantDigits" - [ test "format" <| - \() -> Expect.equal (format 123.456) "100" - , test "resolvedOptions" <| - \() -> Expect.equal - resolved.maximumSignificantDigits - options.maximumSignificantDigits + let + fromLocaleTests = + describe "fromLocale" + [ test "formats numbers" <| + \() -> + let + format = + NumberFormat.format (NumberFormat.fromLocale Locale.en) + in + Expect.equal (format 12345.6789) "12,345.679" + ] + + fromOptionsTests = + describe "specified options" + [ let + options = + { defaults + | style = NumberFormat.PercentStyle + , maximumSignificantDigits = Just 3 + } + + format = + NumberFormat.format (NumberFormat.fromOptions options) + + resolved = + NumberFormat.resolvedOptions (NumberFormat.fromOptions options) + in + describe "percent" + [ test "format" <| + \() -> Expect.equal (format 0.12345) "12.3%" + , test "resolvedOptions" <| + \() -> + Expect.equal + resolved.maximumSignificantDigits + options.maximumSignificantDigits + ] + , let + options = + { defaults + | style = NumberFormat.PercentStyle + , minimumFractionDigits = Just 2 + } + + format = + NumberFormat.format (NumberFormat.fromOptions options) + + resolved = + NumberFormat.resolvedOptions (NumberFormat.fromOptions options) + in + describe "percent" + [ test "format" <| + \() -> Expect.equal (format 1) "100.00%" + , test "resolvedOptions" <| + \() -> + Expect.equal + resolved.minimumFractionDigits + options.minimumFractionDigits + ] + , let + options = + { defaults + | style = NumberFormat.CurrencyStyle + , currency = Currency.cad + , currencyDisplay = NumberFormat.CurrencyCode + , minimumFractionDigits = Just 2 + } + + format = + NumberFormat.format (NumberFormat.fromOptions options) + + resolved = + NumberFormat.resolvedOptions (NumberFormat.fromOptions options) + in + describe "dollars" + [ test "format" <| + \() -> Expect.equal (format 42) "CAD42.00" + , test "resolvedOptions" <| + \() -> + Expect.equal + resolved.currency + options.currency + ] + , let + options = + { defaults + | style = NumberFormat.CurrencyStyle + , currency = Currency.chf + , currencyDisplay = NumberFormat.CurrencyName + } + + format = + NumberFormat.format (NumberFormat.fromOptions options) + + resolved = + NumberFormat.resolvedOptions (NumberFormat.fromOptions options) + in + describe "francs" + [ test "format" <| + \() -> Expect.equal (format 42) "42.00 Swiss francs" + , test "resolvedOptions" <| + \() -> + Expect.equal + resolved.currencyDisplay + options.currencyDisplay + ] + , let + options = + { defaults + | style = NumberFormat.CurrencyStyle + , currency = Currency.jpy + , currencyDisplay = NumberFormat.CurrencySymbol + } + + format = + NumberFormat.format (NumberFormat.fromOptions options) + + resolved = + NumberFormat.resolvedOptions (NumberFormat.fromOptions options) + in + describe "yen" + [ test "format" <| + \() -> Expect.equal (format 3456) "¥3,456" + , test "resolvedOptions" <| + \() -> + Expect.equal + resolved.currencyDisplay + options.currencyDisplay + ] + , let + options = + { defaults + | minimumIntegerDigits = Just 2 + } + + format = + NumberFormat.format (NumberFormat.fromOptions options) + + resolved = + NumberFormat.resolvedOptions (NumberFormat.fromOptions options) + in + describe "minimumIntegerDigits" + [ test "format" <| + \() -> Expect.equal (format 0.3456) "00.346" + , test "resolvedOptions" <| + \() -> + Expect.equal + resolved.minimumIntegerDigits + options.minimumIntegerDigits + ] + , let + options = + { defaults + | minimumFractionDigits = Just 3 + } + + format = + NumberFormat.format (NumberFormat.fromOptions options) + + resolved = + NumberFormat.resolvedOptions (NumberFormat.fromOptions options) + in + describe "minimumFractionDigits" + [ test "format" <| + \() -> Expect.equal (format 2) "2.000" + , test "resolvedOptions" <| + \() -> + Expect.equal + resolved.minimumFractionDigits + options.minimumFractionDigits + ] + , let + options = + { defaults + | maximumFractionDigits = Just 1 + } + + format = + NumberFormat.format (NumberFormat.fromOptions options) + + resolved = + NumberFormat.resolvedOptions (NumberFormat.fromOptions options) + in + describe "maximumFractionDigits" + [ test "format" <| + \() -> Expect.equal (format 0.1234) "0.1" + , test "resolvedOptions" <| + \() -> + Expect.equal + resolved.maximumFractionDigits + options.maximumFractionDigits + ] + , let + options = + { defaults + | minimumSignificantDigits = Just 5 + } + + format = + NumberFormat.format (NumberFormat.fromOptions options) + + resolved = + NumberFormat.resolvedOptions (NumberFormat.fromOptions options) + in + describe "minimumSignificantDigits" + [ test "format" <| + \() -> Expect.equal (format 0) "0.0000" + , test "resolvedOptions" <| + \() -> + Expect.equal + resolved.minimumSignificantDigits + options.minimumSignificantDigits + ] + , let + options = + { defaults + | maximumSignificantDigits = Just 1 + } + + format = + NumberFormat.format (NumberFormat.fromOptions options) + + resolved = + NumberFormat.resolvedOptions (NumberFormat.fromOptions options) + in + describe "maximumSignificantDigits" + [ test "format" <| + \() -> Expect.equal (format 123.456) "100" + , test "resolvedOptions" <| + \() -> + Expect.equal + resolved.maximumSignificantDigits + options.maximumSignificantDigits + ] + ] + + supportedLocalesOfTests = + describe "supportedLocalesOf" + [ test "at least one predefined locale is supported" <| + \() -> + Expect.atLeast 1 + (length (NumberFormat.supportedLocalesOf predefinedLocales)) + , test "not all locales are supported" <| + \() -> + Expect.equal + (NumberFormat.supportedLocalesOf + [ withDefault Locale.en (Locale.fromLanguageTag "tlh") + -- Klingon + , withDefault Locale.en (Locale.fromLanguageTag "qya") + -- Elvish + ] + ) + [] + ] + + defaultsTests = + describe "defaults" + [ test "ends up having specific options" <| + \() -> + let + resolved = + NumberFormat.fromOptions defaults + |> NumberFormat.resolvedOptions + in + Expect.equal resolved + { defaults + | maximumFractionDigits = Just 3 + , minimumFractionDigits = Just 0 + , minimumIntegerDigits = Just 1 + } + ] + in + describe "Intl.NumberFormat" + [ fromLocaleTests + , fromOptionsTests + , supportedLocalesOfTests + , defaultsTests ] - ] - supportedLocalesOfTests = describe "supportedLocalesOf" - [ test "at least one predefined locale is supported" <| - \() -> - Expect.atLeast 1 - (length (NumberFormat.supportedLocalesOf predefinedLocales)) - , test "not all locales are supported" <| - \() -> - Expect.equal - ( NumberFormat.supportedLocalesOf - [ withDefault Locale.en (Locale.fromLanguageTag "tlh") -- Klingon - , withDefault Locale.en (Locale.fromLanguageTag "qya") -- Elvish - ] - ) - [] - ] - defaultsTests = describe "defaults" - [ test "ends up having specific options" <| - \() -> - let - resolved = - NumberFormat.fromOptions defaults - |> NumberFormat.resolvedOptions - in - Expect.equal resolved - { defaults - | maximumFractionDigits = Just 3 - , minimumFractionDigits = Just 0 - , minimumIntegerDigits = Just 1 - } - ] - in - describe "Intl.NumberFormat" - [ fromLocaleTests - , fromOptionsTests - , supportedLocalesOfTests - , defaultsTests - ] defaults : NumberFormat.Options defaults = - NumberFormat.defaults + NumberFormat.defaults + predefinedLocales : List Locale.Locale predefinedLocales = - [ Locale.en - , Locale.zhCN - , Locale.zhTW - , Locale.fr - , Locale.de - , Locale.it - , Locale.ja - , Locale.ko - ] + [ Locale.en + , Locale.zhCN + , Locale.zhTW + , Locale.fr + , Locale.de + , Locale.it + , Locale.ja + , Locale.ko + ] diff --git a/tests/Test/TimeZone.elm b/tests/Test/TimeZone.elm index ece841a..203aea9 100644 --- a/tests/Test/TimeZone.elm +++ b/tests/Test/TimeZone.elm @@ -3,65 +3,72 @@ module Test.TimeZone exposing (all) import Test exposing (..) import Fuzz exposing (string) import Expect - import Intl.TimeZone as TimeZone import Maybe exposing (..) import String exposing (toLower) + all : Test all = - let - fromIANATimeZoneNameTests = describe "fromIANATimeZoneName" - [ test "empty string" <| - \() -> - Expect.equal (TimeZone.fromIANATimeZoneName "") Nothing - , test "invalid characters" <| - \() -> - Expect.equal (TimeZone.fromIANATimeZoneName "$@#") Nothing - , test "utc" <| - \() -> - Expect.equal (TimeZone.fromIANATimeZoneName "utc") (Just TimeZone.utc) - , test "maps Etc/UTC to UTC" <| - \() -> - Expect.equal (TimeZone.fromIANATimeZoneName "Etc/UTC") (Just TimeZone.utc) - , test "canonicalizes time zones" <| - \() -> - Expect.equal - ( TimeZone.fromIANATimeZoneName "Europe/Belfast" - |> withDefault TimeZone.utc - |> TimeZone.toIANATimeZoneName - ) - "Europe/London" - , test "normalizes capitalization" <| - \() -> - Expect.equal - ( TimeZone.fromIANATimeZoneName "aMerIcA/BOISE" - |> withDefault TimeZone.utc - |> TimeZone.toIANATimeZoneName - ) - "America/Boise" - , fuzz string "doesn't crash on bad inputs" <| - \name -> - case TimeZone.fromIANATimeZoneName name of - Nothing -> Expect.pass - Just _ -> Expect.pass - ] + let + fromIANATimeZoneNameTests = + describe "fromIANATimeZoneName" + [ test "empty string" <| + \() -> + Expect.equal (TimeZone.fromIANATimeZoneName "") Nothing + , test "invalid characters" <| + \() -> + Expect.equal (TimeZone.fromIANATimeZoneName "$@#") Nothing + , test "utc" <| + \() -> + Expect.equal (TimeZone.fromIANATimeZoneName "utc") (Just TimeZone.utc) + , test "maps Etc/UTC to UTC" <| + \() -> + Expect.equal (TimeZone.fromIANATimeZoneName "Etc/UTC") (Just TimeZone.utc) + , test "canonicalizes time zones" <| + \() -> + Expect.equal + (TimeZone.fromIANATimeZoneName "Europe/Belfast" + |> withDefault TimeZone.utc + |> TimeZone.toIANATimeZoneName + ) + "Europe/London" + , test "normalizes capitalization" <| + \() -> + Expect.equal + (TimeZone.fromIANATimeZoneName "aMerIcA/BOISE" + |> withDefault TimeZone.utc + |> TimeZone.toIANATimeZoneName + ) + "America/Boise" + , fuzz string "doesn't crash on bad inputs" <| + \name -> + case TimeZone.fromIANATimeZoneName name of + Nothing -> + Expect.pass + + Just _ -> + Expect.pass + ] + + toIANATimeZoneNameTests = + describe "toIANATimeZoneName" + [ test "utc" <| + \() -> + Expect.equal (TimeZone.toIANATimeZoneName TimeZone.utc) "UTC" + , fuzz string "doesn't crash on random TimeZones" <| + \name -> + case TimeZone.fromIANATimeZoneName name of + Nothing -> + Expect.pass - toIANATimeZoneNameTests = describe "toIANATimeZoneName" - [ test "utc" <| - \() -> - Expect.equal (TimeZone.toIANATimeZoneName TimeZone.utc) "UTC" - , fuzz string "doesn't crash on random TimeZones" <| - \name -> - case TimeZone.fromIANATimeZoneName name of - Nothing -> Expect.pass - Just timeZone -> - Expect.equal - (toLower (TimeZone.toIANATimeZoneName timeZone)) - (toLower name) - ] - in - describe "Intl.TimeZone" - [ fromIANATimeZoneNameTests - , toIANATimeZoneNameTests - ] + Just timeZone -> + Expect.equal + (toLower (TimeZone.toIANATimeZoneName timeZone)) + (toLower name) + ] + in + describe "Intl.TimeZone" + [ fromIANATimeZoneNameTests + , toIANATimeZoneNameTests + ] From 60b6b6352c9747087cbdc7da8ba222f5a403e7bc Mon Sep 17 00:00:00 2001 From: Luke Plant Date: Thu, 9 Aug 2018 11:22:50 +0100 Subject: [PATCH 2/5] Updated to Elm 0.18 and latest elm-test --- .travis.yml | 2 +- elm-package.json | 6 +++--- tests/Main.elm | 13 ------------- tests/elm-package.json | 7 +++---- 4 files changed, 7 insertions(+), 21 deletions(-) delete mode 100644 tests/Main.elm diff --git a/.travis.yml b/.travis.yml index 3b1bc60..2f13157 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ node_js: - lts/* - stable install: - - npm install -g standard elm@0.17 elm-test@0.17 + - npm install -g standard elm@0.18 elm-test@0.18 - elm-package install -y - pushd tests && elm-package install -y && popd script: diff --git a/elm-package.json b/elm-package.json index 9ee030d..65eb21a 100644 --- a/elm-package.json +++ b/elm-package.json @@ -1,5 +1,5 @@ { - "version": "1.0.0", + "version": "2.0.0", "summary": "Bindings to JavaScript Internationalization API", "repository": "https://github.com/vanwagonet/elm-intl.git", "license": "BSD3", @@ -16,7 +16,7 @@ ], "native-modules": true, "dependencies": { - "elm-lang/core": "4.0.5 <= v < 5.0.0" + "elm-lang/core": "5.1.1 <= v < 6.0.0" }, - "elm-version": "0.17.1 <= v < 0.18.0" + "elm-version": "0.18.0 <= v < 0.19.0" } diff --git a/tests/Main.elm b/tests/Main.elm deleted file mode 100644 index dbd22a1..0000000 --- a/tests/Main.elm +++ /dev/null @@ -1,13 +0,0 @@ -port module Main exposing (..) - -import Tests -import Test.Runner.Node exposing (run) -import Json.Encode exposing (Value) - - -main : Program Value -main = - run emit Tests.all - - -port emit : ( String, Value ) -> Cmd msg diff --git a/tests/elm-package.json b/tests/elm-package.json index 26ea67a..e780a35 100644 --- a/tests/elm-package.json +++ b/tests/elm-package.json @@ -10,9 +10,8 @@ "exposed-modules": [], "native-modules": true, "dependencies": { - "elm-lang/core": "4.0.0 <= v < 5.0.0", - "elm-community/elm-test": "2.0.0 <= v < 3.0.0", - "rtfeldman/node-test-runner": "2.0.0 <= v < 3.0.0" + "elm-lang/core": "5.0.0 <= v < 6.0.0", + "elm-community/elm-test": "4.0.0 <= v < 5.0.0" }, - "elm-version": "0.17.0 <= v < 0.18.0" + "elm-version": "0.18.0 <= v < 0.19.0" } From 465b1c93df54206bd4c5c3c23bd449a67472cfa0 Mon Sep 17 00:00:00 2001 From: Luke Plant Date: Thu, 9 Aug 2018 11:31:10 +0100 Subject: [PATCH 3/5] Got all tests running with recent elm-test --- tests/Test/Collator.elm | 2 +- tests/Test/DateTimeFormat.elm | 2 +- tests/Test/NumberFormat.elm | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Test/Collator.elm b/tests/Test/Collator.elm index 25bf6be..46d4c74 100644 --- a/tests/Test/Collator.elm +++ b/tests/Test/Collator.elm @@ -33,7 +33,7 @@ all = describe "fromOptions and resolvedOptions" (map (\options -> - test "options" <| + test ("options " ++ toString options) <| \() -> let resolved = diff --git a/tests/Test/DateTimeFormat.elm b/tests/Test/DateTimeFormat.elm index 896c165..5781122 100644 --- a/tests/Test/DateTimeFormat.elm +++ b/tests/Test/DateTimeFormat.elm @@ -32,7 +32,7 @@ all = describe "fromOptions and resolvedOptions" (map (\options -> - test "options" <| + test ("options " ++ toString options) <| \() -> let resolved = diff --git a/tests/Test/NumberFormat.elm b/tests/Test/NumberFormat.elm index 94779c2..f7fc23a 100644 --- a/tests/Test/NumberFormat.elm +++ b/tests/Test/NumberFormat.elm @@ -38,7 +38,7 @@ all = resolved = NumberFormat.resolvedOptions (NumberFormat.fromOptions options) in - describe "percent" + describe "percent maximumSignificantDigits" [ test "format" <| \() -> Expect.equal (format 0.12345) "12.3%" , test "resolvedOptions" <| @@ -60,7 +60,7 @@ all = resolved = NumberFormat.resolvedOptions (NumberFormat.fromOptions options) in - describe "percent" + describe "percent minimumFractionDigits" [ test "format" <| \() -> Expect.equal (format 1) "100.00%" , test "resolvedOptions" <| From 6d853a74d0bba3e7e9dcf5ab548a8f1881fb9aef Mon Sep 17 00:00:00 2001 From: Luke Plant Date: Mon, 13 Aug 2018 20:31:13 +0100 Subject: [PATCH 4/5] Deleted unneeded Tests.elm file All the tests are found without this using new elm-test, and with it the tests are duplicated. --- tests/Tests.elm | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 tests/Tests.elm diff --git a/tests/Tests.elm b/tests/Tests.elm deleted file mode 100644 index 90a5b78..0000000 --- a/tests/Tests.elm +++ /dev/null @@ -1,21 +0,0 @@ -module Tests exposing (..) - -import Test exposing (..) - -import Test.Collator as Collator -import Test.Currency as Currency -import Test.DateTimeFormat as DateTimeFormat -import Test.Locale as Locale -import Test.NumberFormat as NumberFormat -import Test.TimeZone as TimeZone - -all : Test -all = - describe "Tests for Internationalization API bindings" - [ Collator.all - , Currency.all - , DateTimeFormat.all - , Locale.all - , NumberFormat.all - , TimeZone.all - ] From 17c65cb37023f7a30028f27e3bb345561245c8ee Mon Sep 17 00:00:00 2001 From: Luke Plant Date: Mon, 20 Aug 2018 20:28:22 +0100 Subject: [PATCH 5/5] Fixed issues raised by 'standard' --- src/Native/Intl/DateTimeFormat.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Native/Intl/DateTimeFormat.js b/src/Native/Intl/DateTimeFormat.js index 34b2e43..37782b1 100644 --- a/src/Native/Intl/DateTimeFormat.js +++ b/src/Native/Intl/DateTimeFormat.js @@ -56,7 +56,6 @@ var _thetalecrafter$elm_intl$Native_Intl_DateTimeFormat = function () { return 'long' case _thetalecrafter$elm_intl$Intl_DateTimeFormat$OmitName: default: - return } } @@ -79,7 +78,6 @@ var _thetalecrafter$elm_intl$Native_Intl_DateTimeFormat = function () { return '2-digit' case _thetalecrafter$elm_intl$Intl_DateTimeFormat$OmitNumber: default: - return } } @@ -114,7 +112,6 @@ var _thetalecrafter$elm_intl$Native_Intl_DateTimeFormat = function () { return '2-digit' case _thetalecrafter$elm_intl$Intl_DateTimeFormat$OmitMonth: default: - return } } @@ -137,7 +134,6 @@ var _thetalecrafter$elm_intl$Native_Intl_DateTimeFormat = function () { return 'long' case _thetalecrafter$elm_intl$Intl_DateTimeFormat$OmitTimeZone: default: - return } }