// Test Helpers
// ============

$true-terminal-output: details;

$output-test-context: true;
$output-test-results: true;

$output-test-slug: null;
$output-assert-slug: null;


// reset the original grid
@mixin original-grid {
  $susy: $susy-defaults !global;
}


// Output Test Setup/Teardown
// --------------------------

@mixin assert-setup(
  $slug: $output-test-slug,
  $grid: false,
  $output: $output-test-context
) {
  $output-assert-slug: $slug !global;

  @if $grid {
    @include layout($grid);
    @if $output {
      .test__#{$output-test-slug} .assert__#{$output-assert-slug} {
        @if map-get(layout($grid), columns) {
          @include container(show-columns);
        } @else {
          background: rgba(#ccf, .5);
        }
      }
    }
  } @else if $output {
    .test__#{$output-test-slug} .assert__#{$output-assert-slug} {
      overflow: hidden;
      background: rgba(#ccf, .5);
    }
  }

  @if $output {
    .test__#{$output-test-slug} .assert__#{$output-assert-slug} {
      @content;
    }
  }
}

@mixin assert-teardown(
) {
  $output-assert-slug: null !global;
  @include original-grid;
}

// Output Test
// -----------

@mixin output-test(
  $slug
) {
  $output-test-slug: $slug !global;

  /* - [mixin] #{$output-test-slug} */
  @content;

  $output-test-slug: null !global;
}

// Assert Output
// -------------

@mixin assert-output(
  $message: null,
  $output-test-results: $output-test-results,
  $output-test-context: $output-test-context
) {
  @if $output-test-results {
    /* "#{$message}" */
  }

  .test__#{$output-test-slug} .assert__#{$output-assert-slug} {
    @if $output-test-context and $message {
      &:before {
        content: $message;
        display: block;
        padding: .25rem .5rem;
        text-align: left;
        font-style: italic;
      }
    }
    @if $output-test-results {
      @content;
    }
  }

  @include assert-teardown;
}

// compare two maps
@mixin compare-maps(
  $test,
  $expect,
  $name
) {
  @each $key, $value in $expect {
    $this: map-get($test, $key);

    @if type-of($value) == map {
      @include compare-maps($this, $value,
      '#{$name} » #{$key}');
    } @else {
      @include assert-equal($this, $value,
        '[#{$name}] Returns the correct #{$key}.');
    }
  }
}
