LP#712490 Vandelay replace/merge PGTAP tests
authorBill Erickson <berickxx@gmail.com>
Thu, 19 Oct 2017 15:42:43 +0000 (11:42 -0400)
committerJason Stephenson <jason@sigio.com>
Fri, 8 Mar 2019 18:51:34 +0000 (13:51 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Signed-off-by: Jason Stephenson <jason@sigio.com>
Open-ILS/src/sql/Pg/t/lp712490-vand-replace-field-merge.pg [new file with mode: 0644]

diff --git a/Open-ILS/src/sql/Pg/t/lp712490-vand-replace-field-merge.pg b/Open-ILS/src/sql/Pg/t/lp712490-vand-replace-field-merge.pg
new file mode 100644 (file)
index 0000000..ca262d8
--- /dev/null
@@ -0,0 +1,135 @@
+BEGIN;
+
+-- Plan the tests.
+SELECT plan(5);
+
+SELECT is(
+    (SELECT vandelay.replace_field($$
+<record xmlns="http://www.loc.gov/MARC21/slim" 
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+  xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">
+  <leader>         a              </leader>
+  <datafield tag="100" ind1="1" ind2=" ">
+    <subfield code="a">Banks, Iain M</subfield>
+    <subfield code="d">1954-</subfield>
+  </datafield>
+</record>
+$$, $$
+<record xmlns="http://www.loc.gov/MARC21/slim"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+  xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">
+  <datafield tag="100" ind1="1" ind2=" ">
+    <subfield code="a">Banks, Iain M</subfield>
+    <subfield code="d">1954-2013</subfield>
+  </datafield>
+</record>
+$$, '100abcdef')),
+    '<record    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"    xmlns="http://www.loc.gov/MARC21/slim"><leader>         a              </leader><datafield tag="100" ind1="1" ind2=" "><subfield code="a">Banks, Iain M</subfield><subfield code="d">1954-2013</subfield></datafield></record>',
+    'Replacing a value for a single existing subfield'
+);
+
+SELECT is(
+    (SELECT vandelay.replace_field($$
+<record xmlns="http://www.loc.gov/MARC21/slim"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+  xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">
+  <leader>         a              </leader>
+  <datafield tag="100" ind1="1" ind2=" ">
+    <subfield code="a">Banks, Iain M</subfield>
+  </datafield>
+</record>
+$$, $$
+<record xmlns="http://www.loc.gov/MARC21/slim"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+  xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">
+  <datafield tag="100" ind1="1" ind2=" ">
+    <subfield code="a">Banks, Iain M</subfield>
+    <subfield code="d">1954-2013</subfield>
+  </datafield>
+</record>
+$$, '100abcdef')),
+    '<record    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"    xmlns="http://www.loc.gov/MARC21/slim"><leader>         a              </leader><datafield tag="100" ind1="1" ind2=" "><subfield code="a">Banks, Iain M</subfield><subfield code="d">1954-2013</subfield></datafield></record>',
+    'Adding a missing field'
+);
+
+SELECT is(
+    (SELECT vandelay.replace_field($$
+<record xmlns="http://www.loc.gov/MARC21/slim"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+  xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">
+  <leader>         a              </leader>
+  <datafield tag="100" ind1="1" ind2=" ">
+    <subfield code="a">Banks, Iain M</subfield>
+    <subfield code="d">1954-</subfield>
+  </datafield>
+</record>
+$$, $$
+<record xmlns="http://www.loc.gov/MARC21/slim"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+  xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">
+  <datafield tag="100" ind1="1" ind2=" ">
+    <subfield code="a">Banks, Iain M</subfield>
+    <subfield code="b">HELLO</subfield>
+    <subfield code="d">1954-2013</subfield>
+  </datafield>
+</record>
+$$, '100abcdef')),
+    '<record    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"    xmlns="http://www.loc.gov/MARC21/slim"><leader>         a              </leader><datafield tag="100" ind1="1" ind2=" "><subfield code="a">Banks, Iain M</subfield><subfield code="b">HELLO</subfield><subfield code="d">1954-2013</subfield></datafield></record>',
+    'Splicing a new field into the existing fields'
+);
+
+SELECT is(
+    (SELECT vandelay.replace_field($$
+<record xmlns="http://www.loc.gov/MARC21/slim"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+  xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">
+  <leader>         a              </leader>
+  <datafield tag="100" ind1="1" ind2=" ">
+    <subfield code="a">Banks, Iain M</subfield>
+    <subfield code="d">1954-</subfield>
+    <subfield code="z">STAY PUT</subfield>
+  </datafield>
+</record>
+$$, $$
+<record xmlns="http://www.loc.gov/MARC21/slim"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+  xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">
+  <datafield tag="100" ind1="1" ind2=" ">
+    <subfield code="a">Banks, Iain M</subfield>
+    <subfield code="b">HELLO</subfield>
+    <subfield code="y">IGNORE ME</subfield>
+    <subfield code="d">1954-2013</subfield>
+  </datafield>
+</record>
+$$, '100abcdef')),
+    '<record    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"    xmlns="http://www.loc.gov/MARC21/slim"><leader>         a              </leader><datafield tag="100" ind1="1" ind2=" "><subfield code="a">Banks, Iain M</subfield><subfield code="b">HELLO</subfield><subfield code="d">1954-2013</subfield><subfield code="z">STAY PUT</subfield></datafield></record>',
+    'Splice new field, ignore uncontrolled source field, leave uncontrolled target field in place'
+);
+
+SELECT is(
+    (SELECT vandelay.replace_field($$
+<record xmlns="http://www.loc.gov/MARC21/slim"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+  xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">
+  <leader>         a              </leader>
+  <datafield tag="100" ind1="1" ind2=" ">
+    <subfield code="a">Banks, Iain M</subfield>
+    <subfield code="d">1954-</subfield>
+  </datafield>
+</record>
+$$, $$
+<record xmlns="http://www.loc.gov/MARC21/slim"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+  xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">
+  <datafield tag="100" ind1="1" ind2=" ">
+    <subfield code="a">Banks, Iain M</subfield>
+  </datafield>
+</record>
+$$, '100abcdef')),
+    '<record    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"    xmlns="http://www.loc.gov/MARC21/slim"><leader>         a              </leader><datafield tag="100" ind1="1" ind2=" "><subfield code="a">Banks, Iain M</subfield></datafield></record>',
+    'Removing a subfield'
+);
+
+SELECT * FROM finish();
+ROLLBACK;
+