POC E.num

This commit is contained in:
Zach Eriksen 2020-09-29 08:31:55 -05:00
parent 49dfe0f214
commit a04ecbdd71
8 changed files with 148 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/

28
Package.swift Normal file
View File

@ -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"]),
]
)

29
Sources/E.num/E_num.swift Normal file
View File

@ -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)
}
}
}

View File

@ -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
}
}

View File

@ -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<Variable>)
case array([Variable])
case dictionary([Variable: Variable])
}

View File

@ -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),
]
}

View File

@ -0,0 +1,9 @@
import XCTest
#if !canImport(ObjectiveC)
public func allTests() -> [XCTestCaseEntry] {
return [
testCase(E_numTests.allTests),
]
}
#endif

7
Tests/LinuxMain.swift Normal file
View File

@ -0,0 +1,7 @@
import XCTest
import E_numTests
var tests = [XCTestCaseEntry]()
tests += E_numTests.allTests()
XCTMain(tests)