Skip to content

Commit

Permalink
Added tests for sum input formatter with erasing by 1 symbol.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandr Orlov committed Jun 15, 2019
1 parent ec74c87 commit 2cf0472
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 182 deletions.
8 changes: 4 additions & 4 deletions AnyFormatKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
30A0495D22B5240E001F6282 /* SumTextInputFormatterWithPrefixBy1SymbolErasingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30A0495C22B5240E001F6282 /* SumTextInputFormatterWithPrefixBy1SymbolErasingTests.swift */; };
30A0495F22B52752001F6282 /* SumTextInputFormatterWithPrefixDelete3SymbolsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30A0495E22B52752001F6282 /* SumTextInputFormatterWithPrefixDelete3SymbolsTests.swift */; };
30A0496F22B52F86001F6282 /* SumTextInputFormatterInputTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30A0496E22B52F86001F6282 /* SumTextInputFormatterInputTests.swift */; };
30A0497122B52F8C001F6282 /* SumTextInputFormatterDeleteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30A0497022B52F8C001F6282 /* SumTextInputFormatterDeleteTests.swift */; };
30A0497322B532FC001F6282 /* SumTextInputFormatterInsert3Symbols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30A0497222B532FC001F6282 /* SumTextInputFormatterInsert3Symbols.swift */; };
30A0497522B535CF001F6282 /* SumTextInputFormatterReplace3SymbolsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30A0497422B535CF001F6282 /* SumTextInputFormatterReplace3SymbolsTests.swift */; };
30A0497722B537F4001F6282 /* SumTextInputFormatterErasingBy1SymbolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30A0497622B537F4001F6282 /* SumTextInputFormatterErasingBy1SymbolTests.swift */; };
30BD66911FAC789A002BFA4A /* demo.gif in Resources */ = {isa = PBXBuildFile; fileRef = 30BD66901FAC789A002BFA4A /* demo.gif */; };
30C156001FBC4DCC00C7229D /* SumEuropeanFormatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30C155FF1FBC4DCC00C7229D /* SumEuropeanFormatTests.swift */; };
30C5F53C1FAB6593003711D1 /* anyformatkit.png in Resources */ = {isa = PBXBuildFile; fileRef = 30C5F53B1FAB6593003711D1 /* anyformatkit.png */; };
Expand Down Expand Up @@ -92,9 +92,9 @@
30A0495C22B5240E001F6282 /* SumTextInputFormatterWithPrefixBy1SymbolErasingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SumTextInputFormatterWithPrefixBy1SymbolErasingTests.swift; sourceTree = "<group>"; };
30A0495E22B52752001F6282 /* SumTextInputFormatterWithPrefixDelete3SymbolsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SumTextInputFormatterWithPrefixDelete3SymbolsTests.swift; sourceTree = "<group>"; };
30A0496E22B52F86001F6282 /* SumTextInputFormatterInputTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SumTextInputFormatterInputTests.swift; sourceTree = "<group>"; };
30A0497022B52F8C001F6282 /* SumTextInputFormatterDeleteTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SumTextInputFormatterDeleteTests.swift; sourceTree = "<group>"; };
30A0497222B532FC001F6282 /* SumTextInputFormatterInsert3Symbols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SumTextInputFormatterInsert3Symbols.swift; sourceTree = "<group>"; };
30A0497422B535CF001F6282 /* SumTextInputFormatterReplace3SymbolsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SumTextInputFormatterReplace3SymbolsTests.swift; sourceTree = "<group>"; };
30A0497622B537F4001F6282 /* SumTextInputFormatterErasingBy1SymbolTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SumTextInputFormatterErasingBy1SymbolTests.swift; sourceTree = "<group>"; };
30BD66901FAC789A002BFA4A /* demo.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = demo.gif; sourceTree = "<group>"; };
30C155FF1FBC4DCC00C7229D /* SumEuropeanFormatTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SumEuropeanFormatTests.swift; sourceTree = "<group>"; };
30C5F53B1FAB6593003711D1 /* anyformatkit.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = anyformatkit.png; sourceTree = "<group>"; };
Expand Down Expand Up @@ -298,7 +298,7 @@
30A0496822B52AE0001F6282 /* Delete */ = {
isa = PBXGroup;
children = (
30A0497022B52F8C001F6282 /* SumTextInputFormatterDeleteTests.swift */,
30A0497622B537F4001F6282 /* SumTextInputFormatterErasingBy1SymbolTests.swift */,
);
path = Delete;
sourceTree = "<group>";
Expand Down Expand Up @@ -545,7 +545,6 @@
307EA2311FAA1B5B00DE439D /* DefaultTextInputFormatter.swift in Sources */,
30D7EAA4229C65570014E31B /* SumFormatParser.swift in Sources */,
307EA2341FAA1B5B00DE439D /* TextFormatter.swift in Sources */,
30A0497122B52F8C001F6282 /* SumTextInputFormatterDeleteTests.swift in Sources */,
307DCD4B1FC2CFA700889A52 /* SumTextFormatter.swift in Sources */,
307EA2411FAA1B5B00DE439D /* String+Extension.swift in Sources */,
30A0496F22B52F86001F6282 /* SumTextInputFormatterInputTests.swift in Sources */,
Expand Down Expand Up @@ -585,6 +584,7 @@
307DCD4D1FC2F2D700889A52 /* SumUSFormatTests.swift in Sources */,
30FE6FE71FAA13D30024D1B1 /* AnyFormatKitTests.swift in Sources */,
30824C0F22B17329008E1E4E /* SumTextInputFormatterWithSuffixReplace3SymbolsTests.swift in Sources */,
30A0497722B537F4001F6282 /* SumTextInputFormatterErasingBy1SymbolTests.swift in Sources */,
306EBE991FC4268200E49BB8 /* NegativeSumFormatTests.swift in Sources */,
30FF731722ADB380005FBC38 /* DefaultTextInputFormatter3SymbolsReplace.swift in Sources */,
30824C1122B176F2008E1E4E /* SumTextInputFormatterWithSuffixReplaceWith0Tests.swift in Sources */,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//
// SumTextInputFormatterErasingBy1SymbolTests.swift
// AnyFormatKitTests
//
// Created by branderstudio on 15.06.2019.
// Copyright © 2019 BRANDERSTUDIO. All rights reserved.
//

import XCTest
@testable import AnyFormatKit

class SumTextInputFormatterErasingBy1SymbolTests: XCTestCase {

let formatter = SumTextInputFormatter(textPattern: "#,###.##")

// 12,345.6|7| -> 12,345.6|
func test1() {
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, "\(expectedResult) must be equal to \(actualResult)")
}

// 12,345.|6| -> 12,345.|
func test2() {
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, "\(expectedResult) must be equal to \(actualResult)")
}

// 12,345|.| -> 12,345|
func test3() {
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, "\(expectedResult) must be equal to \(actualResult)")
}

// 12,34|5| -> 1,234|
func test4() {
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, "\(expectedResult) must be equal to \(actualResult)")
}

// 1,23|4| -> 123|
func test5() {
let actualResult = formatter.formatInput(
currentText: "1,234",
range: NSRange(location: 4, length: 1),
replacementString: "")
let expectedResult = FormattedTextValue(formattedText: "123", caretBeginOffset: 3)
XCTAssert(actualResult == expectedResult, "\(expectedResult) must be equal to \(actualResult)")
}

// 12|3| -> 12|
func test6() {
let actualResult = formatter.formatInput(
currentText: "123",
range: NSRange(location: 2, length: 1),
replacementString: "")
let expectedResult = FormattedTextValue(formattedText: "12", caretBeginOffset: 2)
XCTAssert(actualResult == expectedResult, "\(expectedResult) must be equal to \(actualResult)")
}

// 1|2| -> 1|
func test7() {
let actualResult = formatter.formatInput(
currentText: "12",
range: NSRange(location: 1, length: 1),
replacementString: "")
let expectedResult = FormattedTextValue(formattedText: "1", caretBeginOffset: 1)
XCTAssert(actualResult == expectedResult, "\(expectedResult) must be equal to \(actualResult)")
}

// |1| -> "|"
func test8() {
let actualResult = formatter.formatInput(
currentText: "1",
range: NSRange(location: 0, length: 1),
replacementString: "")
let expectedResult = FormattedTextValue(formattedText: "", caretBeginOffset: 0)
XCTAssert(actualResult == expectedResult, "\(expectedResult) must be equal to \(actualResult)")
}

}

0 comments on commit 2cf0472

Please sign in to comment.