<commit_before>package org.exist.xquery.functions.util;

import com.googlecode.junittoolbox.ParallelRunner;
import org.custommonkey.xmlunit.exceptions.XpathException;
import org.exist.test.ExistXmldbEmbeddedServer;
import org.junit.ClassRule;
import org.junit.Test;

import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
import static org.junit.Assert.*;

import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;

import org.junit.runner.RunWith;
import org.xml.sax.SAXException;
import java.io.IOException;

import org.custommonkey.xmlunit.XMLUnit;
import org.exist.xquery.XPathException;

import org.xmldb.api.base.ResourceSet;
import org.xmldb.api.base.XMLDBException;

/**
 *
 * @author <EMAIL>
 */
@RunWith(ParallelRunner.class)
public class SerializeTest {

    @ClassRule
    public static final ExistXmldbEmbeddedServer existEmbeddedServer = new ExistXmldbEmbeddedServer(false, true);

    @Test
    public void testSerialize() throws XPathException, XMLDBException, IOException, SAXException {
        final String query = "let $xml := <test/>\n" +
                "return\n" +
                "util:serialize($xml,'method=xml')";
        final ResourceSet result = existEmbeddedServer.executeQuery(query);
        final String r = (String) result.getResource(0).getContent();
        assertXMLEqual(r,"<test/>");
    }

    @Test
    public void testSerialize2() throws XPathException, XMLDBException, IOException, SAXException {
        final String query = "let $xml := <test><a/><b/></test>\n" +
                "return\n" +
                "util:serialize($xml,'method=xml indent=no')";
        final ResourceSet result = existEmbeddedServer.executeQuery(query);
        final String r = (String) result.getResource(0).getContent();
        assertXMLEqual(r,"<test><a/><b/></test>");
    }

    @Test
    public void testSerializeText() throws XPathException, XMLDBException, IOException, SAXException {
        final String query = "let $xml := <test><a>test</a></test>\n" +
                "return\n" +
                "util:serialize($xml,'method=text indent=no')";
        final ResourceSet result = existEmbeddedServer.executeQuery(query);
        final String r = (String) result.getResource(0).getContent();
        assertEquals(r,"test");
    } 

    @Test
    public void testSerializeIndent() throws XPathException, XMLDBException, IOException, SAXException {
        final String query = "let $xml := <test><a/><b/></test>\n" +
                "return\n" +
                "util:serialize($xml,'method=xml indent=yes')";
        final ResourceSet result = existEmbeddedServer.executeQuery(query);
        final String r = (String) result.getResource(0).getContent();
        XMLUnit.setIgnoreWhitespace(true);
        assertXMLEqual(r,"<test><a/><b/></test>");<commit_msg>[bugfix] Correct expected actual test value order<commit_after>package org.exist.xquery.functions.util;

import com.googlecode.junittoolbox.ParallelRunner;
import org.custommonkey.xmlunit.exceptions.XpathException;
import org.exist.test.ExistXmldbEmbeddedServer;
import org.junit.ClassRule;
import org.junit.Test;

import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
import static org.junit.Assert.*;

import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;

import org.junit.runner.RunWith;
import org.xml.sax.SAXException;
import java.io.IOException;

import org.custommonkey.xmlunit.XMLUnit;
import org.exist.xquery.XPathException;

import org.xmldb.api.base.ResourceSet;
import org.xmldb.api.base.XMLDBException;

/**
 *
 * @author <EMAIL>
 */
@RunWith(ParallelRunner.class)
public class SerializeTest {

    @ClassRule
    public static final ExistXmldbEmbeddedServer existEmbeddedServer = new ExistXmldbEmbeddedServer(false, true);

    @Test
    public void testSerialize() throws XPathException, XMLDBException, IOException, SAXException {
        final String query = "let $xml := <test/>\n" +
                "return\n" +
                "util:serialize($xml,'method=xml')";
        final ResourceSet result = existEmbeddedServer.executeQuery(query);
        final String r = (String) result.getResource(0).getContent();
        assertXMLEqual("<test/>", r);
    }

    @Test
    public void testSerialize2() throws XPathException, XMLDBException, IOException, SAXException {
        final String query = "let $xml := <test><a/><b/></test>\n" +
                "return\n" +
                "util:serialize($xml,'method=xml indent=no')";
        final ResourceSet result = existEmbeddedServer.executeQuery(query);
        final String r = (String) result.getResource(0).getContent();
        assertXMLEqual("<test><a/><b/></test>", r);
    }

    @Test
    public void testSerializeText() throws XPathException, XMLDBException, IOException, SAXException {
        final String query = "let $xml := <test><a>test</a></test>\n" +
                "return\n" +
                "util:serialize($xml,'method=text indent=no')";
        final ResourceSet result = existEmbeddedServer.executeQuery(query);
        final String r = (String) result.getResource(0).getContent();
        assertEquals("test", r);
    } 

    @Test
    public void testSerializeIndent() throws XPathException, XMLDBException, IOException, SAXException {
        final String query = "let $xml := <test><a/><b/></test>\n" +
                "return\n" +
                "util:serialize($xml,'method=xml indent=yes')";
        final ResourceSet result = existEmbeddedServer.executeQuery(query);
        final String r = (String) result.getResource(0).getContent();
        XMLUnit.setIgnoreWhitespace(true);
        assertXMLEqual("<test><a/><b/></test>", r);
{'fraction_non_alphanumeric': 0.1290436005625879, 'fraction_numerical': 0.0017580872011251757, 'mean_word_length': 3.5403032721468475, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 36}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6442349', 'n_tokens_mistral': 1720, 'n_tokens_neox': 1685, 'n_words': 333}