@include test-module('_index-of') {
    $list: 1 2 3 1 2 3;

    @include test('should return the index of the first matched value') {
        @include assert-equal(_index-of($list, 3), 3);
    }

    @include test('should work with a positive from-index') {
        @include assert-equal(_index-of($list, 1, 2), 4);
    }

    @include test('should work with from-index >= list length') {
        $values: 6 8 _pow(2, 32);

        @each $value in $values {
            @include assert-equal(_index-of($list, 1, $value), -1);
        }
    }

    @include test('should treat falsey from-index values as 0') {
        @each $value in $test-falsey {
            @include assert-equal(_index-of($list, 1, $value), 1);
        }
    }

    @include test('should work with a negative from-index') {
        @include assert-equal(_index-of($list, 2, -3), 5);
    }

    @include test('should work with a negative from-index <= -list length') {
        @each $value in -6 -8 (_pow(2, 32) * -1) {
            @include assert-equal(_index-of($list, 1, $value), 1);
        }
    }
}


@include test-module('_last-index-of') {
    $list: 1 2 3 1 2 3;

    @include test('should return the index of the last matched value') {
        @include assert-equal(_last-index-of($list, 3), 6);
    }

    @include test('should work with a positive from-index') {
        @include assert-equal(_last-index-of($list, 1, 3), 1);
    }

    @include test('should work with from-index >= list length') {
        $values: 6, 8, _pow(2, 32), 9999;

        @each $value in $values {
            @include assert-equal(_last-index-of($list, null, $value), -1);
            @include assert-equal(_last-index-of($list, 1, $value), 4);
        }
    }

    @include test('should treat falsey from-index values, except 0, as list length') {
        @each $value in $test-falsey {
            @include assert-equal(_last-index-of($list, 3, $value), if($value == 0, -1, 6));
        }
    }

    @include test('should work with a negative from-index') {
        @include assert-equal(_last-index-of($list, 2, -3), 2);
    }

    @include test('should work with a negative from-index <= (negative) list length') {
        $values: -6, -8, -9999;

        @each $value in $values {
            @include assert-equal(_last-index-of($list, 1, $value), 1);
        }
    }
}

@include test-module('index-of methods') {
    @each $method-name in 'index-of', 'last-index-of' {
        $func: unquote('_#{$method-name}');

        @include test('#{$func} should accept falsey list argument') {
            @each $value in $test-falsey {
                @include assert-equal(_call($func, null, $value), -1);
            }
        }

        @include test('#{$func} should return -1 for an unmatched value') {
            $list: 1 2 3;
            $empty: ();

            @include assert-equal(_call($func, null, $list, 4), -1);
            @include assert-equal(_call($func, null, $list, 4, true), -1);

            @include assert-equal(_call($func, null, $empty, null), -1);
            @include assert-equal(_call($func, null, $empty, null, true), -1);
        }

        @include test('#{$func} should not match values on empty lists') {
            $list: ();

            @include assert-equal(_call($func, null, $list, null), -1);
            @include assert-equal(_call($func, null, $list, 0), -1);
        }
    }
}
