// Copyright (c) roydukkey. All rights reserved.
// Licensed under the MIT. See LICENSE file in the project root for full license information.
////
/// @author roydukkey
/// @group tests
////

@use 'sass:list'
@use 'sass:meta'
@use 'src'
@use 'true'


@function _is-number($item, $args...)
	@return meta.type-of($item) == 'number'


@function _is-fourth-item($item, $index, $list)
	@return $index % 4 == 0


@function _greater-than-1n-plus-index($item, $index, $list)
	$n: if($index == list.length($list), 1, $index + 1)
	@return $item > list.nth($list, $n)


@include true.describe('@function src.find')
	$list: 'a' true 8 'b' null 2 4 'c' 10 false

	@include true.it('Find an item from a list')
		$assert: src.find($list, meta.get-function('_is-number'))
		$expected: 8
		@include true.assert-equal($assert, $expected)

	@include true.it('Transformer receives the item indexes')
		$assert: src.find($list, meta.get-function('_is-fourth-item'))
		$expected: 'b'
		@include true.assert-equal($assert, $expected)

	@include true.it('Transformer receives the calling list')
		$assert: src.find(1 3 4 6 7 7 8 -3 10, meta.get-function('_greater-than-1n-plus-index'))
		$expected: 8
		@include true.assert-equal($assert, $expected, '[1 3 4 6 7 7 8 -3 10]')

	@include true.it('Throws when $predicate is not a function')
		$assert: src.find(null, null)
		$expected: 'ERROR: $predicate: `null` is not a function for `find()`.'
		@include true.assert-equal($assert, $expected)
