Skip to content

Commit

Permalink
Add test, .vscode/settings.json, license headers
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxDesiatov committed May 28, 2020
1 parent b525532 commit 09b37c6
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"licenser.author": "CoreOffice contributors",
"editor.tabSize": 2,
"editor.detectIndentation": false,
"editor.formatOnSave": true
}
9 changes: 9 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
"revision": "d67ac68d09a95443303e9d6e37b34e7ba101d5f1",
"version": "1.0.1"
}
},
{
"package": "ZIPFoundation",
"repositoryURL": "https://github.com/weichsel/ZIPFoundation.git",
"state": {
"branch": null,
"revision": "ec32d62d412578542c0ffb7a6ce34d3e64b43b94",
"version": "0.9.11"
}
}
]
},
Expand Down
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ let package = Package(
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/apple/swift-crypto.git", from: "1.0.1"),
.package(url: "https://github.com/CoreOffice/OLEKit.git", .branch("master")),
.package(url: "https://github.com/weichsel/ZIPFoundation.git", .upToNextMinor(from: "0.9.11")),
],
targets: [
// Targets are the basic building blocks of a package. A target can define
// a module or a test suite.
// Targets can depend on other targets in this package, and on products in
// packages which this package depends on.
.target(name: "CryptoOffice", dependencies: ["OLEKit", "Crypto"]),
.testTarget(name: "CryptoOfficeTests", dependencies: ["CryptoOffice"]),
.testTarget(name: "CryptoOfficeTests", dependencies: ["CryptoOffice", "ZIPFoundation"]),
]
)
30 changes: 28 additions & 2 deletions Sources/CryptoOffice/CryptoOffice.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
struct CryptoOffice {
var text = "Hello, World!"
// Copyright 2020 CoreOffice contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import Crypto
import Foundation
import OLEKit

public final class CryptoOfficeFile {
private let oleFile: OLEFile

public init(path: String) throws {
do {
oleFile = try OLEFile(path)
} catch let OLEError.fileIsNotOLE(path) {
throw CryptoOfficeError.fileIsNotEncrypted(path: path)
}
}
}
17 changes: 17 additions & 0 deletions Sources/CryptoOffice/CryptoOfficeError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2020 CoreOffice contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

enum CryptoOfficeError: Error {
case fileIsNotEncrypted(path: String)
}
25 changes: 20 additions & 5 deletions Tests/CryptoOfficeTests/CryptoOfficeTests.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
// Copyright 2020 CoreOffice contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

@testable import CryptoOffice
import XCTest

final class CryptoOfficeTests: XCTestCase {
func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct
// results.
XCTAssertEqual(CryptoOffice().text, "Hello, World!")
func testWorkbook() throws {
let url = URL(fileURLWithPath: #file)
.deletingLastPathComponent()
.appendingPathComponent("TestWorkbook.xlsx")

_ = try CryptoOfficeFile(path: url.path)
}
}
Binary file added Tests/CryptoOfficeTests/TestWorkbook.xlsx
Binary file not shown.

0 comments on commit 09b37c6

Please sign in to comment.