diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..95c4320 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.DS_Store +/.build +/Packages +/*.xcodeproj +xcuserdata/ diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..aaee926 --- /dev/null +++ b/Package.swift @@ -0,0 +1,28 @@ +// swift-tools-version:5.2 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "E.num", + products: [ + // Products define the executables and libraries produced by a package, and make them visible to other packages. + .library( + name: "E.num", + targets: ["E.num"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + 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: "E.num", + dependencies: []), + .testTarget( + name: "E.numTests", + dependencies: ["E.num"]), + ] +) diff --git a/Sources/E.num/E_num.swift b/Sources/E.num/E_num.swift new file mode 100644 index 0000000..72c2f2e --- /dev/null +++ b/Sources/E.num/E_num.swift @@ -0,0 +1,29 @@ +struct E_num { + var list: Variable = .array( + [ + .bool(false), + .string("False"), + .int(0) + ] + ) + + var dictionary: Variable = .dictionary( + [ + .bool(false): .double(3.14) + ] + ) + + var text: Variable = .string("Hello, World!") + + func stupid() { + if case .string(let value) = text { + print("Stupid String: \(value)") + } + + if case .array(let value) = list, + let firstValue = value.last, + case .int(let number) = firstValue { + print(number * 99) + } + } +} diff --git a/Sources/E.num/Function.swift b/Sources/E.num/Function.swift new file mode 100644 index 0000000..b5c9d9d --- /dev/null +++ b/Sources/E.num/Function.swift @@ -0,0 +1,35 @@ +// +// Function.swift +// E.num +// +// Created by Zach Eriksen on 9/29/20. +// + +import Foundation + +enum Function { + case void(() -> ()) + case `in`((Variable) -> ()) + case out(() -> Variable) + case `inout`((Variable) -> Variable) + + @discardableResult + func run(_ value: Variable? = nil) -> Variable? { + switch self { + case .void(let closure): + closure() + case .in(let closure): + if let value = value { + closure(value) + } + case .out(let closure): + return closure() + case .inout(let closure): + if let value = value { + return closure(value) + } + } + + return nil + } +} diff --git a/Sources/E.num/Variable.swift b/Sources/E.num/Variable.swift new file mode 100644 index 0000000..67407df --- /dev/null +++ b/Sources/E.num/Variable.swift @@ -0,0 +1,20 @@ +// +// Variable.swift +// E.num +// +// Created by Zach Eriksen on 9/29/20. +// + +import Foundation + +enum Variable: Equatable, Hashable { + case void + case bool(Bool) + case int(Int) + case float(Float) + case double(Double) + case string(String) + case set(Set) + case array([Variable]) + case dictionary([Variable: Variable]) +} diff --git a/Tests/E.numTests/E_numTests.swift b/Tests/E.numTests/E_numTests.swift new file mode 100644 index 0000000..0bbf129 --- /dev/null +++ b/Tests/E.numTests/E_numTests.swift @@ -0,0 +1,15 @@ +import XCTest +@testable import E_num + +final class E_numTests: 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(E_num().text, .string("Hello, World!")) + } + + static var allTests = [ + ("testExample", testExample), + ] +} diff --git a/Tests/E.numTests/XCTestManifests.swift b/Tests/E.numTests/XCTestManifests.swift new file mode 100644 index 0000000..ea6f86c --- /dev/null +++ b/Tests/E.numTests/XCTestManifests.swift @@ -0,0 +1,9 @@ +import XCTest + +#if !canImport(ObjectiveC) +public func allTests() -> [XCTestCaseEntry] { + return [ + testCase(E_numTests.allTests), + ] +} +#endif diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift new file mode 100644 index 0000000..f19a446 --- /dev/null +++ b/Tests/LinuxMain.swift @@ -0,0 +1,7 @@ +import XCTest + +import E_numTests + +var tests = [XCTestCaseEntry]() +tests += E_numTests.allTests() +XCTMain(tests)