An advanced Ethereum/EVM mobile wallet
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
alpha-wallet-ios/AlphaWalletTests/Foundation/DecimalNumberFormatterTest....

50 lines
2.5 KiB

// Copyright SIX DAY LLC. All rights reserved.
@testable import AlphaWallet
import XCTest
class DecimalFormatterTest: XCTestCase {
let usDecimalFormatter = DecimalFormatter(locale: Locale(identifier: "en_US"))
let frDecimalFormatter = DecimalFormatter(locale: Locale(identifier: "fr_FR"))
func testDecimalPointInUS() {
XCTAssertEqual(usDecimalFormatter.number(from: "1000.25"), NSNumber(value: 1000.25))
XCTAssertEqual(usDecimalFormatter.number(from: ".25"), NSNumber(value: 0.25))
}
func testDecimalAndThousandsPointsInUS() {
XCTAssertEqual(usDecimalFormatter.number(from: "1,000.25"), NSNumber(value: 1000.25))
XCTAssertEqual(usDecimalFormatter.number(from: "1.000,25"), NSNumber(value: 1000.25))
XCTAssertEqual(usDecimalFormatter.number(from: "1'000,25"), NSNumber(value: 1000.25))
}
func testThousandsPointsInUS() {
XCTAssertEqual(usDecimalFormatter.number(from: ",25"), NSNumber(value: 25))
}
func testNumberToStingInUS() {
XCTAssertEqual(usDecimalFormatter.string(from: NSNumber(value: 1000.25)), "1,000.25")
XCTAssertEqual(usDecimalFormatter.string(from: NSNumber(value: 0.25)), "0.25")
}
func testInvalidStringInUS() {
XCTAssertEqual(usDecimalFormatter.number(from: "test"), nil)
}
func testDecimalPointInFr() {
XCTAssertEqual(frDecimalFormatter.number(from: "1 000,25"), NSNumber(value: 1000.25))
XCTAssertEqual(frDecimalFormatter.number(from: ".25"), NSNumber(value: 25))
}
func testDecimalAndThousandsPointsInFr() {
XCTAssertEqual(frDecimalFormatter.number(from: "1,000.25"), NSNumber(value: 1000.25))
XCTAssertEqual(frDecimalFormatter.number(from: "1.000,25"), NSNumber(value: 1000.25))
XCTAssertEqual(frDecimalFormatter.number(from: "1'000,25"), NSNumber(value: 1000.25))
}
func testThousandsPointsInFr() {
XCTAssertEqual(frDecimalFormatter.number(from: ",25"), NSNumber(value: 0.25))
}
func testNumberToStingInFr() {
//NOTE: There some cases when for different simulators it uses different characters for space like \u{202F} or \u{00A0}.
let value: String = "1"+frDecimalFormatter.groupingSeparator+"000,25"
XCTAssertEqual(frDecimalFormatter.string(from: NSNumber(value: 1000.25))!, value)
XCTAssertEqual(frDecimalFormatter.string(from: NSNumber(value: 0.25)), "0,25")
}
func testInvalidStringInFr() {
XCTAssertEqual(frDecimalFormatter.number(from: "test"), nil)
}
}