<commit_before>'use strict';

const assert = require('assert');

const sharp = require('../../');
const fixtures = require('../fixtures');

describe('Trim borders', function () {
  it('Threshold default', function (done) {
    const expected = fixtures.expected('alpha-layer-1-fill-trim-resize.png');
    sharp(fixtures.inputPngOverlayLayer1)
      .resize(450, 322)
      .trim()
      .toBuffer(function (err, data, info) {
        if (err) throw err;
        assert.strictEqual('png', info.format);
        assert.strictEqual(450, info.width);
        assert.strictEqual(322, info.height);
        assert.strictEqual(-204, info.trimOffsetLeft);
        assert.strictEqual(0, info.trimOffsetTop);
        fixtures.assertSimilar(expected, data, done);
      });
  });

  it('Skip shrink-on-load', function (done) {
    const expected = fixtures.expected('alpha-layer-2-trim-resize.jpg');
    sharp(fixtures.inputJpgOverlayLayer2)
      .trim()
      .resize(300)
      .toBuffer(function (err, data, info) {
        if (err) throw err;
        assert.strictEqual('jpeg', info.format);
        assert.strictEqual(300, info.width);
        assert.strictEqual(-873, info.trimOffsetLeft);
        assert.strictEqual(-554, info.trimOffsetTop);
        fixtures.assertSimilar(expected, data, done);
      });
  });

  it('16-bit PNG with alpha channel', function (done) {<commit_msg>Threshold trim tests for non-turbo libjpeg<commit_after>'use strict';

const assert = require('assert');

const sharp = require('../../');
const inRange = require('../../lib/is').inRange;
const fixtures = require('../fixtures');

describe('Trim borders', function () {
  it('Threshold default', function (done) {
    const expected = fixtures.expected('alpha-layer-1-fill-trim-resize.png');
    sharp(fixtures.inputPngOverlayLayer1)
      .resize(450, 322)
      .trim()
      .toBuffer(function (err, data, info) {
        if (err) throw err;
        assert.strictEqual('png', info.format);
        assert.strictEqual(450, info.width);
        assert.strictEqual(322, info.height);
        assert.strictEqual(-204, info.trimOffsetLeft);
        assert.strictEqual(0, info.trimOffsetTop);
        fixtures.assertSimilar(expected, data, done);
      });
  });

  it('Skip shrink-on-load', function (done) {
    const expected = fixtures.expected('alpha-layer-2-trim-resize.jpg');
    sharp(fixtures.inputJpgOverlayLayer2)
      .trim()
      .resize({
        width: 300,
        fastShrinkOnLoad: false
      })
      .toBuffer(function (err, data, info) {
        if (err) throw err;
        assert.strictEqual('jpeg', info.format);
        assert.strictEqual(300, info.width);
        assert.strictEqual(true, inRange(info.trimOffsetLeft, -873, -870));
        assert.strictEqual(-554, info.trimOffsetTop);
        fixtures.assertSimilar(expected, data, done);
      });
  });

  it('16-bit PNG with alpha channel', function (done) {
{'fraction_non_alphanumeric': 0.1548232063165122, 'fraction_numerical': 0.02437349811191212, 'mean_word_length': 3.041608876560333, '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': '4356572', 'n_tokens_mistral': 930, 'n_tokens_neox': 864, 'n_words': 178}