[swift-corelibs-dev] Strange behavior the same code fails when building a Cocoa CLI and succeeds in Swift-corelibs-foundation context.
Benoit Pereira da silva
bpds at me.com
Mon Dec 18 10:44:48 CST 2017
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-corelibs-dev/attachments/20171218/10d611a1/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bannerp.jpg
Type: image/jpeg
Size: 27829 bytes
Desc: not available
URL: <https://lists.swift.org/pipermail/swift-corelibs-dev/attachments/20171218/10d611a1/attachment.jpg>
More information about the swift-corelibs-dev
mailing list