// polyfill.number.toLocaleString
/*global describe, it, expect*/

describe('number.toLocaleString(locale) polyfill', function() {
    'use strict';

    it('needs to be overridden for phantomjs', function() {
        var num = 123456;
        var locale = 'iq';

        function testLocale() {
            return (num).toLocaleString(locale);
        }
        
        expect(testLocale).not.toThrow();
    });

    it('returns a string', function() {
        var num = 123456;
        var locale = 'CA';
        expect(typeof (num.toLocaleString(locale))).toBe('string');
    });

    it('returns a string formatted in FR style (1\u00A0234.5) when passed FR', function() {
        var num = 1234.5;
        var locale = 'FR';

        expect(num.toLocaleString(locale)).toEqual('1\u00A0234,5');
    });

    it('returns a string formatted in US style (1,234.5) when passed US', function() {
        var num = 1234.5;
        var locale = 'US';

        expect(num.toLocaleString(locale)).toBe('1,234.5');
    });

    it('returns a string formatted in IT style (1.234,5) when passed IT', function() {
        var num = 1234.5;
        var locale = 'IT';

        expect(num.toLocaleString(locale)).toBe('1.234,5');
    });

    it('returns a formatted string based only on the language code in complex locale codes', function() {
        var num = 1234.5;
        var locale = 'it-US';

        expect(num.toLocaleString(locale)).toBe('1.234,5');
    });

	it('returns a string formatted in KR style (1,234.5) when passed KR', function() {
		var num = 1234.5;
		var locale = 'KR';

		expect(num.toLocaleString(locale)).toBe('1,234.5');
	});

    it('throws when the language tag does not conform to the standard', function() {
        var num = 1234.5;
        var locale = 'i';

        function testLocale() {
            return (num).toLocaleString(locale);
        }

        expect(testLocale).toThrow(new RangeError("Invalid language tag: " + locale));
    });

    it('should support options with minimumFractionDigits', function() {
        var num = 1234;
        var locale = 'it-IT';

        expect(num.toLocaleString(locale, { minimumFractionDigits: 2 })).toBe('1.234,00');
    });

    it('should support options with minimumFractionDigits', function() {
        var num = 1234.0000;
        var locale = 'it-IT';

        expect(num.toLocaleString(locale, { minimumFractionDigits: 4 })).toBe('1.234,0000');
    });

    it('returns a string formatted in US style (1,234.5) by default', function() {
        var num = 1234.5;
        
        expect(num.toLocaleString()).toBe('1,234.5');
        expect(num.toLocaleString('MX')).toBe('1,234.5');
        expect(num.toLocaleString('AU')).toBe('1,234.5');
    });

    it('returns currency properly formatted for the locale specified', function() {
        var num = 1234.56;
        var style = "currency";
        var currency = "USD";
        var currencyDisplay = "symbol";

        expect(num.toLocaleString("en-US", {
            style: style,
            currency: currency
        })).toBe("$1,234.56");

        expect(num.toLocaleString("de-DE", {
            style: style,
            currency: currency
        })).toBe("1.234,56 $");

	    expect(num.toLocaleString("ko-KR", {
		    style: style,
		    currency: "krw"
	    })).toBe("₩1,234.56");

	    expect(num.toLocaleString("ja-JP", {
		    style: style,
		    currency: "jpy"
	    })).toBe("￥1,234.56");
    });
});

@@ -348,24 +348,16 @@
       %7D%0A
-        
 %0A       
@@ -2533,17 +2533,9 @@
 .5;%0A
-        
 %0A
+
     
@@ -2634,32 +2634,32 @@
 oBe('1,234.5');%0A
-
         expect(n
@@ -2701,32 +2701,291 @@
 4.5');%0A    %7D);%0A%0A
+    it('returns a string formatted in Hungarian style (1 234,56) by default', function() %7B%0A        var num = 1234.56;%0A%0A        expect(num.toLocaleString('hu')).toBe('1%5Cu00A0234,56');%0A        expect(num.toLocaleString('hu-HU')).toBe('1%5Cu00A0234,56');%0A    %7D);%0A%0A
     it('returns 
@@ -3675,16 +3675,291 @@
 34.56%22);
+%0A%0A        expect(num.toLocaleString(%22hu%22, %7B%0A            style: style,%0A            currency: %22huf%22%0A        %7D)).toBe(%221%5Cu00A0234,56 HUF%22);%0A%0A        expect(num.toLocaleString(%22hu-HU%22, %7B%0A            style: style,%0A            currency: %22huf%22%0A        %7D)).toBe(%221%5Cu00A0234,56 HUF%22);
 %0A    %7D);

test added for hungarian support