--[[----------------------------------------------------------------------------

KSArrayUtilsTest.lua

--------------------------------------------------------------------------------

ADOBE CONFIDENTIAL
------------------
Copyright 2011 Adobe Systems Incorporated
All Rights Reserved.

NOTICE: All information contained herein is, and remain the property of
Adobe Systems Incorporated and its suppliers, if any. The intellectual and
technical concepts contained herein are proprietary to Adobe Systems
Incorporated and its suppliers and may be covered by U.S. and Foreign
Patents, patents in process, and are protected by trade secret or copyright
law.  Dissemination of this information or reproduction of this material is
strictly forbidden unless prior written permission is obtained from
Adobe Systems Incorporated.

------------------------------------------------------------------------------]]

local T = { }

--------------------------------------------------------------------------------

local function mustFail( ... )
	if pcall( ... ) then
		assert( false, "Expected to fail: " .. debug.traceback() )
	end
end
	
--------------------------------------------------------------------------------

function T.testOverwrite()

	local KSArrayUtils = require "KSArrayUtils"
	
	local overwriteAt = assert( KSArrayUtils.overwriteAt, "No overwriteAt" )
	
	local arr = { }
	
	assert( 5 == overwriteAt( arr, 1, "a", "b", "c", nil, "e" ), "Should have overwritten 5 values" )
	
	assert( arr[ 1 ] == "a" )
	assert( arr[ 2 ] == "b" )
	assert( arr[ 3 ] == "c" )
	assert( arr[ 4 ] == nil )
	assert( arr[ 5 ] == "e" )
	
	assert( 0 == overwriteAt( arr, 3 ), "Should have overwritten zero values" )
	
	assert( arr[ 1 ] == "a" )
	assert( arr[ 2 ] == "b" )
	assert( arr[ 3 ] == "c" )
	assert( arr[ 4 ] == nil )
	assert( arr[ 5 ] == "e" )
	
	assert( 2 == overwriteAt( arr, 3, "x", "y" ), "Should have overwritten two values" )
	
	assert( arr[ 1 ] == "a" )
	assert( arr[ 2 ] == "b" )
	assert( arr[ 3 ] == "x" )
	assert( arr[ 4 ] == "y" )
	assert( arr[ 5 ] == "e" )
	
	mustFail( overwriteAt, "foo", 3, "u", "v" )
	mustFail( overwriteAt, { }, -1, "u", "v" )
	mustFail( overwriteAt, { }, "foo", "u", "v" )
	mustFail( overwriteAt )
	
end
	
--------------------------------------------------------------------------------

return T
