<commit_before>package org.testng.reporters.jq;

import org.testng.IReporter;
import org.testng.ISuite;
import org.testng.ISuiteResult;
import org.testng.ITestContext;
import org.testng.ITestResult;
import org.testng.internal.Utils;
import org.testng.reporters.Files;
import org.testng.reporters.XMLStringBuffer;
import org.testng.xml.XmlSuite;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

public class Main implements IReporter {
  public static final String C = "class";
  public static final String D = "div";
  public static final String S = "span";

  private static final String PASSED = "passed";
  private static final String SKIPPED = "skipped";
  private static final String FAILED = "failed";

  private Model m_model;
  private String m_outputDirectory;
  private List<ISuite> m_suites;

  @Override
  public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites,
      String outputDirectory) {
    m_suites = suites;
    m_model = new Model(suites);
    m_outputDirectory = "/Users/cedric/java/misc/jquery";

    XMLStringBuffer xsb = new XMLStringBuffer("  ");
    xsb.push(D, C, "navigator-root");
    generateNavigator(xsb);
    xsb.pop(D);

    xsb.push(D, C, "wrapper");
    xsb.push(D, "class", "main-panel-root");

    //
    // Suite panels
    //
    for (ISuite s : suites) {
      generateSuitePanel(s, xsb, m_model.getTag(s));
    }

    //
    // Panel that displays the list of test names
    //
    new TestPanel().generate(suites, xsb);

    //
    // Panel that displays the content of testng.xml
    //
    new TestNgXmlPanel().generate(suites, xsb);

    xsb.pop(D); // main-panel-root
    xsb.pop(D); // wrapper

    String all;
    try {
      all = Files.readFile(new File("/Users/cedric/java/misc/jquery/head3"));
      Utils.writeFile(m_outputDirectory, "index3.html", all + xsb.toXML());
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }

  private String maybe(int count, String s, String sep) {
    return count > 0 ? count + " " + s + sep: "";
  }
  /**
   * Create the left hand navigator.
   */
  private void generateNavigator(XMLStringBuffer main) {
    int suiteCount = 0;
    for (ISuite suite : m_suites) {
      if (suite.getResults().size() == 0) {
        continue;
      }

      String suiteName = "suite-" + suiteCount;

      XMLStringBuffer header = new XMLStringBuffer(main.getCurrentIndent());

      Map<String, ISuiteResult> results = suite.getResults();
      int failed = 0;
      int skipped = 0;
      int passed = 0;
      for (ISuiteResult result : results.values()) {
        ITestContext context = result.getTestContext();
        failed += context.getFailedTests().size();
        skipped += context.getSkippedTests().size();
        passed += context.getPassedTests().size();
      }

      header.push(D, C, "suite");
      header.push(D, C, "suite-header rounded-window");
      header.push("a", "href", "#", "class", "navigator-link " + suiteName);
      header.addOptional(S, suite.getName(), C, "suite-name");
      header.pop("a");
      header.push(D, C, "stats");
      int total = failed + skipped + passed;
      String stats = String.format("%s, %s %s %s",
          pluralize(total, "method"),
          maybe(failed, "failed", ", "),
          maybe(skipped, "skipped", ", "),
          maybe(passed, "passed", ""));
      header.push("ul");

      // Tests
      header.push("li");
      header.push("a", "href", "#", "class", "navigator-link " + TestPanel.getTag());
      header.addOptional(S, String.format("%s ", pluralize(results.values().size(), "test"),
          C, "test-stats"));
      header.pop("a");
      header.pop("li");

      // testng.xml
      header.push("li");
      header.push("a", "href", "#", "class", "navigator-link " + TestNgXmlPanel.getTag(suiteCount));
      String fqName = suite.getXmlSuite().getFileName();
      header.addOptional(S, fqName.substring(fqName.lastIndexOf("/") + 1),
          C, "testng-xml");
      header.pop("a");
      header.pop("li");

      // Method stats
      header.push("li");
      header.addOptional(S, stats, C, "method-stats");
      header.pop("li");

      generateMethodList("Failed methods", ITestResult.FAILURE, suite, suiteName, header);
      generateMethodList("Skipped methods", ITestResult.SKIP, suite, suiteName, header);

      header.pop("ul");
      header.pop(D); // stats

      header.pop(D); // suite-header
      header.pop(D); // suite

      main.addString(header.toXML());

      suiteCount++;
    }
  }

  private void generateMethodList(String name, int status, ISuite suite, String suiteName,
      XMLStringBuffer main) {
    XMLStringBuffer xsb = new XMLStringBuffer(main.getCurrentIndent());

    // Failed methods
    xsb.push("li");
    xsb.addString(name);

    // List of failed methods
    xsb.push("ul");
    int count = 0;
    for (ITestResult tr : m_model.getTestResults(suite)) {
      if (tr.getStatus() == status) {
        String testName = Model.getTestResultName(tr);
        xsb.push("li");
        xsb.addOptional("a", testName, "href", "#",
            C, "method " + m_model.getTag(tr) + " " + suiteName);
        xsb.pop("li");
        count++;
      }
    }
    xsb.pop("ul");
    xsb.pop("li");
<commit_msg>Use data to store important stuff.<commit_after>package org.testng.reporters.jq;

import org.testng.IReporter;
import org.testng.ISuite;
import org.testng.ISuiteResult;
import org.testng.ITestContext;
import org.testng.ITestResult;
import org.testng.internal.Utils;
import org.testng.reporters.Files;
import org.testng.reporters.XMLStringBuffer;
import org.testng.xml.XmlSuite;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

public class Main implements IReporter {
  public static final String C = "class";
  public static final String D = "div";
  public static final String S = "span";

  private static final String PASSED = "passed";
  private static final String SKIPPED = "skipped";
  private static final String FAILED = "failed";

  private Model m_model;
  private String m_outputDirectory;
  private List<ISuite> m_suites;

  @Override
  public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites,
      String outputDirectory) {
    m_suites = suites;
    m_model = new Model(suites);
    m_outputDirectory = "/Users/cedric/java/misc/jquery";

    XMLStringBuffer xsb = new XMLStringBuffer("  ");
    xsb.push(D, C, "navigator-root");
    generateNavigator(xsb);
    xsb.pop(D);

    xsb.push(D, C, "wrapper");
    xsb.push(D, "class", "main-panel-root");

    //
    // Suite panels
    //
    for (ISuite s : suites) {
      generateSuitePanel(s, xsb, m_model.getTag(s));
    }

    //
    // Panel that displays the list of test names
    //
    new TestPanel().generate(suites, xsb);

    //
    // Panel that displays the content of testng.xml
    //
    new TestNgXmlPanel().generate(suites, xsb);

    xsb.pop(D); // main-panel-root
    xsb.pop(D); // wrapper

    String all;
    try {
      all = Files.readFile(new File("/Users/cedric/java/misc/jquery/head3"));
      Utils.writeFile(m_outputDirectory, "index3.html", all + xsb.toXML());
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }

  private String maybe(int count, String s, String sep) {
    return count > 0 ? count + " " + s + sep: "";
  }
  /**
   * Create the left hand navigator.
   */
  private void generateNavigator(XMLStringBuffer main) {
    int suiteCount = 0;
    for (ISuite suite : m_suites) {
      if (suite.getResults().size() == 0) {
        continue;
      }

      String suiteName = "suite-" + suiteCount;

      XMLStringBuffer header = new XMLStringBuffer(main.getCurrentIndent());

      Map<String, ISuiteResult> results = suite.getResults();
      int failed = 0;
      int skipped = 0;
      int passed = 0;
      for (ISuiteResult result : results.values()) {
        ITestContext context = result.getTestContext();
        failed += context.getFailedTests().size();
        skipped += context.getSkippedTests().size();
        passed += context.getPassedTests().size();
      }

      header.push(D, C, "suite");
      header.push(D, C, "suite-header rounded-window");
      header.push("a", "href", "#",
          "panel-name", suiteName,
          C, "navigator-link");
      header.addOptional(S, suite.getName(), C, "suite-name");
      header.pop("a");
      header.push(D, C, "stats");
      int total = failed + skipped + passed;
      String stats = String.format("%s, %s %s %s",
          pluralize(total, "method"),
          maybe(failed, "failed", ", "),
          maybe(skipped, "skipped", ", "),
          maybe(passed, "passed", ""));
      header.push("ul");

      // Tests
      header.push("li");
      header.push("a", "href", "#",
          "panel-name",  TestPanel.getTag(),
          C, "navigator-link ");
      header.addOptional(S, String.format("%s ", pluralize(results.values().size(), "test"),
          C, "test-stats"));
      header.pop("a");
      header.pop("li");

      // testng.xml
      header.push("li");
      header.push("a", "href", "#",
          "panel-name", TestNgXmlPanel.getTag(suiteCount),
          C, "navigator-link");
      String fqName = suite.getXmlSuite().getFileName();
      header.addOptional(S, fqName.substring(fqName.lastIndexOf("/") + 1),
          C, "testng-xml");
      header.pop("a");
      header.pop("li");

      // Method stats
      header.push("li");
      header.addOptional(S, stats, C, "method-stats");
      header.pop("li");

      generateMethodList("Failed methods", ITestResult.FAILURE, suite, suiteName, header);
      generateMethodList("Skipped methods", ITestResult.SKIP, suite, suiteName, header);

      header.pop("ul");
      header.pop(D); // stats

      header.pop(D); // suite-header
      header.pop(D); // suite

      main.addString(header.toXML());

      suiteCount++;
    }
  }

  private void generateMethodList(String name, int status, ISuite suite, String suiteName,
      XMLStringBuffer main) {
    XMLStringBuffer xsb = new XMLStringBuffer(main.getCurrentIndent());

    // Failed methods
    xsb.push("li");
    xsb.addString(name);

    // List of failed methods
    xsb.push("ul");
    int count = 0;
    for (ITestResult tr : m_model.getTestResults(suite)) {
      if (tr.getStatus() == status) {
        String testName = Model.getTestResultName(tr);
        xsb.push("li");
        xsb.addOptional("a", testName, "href", "#",
            "hash-for-method", m_model.getTag(tr),
            "panel-name", suiteName,
            C, "method navigator-link");
        xsb.pop("li");
        count++;
      }
    }
    xsb.pop("ul");
    xsb.pop("li");

{'fraction_non_alphanumeric': 0.1534195933456562, 'fraction_numerical': 0.0018484288354898336, 'mean_word_length': 2.7494802494802495, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '4325047', 'n_tokens_mistral': 3519, 'n_tokens_neox': 3428, 'n_words': 771}