Skip to content

Commit

Permalink
DMN 1.4 - 1147-feel-context-merge-function (#598)
Browse files Browse the repository at this point in the history
* 1147-feel-context-merge-function

* replace xsd:double with xsd:decimal
  • Loading branch information
StrayAlien authored Oct 19, 2023
1 parent d4bd274 commit 6b074ce
Show file tree
Hide file tree
Showing 2 changed files with 270 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Contributed to DMN TCK by StrayAlien -->
<testCases xmlns="http://www.omg.org/spec/DMN/20160719/testcase"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=""
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<modelName>1147-feel-context-merge-function.dmn</modelName>
<labels>
<label>Compliance Level 3</label>
<label>Data Type: Context</label>
<label>FEEL Functions: context</label>
</labels>

<testCase id="001">
<description>Will merge a context</description>
<resultNode name="decision001" type="decision">
<expected>
<component name="a">
<value xsi:type="xsd:decimal">1</value>
</component>
</expected>
</resultNode>
</testCase>

<testCase id="001_a">
<description>Will merge empty context</description>
<resultNode name="decision001_a" type="decision">
<expected>
<value xsi:type="xsd:boolean">true</value>
</expected>
</resultNode>
</testCase>

<testCase id="002">
<description>Will merge multiple contexts</description>
<resultNode name="decision002" type="decision">
<expected>
<component name="a">
<value xsi:type="xsd:decimal">1</value>
</component>
<component name="b">
<value xsi:type="xsd:decimal">2</value>
</component>
</expected>
</resultNode>
</testCase>

<testCase id="003">
<description>Will overwrite existing context entry</description>
<resultNode name="decision003" type="decision">
<expected>
<component name="a">
<value xsi:type="xsd:decimal">2</value>
</component>
</expected>
</resultNode>
</testCase>

<testCase id="004">
<description>Will overwrite (not merge) nested contexts</description>
<resultNode name="decision004" type="decision">
<expected>
<component name="a">
<component name="bb">
<value xsi:type="xsd:decimal">2</value>
</component>
</component>
</expected>
</resultNode>
</testCase>

<testCase id="005">
<description>Null contexts param gives null</description>
<resultNode errorResult="true" name="decision005" type="decision">
<expected>
<value xsi:nil="true"/>
</expected>
</resultNode>
</testCase>

<testCase id="006">
<description>Too few params gives null</description>
<resultNode errorResult="true" name="decision006" type="decision">
<expected>
<value xsi:nil="true"/>
</expected>
</resultNode>
</testCase>

<testCase id="007">
<description>Too many params gives null</description>
<resultNode errorResult="true" name="decision007" type="decision">
<expected>
<value xsi:nil="true"/>
</expected>
</resultNode>
</testCase>

<testCase id="008">
<description>named params</description>
<resultNode name="decision008" type="decision">
<expected>
<component name="a">
<value xsi:type="xsd:decimal">1</value>
</component>
</expected>
</resultNode>
</testCase>

<testCase id="009">
<description>Incorrect named param gives null</description>
<resultNode errorResult="true" name="decision009" type="decision">
<expected>
<value xsi:nil="true"/>
</expected>
</resultNode>
</testCase>

<testCase id="010">
<description>Incorrect 'contexts' type gives null</description>
<resultNode errorResult="true" name="decision010" type="decision">
<expected>
<value xsi:nil="true"/>
</expected>
</resultNode>
</testCase>

<testCase id="011">
<description>Non-context entry in 'contexts' gives null</description>
<resultNode errorResult="true" name="decision011" type="decision">
<expected>
<value xsi:nil="true"/>
</expected>
</resultNode>
</testCase>

<testCase id="012">
<description>Will coerce single context to list</description>
<resultNode name="decision012" type="decision">
<expected>
<component name="a">
<value xsi:type="xsd:decimal">1</value>
</component>
</expected>
</resultNode>
</testCase>

<testCase id="013">
<description>Will coerce single name param entry to list</description>
<resultNode name="decision013" type="decision">
<expected>
<component name="a">
<value xsi:type="xsd:decimal">1</value>
</component>
</expected>
</resultNode>
</testCase>

</testCases>
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions namespace="http://www.montera.com.au/spec/DMN/1147-feel-context-merge-function"
name="1147-feel-context-merge-function"
id="_i9fboPUUEeesLuP4RHs4vA"
xmlns="https://www.omg.org/spec/DMN/20211108/MODEL/"
xmlns:di="http://www.omg.org/spec/DMN/20180521/DI/"
xmlns:dmndi="https://www.omg.org/spec/DMN/20191111/DMNDI/"
xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<description>FEEL built-in function 'context put(context, key, value)' in category context functions</description>

<decision name="decision001" id="_decision001">
<variable name="decision001"/>
<literalExpression>
<text>context merge([{"a": 1}])</text>
</literalExpression>
</decision>

<decision name="decision001_a" id="_decision001_a">
<variable name="decision001_a"/>
<literalExpression>
<text>context merge([{}]) = {}</text>
</literalExpression>
</decision>

<decision name="decision002" id="_decision002">
<variable name="decision002"/>
<literalExpression>
<text>context merge([{"a": 1}, {"b": 2}])</text>
</literalExpression>
</decision>

<decision name="decision003" id="_decision003">
<variable name="decision003"/>
<literalExpression>
<text>context merge([{"a": 1}, {"a": 2}])</text>
</literalExpression>
</decision>

<decision name="decision004" id="_decision004">
<variable name="decision004"/>
<literalExpression>
<text>context merge([{"a": {"aa": 1}}, {"a": {"bb": 2}}])</text>
</literalExpression>
</decision>

<decision name="decision005" id="_decision005">
<variable name="decision005"/>
<literalExpression>
<text>context merge(null)</text>
</literalExpression>
</decision>

<decision name="decision006" id="_decision006">
<variable name="decision006"/>
<literalExpression>
<text>context merge()</text>
</literalExpression>
</decision>

<decision name="decision007" id="_decision007">
<variable name="decision007"/>
<literalExpression>
<text>context merge([],"foo")</text>
</literalExpression>
</decision>

<decision name="decision008" id="_decision008">
<variable name="decision008"/>
<literalExpression>
<text>context merge(contexts: [{"a": 1}])</text>
</literalExpression>
</decision>

<decision name="decision009" id="_decision009">
<variable name="decision009"/>
<literalExpression>
<text>context merge(context: [{"a": 1}])</text>
</literalExpression>
</decision>

<decision name="decision010" id="_decision010">
<variable name="decision010"/>
<literalExpression>
<text>context merge([1,2,3])</text>
</literalExpression>
</decision>

<decision name="decision011" id="_decision011">
<variable name="decision011"/>
<literalExpression>
<text>context merge([{"a": 1},2,{"b": 2}])</text>
</literalExpression>
</decision>

<decision name="decision012" id="_decision012">
<variable name="decision012"/>
<literalExpression>
<text>context merge({"a": 1})</text>
</literalExpression>
</decision>

<decision name="decision013" id="_decision013">
<variable name="decision013"/>
<literalExpression>
<text>context merge(contexts: {"a": 1})</text>
</literalExpression>
</decision>

</definitions>

0 comments on commit 6b074ce

Please sign in to comment.