forked from paul-griffith/ignition-extensions
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
randomUUID
expression and scripting functions (#94)
Thanks for the contribution!
- Loading branch information
Showing
8 changed files
with
86 additions
and
0 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
23 changes: 23 additions & 0 deletions
23
common/src/main/kotlin/org/imdc/extensions/common/expressions/UUID4Function.kt
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,23 @@ | ||
package org.imdc.extensions.common.expressions | ||
|
||
import com.inductiveautomation.ignition.common.expressions.Expression | ||
import com.inductiveautomation.ignition.common.expressions.functions.AbstractFunction | ||
import com.inductiveautomation.ignition.common.model.values.BasicQualifiedValue | ||
import com.inductiveautomation.ignition.common.model.values.QualifiedValue | ||
import java.util.UUID | ||
|
||
class UUID4Function : AbstractFunction() { | ||
override fun validateNumArgs(num: Int): Boolean = num == 0 | ||
override fun execute(expressions: Array<out Expression>): QualifiedValue { | ||
return BasicQualifiedValue(UUID.randomUUID()) | ||
} | ||
|
||
override fun getArgDocString(): String = "" | ||
override fun getFunctionDisplayName(): String = NAME | ||
override fun getType(): Class<*> = UUID::class.java | ||
|
||
companion object { | ||
const val NAME = "uuid4" | ||
const val CATEGORY = "Advanced" | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
common/src/test/kotlin/org/imdc/extensions/common/UUID4Tests.kt
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,24 @@ | ||
package org.imdc.extensions.common | ||
|
||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.should | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.matchers.types.beInstanceOf | ||
import org.imdc.extensions.common.ExpressionTestHarness.Companion.withFunction | ||
import org.imdc.extensions.common.expressions.UUID4Function | ||
import java.util.* | ||
|
||
class UUID4Tests : FunSpec() { | ||
init { | ||
context("RandomUUID") { | ||
withFunction("uuid4", UUID4Function()) { | ||
test("Instance of UUID") { | ||
evaluate("uuid4()") should beInstanceOf<UUID>() | ||
} | ||
test("Unique results") { | ||
evaluate("uuid4() = uuid4()") shouldBe false | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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