Hi,
Note: I'm using xcode 6.3.2, deployment target is iOS 8.3.
I'm trying to compare Strings containing currency symbols (namely the euro symbol). I wrote the following test:
// Given
let price = Money(amount: 50)
// When
let priceTag = price.format()
// Then
let expectedPriceTag = "50,00 €"
XCTAssertEqual(expectedPriceTag, priceTag, "Invalid formatting")
The Money format method is basically:
NSNumberFormatter.localizedStringFromNumber(amount, numberStyle: .CurrencyStyle)
The expectedPriceTag euro symbol is inserted using the Edit > Emoji & Symbols menu of xcode.
When running the test, I get the following failure message:
/Users/brieuc/Projects/Nestor/Nestor-iOS-Swift/NestorTests/MoneyTest.swift:104: error: -[NestorTests.MoneyTest testFormat2] :
XCTAssertEqual failed: ("50,00 €") is not equal to ("50,00 €") - Invalid formatting
I've looked twice but... yeah it's real. After looking at the content of the strings, it turns out that both strings have the same number of unicode scalars but differ by one...
priceTag: 53 48 44 48 48 160 8364
expectedPriceTag: 53 48 44 48 48 32 8364
So the NSNumberFormatter.localizedStringFromNumber with currency style inserts a unicode scalar with value 160 as a whitespace...
What should I do to make my code pass the test reliably ?
I've tried to insert this unicode scalar instead of a whitespace in expectedPriceTag but it does give me what I expected...
Any help and/or background info on how to fix this would be greatly appreciated
Thanks