Dear All,

I do encounter a very strange Issue.

I have been adding a test to 
`swift-corelibs-foundation/testJSONSerialization.swift`
This test succeed within swift-corelibs-foundation test, but fails when 
repackaged to a Cocoa CLI app.

The  swift-corelibs-foundation test : 


    func test_serializeFloatingPointWithANonDotDecimalSeparatorLocale() {
        // We use a locale that is using "," as decimal separator.
        setlocale(LC_ALL,"fr_FR")

        let dictionary = ["decimalValue":1.1]
        do{
            let data = try JSONSerialization.data(withJSONObject: dictionary)
            if let json =  String(data:data, encoding:.utf8){
                XCTAssert(!json.contains(","), "Expected result: 
\"{\"decimalValue\":1.1000000000000001}\" found: \"\(json)\"" )
            }else{
                XCTFail("Failed during string encoding")
            }
        }catch{
            XCTFail("Failed during serialization")
        }
    }


The simple CLI code that proves the bug (https://bugs.swift.org/browse/SR-6631 
<https://bugs.swift.org/browse/SR-6631>)

//
//  main.swift
//  doubleEncoding
//
//  Created by Benoit Pereira da silva on 02/12/2017.
//  Copyright © 2017 Pereira da Silva. All rights reserved.
//

import Foundation

// Let's set to french
setlocale(LC_ALL,"fr_FR")

do{
    let dictionary = ["decimalValue":1.1]
    let data = try JSONSerialization.data(withJSONObject: dictionary)
    if let json =  String(data:data, encoding:.utf8){
        // the result is : "{"decimalValue":1,1000000000000001}"
        // The decimal separator should not be "," but "."
        print(json)
    }
}catch{
    print("\(error)")
}



Any idea ?
I do use Toolchain: Swift Development Snapshot 2017-12-17 (a)


Benoit



Benoit Pereira da Silva
Ultra Mobile Developer & Movement Activist
Développeur Ultra Mobile & Militant du mouvement
https://pereira-da-silva.com <https://pereira-da-silva.com/>





✄ --------------------------------
This e-mail is confidential. Distribution, copy, publication or use of this 
information for any purpose is prohibited without agreement of the sender.
Ce message est confidentiel. Toute distribution, copie, publication ou usage 
des informations contenues dans ce message sont interdits sans agrément 
préalable de l'expéditeur.



_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev

Reply via email to