-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix type resolution in sub execution #209
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7d5264a
fixing variable type resolution if the definition is in a sub execution
adridadou f72822e
fixing situation where a parameter is not known, instead of returning…
adridadou e38a443
Merge branch 'master' into fix-type-resolution-in-sub-execution
adridadou f263389
Merge branch 'master' into fix-type-resolution-in-sub-execution
adridadou 5aeb185
remove println
adridadou c778a3f
Merge branch 'master' into fix-type-resolution-in-sub-execution
adridadou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -728,6 +728,75 @@ class OpenlawExecutionEngineSpec extends FlatSpec with Matchers { | |
} | ||
} | ||
|
||
it should "look at sub execution results for variable type" in { | ||
val mainTemplate = compile("""[[c:Clause("clause")]]""") | ||
val clauseTemplate = compile( | ||
""" | ||
|<% | ||
|# Arranged Variables by Header | ||
|==MOU Terms== | ||
|[[Terms: Collection<Text>]] | ||
| | ||
|==MOU Parties== | ||
|[[Party Info: Structure( | ||
| Party Name: Text; | ||
| Party Email: Identity | ||
| )]] | ||
|[[#Parties: Collection<Party Info>]] | ||
|%> | ||
| | ||
|\centered **__MEMORANDUM OF UNDERSTANDING__** | ||
| | ||
|**NOW, THEREFORE,** the undersigned parties (the "***Parties***") see mutual benefit in entering into a partnership and formalizing their cooperation over the matters and under the terms sufficiently described in this Memorandum of Understanding ("***MOU***"): | ||
| | ||
|{{#for each Term: Terms => | ||
| | ||
| ^^[[Term]] | ||
|}} | ||
| | ||
|The Parties shall keep confidential and shall not divulge to any other party, without the other's prior written consent, any non-public information concerning this MOU and the cooperation contemplated hereby, treating such confidential information with the same due care as their own proprietary information. | ||
| | ||
|The Parties shall jointly operate and exchange information with the intention of completing the transactions contemplated hereby and within determined timeframes and reasonable best efforts. | ||
| | ||
|After a preliminary review period, not to exceed two (2) months from the date of mutual execution below, the Parties may enter into a legally-binding agreement regarding these matters and shall make reasonable best efforts to conduct a meeting regarding the same following such MOU review period. | ||
| | ||
|This MOU is not a legally-binding agreement. | ||
| | ||
|***__SIGNATORIES__*** | ||
| | ||
|{{#for each Party: Parties => | ||
| | ||
|**[[Party.Party Name | Uppercase]]** | ||
| | ||
|*__[[Party.Party Email | Signature]]__* | ||
|Authorized Representative | ||
| | ||
|}} | ||
|""".stripMargin) | ||
|
||
engine.execute(mainTemplate, TemplateParameters(), Map(TemplateSourceIdentifier(TemplateTitle("clause")) -> clauseTemplate,TemplateSourceIdentifier(TemplateTitle("clause")) -> clauseTemplate)) match { | ||
case Right(result) => | ||
val variable = VariableDefinition(VariableName("Parties"), Some(VariableTypeDefinition("Collection",Some(VariableTypeDefinition("Parefhuzegfty Info",None))))) | ||
getCollection(variable, result, "") | ||
case Left(ex) => | ||
fail(ex.message, ex) | ||
} | ||
} | ||
|
||
def getCollection(variable:VariableDefinition, executionResult: TemplateExecutionResult, value:String):CollectionValue = { | ||
println(variable.variableTypeDefinition) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we can remove this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're right |
||
variable.varType(executionResult) match { | ||
case collectionType:CollectionType => | ||
if(value.isEmpty) { | ||
CollectionValue(collectionType = collectionType) | ||
} else { | ||
VariableType.convert[CollectionValue](collectionType.cast(value, executionResult).getOrThrow()).getOrThrow() | ||
} | ||
case other => | ||
throw new RuntimeException(s"add element to collection only works for a variable of type Collection, not '${other.name}'") | ||
} | ||
} | ||
|
||
it should "fail if it makes a divide by zero error" in { | ||
val template = | ||
compile(""" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about adding an assert here to check if the returned type is indeed a collection value type with the expected values? If the returned collection is empty, should it break the test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The collection will be empty because the internal format value is an empty string.
The test here is more to check that the call actually works, there was an issue with this call previously