<?xml version="1.0" encoding="UTF-8"?>
<t:test expected="pass"
        xmlns:t="http://xproc.org/ns/testsuite/3.0">
  <t:info>
    <t:title>json-patch-merge-002</t:title>
    <t:revision-history>
      <t:revision>
        <t:date>2025-05-09</t:date>
        <t:author>
          <t:name>Norm Tovey-Walsh</t:name>
        </t:author>
        <t:description xmlns="http://www.w3.org/1999/xhtml">
          <p>Created test.</p>
        </t:description>
      </t:revision>
    </t:revision-history>
  </t:info>
  <t:description xmlns="http://www.w3.org/1999/xhtml">
    <p>Example test from RFC 7386.</p>
  </t:description>
  <t:pipeline>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
                xmlns:cx="http://xmlcalabash.com/ns/extensions"
                name="main" version="3.0" expand-text="false">
  <p:import href="https://xmlcalabash.com/ext/library/json-patch.xpl"/>
  <p:output port="result"/>

  <p:add-xml-base all="true" relative="false">
    <p:with-input><doc/></p:with-input>
  </p:add-xml-base>

  <cx:json-patch cx:expand-text="false" merge="true">
    <p:with-input>
      <p:inline content-type="application/json">{"a":"b"}</p:inline>
    </p:with-input>
    <p:with-input port="patch">
      <p:inline content-type="application/json">{"b":"c"}</p:inline>
    </p:with-input>
  </cx:json-patch>

  <p:cast-content-type content-type="application/xml"/>
</p:declare-step>
  </t:pipeline>
  <t:schematron>
    <s:schema queryBinding="xslt2"
              xmlns:s="http://purl.oclc.org/dsdl/schematron">
      <s:ns prefix="fn" uri="http://www.w3.org/2005/xpath-functions"/>
      <s:pattern>
        <s:rule context="/">
          <s:assert test="fn:map">The root is not map.</s:assert>
          <s:assert test="count(fn:map/*) = 2">Wrong number of keys.</s:assert>
          <s:assert test="fn:map/fn:string[@key='a']='b'">a != b</s:assert>
          <s:assert test="fn:map/fn:string[@key='b']='c'">b != c</s:assert>
        </s:rule>
      </s:pattern>
    </s:schema>
  </t:schematron>
</t:test>

