<commit_before>"use babel";

import ReactDOM from "react-dom";
import { CompositeDisposable } from "atom";

import {
  reactFactory,
  grammarToLanguage,
  isMultilanguageGrammar,
  getEmbeddedScope
} from "./../lib/utils";

describe("grammarToLanguage", () => {
  expect(grammarToLanguage({ name: "Kernel Name" })).toEqual("kernel name");
  expect(grammarToLanguage(null)).toBeNull();
  expect(grammarToLanguage(undefined)).toBeNull();
});

describe("reactFactory", () => {
  const compDisposable = new CompositeDisposable();
  spyOn(compDisposable, "add").andCallThrough();
  spyOn(ReactDOM, "render");
  spyOn(ReactDOM, "unmountComponentAtNode");
  const teardown = jasmine.createSpy("teardown");

  reactFactory("reactElement", "domElement", teardown, compDisposable);

  expect(ReactDOM.render).toHaveBeenCalledWith("reactElement", "domElement");
  expect(compDisposable.add).toHaveBeenCalled();

  expect(ReactDOM.unmountComponentAtNode).not.toHaveBeenCalled();
  expect(teardown).not.toHaveBeenCalled();
  compDisposable.dispose();
  expect(ReactDOM.unmountComponentAtNode).toHaveBeenCalledWith("domElement");
  expect(teardown).toHaveBeenCalled();
});

describe("isMultilanguageGrammar", () => {
  expect(
    isMultilanguageGrammar(atom.workspace.buildTextEditor().getGrammar())
  ).toBe(false);
  expect(isMultilanguageGrammar({ scopeName: "source.gfm" })).toBe(true);
  expect(isMultilanguageGrammar({ scopeName: "source.asciidoc" })).toBe(true);
});

describe("getEmbeddedScope", () => {
  const editor = {
    scopeDescriptorForBufferPosition: () => {
      return {
        getScopesArray: () => [
          "text.md",
          "fenced.code.md",
          "source.embedded.python"
        ]
      };
    }
  };
  spyOn(editor, "scopeDescriptorForBufferPosition").andCallThrough();
  const scope = getEmbeddedScope(editor, "position");
  expect(scope).toEqual("source.embedded.python");
  expect(editor.scopeDescriptorForBufferPosition).toHaveBeenCalledWith(
    "position"
  );
});<commit_msg>Use it in specs to get better error messages<commit_after>"use babel";

import ReactDOM from "react-dom";
import { CompositeDisposable } from "atom";

import {
  reactFactory,
  grammarToLanguage,
  isMultilanguageGrammar,
  getEmbeddedScope
} from "./../lib/utils";

describe("utils", () => {
  it("grammarToLanguage", () => {
    expect(grammarToLanguage({ name: "Kernel Name" })).toEqual("kernel name");
    expect(grammarToLanguage(null)).toBeNull();
    expect(grammarToLanguage(undefined)).toBeNull();
  });

  it("reactFactory", () => {
    const compDisposable = new CompositeDisposable();
    spyOn(compDisposable, "add").andCallThrough();
    spyOn(ReactDOM, "render");
    spyOn(ReactDOM, "unmountComponentAtNode");
    const teardown = jasmine.createSpy("teardown");

    reactFactory("reactElement", "domElement", teardown, compDisposable);

    expect(ReactDOM.render).toHaveBeenCalledWith("reactElement", "domElement");
    expect(compDisposable.add).toHaveBeenCalled();

    expect(ReactDOM.unmountComponentAtNode).not.toHaveBeenCalled();
    expect(teardown).not.toHaveBeenCalled();
    compDisposable.dispose();
    expect(ReactDOM.unmountComponentAtNode).toHaveBeenCalledWith("domElement");
    expect(teardown).toHaveBeenCalled();
  });

  it("isMultilanguageGrammar", () => {
    expect(
      isMultilanguageGrammar(atom.workspace.buildTextEditor().getGrammar())
    ).toBe(false);
    expect(isMultilanguageGrammar({ scopeName: "source.gfm" })).toBe(true);
    expect(isMultilanguageGrammar({ scopeName: "source.asciidoc" })).toBe(true);
  });

  it("getEmbeddedScope", () => {
    const editor = {
      scopeDescriptorForBufferPosition: () => {
        return {
          getScopesArray: () => [
            "text.md",
            "fenced.code.md",
            "source.embedded.python"
          ]
        };
      }
    };
    spyOn(editor, "scopeDescriptorForBufferPosition").andCallThrough();
    const scope = getEmbeddedScope(editor, "position");
    expect(scope).toEqual("source.embedded.python");
    expect(editor.scopeDescriptorForBufferPosition).toHaveBeenCalledWith(
      "position"
    );
  });
});
{'fraction_non_alphanumeric': 0.1548854041013269, 'fraction_numerical': 0.0, 'mean_word_length': 4.758333333333334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3173566', 'n_tokens_mistral': 1317, 'n_tokens_neox': 1309, 'n_words': 173}