This repository has been archived by the owner on May 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #552: Added SwiftDomainParser to get eTLD+1 and manage textAlignm…
…ent (#869)
- Loading branch information
1 parent
4bf518f
commit f5d3d99
Showing
11 changed files
with
3,442 additions
and
986 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
@testable import Client | ||
import XCTest | ||
|
||
class DisplayTextFieldTest: XCTestCase { | ||
|
||
func testRightAlignedTLD() { | ||
let textField = DisplayTextField(frame: CGRect(width: 250, height: 44)) | ||
|
||
let urlCases: [URL] = [URL(string: "https://www.google.com")!, | ||
URL(string: "http://myaccountsecure.testmycase.co.uk/asd?a=1")!, | ||
URL(string: "http://testmycase.co.uk/something/path/asd?a=1")!, | ||
URL(string: "http://myaccountsecure.secured.testmycase.co.uk/asd?a=1")!, | ||
URL(string: "http://myaccountsecure.testmycase.co.uk")!] | ||
urlCases.forEach({textField.assertWidth(text: $0.schemelessAbsoluteString, hostString: $0.host ?? "")}) | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
|
||
extension DisplayTextField { | ||
func assertWidth(text: String, hostString: String) { | ||
self.hostString = hostString | ||
self.text = text | ||
let rect = self.textRect(forBounds: self.bounds) | ||
if rect.width > self.bounds.width, let upperBound = text.range(of: hostString)?.upperBound { | ||
let pathString = text[upperBound...] | ||
let widthPath = (pathString as NSString).size(withAttributes: [.font: self.font!]).width | ||
let widthText = (text as NSString).size(withAttributes: [.font: self.font!]).width | ||
|
||
let test1 = rect.width + widthPath - pathPadding == widthText | ||
let test2 = rect.origin.x == self.bounds.width - widthText + widthPath - pathPadding | ||
XCTAssert(test1 && test2) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.