Skip to content

Commit

Permalink
Fix custom function in function cannot be executed
Browse files Browse the repository at this point in the history
  • Loading branch information
david-swift committed May 28, 2023
1 parent ca14f76 commit 643dbd7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 33 deletions.
3 changes: 3 additions & 0 deletions Sources/ActionKit/Model/Extensions/Function+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ extension Function {
var output = try functions[id: node.function]?.function(
input: inputValues.map { $0.value }
) ?? []
if output.first as? ControlFlow != .signal {
output.insert(ControlFlow.signal, at: 0)
}
for (outputIndex, value) in output.enumerated() {
data.append(.init(position: .output(node: index, point: outputIndex), value: value))
}
Expand Down
29 changes: 22 additions & 7 deletions Tests/ActionKitTests/ActionKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ final class ActionKitTests: XCTestCase {

/// Test the execution of functions.
func testExecution() throws {
separator()
print("Function \"Print Text\"")
separator(function: "Print Text")
_ = try printText.run(input: ["Hello, world!"])

separator()
print("Function \"Text\"")
separator(function: "Text")
let simpleCustomFunction = Function(
id: "text",
name: "Text",
Expand All @@ -62,8 +60,7 @@ final class ActionKitTests: XCTestCase {
)
XCTAssertEqual(try simpleCustomFunction.run(input: ["Hello"]) as? [String] ?? [], ["Hello", "Hello"])

separator()
print("Function \"Add\"")
separator(function: "Add")
let addCustomFunction = Function(
id: "custom-add",
name: "Add",
Expand All @@ -79,11 +76,29 @@ final class ActionKitTests: XCTestCase {
functions: [.init("", icon: .init("")) { add }]
)
XCTAssertEqual(try addCustomFunction.run(input: [1.0, 2.0]) as? [Double] ?? [], [3.0])

separator(function: "Custom in Custom")
let customInCustomFunction = Function(
id: "custom-in-custom",
name: "Custom in Custom",
description: "Custom in Custom",
input: [.init("Number 1", type: Double.self), .init("Number 2", type: Double.self)],
output: [.init("Number", type: Double.self)],
nodes: [.init(function: "custom-add")],
wires: [
.init(from: (0, 1), to: (1, 1)),
.init(from: (0, 2), to: (1, 2)),
.init(from: (1, 1), to: (2, 1))
],
functions: [.init("", icon: .init("")) { addCustomFunction }]
)
XCTAssertEqual(try customInCustomFunction.run(input: [1.0, 2.0]) as? [Double] ?? [], [3.0])
}

/// Print a separator.
func separator() {
func separator(function: String) {
print("-------------------------")
print("Function \"\(function)\"")
}

}
26 changes: 0 additions & 26 deletions Tests/ActionKitTests/TestApp/TestApp/CodableFunction.swift

This file was deleted.

0 comments on commit 643dbd7

Please sign in to comment.