<commit_before>helpers = require './spec-helpers'
Latex = require '../lib/latex'

describe "Latex", ->
  [latex] = []

  beforeEach ->
    latex = new Latex()

  describe "initialize", ->
    it "initializes all properties", ->
      latex.initialize()

      expect(latex.builder).toBeDefined()
      expect(latex.logger).toBeDefined()
      expect(latex.opener).toBeDefined()

  describe "setDefaultBuilder", ->
    it "sets the default builder to LatexmkBuilder", ->
      origin = latex.builder
      latex.setDefaultBuilder()

      expect(origin).toBeUndefined()
      expect(latex.builder.constructor.name).toBe 'LatexmkBuilder'

  describe "setDefaultLogger", ->
    it "sets the default logger to ConsoleLogger", ->
      origin = latex.logger
      latex.setDefaultLogger()

      expect(origin).toBeUndefined()
      expect(latex.logger.constructor.name).toBe 'ConsoleLogger'

  describe "setDefaultOpener", ->
    it "sets the default logger as resolved", ->
      origin = latex.opener
      opener = helpers.nullOpener()
      spyOn(latex, 'resolveOpenerImplementation').andReturn(opener.constructor)
      latex.setDefaultOpener()

      expect(origin).toBeUndefined()
      expect(latex.opener.constructor.name).toEqual(opener.constructor.name)

  describe "Logger proxy", ->
    [logger] = []

    beforeEach ->
      logger = jasmine.createSpyObj('MockLogger', ['error', 'warning', 'info'])
      latex.setLogger(logger)
      latex.createLogProxy()

    it "correctly proxies error to error", ->
      statusCode = 0
      result = foo: 'bar'
      builder = run: -> ''
      latex.log.error(statusCode, result, builder)

      expect(logger.error).toHaveBeenCalledWith(statusCode, result, builder)

    it "correctly proxies warning to warning", ->
      message = "foo"
      latex.log.warning(message)

      expect(logger.warning).toHaveBeenCalledWith(message)

    it "correctly proxies info to info", ->
      message = "foo"
      latex.log.info(message)

      expect(logger.info).toHaveBeenCalledWith(message)

  describe "resolveOpenerImplementation", ->
    it "returns SkimOpener when installed, and running on OS X", ->
      atom.config.set('latex.skimPath', '/Applications/Skim.app')

      existsSync = fs.existsSync
      spyOn(fs, 'existsSync').andCallFake (filePath) ->
        return true if filePath is '/Applications/Skim.app'
        existsSync(filePath)

      opener = latex.resolveOpenerImplementation('darwin')

      expect(opener.name).toEqual('SkimOpener')

    it "returns PreviewOpener when Skim is not installed, and running on OS X", ->
      atom.config.set('latex.skimPath', '/foo/Skim.app')
      helpers.overridePlatform('darwin')
      opener = latex.resolveOpenerImplementation('darwin')

      expect(opener.name).toBe 'PreviewOpener'<commit_msg>:green_heart: Remove unintended process.platform override<commit_after>helpers = require './spec-helpers'
Latex = require '../lib/latex'

describe "Latex", ->
  [latex] = []

  beforeEach ->
    latex = new Latex()

  describe "initialize", ->
    it "initializes all properties", ->
      opener = helpers.nullOpener()
      spyOn(latex, 'resolveOpenerImplementation').andReturn(opener.constructor)
      latex.initialize()

      expect(latex.builder).toBeDefined()
      expect(latex.logger).toBeDefined()
      expect(latex.opener).toBeDefined()

  describe "setDefaultBuilder", ->
    it "sets the default builder to LatexmkBuilder", ->
      origin = latex.builder
      latex.setDefaultBuilder()

      expect(origin).toBeUndefined()
      expect(latex.builder.constructor.name).toBe 'LatexmkBuilder'

  describe "setDefaultLogger", ->
    it "sets the default logger to ConsoleLogger", ->
      origin = latex.logger
      latex.setDefaultLogger()

      expect(origin).toBeUndefined()
      expect(latex.logger.constructor.name).toBe 'ConsoleLogger'

  describe "setDefaultOpener", ->
    it "sets the default logger as resolved", ->
      origin = latex.opener
      opener = helpers.nullOpener()
      spyOn(latex, 'resolveOpenerImplementation').andReturn(opener.constructor)
      latex.setDefaultOpener()

      expect(origin).toBeUndefined()
      expect(latex.opener.constructor.name).toEqual(opener.constructor.name)

  describe "Logger proxy", ->
    [logger] = []

    beforeEach ->
      logger = jasmine.createSpyObj('MockLogger', ['error', 'warning', 'info'])
      latex.setLogger(logger)
      latex.createLogProxy()

    it "correctly proxies error to error", ->
      statusCode = 0
      result = foo: 'bar'
      builder = run: -> ''
      latex.log.error(statusCode, result, builder)

      expect(logger.error).toHaveBeenCalledWith(statusCode, result, builder)

    it "correctly proxies warning to warning", ->
      message = "foo"
      latex.log.warning(message)

      expect(logger.warning).toHaveBeenCalledWith(message)

    it "correctly proxies info to info", ->
      message = "foo"
      latex.log.info(message)

      expect(logger.info).toHaveBeenCalledWith(message)

  describe "resolveOpenerImplementation", ->
    it "returns SkimOpener when installed, and running on OS X", ->
      atom.config.set('latex.skimPath', '/Applications/Skim.app')

      existsSync = fs.existsSync
      spyOn(fs, 'existsSync').andCallFake (filePath) ->
        return true if filePath is '/Applications/Skim.app'
        existsSync(filePath)

      opener = latex.resolveOpenerImplementation('darwin')

      expect(opener.name).toEqual('SkimOpener')

    it "returns PreviewOpener when Skim is not installed, and running on OS X", ->
      atom.config.set('latex.skimPath', '/foo/Skim.app')
      opener = latex.resolveOpenerImplementation('darwin')

      expect(opener.name).toBe 'PreviewOpener'
{'fraction_non_alphanumeric': 0.12580701448263829, 'fraction_numerical': 0.00034897923573547375, 'mean_word_length': 3.2840059790732434, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 43, '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': '6237302', 'n_tokens_mistral': 1750, 'n_tokens_neox': 1692, 'n_words': 348}