@@ -4,37 +4,68 @@ module.exports = {
44
55 testLocaleDisplayNames : function ( json ) {
66 let locale = 'en' ; // Default
7- let options = { } ;
87 if ( json [ 'locale_label' ] ) {
98 // Fix to use dash, not underscore.
109 locale = json [ 'locale_label' ] . replace ( / _ / g, '-' ) ;
1110 }
1211
13- // options = json['options'];
14- options = { type : 'language' , languageDisplay : 'standard' } ;
12+ // Standard for this type of testing.
13+ let options = { type : 'language' ,
14+ languageDisplay : 'standard' ,
15+ style : 'long' } ;
16+
1517 let label = json [ 'label' ] ;
1618 let input = json [ 'language_label' ] . replace ( / _ / g, '-' ) ;
19+ let outputLine = {
20+ "label" : json [ 'label' ] ,
21+ "locale_label" : locale ,
22+ "language_label" : input ,
23+ } ;
24+
25+ try {
26+ const supported_locales =
27+ Intl . DisplayNames . supportedLocalesOf ( [ locale ] ) ;
28+ } catch ( error ) {
29+ // Something wrong with the locale for this
30+ outputLine [ "error_detail" ] = locale
31+ outputLine [ "error_type" ] = 'unsupported locale' ;
32+ outputLine [ "unsupported" ] = error . toString ( ) ;
33+ return outputLine ;
34+ }
35+
36+ // Check the language to be formatted
37+ try {
38+ let language_label_locale = new Intl . Locale ( input ) ;
39+ } catch ( error ) {
40+ // Something wrong with the locale for this
41+ outputLine [ "error_detail" ] = input ;
42+ outputLine [ "error_type" ] = 'Problem with language label' ;
43+ outputLine [ "unsupported" ] = error . toString ( ) ;
44+ outputLine [ "actual_options" ] = JSON . stringify ( options ) ;
45+ return outputLine ;
46+ }
1747
1848 if ( json [ 'languageDisplay' ] ) {
19- // Fix to use dash, not underscore.
2049 options [ 'languageDisplay' ] = json [ 'languageDisplay' ] ;
2150 }
2251
23- let outputLine ;
24-
2552 let dn ;
2653 try {
2754 dn = new Intl . DisplayNames ( [ locale ] , options ) ;
2855 } catch ( error ) {
2956 outputLine = {
3057 "error" : error . toString ( ) ,
31- "label" : json [ 'label' ] ,
3258 "locale_label" : locale ,
33- "language_label" : input ,
34- "test_type" : "display_names" ,
35- "error_type" : "unsupported" ,
59+ "error_detail" : "Bad constructor for locale: " + locale + ' ' + options ,
3660 "error_retry" : false // Do not repeat
3761 } ;
62+ if ( error instanceof RangeError ) {
63+ // The locale can't be handled for some reason!
64+ outputLine [ "error_type" ] = 'unsupported' ;
65+ outputLine [ "unsupported" ] = error . toString ( ) ;
66+ outputLine [ "error_detail" ] = locale ;
67+ outputLine [ "actual_options" ] = JSON . stringify ( options ) ;
68+ }
3869 return outputLine ;
3970 }
4071
@@ -45,12 +76,15 @@ module.exports = {
4576 "result" : resultString
4677 } ;
4778 } catch ( error ) {
79+ const error_string = error . toString ( ) ;
4880 outputLine = { "label" : json [ 'label' ] ,
4981 "locale_label" : locale ,
5082 "language_label" : input ,
5183 "result" : resultString ,
52- "error" : error . toString ( ) ,
53- "actual_options" : options . toString ( )
84+ "error_type" : 'unsupported' ,
85+ "unsupported" : error . toString ( ) ,
86+ "error_detail" : input ,
87+ "actual_options" : JSON . stringify ( options )
5488 } ;
5589 }
5690 return outputLine ;
0 commit comments