-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NU-7142] Lift TypingResult for dicts
- Loading branch information
Piotr Rudnicki
committed
Nov 14, 2024
1 parent
15a4f9d
commit 10ee2df
Showing
3 changed files
with
61 additions
and
3 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
42 changes: 42 additions & 0 deletions
42
...touk/nussknacker/engine/language/dictWithLabel/DictKeyWithLabelExpressionParserTest.scala
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,42 @@ | ||
package pl.touk.nussknacker.engine.language.dictWithLabel | ||
|
||
import org.scalatest.Inside.inside | ||
import org.scalatest.OptionValues | ||
import org.scalatest.funsuite.AnyFunSuite | ||
import org.scalatest.matchers.should.Matchers | ||
import pl.touk.nussknacker.engine.api.context.ValidationContext | ||
import pl.touk.nussknacker.engine.api.typed.typing.{Typed, TypedClass, TypedObjectWithValue} | ||
|
||
import scala.reflect.ClassTag | ||
|
||
class DictKeyWithLabelExpressionParserTest extends AnyFunSuite with Matchers with OptionValues { | ||
private val dictKeyWithLabelExpressionParser = DictKeyWithLabelExpressionParser | ||
|
||
test("should parse dict key with label String expression and lift typing information") { | ||
checkForDictKeyWithLabelExpressionTypingInfo[String]("'pizza'", "pizza") | ||
} | ||
|
||
test("should parse dict key with label Long expression and lift typing information") { | ||
checkForDictKeyWithLabelExpressionTypingInfo[Long](42, "number") | ||
} | ||
|
||
test("should parse dict key with label Boolean expression and lift typing information") { | ||
checkForDictKeyWithLabelExpressionTypingInfo[Boolean](true, "judge") | ||
} | ||
|
||
private def checkForDictKeyWithLabelExpressionTypingInfo[T: ClassTag](key: T, label: String) = { | ||
val jsonString = s"""{"key":"$key","label":"$label"}""" | ||
val parsedTypingResult = dictKeyWithLabelExpressionParser | ||
.parse(jsonString, ValidationContext.empty, Typed.typedClass[T]) | ||
.toOption | ||
.value | ||
.typingInfo | ||
.typingResult | ||
|
||
inside(parsedTypingResult) { case typedObjectWithValue: TypedObjectWithValue => | ||
typedObjectWithValue.underlying shouldBe Typed.typedClass[T] | ||
typedObjectWithValue.valueOpt shouldBe Some(key) | ||
} | ||
} | ||
|
||
} |