// Bleed Syntax Tests
// ==================

@include test-module('Bleed Syntax') {

  // bleed [mixin]
  // -------------

  @include output-test('bleed') {

    // simple
    @include assert-setup('simple', $grid: 9 .5) {
      .nest { @include squish(1); }
    }
    @include assert-output(
      'Items should bleed 1 column outside their nested context'
    ) {
      .test { @include bleed(0 1 of 7); }
      .expect {
        margin-right: -15%;
        margin-left: -15%;
        padding-right: 15%;
        padding-left: 15%;
      }
    }

    // explicit inside-static
    @include assert-setup('inside', $grid: 10 (4em 1em) inside-static) {
      .nest {
        @include squish(1);
        margin-bottom: 1rem;
        margin-top: 1rem;
      }
    }
    @include assert-output(
      'Items should bleed 1em on all sides, and retain their static gutters'
    ) {
      .test { @include bleed(1em of 8); }
      .expect {
        margin: -1em;
        padding: 1em 1.5em;
      }
    }

    // split
    @include assert-setup('split', $grid: 12 (4em 1em) split) {
      .nest { @include squish(2); }
    }
    @include assert-output(
      'Items should bleed 1 column horizontal, and retain gutters.'
    ) {
      .test { @include bleed(0 1 of 8); }
      .expect {
        margin-right: -12.5%;
        margin-left: -12.5%;
        padding-right: 12.5%;
        padding-left: 12.5%;
      }
    }
  }

  // bleed-x [mixin]
  // ---------------

  @include output-test('bleed-x') {

    // simple
    @include assert-setup('simple', $grid: 11 .5) {
      .nest { @include squish(2); }
    }
    @include assert-output(
      'Items should bleed 1 column left, and 2 columns right'
    ) {
      .test { @include bleed-x(1 2 of 7); }
      .expect {
        margin-right: -30%;
        margin-left: -15%;
        padding-right: 30%;
        padding-left: 15%;
      }
    }

    // inside
    @include assert-setup('inside', $grid: 10 .25 inside) {
      .nest { @include squish(1); }
    }
    @include assert-output(
      'Items should bleed 1 column, and retain their gutters'
    ) {
      .test { @include bleed-x(1 of 8); }
      .expect {
        margin-right: -12.5%;
        margin-left: -12.5%;
        padding-right: 13.75%;
        padding-left: 13.75%;
      }
    }
  }

  // bleed-y [mixin]
  // ---------------

  @include output-test('bleed-y') {

    // simple
    @include assert-setup('simple', $grid: 11 .5) {
      .nest {
        @include squish(1);
        margin-bottom: 1rem;
        margin-top: 1rem;
      }
    }
    @include assert-output(
      'Items should bleed .5em top, and 1em bottom.'
    ) {
      .test { @include bleed-y(.5em 1em); }
      .expect {
        margin-top: -0.5em;
        margin-bottom: -1em;
        padding-top: 0.5em;
        padding-bottom: 1em;
      }
    }
  }

  // get-bleed [function]
  // --------------------

  @include test('[function] get-bleed') {
    $test: get-bleed(0 1 1em of 7 .5);
    $expect: (
      margin-top: null,
      padding-top: null,
      margin-right: -15%,
      padding-right: 15%,
      margin-bottom: -1em,
      padding-bottom: 1em,
      margin-left: -15%,
      padding-left: 15%,
    );
    @include assert-equal($test, $expect,
      'get-bleed handles 0, span, and length arguments.');

    // inside
    $test: get-bleed(0 1 10% of 8 .25 inside);
    $expect: (
      margin-top: null,
      padding-top: null,
      margin-right: -12.5%,
      padding-right: 13.75%,
      margin-bottom: -10%,
      padding-bottom: 10%,
      margin-left: -12.5%,
      padding-left: 13.75%,
    );
    @include assert-equal($test, $expect,
      'get-bleed handles inside gutters.');

    // no-gutters inside
    $test: get-bleed(0 3em no-gutters inside);
    $expect: (
      margin-top: null,
      padding-top: null,
      margin-right: -3em,
      padding-right: 3em,
      margin-bottom: null,
      padding-bottom: null,
      margin-left: -3em,
      padding-left: 3em,
    );
    @include assert-equal($test, $expect,
      'get-bleed can handle no-gutters inside.');
  }

  // bleed shorthand
  // ---------------

  @include test('[function] bleed-shorthand') {
    $bleed: (
      margin-top: -1em,
      padding-top: 1em,
      margin-right: -2em,
      padding-right: 2em,
      margin-bottom: -3em,
      padding-bottom: 1em,
      margin-left: -4em,
      padding-left: 2em,
    );
    $test: bleed-shorthand($bleed);
    $expect: (
      margin: -1em -2em -3em -4em,
      padding: 1em 2em,
    );
    @include assert-equal($test, $expect,
      'Returns shorthand for margin and padding, separate or combined.');

    $bleed: (
      margin-top: -1em,
      padding-top: 1em,
      margin-right: -1em,
      padding-right: 2em,
      margin-bottom: -1em,
      padding-bottom: 1em,
      margin-left: -1em,
      padding-left: null,
    );
    $test: bleed-shorthand($bleed);
    $expect: (
      margin: -1em,
      padding-top: 1em,
      padding-right: 2em,
      padding-bottom: 1em,
      padding-left: null,
    );
    @include assert-equal($test, $expect,
      'Returns combined shorthand for margin, no shorthand for padding.');
  }
}
