From 3157ee84fc610e7bf2d9655d709ace474b6c395a Mon Sep 17 00:00:00 2001 From: fwcd Date: Tue, 25 Feb 2020 01:52:32 +0100 Subject: [PATCH] Add Swift unit test and usage example to Readme --- Readme.markdown | 6 +++ .../QRCodeGeneratorTests.swift | 49 ++++++++++++++++--- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/Readme.markdown b/Readme.markdown index e6b09c5..87462eb 100644 --- a/Readme.markdown +++ b/Readme.markdown @@ -171,6 +171,12 @@ Rust language: } } +Swift language: + + import QRCodeGenerator + + let qr = try! QRCode.encode(text: text, ecl: .medium) + let svg = qr.toSVGString(border: 4) License ------- diff --git a/swift/Tests/QRCodeGeneratorTests/QRCodeGeneratorTests.swift b/swift/Tests/QRCodeGeneratorTests/QRCodeGeneratorTests.swift index 54d0cc6..9948753 100644 --- a/swift/Tests/QRCodeGeneratorTests/QRCodeGeneratorTests.swift +++ b/swift/Tests/QRCodeGeneratorTests/QRCodeGeneratorTests.swift @@ -1,15 +1,48 @@ +/* + * QR Code generator library (Swift) + * + * Copyright (c) Project Nayuki. (MIT License) + * https://www.nayuki.io/page/qr-code-generator-library + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * - The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * - The Software is provided "as is", without warranty of any kind, express or + * implied, including but not limited to the warranties of merchantability, + * fitness for a particular purpose and noninfringement. In no event shall the + * authors or copyright holders be liable for any claim, damages or other + * liability, whether in an action of contract, tort or otherwise, arising from, + * out of or in connection with the Software or the use or other dealings in the + * Software. + */ + import XCTest @testable import QRCodeGenerator final class QRCodeGeneratorTests: 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(QRCodeGenerator().text, "Hello, World!") - } - static var allTests = [ - ("testExample", testExample), + ("testQRCodeGeneration", testQRCodeGeneration), ] + + func testQRCodeGeneration() throws { + // Tested against the JS implementation using https://www.nayuki.io/page/qr-code-generator-library + + let text = "test" + let qr = try QRCode.encode(text: text, ecl: .low) + let svg = qr.toSVGString(border: 4) + + XCTAssertEqual(svg, """ + + + + + + + """) + } }