forked from luximetr/AnyFormatKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed sum formatting with 2 symbol suffix.
- Loading branch information
Aleksandr Orlov
committed
Jun 20, 2019
1 parent
26caf82
commit e4e30df
Showing
18 changed files
with
496 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
116 changes: 116 additions & 0 deletions
116
...x/2SymbolSuffix/Delete/SumTextInputFormatterWith2SymbolsSuffixBy1SymbolErasingTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// | ||
// SumTextInputFormatterWith2SymbolsSuffixBy1SymbolErasingTests.swift | ||
// AnyFormatKitTests | ||
// | ||
// Created by branderstudio on 20.06.2019. | ||
// Copyright © 2019 BRANDERSTUDIO. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import AnyFormatKit | ||
|
||
class SumTextInputFormatterWith2SymbolsSuffixBy1SymbolErasingTests: XCTestCase { | ||
|
||
private let formatter = SumTextInputFormatter(textPattern: "#,###.## $") | ||
|
||
// 12,345.67 |$| -> 12,345.67 |$ | ||
func test1() { | ||
let actualResult = formatter.formatInput( | ||
currentText: "12,345.67 $", | ||
range: NSRange(location: 10, length: 1), | ||
replacementString: "") | ||
let expectedResult = FormattedTextValue(formattedText: "12,345.67 $", caretBeginOffset: 10) | ||
XCTAssert(actualResult == expectedResult, "\n\(actualResult) must be equal to\n\(expectedResult)") | ||
} | ||
|
||
// 12,345.67| |$ -> 12,345.67| $ | ||
func test2() { | ||
let actualResult = formatter.formatInput( | ||
currentText: "12,345.67 $", | ||
range: NSRange(location: 9, length: 1), | ||
replacementString: "") | ||
let expectedResult = FormattedTextValue(formattedText: "12,345.67 $", caretBeginOffset: 9) | ||
XCTAssert(actualResult == expectedResult, "\n\(actualResult) must be equal to\n\(expectedResult)") | ||
} | ||
|
||
// 12,345.6|7| $ -> 12,345.6| $ | ||
func test3() { | ||
let actualResult = formatter.formatInput( | ||
currentText: "12,345.67 $", | ||
range: NSRange(location: 8, length: 1), | ||
replacementString: "") | ||
let expectedResult = FormattedTextValue(formattedText: "12,345.6 $", caretBeginOffset: 8) | ||
XCTAssert(actualResult == expectedResult, "\n\(actualResult) must be equal to\n\(expectedResult)") | ||
} | ||
|
||
// 12,345.|6| $ -> 12,345.| $ | ||
func test4() { | ||
let actualResult = formatter.formatInput( | ||
currentText: "12,345.6 $", | ||
range: NSRange(location: 7, length: 1), | ||
replacementString: "") | ||
let expectedResult = FormattedTextValue(formattedText: "12,345. $", caretBeginOffset: 7) | ||
XCTAssert(actualResult == expectedResult, "\n\(actualResult) must be equal to\n\(expectedResult)") | ||
} | ||
|
||
// 12,345|.| $ -> 12,345| $ | ||
func test5() { | ||
let actualResult = formatter.formatInput( | ||
currentText: "12,345. $", | ||
range: NSRange(location: 6, length: 1), | ||
replacementString: "") | ||
let expectedResult = FormattedTextValue(formattedText: "12,345 $", caretBeginOffset: 6) | ||
XCTAssert(actualResult == expectedResult, "\n\(actualResult) must be equal to\n\(expectedResult)") | ||
} | ||
|
||
// 12,34|5| $ -> 1,234| $ | ||
func test6() { | ||
let actualResult = formatter.formatInput( | ||
currentText: "12,345 $", | ||
range: NSRange(location: 5, length: 1), | ||
replacementString: "") | ||
let expectedResult = FormattedTextValue(formattedText: "1,234 $", caretBeginOffset: 5) | ||
XCTAssert(actualResult == expectedResult, "\n\(actualResult) must be equal to\n\(expectedResult)") | ||
} | ||
|
||
// 1,23|4| $ -> 123| $ | ||
func test7() { | ||
let actualResult = formatter.formatInput( | ||
currentText: "1,234 $", | ||
range: NSRange(location: 4, length: 1), | ||
replacementString: "") | ||
let expectedResult = FormattedTextValue(formattedText: "123 $", caretBeginOffset: 3) | ||
XCTAssert(actualResult == expectedResult, "\n\(actualResult) must be equal to\n\(expectedResult)") | ||
} | ||
|
||
// 12|3| $ -> 12| $ | ||
func test8() { | ||
let actualResult = formatter.formatInput( | ||
currentText: "123 $", | ||
range: NSRange(location: 2, length: 1), | ||
replacementString: "") | ||
let expectedResult = FormattedTextValue(formattedText: "12 $", caretBeginOffset: 2) | ||
XCTAssert(actualResult == expectedResult, "\n\(actualResult) must be equal to\n\(expectedResult)") | ||
} | ||
|
||
// 1|2| $ -> 1| $ | ||
func test9() { | ||
let actualResult = formatter.formatInput( | ||
currentText: "12 $", | ||
range: NSRange(location: 1, length: 1), | ||
replacementString: "") | ||
let expectedResult = FormattedTextValue(formattedText: "1 $", caretBeginOffset: 1) | ||
XCTAssert(actualResult == expectedResult, "\n\(actualResult) must be equal to\n\(expectedResult)") | ||
} | ||
|
||
// |1| $ -> "| $" | ||
func test10() { | ||
let actualResult = formatter.formatInput( | ||
currentText: "1 $", | ||
range: NSRange(location: 0, length: 1), | ||
replacementString: "") | ||
let expectedResult = FormattedTextValue(formattedText: " $", caretBeginOffset: 0) | ||
XCTAssert(actualResult == expectedResult, "\n\(actualResult) must be equal to\n\(expectedResult)") | ||
} | ||
|
||
} |
106 changes: 106 additions & 0 deletions
106
...fix/2SymbolSuffix/Delete/SumTextInputFormatterWith2SymbolsSuffixDelete3SymbolsTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// | ||
// SumTextInputFormatterWith2SymbolsSuffixDelete3SymbolsTests.swift | ||
// AnyFormatKitTests | ||
// | ||
// Created by branderstudio on 20.06.2019. | ||
// Copyright © 2019 BRANDERSTUDIO. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import AnyFormatKit | ||
|
||
class SumTextInputFormatterWith2SymbolsSuffixDelete3SymbolsTests: XCTestCase { | ||
|
||
private let formatter = SumTextInputFormatter(textPattern: "#,###.## $") | ||
|
||
// |12,|345.67 $ -> |345.67 $ | ||
func test1() { | ||
let actualResult = formatter.formatInput( | ||
currentText: "12,345.67 $", | ||
range: NSRange(location: 0, length: 3), | ||
replacementString: "") | ||
let expectedResult = FormattedTextValue(formattedText: "345.67 $", caretBeginOffset: 0) | ||
XCTAssert(actualResult == expectedResult, "\n\(actualResult) must be equal to\n\(expectedResult)") | ||
} | ||
|
||
// 1|2,3|45.67 $ -> 1|45.67 $ | ||
func test2() { | ||
let actualResult = formatter.formatInput( | ||
currentText: "12,345.67 $", | ||
range: NSRange(location: 1, length: 3), | ||
replacementString: "") | ||
let expectedResult = FormattedTextValue(formattedText: "145.67 $", caretBeginOffset: 1) | ||
XCTAssert(actualResult == expectedResult, "\n\(actualResult) must be equal to\n\(expectedResult)") | ||
} | ||
|
||
// 12|,34|5.67 $ -> 12|5.67 $ | ||
func test3() { | ||
let actualResult = formatter.formatInput( | ||
currentText: "12,345.67 $", | ||
range: NSRange(location: 2, length: 3), | ||
replacementString: "") | ||
let expectedResult = FormattedTextValue(formattedText: "125.67 $", caretBeginOffset: 2) | ||
XCTAssert(actualResult == expectedResult, "\n\(actualResult) must be equal to\n\(expectedResult)") | ||
} | ||
|
||
// 12,|345|.67 $ -> 12|.67 $ | ||
func test4() { | ||
let actualResult = formatter.formatInput( | ||
currentText: "12,345.67 $", | ||
range: NSRange(location: 3, length: 3), | ||
replacementString: "") | ||
let expectedResult = FormattedTextValue(formattedText: "12.67 $", caretBeginOffset: 2) | ||
XCTAssert(actualResult == expectedResult, "\n\(actualResult) must be equal to\n\(expectedResult)") | ||
} | ||
|
||
// 12,3|45.|67 $ -> 12,3|67 $ | ||
func test5() { | ||
let actualResult = formatter.formatInput( | ||
currentText: "12,345.67 $", | ||
range: NSRange(location: 4, length: 3), | ||
replacementString: "") | ||
let expectedResult = FormattedTextValue(formattedText: "12,367 $", caretBeginOffset: 4) | ||
XCTAssert(actualResult == expectedResult, "\n\(actualResult) must be equal to\n\(expectedResult)") | ||
} | ||
|
||
// 12,34|5.6|7 $ -> 12,34|7 $ | ||
func test6() { | ||
let actualResult = formatter.formatInput( | ||
currentText: "12,345.67 $", | ||
range: NSRange(location: 5, length: 3), | ||
replacementString: "") | ||
let expectedResult = FormattedTextValue(formattedText: "12,347 $", caretBeginOffset: 5) | ||
XCTAssert(actualResult == expectedResult, "\n\(actualResult) must be equal to\n\(expectedResult)") | ||
} | ||
|
||
// 12,345|.67| $ -> 12,345| $ | ||
func test7() { | ||
let actualResult = formatter.formatInput( | ||
currentText: "12,345.67 $", | ||
range: NSRange(location: 6, length: 3), | ||
replacementString: "") | ||
let expectedResult = FormattedTextValue(formattedText: "12,345 $", caretBeginOffset: 6) | ||
XCTAssert(actualResult == expectedResult, "\n\(actualResult) must be equal to\n\(expectedResult)") | ||
} | ||
|
||
// 12,345.|67 |$ -> 12,345.| $ | ||
func test8() { | ||
let actualResult = formatter.formatInput( | ||
currentText: "12,345.67 $", | ||
range: NSRange(location: 7, length: 3), | ||
replacementString: "") | ||
let expectedResult = FormattedTextValue(formattedText: "12,345. $", caretBeginOffset: 7) | ||
XCTAssert(actualResult == expectedResult, "\n\(actualResult) must be equal to\n\(expectedResult)") | ||
} | ||
|
||
// 12,345.6|7 $| -> 12,345.6| $ | ||
func test9() { | ||
let actualResult = formatter.formatInput( | ||
currentText: "12,345.67 $", | ||
range: NSRange(location: 8, length: 3), | ||
replacementString: "") | ||
let expectedResult = FormattedTextValue(formattedText: "12,345.6 $", caretBeginOffset: 8) | ||
XCTAssert(actualResult == expectedResult, "\n\(actualResult) must be equal to\n\(expectedResult)") | ||
} | ||
|
||
} |
Oops, something went wrong.