<commit_before>'use strict';

var assert = require('chai').assert;
var expect = require('chai').expect;
var sinon = require('sinon');
var rewire = require('rewire');
var sp = rewire('../lib/sys_profiler.js');

var TIMEOUT = 45 * 1000;

describe('sys_profiler.js', function() {

  describe('#getAppData()', function() {

    it('should return system profile application data.', function(done) {
      this.timeout(TIMEOUT);
      var expected = 'Applications:';
      sp.getAppData(function(err, data) {
        var match = data.match(/^(.*)\n/);
        var result = match && match[1] ? match[1] : data.substring(0, 1024);
        expect(err).to.equal(null);
        expect(result).to.equal(expected);
        done();
      });
    });

    it('should return an applications data, when an app arg is passed.', function(done) {
      this.timeout(TIMEOUT);
      var expected = 'SystemUIServer';
      sp.getAppData('SystemUIServer', function(err, data) {
        data = data.substring(0, 1024);
        expect(err).to.equal(null);
        expect(data).to.equal(expected);
        done();
      });
    });

    it('should return null when an uninstalled app arg is passed.', function(done) {
      this.timeout(TIMEOUT);
      var expected = null;
      sp.getAppData('FakeNotInstalledApp', function(err, data) {
        if (data) {
          data = data.substring(0, 1024);
        }
        expect(err).to.equal(null);
        expect(data).to.equal(expected);
        done();
      });
    });

  });

  describe('#isAppInstalled()', function() {

    var test = function(desc, input, expected) {
      it(desc, function(done) {
        this.timeout(TIMEOUT);
        sp.isAppInstalled(input, function(err, isInstalled) {
          expect(err).to.equal(null);
          expect(isInstalled).to.equal(expected);
          done();
        });
      });
    };

    test('should return TRUE when an app is installed.',
      'SystemUIServer',
      true
    );
    test('should return TRUE when an app is installed, and be case insenitive.',
      'sYsteMuiseRver',
      true
    );
    test('should return FALSE when an app is NOT installed.',
      'FakeNotInstalledApp',
      false
    );

  });

});<commit_msg>Wrapping OSX specific unit tests in a check, so they are only run on OSX.<commit_after>'use strict';

var assert = require('chai').assert;
var expect = require('chai').expect;
var sinon = require('sinon');
var rewire = require('rewire');
var sp = rewire('../lib/sys_profiler.js');

var TIMEOUT = 45 * 1000;

var PLATFORM_OSX = 'darwin';
var PLATFORM_WINDOWS = 'win32';
var PLATFORM_LINUX = 'linux';

describe('#process.platform', function() {
  it('should be an expected value.', function() {
    var expectedPlatforms = [
      PLATFORM_OSX,
      PLATFORM_LINUX,
      PLATFORM_WINDOWS
    ];
    var platform = process.platform;
    expect(expectedPlatforms).to.contain(process.platform);
  });
});

// Only run these unit tests if we are on OSX.
if (process.platform === PLATFORM_OSX) {

  describe('sys_profiler.js', function() {

    describe('#getAppData()', function() {

      it('should return system profile application data.', function(done) {
        this.timeout(TIMEOUT);
        var expected = 'Applications:';
        sp.getAppData(function(err, data) {
          var match = data.match(/^(.*)\n/);
          var result = match && match[1] ? match[1] : data.substring(0, 1024);
          expect(err).to.equal(null);
          expect(result).to.equal(expected);
          done();
        });
      });

      it('should return an applications data, when an app arg is passed.', function(done) {
        this.timeout(TIMEOUT);
        var expected = 'SystemUIServer';
        sp.getAppData('SystemUIServer', function(err, data) {
          data = data.substring(0, 1024);
          expect(err).to.equal(null);
          expect(data).to.equal(expected);
          done();
        });
      });

      it('should return null when an uninstalled app arg is passed.', function(done) {
        this.timeout(TIMEOUT);
        var expected = null;
        sp.getAppData('FakeNotInstalledApp', function(err, data) {
          if (data) {
            data = data.substring(0, 1024);
          }
          expect(err).to.equal(null);
          expect(data).to.equal(expected);
          done();
        });
      });

    });

    describe('#isAppInstalled()', function() {

      var test = function(desc, input, expected) {
        it(desc, function(done) {
          this.timeout(TIMEOUT);
          sp.isAppInstalled(input, function(err, isInstalled) {
            expect(err).to.equal(null);
            expect(isInstalled).to.equal(expected);
            done();
          });
        });
      };

      test('should return TRUE when an app is installed.',
        'SystemUIServer',
        true
      );
      test('should return TRUE when an app is installed, and be case insenitive.',
        'sYsteMuiseRver',
        true
      );
      test('should return FALSE when an app is NOT installed.',
        'FakeNotInstalledApp',
        false
      );

    });

  });

}
{'fraction_non_alphanumeric': 0.14806824867621102, 'fraction_numerical': 0.009413610511865072, 'mean_word_length': 2.445945945945946, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5417565', 'n_tokens_mistral': 1568, 'n_tokens_neox': 1505, 'n_words': 359}