<commit_before>import parse from "../lib/index.js";
import { expect } from "chai";
import assert from "assert";

const __dirname = process.cwd();
const POM_PATH = __dirname + "/test/fixture/pom.xml";

describe('require("pom-parser")', function () {
  describe("loading from files", function () {
    // Setup the tests using mocha's promise.
    // https://lostechies.com/derickbailey/2012/08/17/asynchronous-unit-tests-with-mocha-promises-and-winjs/
    let pom: any, xml: string;
    before(function (done) {
      parse({ filePath: POM_PATH }, function (err, response) {
        expect(err).to.be.null;
        if (response) {
          expect(response).to.be.an("object");
          ({ pomObject: pom, pomXml: xml } = response);
        } else {
          expect(false).to.be.true;
        }
        done();
      });
    });

    // Tear down the tests by printing the loaded xml and the parsed object.
    after(function (done) {
      console.log("\n\nThe XML loaded");
      console.log(xml);
      console.log("\n\nThe parsed XML");
      console.log(JSON.stringify(pom, null, 2));
      done();
    });

    it("can load any pom.xml properly", function (done) {
      expect(xml).to.be.an("string");
      expect(pom).to.be.an("object");
      done();
    });

    it("parses xml attributes as properties", function (done) {
      expect(pom.project.xmlns).to.equal("http://maven.apache.org/POM/4.0.0");
      expect(pom.project["xmlns:xsi"]).to.equal(
        "http://www.w3.org/2001/XMLSchema-instance"
      );
      done();
    });

    it("parses xml elements as properties", function (done) {
      expect(pom.project.parent).to.be.an("object");
      expect(pom.project.parent.artifactid).to.equal("tynamo-parent");
      done();
    });
  });

  describe("when opts is null", function () {
    it("parser should throw an error", function () {
      assert.throws(function () {
        parse(null, function (err, response) {});
      });
    });
  });

  describe("when opts is empty", function () {
    it("parser should throw an error", function () {
      assert.throws(function () {
        parse({}, function (err, response) {});
      });
    });
  });

  describe("error scenarios", function () {
    it("should return error if file does not exist", function (done) {
      parse(
        { filePath: __dirname + "incorrect-file-path" },
        function (err, response) {
          expect(response).to.be.null;
          expect(err).to.not.be.null;
          done();
        }
      );
    });

    it("should return error if invalid xml file", function (done) {
      parse(
        { filePath: __dirname + "/fixture/pom2.xml" },
        function (err, response) {
          expect(response).to.be.null;
          expect(err).to.not.be.null;
          done();
        }
      );
    });

    it("should return error if invalid xml content", function (done) {
      const invalidXml = "<parent>this is invalid</PARENT>";
      parse({ xmlContent: invalidXml }, function (err) {
        expect(err).to.not.be.null;
        done();
      });
    });
  });
});
<commit_msg>add jsodcs<commit_after>import parse from "../lib/index.js";
import { expect } from "chai";
import assert from "assert";

// read the current working directory, where
// package.json file lives
const __dirname = process.cwd();

// form path to test fixtures
const POM_PATH = __dirname + "/test/fixture/pom.xml";

describe('require("pom-parser")', function () {
  describe("loading from files", function () {
    // Setup the tests using mocha's promise.
    // https://lostechies.com/derickbailey/2012/08/17/asynchronous-unit-tests-with-mocha-promises-and-winjs/
    let pom: any, xml: string;
    before(function (done) {
      parse({ filePath: POM_PATH }, function (err, response) {
        expect(err).to.be.null;
        if (response) {
          expect(response).to.be.an("object");
          ({ pomObject: pom, pomXml: xml } = response);
        } else {
          expect(false).to.be.true;
        }
        done();
      });
    });

    // Tear down the tests by printing the loaded xml and the parsed object.
    after(function (done) {
      console.log("\n\nThe XML loaded");
      console.log(xml);
      console.log("\n\nThe parsed XML");
      console.log(JSON.stringify(pom, null, 2));
      done();
    });

    it("can load any pom.xml properly", function (done) {
      expect(xml).to.be.an("string");
      expect(pom).to.be.an("object");
      done();
    });

    it("parses xml attributes as properties", function (done) {
      expect(pom.project.xmlns).to.equal("http://maven.apache.org/POM/4.0.0");
      expect(pom.project["xmlns:xsi"]).to.equal(
        "http://www.w3.org/2001/XMLSchema-instance"
      );
      done();
    });

    it("parses xml elements as properties", function (done) {
      expect(pom.project.parent).to.be.an("object");
      expect(pom.project.parent.artifactid).to.equal("tynamo-parent");
      done();
    });
  });

  describe("when opts is null", function () {
    it("parser should throw an error", function () {
      assert.throws(function () {
        parse(null, function (err, response) { });
      });
    });
  });

  describe("when opts is empty", function () {
    it("parser should throw an error", function () {
      assert.throws(function () {
        parse({}, function (err, response) { });
      });
    });
  });

  describe("error scenarios", function () {
    it("should return error if file does not exist", function (done) {
      parse(
        { filePath: __dirname + "incorrect-file-path" },
        function (err, response) {
          expect(response).to.be.null;
          expect(err).to.not.be.null;
          done();
        }
      );
    });

    it("should return error if invalid xml file", function (done) {
      parse(
        { filePath: __dirname + "/fixture/pom2.xml" },
        function (err, response) {
          expect(response).to.be.null;
          expect(err).to.not.be.null;
          done();
        }
      );
    });

    it("should return error if invalid xml content", function (done) {
      const invalidXml = "<parent>this is invalid</PARENT>";
      parse({ xmlContent: invalidXml }, function (err) {
        expect(err).to.not.be.null;
        done();
      });
    });
  });
});

{'fraction_non_alphanumeric': 0.1687857596948506, 'fraction_numerical': 0.00572155117609663, 'mean_word_length': 2.37788513150832, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 30}, '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': '4505350', 'n_tokens_mistral': 1979, 'n_tokens_neox': 1927, 'n_words': 433}