// Scale Tests
// ===========


$test-sizes: (
  'big': 'text' ('fifth': 5),
  'small': 'text' ('octave': -1),
  'viewport': 10vw,
  'percent': 20%,
);

$sizes: map-merge($sizes, $test-sizes);


// Size [function]
// ---------------
@include test-module('size [function]') {
  @include test('Get size from map setting') {
    @include assert-equal(
      size('root'),
      16px,
      'Returns named size from $sizes map.');
  }

  @include test('Get size from unit adjustment') {
    @include assert-equal(
      size('text'),
      1rem,
      'Returns size calculated from unit adjustment.');
  }

  @include test('Get size from linear adjustment') {
    @include assert-equal(
      size('h3'),
      2rem,
      'Returns size calculated from linear adjustment.');
  }

  @include test('Get size from ratio adjustment') {
    @include assert-equal(
      size('big'),
      7.59375rem,
      'Returns size calculated from ratio adjustment.');
  }

  @include test('Get size from negative ratio') {
    @include assert-equal(
      size('small'),
      0.5rem,
      'Returns size calculated from negative ratio.');
  }

  @include test('Get unit-adjusted size') {
    @include assert-equal(
      size(24px, 'rem'),
      1.5rem,
      'Returns size converted from explicit length.');
  }

  @include test('Dont adjust non-comparable units') {
    $test: size(24vmin);
    $expect: 24vmin;
    @include assert-equal($test, $expect,
      'Returns vmin size as given.');
  }

  @include test('Allow viewport units without warning') {
    @include assert-equal(
      size('viewport'),
      10vw);
  }

  @include test('Allow viewport units without warning') {
    @include assert-equal(
      size('percent'),
      20%);
  }
}


// Negative [function]
// -------------------
@include test-module('negative [function]') {
  @include test('Get negative size') {
    @include assert-equal(
      negative('rhythm'),
      0 - size('rhythm'),
      'Returns a keyword size, subtracted from zero.');
  }
}


// Square [mixin]
// --------------
@include test-module('square [mixin]') {
  @include test('Set height and width') {
    @include assert('Output height/width based on keyword') {
      @include output {
        @include square('h1');
      }

      @include expect {
        height: 4rem;
        width: 4rem;
      }
    }
  }
}


// For testing...
@function _plus-test-function(
  $size,
  $add
) {
  @return $size + $add;
}


// Adjust Size [function]
// ----------------------
@include test-module('_ac-scale-adjust-size [function]') {
  @include test('Adjust units') {
    @include assert-equal(
      _ac-scale-adjust-size(24px, 'convert-units', 'rem'),
      1.5rem);
  }

  @include test('Linear adjustment') {
    @include assert-equal(
      _ac-scale-adjust-size(24px, 'linear', 3),
      72px);
  }

  @include test('Explicit ratio adjustment') {
    @include assert-equal(
      _ac-scale-adjust-size(24px, 1.5, 2),
      54px);
  }

  @include test('Named ratio adjustment') {
    @include assert-equal(
      _ac-scale-adjust-size(24px, 'fifth', 2),
      54px);
  }

  @include test('Arbitrary adjustment') {
    @include assert-equal(
      _ac-scale-adjust-size(24px, '_plus-test-function', 2px),
      24px + 2px);
  }
}
