Skip to content

Instantly share code, notes, and snippets.

@rudifa
Created May 21, 2022 21:18
Show Gist options
  • Save rudifa/c2adff3a396288687f6bced03346c817 to your computer and use it in GitHub Desktop.
Save rudifa/c2adff3a396288687f6bced03346c817 to your computer and use it in GitHub Desktop.
BackupFileTests.swift
//
// BackupFileTests.swift
// BackupFileTests
//
// Created by Rudolf Farkas on 21.05.22.
//
@testable import BackupFile
import XCTest
class BackupFileTests: XCTestCase {
override func setUpWithError() throws {}
override func tearDownWithError() throws {}
func test_BackupFile() throws {
// a sample struct for use in testing the BackupFile wrapper
struct Sample: Codable {
let name: String
let age: Int
}
let sample = Sample(name: "Rudolf", age: 42)
let backupFile = BackupFile(wrapped: sample)
let encoder = JSONEncoder()
let data = try encoder.encode(backupFile)
let decoder = JSONDecoder()
let restoredBackupFile = try decoder.decode(BackupFile<Sample>.self, from: data)
XCTAssertEqual(restoredBackupFile.wrapped.name, sample.name)
XCTAssertEqual(restoredBackupFile.wrapped.age, sample.age)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment