-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03e4ff5
commit f674d7e
Showing
4 changed files
with
211 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
PlantUMLKeyboard/Sources/PlantUMLKeyboard/PlantUMLSymbolsBuilder.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Bartolomeo Sorrentino on 06/10/22. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Symbol { | ||
|
||
@resultBuilder | ||
struct Builder { | ||
typealias PART2 = (String, String) | ||
typealias PART3 = (String, String, [String]) | ||
|
||
static func buildBlock(_ parts: Any...) -> [Symbol] { | ||
|
||
parts.compactMap { elem in | ||
|
||
if let sym = elem as? Symbol { | ||
return sym | ||
} | ||
else if let str = elem as? String { | ||
return Symbol(str) | ||
} | ||
else if let part2 = elem as? PART2 { | ||
return Symbol(part2.0, part2.1) | ||
} | ||
else if let part3 = elem as? PART3 { | ||
return Symbol(part3.0, part3.1, part3.2) | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
} | ||
|
||
struct Line { | ||
|
||
var content: [Symbol] | ||
|
||
init( @Builder content: () -> [Symbol] ) { | ||
self.content = content() | ||
} | ||
} | ||
|
||
@resultBuilder | ||
struct LineBuilder { | ||
|
||
static func buildBlock(_ parts: Line...) -> [[Symbol]] { | ||
parts.compactMap { $0.content } | ||
} | ||
} | ||
|
||
} | ||
|
||
|
37 changes: 37 additions & 0 deletions
37
PlantUMLKeyboard/Tests/PlantUMLKeyboardTests/PlantUMLKeyboardTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,48 @@ | ||
import XCTest | ||
@testable import PlantUMLKeyboard | ||
|
||
|
||
final class PlantUMLKeyboardTests: XCTestCase { | ||
|
||
@Symbol.LineBuilder func makeDeploymentSymbols() -> [[Symbol]] { | ||
|
||
Symbol.Line { | ||
"actor" | ||
"agent" | ||
"artifact" | ||
"boundary" | ||
"card" | ||
"circle" | ||
"cloud" | ||
"collections" | ||
"component" | ||
"control" | ||
"person" | ||
("queue", "queue as q1") | ||
"rectangle" | ||
} | ||
|
||
Symbol.Line {} | ||
|
||
} | ||
|
||
func testExample() throws { | ||
// This is an example of a functional test case. | ||
// Use XCTAssert and related functions to verify your tests produce the correct | ||
// results. | ||
// XCTAssertEqual(PlantUMLKeyboardView().text, "Hello, World!") | ||
|
||
|
||
let symbols = makeDeploymentSymbols() | ||
|
||
XCTAssertEqual( symbols.count, 2 ) | ||
|
||
XCTAssertEqual( symbols[0].count, 13 ) | ||
XCTAssertEqual( symbols[1].count, 0 ) | ||
|
||
XCTAssertEqual( symbols[0][11].value, "queue as q1" ) | ||
|
||
print( symbols ) | ||
|
||
} | ||
} |