@128technology/yinz
Advanced tools
Comparing version 4.0.14 to 4.0.15
@@ -387,2 +387,32 @@ "use strict"; | ||
}); | ||
it('should handle a choice where a parent node has a true when clause', () => { | ||
const dataModelInstance = getInstance('./data/when/choiceWhenParentTrue.xml'); | ||
const whenPath = [ | ||
{ name: 'authority' }, | ||
{ name: 'router', keys: [{ key: 'name', value: 'athens' }] }, | ||
{ name: 'routing', keys: [{ key: 'type', value: 'rt:default-instance' }] }, | ||
{ name: 'routing-protocol', keys: [{ key: 'type', value: 'rt:bgp' }] }, | ||
{ name: 'neighbor', keys: [{ key: 'neighbor-address', value: '1.1.1.1' }] }, | ||
{ name: 'transport' }, | ||
{ name: 'local-address' }, | ||
{ name: 'source' } | ||
]; | ||
const result = dataModelInstance.evaluateWhenCondition(whenPath); | ||
chai_1.expect(result).to.equal(true); | ||
}); | ||
it('should handle a choice where a parent node has a false when clause', () => { | ||
const dataModelInstance = getInstance('./data/when/choiceWhenParentFalse.xml'); | ||
const whenPath = [ | ||
{ name: 'authority' }, | ||
{ name: 'router', keys: [{ key: 'name', value: 'athens' }] }, | ||
{ name: 'routing', keys: [{ key: 'type', value: 'rt:default-instance' }] }, | ||
{ name: 'routing-protocol', keys: [{ key: 'type', value: 'rt:foo' }] }, | ||
{ name: 'neighbor', keys: [{ key: 'neighbor-address', value: '1.1.1.1' }] }, | ||
{ name: 'transport' }, | ||
{ name: 'local-address' }, | ||
{ name: 'source' } | ||
]; | ||
const result = dataModelInstance.evaluateWhenCondition(whenPath); | ||
chai_1.expect(result).to.equal(false); | ||
}); | ||
}); | ||
@@ -389,0 +419,0 @@ describe('LeafRef Evaluation', () => { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const _ = require("lodash"); | ||
const enum_1 = require("../enum"); | ||
@@ -47,7 +46,6 @@ const _1 = require("./"); | ||
} | ||
const searchPath = model instanceof model_1.Choice ? _.initial(path) : path; | ||
const xPath = util_1.getPathXPath(searchPath); | ||
const xPath = util_1.getPathXPath(path); | ||
let exists = true; | ||
try { | ||
this.getInstance(searchPath); | ||
this.getInstance(path); | ||
} | ||
@@ -59,3 +57,3 @@ catch (e) { | ||
if (!exists) { | ||
instance = util_1.addEmptyTree(searchPath, this.model, instance); | ||
instance = util_1.addEmptyTree(path, this.model, instance); | ||
} | ||
@@ -68,3 +66,3 @@ let instanceRoot = instance.get(xPath); | ||
const { condition, context } = when; | ||
const contextNode = context === enum_1.ContextNode.parent ? instanceRoot.parent() : instanceRoot; | ||
const contextNode = context === enum_1.ContextNode.parent || modelRoot instanceof model_1.Choice ? instanceRoot.parent() : instanceRoot; | ||
const result = contextNode.get(condition, this.model.namespaces); | ||
@@ -71,0 +69,0 @@ if (!result) { |
{ | ||
"name": "@128technology/yinz", | ||
"version": "4.0.14", | ||
"version": "4.0.15", | ||
"description": "A module for injesting a YIN datamodel and handling instance data.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
452985
6278