Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/0xopenbytes/flet
Micro Framework Collection
https://github.com/0xopenbytes/flet
cache composition input output spm swift testing transformations transput
Last synced: 14 days ago
JSON representation
Micro Framework Collection
- Host: GitHub
- URL: https://github.com/0xopenbytes/flet
- Owner: 0xOpenBytes
- Created: 2022-03-19T18:39:20.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-05-06T19:44:04.000Z (over 2 years ago)
- Last Synced: 2024-10-30T17:15:49.403Z (21 days ago)
- Topics: cache, composition, input, output, spm, swift, testing, transformations, transput
- Language: Swift
- Homepage:
- Size: 6.84 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FLet
*A collection of micro frameworks*
## Frameworks
- [t (FLet.testing)](https://github.com/0xOpenBytes/t): ๐งช Quickly test expectations
- `t` is a simple testing framework using closures and errors. You have the ability to create a `suite` that has multiple steps, expectations, and asserts. Expectations can be used to `expect` one or multiple assertions. `t` can be used to test quickly inside a function to make sure something is working as expected. `t` can also be used in unit test if wanted.- [c (FLet.composition)](https://github.com/0xOpenBytes/c): ๐ฆ Micro Composition using Transformations and Cache
- `c` is a simple composition framework. You have the ability to create transformations that are either unidirectional or bidirectional. There is also a cache that values can be set and resolved. `c` can be used anywhere to create transformations or interact with the cache.
- [o (FLet.transput)](https://github.com/0xOpenBytes/o): Output and Input for File, URL, and Console
- `o` is a simple framework to output to a file, url, the console, or even register notification using UserNotifications. `o` can also get input from a file, url, or console. Currently, `o` can be used on macOS, iOS, and watchOS.## Usage
### Testing
Suite```swift
t.suite {
// Add an expectation that asserting true is true and that 2 is equal to 2
try t.expect {
try t.assert(true)
try t.assert(2, isEqualTo: 2)
}
// Add an assertion that asserting false is not true
try t.assert(notTrue: false)
// Add an assertion that "Hello" is not equal to "World"
try t.assert("Hello", isNotEqualTo: "World")
// Log a message
t.log("๐ฃ Test Log Message")
// Log a t.error
t.log(error: t.error(description: "Mock Error"))
// Log any error
struct SomeError: Error { }
t.log(error: SomeError())
// Add an assertion to check if a value is nil
let someValue: String? = nil
try t.assert(isNil: someValue)
// Add an assertion to check if a value is not nil
let someOtherValue: String? = "๐ "
try t.assert(isNotNil: someOtherValue)
}
```
Expect```swift
try t.expect {
let someValue: String? = "Hello"
try t.assert(isNil: someValue)
}
```
Assert```swift
try t.assert("Hello", isEqualTo: "World")
```
Logging```swift
t.log("๐ฃ Test Log Message")
```
XCTest```swift
// Assert suite is true
XCTAssert(
t.suite {
try t.assert(true)
}
)// Assert expectation is true
XCTAssertNoThrow(
try t.expect("true is true and that 2 is equal to 2") {
try t.assert(true)
try t.assert(2, isEqualTo: 2)
}
)// Assert is false
XCTAssertThrowsError(
try t.assert(false)
)
```
### Composition
Local Cache```swift
let cache = c.cache()cache.set(value: Double.pi, forKey: "๐ฅง")
let pi: Double = cache.get("๐ฅง") ?? 0
try t.assert(pi, isEqualTo: .pi)
let resolvedValue: Double = cache.resolve("๐ฅง")
try t.assert(resolvedValue, isEqualTo: .pi)
```
Global Cache```swift
let someCache: Cache = ...// Set the value of a Cache with any hashable key
c.set(value: someCache, forKey: "someCache")// Get an optional Cache using any hashable key
let anotherCache: Cache? = c.get(0)// Require that a Cache exist using a `.get` with a force unwrap
let requiredCache: Cache = c.resolve(0)
```
Transformation```swift
let transformer = c.transformer(
from: { string in Int(string) },
to: { int in "\(String(describing: int))" }
)let string = transformer.to(3)
let int = transformer.from("3")try t.assert(transformer.to(int), isEqualTo: string)
```
### Transput
Console```swift
o.console.out("Value to print: ", terminator: "") // (oTests/oTests.swift@7) [testExample()]: Value to print:
o.console.out(o.console.in()) // Type in "???"; (oTests/oTests.swift@8) [testExample()]: Optional("???")
```
File```swift
let filename: String = ...// Write the value 4, an Int, to the file named `filename`. Files using o.file are base64Encoded.
try o.file.out(4, filename: filename)// Asserts
XCTAssertNoThrow(try o.file.in(filename: filename) as Int)
XCTAssertEqual(try? o.file.in(filename: filename), 4)// Delete the File
try o.file.delete(filename: filename)// Assert deletion
XCTAssertThrowsError(try o.file.in(filename: filename) as Int)
```
URL```swift
struct Post: Codable {
let userId: Int
let id: Int
let title: String
let body: String
}// GET Request
o.url.in(
url: URL(string: "api/posts")!,
successHandler: { (posts: [Post], response) in
print(posts)
}
)// POST Request
let post = Post(userId: 1, id: 1, title: "First!", body: "")
try o.url.out(
url: URL(string: "api/posts/\(post.id)")!,
value: post,
successHandler: { data, response in
print(response)
}
)
```
Notification```swift
// Request Notification Authorization
o.notification.requestAuthorization()// Set UNUserNotificationCenter.current's delegate to `o.notification.delegate`
o.notification.registerDelegate()// Schedule a Notification
o.notification.post(
title: "Hello!",
subtitle: "o.notification",
body: "Woo Hoo!",
trigger: UNTimeIntervalNotificationTrigger(
timeInterval: 3,
repeats: false
)
)
```
### Shorthand Typealias
```swift
public typealias __ = FLet
```