Skip to content
This repository was archived by the owner on Oct 17, 2024. It is now read-only.

Commit 643dbd7

Browse files
committed
Fix custom function in function cannot be executed
1 parent ca14f76 commit 643dbd7

3 files changed

Lines changed: 25 additions & 33 deletions

File tree

Sources/ActionKit/Model/Extensions/Function+.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ extension Function {
5757
var output = try functions[id: node.function]?.function(
5858
input: inputValues.map { $0.value }
5959
) ?? []
60+
if output.first as? ControlFlow != .signal {
61+
output.insert(ControlFlow.signal, at: 0)
62+
}
6063
for (outputIndex, value) in output.enumerated() {
6164
data.append(.init(position: .output(node: index, point: outputIndex), value: value))
6265
}

Tests/ActionKitTests/ActionKitTests.swift

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@ final class ActionKitTests: XCTestCase {
4040

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

47-
separator()
48-
print("Function \"Text\"")
46+
separator(function: "Text")
4947
let simpleCustomFunction = Function(
5048
id: "text",
5149
name: "Text",
@@ -62,8 +60,7 @@ final class ActionKitTests: XCTestCase {
6260
)
6361
XCTAssertEqual(try simpleCustomFunction.run(input: ["Hello"]) as? [String] ?? [], ["Hello", "Hello"])
6462

65-
separator()
66-
print("Function \"Add\"")
63+
separator(function: "Add")
6764
let addCustomFunction = Function(
6865
id: "custom-add",
6966
name: "Add",
@@ -79,11 +76,29 @@ final class ActionKitTests: XCTestCase {
7976
functions: [.init("", icon: .init("")) { add }]
8077
)
8178
XCTAssertEqual(try addCustomFunction.run(input: [1.0, 2.0]) as? [Double] ?? [], [3.0])
79+
80+
separator(function: "Custom in Custom")
81+
let customInCustomFunction = Function(
82+
id: "custom-in-custom",
83+
name: "Custom in Custom",
84+
description: "Custom in Custom",
85+
input: [.init("Number 1", type: Double.self), .init("Number 2", type: Double.self)],
86+
output: [.init("Number", type: Double.self)],
87+
nodes: [.init(function: "custom-add")],
88+
wires: [
89+
.init(from: (0, 1), to: (1, 1)),
90+
.init(from: (0, 2), to: (1, 2)),
91+
.init(from: (1, 1), to: (2, 1))
92+
],
93+
functions: [.init("", icon: .init("")) { addCustomFunction }]
94+
)
95+
XCTAssertEqual(try customInCustomFunction.run(input: [1.0, 2.0]) as? [Double] ?? [], [3.0])
8296
}
8397

8498
/// Print a separator.
85-
func separator() {
99+
func separator(function: String) {
86100
print("-------------------------")
101+
print("Function \"\(function)\"")
87102
}
88103

89104
}

Tests/ActionKitTests/TestApp/TestApp/CodableFunction.swift

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)