<commit_before>PHPCSFixer = require "../src/beautifiers/php-cs-fixer"
Beautifier = require "../src/beautifiers/beautifier"

# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
#
# To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit`
# or `fdescribe`). Remove the `f` to unfocus the block.

describe "PHP-CS-Fixer Beautifier", ->

    beforeEach ->

        # Activate package
        waitsForPromise ->
            activationPromise = atom.packages.activatePackage('atom-beautify')
            # Force activate package
            pack = atom.packages.getLoadedPackage("atom-beautify")
            pack.activateNow()
            # Change logger level
            # atom.config.set('atom-beautify._loggerLevel', 'verbose')
            # Return promise
            return activationPromise

    describe "Beautifier::beautify", ->

        beautifier = null

        beforeEach ->
            beautifier = new PHPCSFixer()

        it "should error when beautifier's program not found", ->
            expect(beautifier).not.toBe(null)
            expect(beautifier instanceof Beautifier).toBe(true)

            waitsForPromise shouldReject: true, ->
                text = ""
                language = "PHP"
                options = {
                    fixers: ""
                    levels: ""
                }
                # Mock
                beautifier.getShellEnvironment = -> Promise.resolve("")
                #
                p = beautifier.beautify(text, language, options)
                expect(p).not.toBe(null)
                expect(p instanceof beautifier.Promise).toBe(true)
                cb = (v) ->
                    console.log(v)
                    expect(v).not.toBe(null)
                    expect(v instanceof Error).toBe(true)
                    expect(v.code).toBe("CommandNotFound")
                    return v
                p.then(cb, cb)
                return p

        # it "should error with help description \
        #     when beautifier's program not found", ->
        #     expect(beautifier).not.toBe(null)
        #     expect(beautifier instanceof Beautifier).toBe(true)
        #
        #     waitsForPromise shouldReject: true, ->
        #         help = {
        #             link: "http://test.com"
        #             program: "test-program"
        #             pathOption: "Lang - Test Program Path"
        #         }
        #         p = beautifier.run("program", [], help: help)
        #         expect(p).not.toBe(null)
        #         expect(p instanceof beautifier.Promise).toBe(true)
        #         cb = (v) ->
        #             # console.log(v)
        #             expect(v).not.toBe(null)
        #             expect(v instanceof Error).toBe(true)
        #             expect(v.code).toBe("CommandNotFound")
        #             expect(v.description).not.toBe(null)
        #             expect(v.description.indexOf(help.link)).not.toBe(-1)
        #             expect(v.description.indexOf(help.program)).not.toBe(-1)
        #             expect(v.description
        #                 .indexOf(help.pathOption)).not.toBe(-1, \
        #                 "Error should have a description.")
        #             return v
        #         p.then(cb, cb)<commit_msg>Fix typo in php-cs-fixer spec, mocking env should be object<commit_after>PHPCSFixer = require "../src/beautifiers/php-cs-fixer"
Beautifier = require "../src/beautifiers/beautifier"

# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
#
# To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit`
# or `fdescribe`). Remove the `f` to unfocus the block.

describe "PHP-CS-Fixer Beautifier", ->

    beforeEach ->

        # Activate package
        waitsForPromise ->
            activationPromise = atom.packages.activatePackage('atom-beautify')
            # Force activate package
            pack = atom.packages.getLoadedPackage("atom-beautify")
            pack.activateNow()
            # Change logger level
            # atom.config.set('atom-beautify._loggerLevel', 'verbose')
            # Return promise
            return activationPromise

    describe "Beautifier::beautify", ->

        beautifier = null

        beforeEach ->
            beautifier = new PHPCSFixer()

        it "should error when beautifier's program not found", ->
            expect(beautifier).not.toBe(null)
            expect(beautifier instanceof Beautifier).toBe(true)

            waitsForPromise shouldReject: true, ->
                text = ""
                language = "PHP"
                options = {
                    fixers: ""
                    levels: ""
                }
                # Mock PATH
                beautifier.getShellEnvironment = -> Promise.resolve({
                    PATH: ''
                })
                #
                p = beautifier.beautify(text, language, options)
                expect(p).not.toBe(null)
                expect(p instanceof beautifier.Promise).toBe(true)
                cb = (v) ->
                    # console.log(v)
                    expect(v).not.toBe(null)
                    expect(v instanceof Error).toBe(true, \
                      "Expected #{v} to be instance of Error")
                    expect(v.code).toBe("CommandNotFound", \
                      "Expected to be CommandNotFound")
                    return v
                p.then(cb, cb)
                return p

        # it "should error with help description \
        #     when beautifier's program not found", ->
        #     expect(beautifier).not.toBe(null)
        #     expect(beautifier instanceof Beautifier).toBe(true)
        #
        #     waitsForPromise shouldReject: true, ->
        #         help = {
        #             link: "http://test.com"
        #             program: "test-program"
        #             pathOption: "Lang - Test Program Path"
        #         }
        #         p = beautifier.run("program", [], help: help)
        #         expect(p).not.toBe(null)
        #         expect(p instanceof beautifier.Promise).toBe(true)
        #         cb = (v) ->
        #             # console.log(v)
        #             expect(v).not.toBe(null)
        #             expect(v instanceof Error).toBe(true)
        #             expect(v.code).toBe("CommandNotFound")
        #             expect(v.description).not.toBe(null)
        #             expect(v.description.indexOf(help.link)).not.toBe(-1)
        #             expect(v.description.indexOf(help.program)).not.toBe(-1)
        #             expect(v.description
        #                 .indexOf(help.pathOption)).not.toBe(-1, \
        #                 "Error should have a description.")
        #             return v
        #         p.then(cb, cb)
{'fraction_non_alphanumeric': 0.11302068161957472, 'fraction_numerical': 0.000873871249635887, 'mean_word_length': 1.4027291812456264, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '7545035', 'n_tokens_mistral': 1842, 'n_tokens_neox': 1774, 'n_words': 371}