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

WFRxArrayDifferTest.lua

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

ADOBE CONFIDENTIAL
------------------
Copyright 2015 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.

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

	-- Rx
local Rx = require 'Rx'
local Subject = Rx.Subject

	-- WF.core.rxlua
local WFRxArrayDiffer = require 'WFRxArrayDiffer'

	-- WF.core.self_test
local WFRxTestCase = require 'WFRxTestCase'


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

local arrayDiffer  = WFRxArrayDiffer


--============================================================================--

local WFRxArrayDifferTest = {}

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

function WFRxArrayDifferTest.rxTestBasic( rxTest )

	local source = Subject()
	local diff = rxTest:observe( source:call( arrayDiffer ) )

	source:onNext( {} )
		-- Empty delta. Nothing should happen.

	source:onNext( { 1, 3, 5, 7 } )
	diff:expectData( { 1, 3, 5, 7 }, {} )

	source:onNext( { 1, 3, 5, 7 } )
		-- Again, empty delta: Nothing should happen.

	source:onNext( { 1, 4, 7, 11 } )
	diff:expectData( { 4, 11 }, { 3, 5 } )

	source:onNext( { 1, 4, "seven", 11 } )
	diff:expectData( { "seven" }, { 7 } )

	source:onNext( {} )
	diff:expectData( {}, { 1, 4, "seven", 11 } )

	source:onCompleted()
	diff:expectCompleted()

end

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

function WFRxArrayDifferTest.rxTestErrorNotTable( rxTest )

	local source = Subject()
	local diff = rxTest:observe( source:call( arrayDiffer ) )

	source:onNext( 42 )
	diff:expectError( ':ignore:' )

end

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

function WFRxArrayDifferTest.rxTestRelaysOnError( rxTest )

	local source = Subject()
	local diff = rxTest:observe( source:call( arrayDiffer ) )

	source:onNext( { 1, 3, 5, 7 } )
	diff:expectData( { 1, 3, 5, 7 }, {} )

	source:onError( "something's not right" )
	diff:expectError( "something's not right" )

end

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

return WFRxTestCase.wrapSuite( 'WFRxArrayDifferTest', WFRxArrayDifferTest )
