#!/usr/bin/env bash # Test: JSON (leaf-)list and YANG. See RFC7951 sec 5.3 / 5.4 # Magic line must be first in script (see README.md) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi : ${clixon_util_json:=clixon_util_json} : ${clixon_util_xml:=clixon_util_xml} fyang=$dir/json.yang cat < $fyang module json{ prefix ex; namespace "urn:example:clixon"; container c{ leaf-list l1{ type int32; } list l2{ key name; leaf name{ type int32; } leaf value{ type string; } } } } EOF # JSON list input/output tests auth test with arguments: # 1. test name # 2. JSON # 3. XML function testrun() { test=$1 json=$2 xml=$3 new "$test json in/out" expecteofx "$clixon_util_json -jy $fyang -D $DBG" 0 "$json" "$json" new "$test json in / xml out" expecteofx "$clixon_util_json -y $fyang -D $DBG" 0 "$json" "$xml" new "$test xml in / json out" expecteofx "$clixon_util_xml -ojvy $fyang -D $DBG" 0 "$xml" "$json" } new "test params: -y $fyang" testrun "one leaf-list" '{"json:c":{"l1":[1]}}' '1' testrun "two leaf-list" '{"json:c":{"l1":[1,2]}}' '12' testrun "three leaf-list" '{"json:c":{"l1":[1,2,3]}}' '123' testrun "one list" '{"json:c":{"l2":[{"name":1,"value":"x"}]}}' '1x' testrun "two list" '{"json:c":{"l2":[{"name":1,"value":"x"},{"name":2,"value":"y"}]}}' '1x2y' testrun "three list" '{"json:c":{"l2":[{"name":1,"value":"x"},{"name":2,"value":"y"},{"name":3,"value":"z"}]}}' '1x2y3z' rm -rf $dir # unset conditional parameters unset clixon_util_json unset clixon_util_xml new "endtest" endtest