// Map Tests
// =========

@include test-module('Map Helpers') {
  $map: (
    one: (
      hello: (
        world: new york,
        pizza: sausage,
      ),
      goodbye: fugard,
    ),
    two: cheese,
  );

  // Truncate List
  // -------------
  @include test('truncate-list') {
    $list: one two three four;
    $test: _susy-truncate-list($list, 3);
    $expect: one two three;
    @include assert-equal($test, $expect,
      'Returns a list truncated to the given length.');
  }

  // Deep Get
  // --------
  @include test('deep-get') {
    $test: _susy-deep-get($map, one, hello, world);
    $expect: new york;
    @include assert-equal($test, $expect,
      'Returns value of deep key.');
  }

  // Deep Set
  // --------
  @include test('deep-set') {
    $test: _susy-deep-set($map, one, hello, pizza, yum);
    $expect: (
      one: (
        hello: (
          world: new york,
          pizza: yum,
        ),
        goodbye: fugard,
      ),
      two: cheese,
    );
    @include assert-equal($test, $expect,
      'Returns map with deep value adjusted.');

    $test: _susy-deep-set($map, one, monkey, three, test);
    $expect: (
      one: (
        hello: (
          world: new york,
          pizza: sausage,
        ),
        goodbye: fugard,
        monkey: (
          three: test,
        ),
      ),
      two: cheese,
    );
    @include assert-equal($test, $expect,
      'Set deep value even in new key path.');
  }

  // Deep Merge
  // ----------
  @include test('deep-merge') {
    $m1: (
      hello: (
        world: new york,
        monday: work,
      ),
      pizza: cheese,
    );
    $m2: (
      hello: (
        world: china,
      ),
      sunday: ice cream,
    );
    $test: _susy-deep-merge($m1, $m2);
    $expect: (
      hello: (
        world: china,
        monday: work,
      ),
      pizza: cheese,
      sunday: ice cream,
    );
    @include assert-equal($test, $expect,
      'Should merge nested maps');
  }


  // Deep Has-Key
  // ------------
  @include test('deep-has-key') {
    $test: _susy-deep-has-key($map, one, hello, world);
    $expect: true;
    @include assert-equal($test, $expect,
      'Returns true for existing deep key.');

    $test: _susy-deep-has-key($map, one, hello, neverland);
    $expect: false;
    @include assert-equal($test, $expect,
      'Returns false for non-existing deep key.');
  }
}
