<commit_before>/*
Copyright 2016 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

'use strict'

define((require) => {
  const assert = require('intern/chai!assert')
  const path = require('intern/dojo/node!path')
  const registerSuite = require('intern!object')
  const sumchecker = require('intern/dojo/node!../index')

  let fixture = (filename) => {
    return path.join('tests', 'fixtures', filename)
  }

  let reject = (deferred) => {
    return deferred.reject.bind(deferred)
  }

  let testSumChecker = (checksumFilename, filesToCheck) => {
    return sumchecker('sha256', fixture(checksumFilename), fixture(''), filesToCheck)
  }

  registerSuite({
    'Checksum validates': function () {
      let deferred = this.async(1000)
      testSumChecker('example.sha256sum', 'example')
        .then(deferred.callback(() => {}), reject(deferred))
    },

    'Checksum validates binary file': function () {
      let deferred = this.async(1000)
      testSumChecker('example.sha256sum', 'example.binary')
        .then(deferred.callback(() => {}), reject(deferred))
    },

    'Checksum file not found': function () {
      let deferred = this.async(1000)
      testSumChecker('nonexistent.sha256sum', 'example')
        .then(reject(deferred), deferred.callback(error => {
          assert.instanceOf(error, Error)
          assert.equal(error.code, 'ENOENT')
        }))
    },

    'Checksum file not parseable': function () {
      let deferred = this.async(1000)
      testSumChecker('invalid.sha256sum', 'example')
        .then(reject(deferred), deferred.callback(error => {
          assert.instanceOf(error, sumchecker.ChecksumParseError)
          assert.strictEqual(error.lineNumber, 1)
          assert.strictEqual(error.line, 'invalid')
        }))
    },

    'Specified file not found in checksum file': function () {
      let deferred = this.async(1000)
      testSumChecker('example.sha256sum', 'nonexistent')
        .then(reject(deferred), deferred.callback(error => {
          assert.instanceOf(error, sumchecker.NoChecksumFoundError)
          assert.equal(error.filename, 'nonexistent')
        }))
    },

    'Specified file does not match checksum': function () {
      let deferred = this.async(1000)
      testSumChecker('example.sha256sum', 'wrong-checksum')
        .then(reject(deferred), deferred.callback(error => {
          assert.instanceOf(error, sumchecker.ChecksumMismatchError)
          assert.equal(error.filename, 'wrong-checksum')
        }))
    },

    'Multiple files specified, one does not match': function () {
      let deferred = this.async(1000)
      testSumChecker('example.sha256sum', ['example', 'wrong-checksum'])
        .then(reject(deferred), deferred.callback(error => {
          assert.instanceOf(error, sumchecker.ChecksumMismatchError)
          assert.equal(error.filename, 'wrong-checksum')
        }))
    }
  })
})<commit_msg>Add tests for the defaultTextEncoding option<commit_after>/*
Copyright 2016 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

'use strict'

define((require) => {
  const assert = require('intern/chai!assert')
  const path = require('intern/dojo/node!path')
  const registerSuite = require('intern!object')
  const sumchecker = require('intern/dojo/node!../index')

  let fixture = (filename) => {
    return path.join('tests', 'fixtures', filename)
  }

  let reject = (deferred) => {
    return deferred.reject.bind(deferred)
  }

  let testSumChecker = (checksumFilename, filesToCheck) => {
    return sumchecker('sha256', fixture(checksumFilename), fixture(''), filesToCheck)
  }

  registerSuite({
    'Checksum validates': function () {
      let deferred = this.async(1000)
      testSumChecker('example.sha256sum', 'example')
        .then(deferred.callback(() => {}), reject(deferred))
    },

    'Checksum validates binary file': function () {
      let deferred = this.async(1000)
      testSumChecker('example.sha256sum', 'example.binary')
        .then(deferred.callback(() => {}), reject(deferred))
    },

    'Checksum file not found': function () {
      let deferred = this.async(1000)
      testSumChecker('nonexistent.sha256sum', 'example')
        .then(reject(deferred), deferred.callback(error => {
          assert.instanceOf(error, Error)
          assert.equal(error.code, 'ENOENT')
        }))
    },

    'Checksum file not parseable': function () {
      let deferred = this.async(1000)
      testSumChecker('invalid.sha256sum', 'example')
        .then(reject(deferred), deferred.callback(error => {
          assert.instanceOf(error, sumchecker.ChecksumParseError)
          assert.strictEqual(error.lineNumber, 1)
          assert.strictEqual(error.line, 'invalid')
        }))
    },

    'Specified file not found in checksum file': function () {
      let deferred = this.async(1000)
      testSumChecker('example.sha256sum', 'nonexistent')
        .then(reject(deferred), deferred.callback(error => {
          assert.instanceOf(error, sumchecker.NoChecksumFoundError)
          assert.equal(error.filename, 'nonexistent')
        }))
    },

    'Specified file does not match checksum': function () {
      let deferred = this.async(1000)
      testSumChecker('example.sha256sum', 'wrong-checksum')
        .then(reject(deferred), deferred.callback(error => {
          assert.instanceOf(error, sumchecker.ChecksumMismatchError)
          assert.equal(error.filename, 'wrong-checksum')
        }))
    },

    'Multiple files specified, one does not match': function () {
      let deferred = this.async(1000)
      testSumChecker('example.sha256sum', ['example', 'wrong-checksum'])
        .then(reject(deferred), deferred.callback(error => {
          assert.instanceOf(error, sumchecker.ChecksumMismatchError)
          assert.equal(error.filename, 'wrong-checksum')
        }))
    },

    'Not specifying a text encoding defaults to utf8': function () {
      let validator = new sumchecker.ChecksumValidator()
      assert.equal(validator.encoding(false), 'utf8')
    },

    'Specifying a text encoding overrides the default': function () {
      let validator = new sumchecker.ChecksumValidator('sha256', 'nonexistent.sha256sum', {defaultTextEncoding: 'hex'})
      assert.equal(validator.encoding(false), 'hex')
    }
  })
})
{'fraction_non_alphanumeric': 0.1277946453215567, 'fraction_numerical': 0.017940932928512284, 'mean_word_length': 3.384150030248034, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5166672', 'n_tokens_mistral': 2189, 'n_tokens_neox': 2057, 'n_words': 501}