-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove unnecessary code * Fix html template * Add bookmarklets.html * Add UtilsTests.swift * Refactor * �Add tearDownWithError * Run `swiftlint --fix` * Add proper setUpWithError and tearDownWithError * Refactor Constants * Refactor
- Loading branch information
Showing
7 changed files
with
68 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<!doctype html> | ||
<html> | ||
<title>Bookmarklets</title> | ||
<h1>Bookmarklets</h1><a href="javascript:(alert(%22testing%22))();%0A">test</a></html> |
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,50 @@ | ||
import Foundation | ||
import Extensions | ||
import XCTest | ||
import Files | ||
import AssertSwiftCLI | ||
|
||
final class UtilsTests: XCTestCase { | ||
override func setUpWithError() throws { | ||
try Constants.homeFolder.createSubfolderIfNeeded(at: ".Hondana").createSubfolderIfNeeded(at: "Bookmarklets") | ||
} | ||
|
||
override func tearDownWithError() throws { | ||
try Constants.hondanaFolder.delete() | ||
} | ||
|
||
enum Utils { | ||
static func generateHTML(from jsFiles: [File]) throws -> File { | ||
let rawHTMLstring = """ | ||
<!doctype html> | ||
<html> | ||
<title>Bookmarklets</title> | ||
<h1>Bookmarklets</h1> | ||
""" + | ||
(try jsFiles | ||
.map { | ||
aTag(url: try $0.readAsString(encodedAs: .utf8).withJSPrefix.minified, | ||
title: $0.nameExcludingExtension.components(separatedBy: "+")[1]) | ||
} | ||
.joined(separator: "\n") | ||
) | ||
+ """ | ||
</html> | ||
""" | ||
return try Constants.hondanaFolder | ||
.createFile(at: "bookmarklets.html", contents: rawHTMLstring.data(using: .utf8)) | ||
} | ||
|
||
private static func aTag(url: String, title: String) -> String { | ||
return "<a href=\"\(url)\">\(title)</a>" | ||
} | ||
} | ||
|
||
func testGenerateHTML() throws { | ||
let bookmarkJS = try File(path: #file).parent!.parent!.file(at: "Fixtures/+test.js") | ||
let bookmarkHtml = try File(path: #file).parent!.parent!.file(at: "Fixtures/bookmarklets.html") | ||
|
||
let file = try Utils.generateHTML(from: [bookmarkJS]) | ||
XCTAssertEqual(try file.readAsString().trimmingLines(), String(try bookmarkHtml.readAsString().trimmingLines().dropLast())) | ||
} | ||
} |