Skip to content

Commit

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

* replace xsd:double with xsd:decimal
  • Loading branch information
StrayAlien authored Oct 19, 2023
1 parent 3ccdd22 commit 49e6b97
Show file tree
Hide file tree
Showing 2 changed files with 341 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
<?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>1145-feel-context-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 create context from entries</description>
<resultNode name="decision001" 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="002">
<description>Will create context from single entry</description>
<resultNode name="decision002" type="decision">
<expected>
<component name="a">
<value xsi:type="xsd:decimal">1</value>
</component>
</expected>
</resultNode>
</testCase>

<testCase id="003">
<!-- spec says "Returns a new context that includes all specified entries." When there
are duplicates we cannot create a new context with 'all specified entries'.
Thus, null. -->
<description>Will return null when duplicate entry keys</description>
<resultNode errorResult="true" name="decision003" type="decision">
<expected>
<value xsi:nil="true"/>
</expected>
</resultNode>
</testCase>

<testCase id="004">
<description>Will create empty context for empty entries array</description>
<resultNode name="decision004" type="decision">
<expected>
<value xsi:type="xsd:boolean">true</value>
</expected>
</resultNode>
</testCase>

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

<testCase id="006">
<description>Will return null when entry is missing key</description>
<resultNode errorResult="true" name="decision006" type="decision">
<expected>
<value xsi:nil="true"/>
</expected>
</resultNode>
</testCase>

<testCase id="007">
<description>Will return null when entry key value is null</description>
<resultNode errorResult="true" name="decision007" type="decision">
<expected>
<value xsi:nil="true"/>
</expected>
</resultNode>
</testCase>

<testCase id="008">
<description>Will return null when entry is missing value</description>
<resultNode errorResult="true" name="decision008" type="decision">
<expected>
<value xsi:nil="true"/>
</expected>
</resultNode>
</testCase>

<testCase id="009">
<description>Will permit null value</description>
<resultNode name="decision009" type="decision">
<expected>
<component name="a">
<value xsi:nil="true"/>
</component>
</expected>
</resultNode>
</testCase>

<testCase id="010">
<description>Will permit empty string as key</description>
<resultNode name="decision010" type="decision">
<expected>
<component name="">
<value xsi:type="xsd:decimal">1</value>
</component>
</expected>
</resultNode>
</testCase>

<testCase id="011">
<description>Null entries list gives null</description>
<resultNode errorResult="true" name="decision011" type="decision">
<expected>
<value xsi:nil="true"/>
</expected>
</resultNode>
</testCase>

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

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

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

<testCase id="014_b">
<description>will coerce non-list named param to list</description>
<resultNode name="decision014_b" type="decision">
<expected>
<component name="a">
<value xsi:type="xsd:decimal">1</value>
</component>
</expected>
</resultNode>
</testCase>

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

<testCase id="016">
<description>Incorrect 'entries' type gives null</description>
<resultNode errorResult="true" name="decision016" type="decision">
<expected>
<value xsi:nil="true"/>
</expected>
</resultNode>
</testCase>

<testCase id="017">
<description>Will ignore extra fields beyond 'key' and 'value'</description>
<resultNode name="decision017" 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,141 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions namespace="http://www.montera.com.au/spec/DMN/1145-feel-context-function"
name="1145-feel-context-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(entries)' in category context functions</description>

<decision name="decision001" id="_decision001">
<variable name="decision001"/>
<literalExpression>
<text>context([{key:"a", value:1}, {key:"b", value:2}])</text>
</literalExpression>
</decision>

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

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

<decision name="decision004" id="_decision004">
<variable name="decision004"/>
<literalExpression>
<text>context([]) = {}</text>
</literalExpression>
</decision>

<decision name="decision005" id="_decision005">
<variable name="decision005"/>
<literalExpression>
<text>context({key:"a", value:1})</text>
</literalExpression>
</decision>

<decision name="decision006" id="_decision006">
<variable name="decision006"/>
<literalExpression>
<text>context({value:1})</text>
</literalExpression>
</decision>

<decision name="decision007" id="_decision007">
<variable name="decision007"/>
<literalExpression>
<text>context({key: null, value:1})</text>
</literalExpression>
</decision>

<decision name="decision008" id="_decision008">
<variable name="decision008"/>
<literalExpression>
<text>context({key: "a"})</text>
</literalExpression>
</decision>

<decision name="decision009" id="_decision009">
<variable name="decision009"/>
<literalExpression>
<text>context({key: "a", value: null})</text>
</literalExpression>
</decision>

<decision name="decision010" id="_decision010">
<variable name="decision010"/>
<literalExpression>
<text>context({key: "", value: 1})</text>
</literalExpression>
</decision>

<decision name="decision011" id="_decision011">
<variable name="decision011"/>
<literalExpression>
<text>context(null)</text>
</literalExpression>
</decision>

<decision name="decision012" id="_decision012">
<variable name="decision012"/>
<literalExpression>
<text>context()</text>
</literalExpression>
</decision>

<decision name="decision013" id="_decision013">
<variable name="decision013"/>
<literalExpression>
<text>context([], "foo")</text>
</literalExpression>
</decision>

<decision name="decision014_a" id="_decision014_a">
<variable name="decision014_a"/>
<literalExpression>
<text>context(entries: [{key:"a", value:1}])</text>
</literalExpression>
</decision>

<decision name="decision014_b" id="_decision014_b">
<variable name="decision014_b"/>
<literalExpression>
<text>context(entries: {key:"a", value:1})</text>
</literalExpression>
</decision>

<decision name="decision015" id="_decision015">
<variable name="decision015"/>
<literalExpression>
<text>context(entris: {key:"a", value:1})</text>
</literalExpression>
</decision>

<decision name="decision016" id="_decision016">
<variable name="decision016"/>
<literalExpression>
<text>context("foo")</text>
</literalExpression>
</decision>

<decision name="decision017" id="_decision017">
<variable name="decision017"/>
<literalExpression>
<text>context(entries: [{key:"a", value:1, ignored: "foo"}])</text>
</literalExpression>
</decision>



</definitions>

0 comments on commit 49e6b97

Please sign in to comment.