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

WFFolderWalkerTest.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.

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

	-- WF.core.os
local KSPathUtils = require 'KSPathUtils'
local WFFolderWalker = require 'WFFolderWalker'
local WFPlatformInfo = require 'WFPlatformInfo'

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


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

if WFPlatformInfo.isAndroid then return {} end
	-- TODO [scouten 2015-06-05]: Not implemented on Android.


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

-- @mark WFFolderWalkerTest

local WFFolderWalkerTest = {}

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

function WFFolderWalkerTest.rxTestBasic( rxTest )

	local filesFound = {}

	local folderToScan = KSPathUtils.getStandardFilePath( 'testdata' )
	folderToScan = KSPathUtils.child( folderToScan, "wffileutils" )

	for path in WFFolderWalker( folderToScan ) do
		-- Note to self: By default, we skip hidden files, unlike KSDirectoryEnumerator.

		path = path:replace( '\\', '/' )

		filesFound[ #filesFound + 1 ] = path:sub( #folderToScan + 2 )
			-- +2 = character after trailing slash, which wasn't present in folderToScan

	end

	table.sort( filesFound )

	rxTest:expectEqual(

		{
			"File With Spaces.txt",
			"File_With_Very_Long_Extension.superlongfiletypeextension",
			"bar/BarFile.txt",
			"bar/baz/BaxFile.txt",
			"directory.with.dots.in.name/FileInDotDirectory.txt",
			"file-2.txt",
			"file-3.txt",
			"file.txt",
			"foo/FooFile.txt",
			"noextensionfile",
		},

		filesFound )

end

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

if WFPlatformInfo.isCocoa then

function WFFolderWalkerTest.rxTestShallow( rxTest )

	local filesFound = {}

	local folderToScan = KSPathUtils.getStandardFilePath( 'testdata' )
	folderToScan = KSPathUtils.child( folderToScan, "wffileutils" )

	for path in WFFolderWalker( folderToScan, { shallow=true} ) do

		path = path:replace( '\\', '/' )

		filesFound[ #filesFound + 1 ] = path:sub( #folderToScan + 2 )
			-- +2 = character after trailing slash, which wasn't present in folderToScan

	end

	table.sort( filesFound )

	rxTest:expectEqual(

		{
			"File With Spaces.txt",
			"File_With_Very_Long_Extension.superlongfiletypeextension",
			"file-2.txt",
			"file-3.txt",
			"file.txt",
			"noextensionfile",
		},

		filesFound )

end

end

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

--[[
function WFFolderWalkerTest.rxTestIncludeDirectories( rxTest )

	local filesFound = {}

	local folderToScan = KSPathUtils.getStandardFilePath( 'testdata' )
	folderToScan = KSPathUtils.child( folderToScan, "wffileutils" )

	for path in WFFolderWalker( folderToScan, { includeDirectories = true } ) do
		-- Note to self: By default, we skip hidden files, unlike KSDirectoryEnumerator.

		path = path:replace( '\\', '/' )

		filesFound[ #filesFound + 1 ] = path:sub( #folderToScan + 2 )
			-- +2 = character after trailing slash, which wasn't present in folderToScan

	end

	table.sort( filesFound )

	rxTest:expectEqual(

		{
			"File With Spaces.txt",
			"File_With_Very_Long_Extension.superlongfiletypeextension",
			"bar/",
			"bar/BarFile.txt",
			"bar/baz/",
			"bar/baz/BaxFile.txt",
			"directory.with.dots.in.name/",
			"directory.with.dots.in.name/FileInDotDirectory.txt",
			"file-2.txt",
			"file-3.txt",
			"file.txt",
			"foo/FooFile.txt",
			"noextensionfile",
		},

		filesFound )

end
]]--

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

return WFRxTestCase.wrapSuite( 'WFFolderWalkerTest', WFFolderWalkerTest )
