<commit_before>/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.rendering.scaffolding;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

import junit.framework.TestSuite;

/**
 * @version $Id$
 * @since 1.6M1
 */
public class RenderingTestSuite extends TestSuite
{
    private static class Data
    {
        public Map<String, String> inputs = new HashMap<String, String>();

        public Map<String, String> expectations = new HashMap<String, String>();
    }

    public RenderingTestSuite(String name)
    {
        super(name);
    }

    public void addTestsFromResource(String testResourceName, boolean runTransformations) throws Exception
    {
        String resourceName = "/" + testResourceName + ".test";
        Data data;
        try {
            data = readTestData(getClass().getResourceAsStream(resourceName), resourceName);
        } catch (Exception e) {
            throw new RuntimeException("Failed to find load test data [" + testResourceName + "]");
        }

        // Create a test case for each input and for each expectation so that each test is executed separately
        // and reported separately by the JUnit test runner.
        for (Map.Entry<String, String> entry : data.inputs.entrySet()) {
            for (String targetSyntaxId : data.expectations.keySet()) {
                String parserId = entry.getKey();
                String input = entry.getValue();

                if (parserId.equals("xhtml/1.0") && !input.startsWith("<?xml") && !input.startsWith("<!DOCTYPE")) {
                    input =
                        "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"<commit_msg>Fixed findbug-reported violation<commit_after>/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.rendering.scaffolding;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

import junit.framework.TestSuite;

/**
 * @version $Id$
 * @since 1.6M1
 */
public class RenderingTestSuite extends TestSuite
{
    private static class Data
    {
        public Map<String, String> inputs = new HashMap<String, String>();

        public Map<String, String> expectations = new HashMap<String, String>();
    }

    public RenderingTestSuite(String name)
    {
        super(name);
    }

    public void addTestsFromResource(String testResourceName, boolean runTransformations) throws Exception
    {
        String resourceName = "/" + testResourceName + ".test";
        Data data;
        try {
            data = readTestData(getClass().getResourceAsStream(resourceName), resourceName);
        } catch (Exception e) {
            throw new RuntimeException("Failed to find load test data [" + testResourceName + "]");
        }

        // Create a test case for each input and for each expectation so that each test is executed separately
        // and reported separately by the JUnit test runner.
        for (Map.Entry<String, String> entry : data.inputs.entrySet()) {
            for (String targetSyntaxId : data.expectations.keySet()) {
                String parserId = entry.getKey();
                String input = entry.getValue();

                if ("xhtml/1.0".equals(parserId) && !input.startsWith("<?xml") && !input.startsWith("<!DOCTYPE")) {
                    input =
                        "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
{'fraction_non_alphanumeric': 0.09690568834537706, 'fraction_numerical': 0.008893829905503057, 'mean_word_length': 2.9867060561299854, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 2}, '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': '4946091', 'n_tokens_mistral': 1451, 'n_tokens_neox': 1387, 'n_words': 535}