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

WFArguments_uuidTest.lua

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

ADOBE CONFIDENTIAL
------------------
Copyright 2012 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 WFArguments = require 'WFArguments'
local _ = require 'WFArguments_uuid'

local WFArguments_uuidTest = {}

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

local function mustFail( ... )

	local success, _ = pcall( ... )
	if success then
		error( "Expected to fail: " .. debug.traceback() )
	else
		-- debug.print( "Test failed with message:", _ )
	end

end
	
--------------------------------------------------------------------------------

function WFArguments_uuidTest.testCustomChecker()

	local check = assert( WFArguments.check )
	
	local function testUuidString( uuid )
		check( 'uuid' )
	end
	
	local function testOptionalUuidString( uuid )
		check( '?uuid' )
	end
	
	testUuidString( '0ecd9a31fa3c4b43a6841dc1f8877711' )
	testUuidString( 'cf4f4b97e8c44cf9aede8257cda79404' )
	
	testOptionalUuidString( 'bc246a7487cd4b30bb97cc937621db7a' )
	testOptionalUuidString( nil )
	
	mustFail( testUuidString, {} )
	mustFail( testUuidString, 42 )
	mustFail( testUuidString, '' )			-- empty string not allowed
	mustFail( testUuidString, '12345' )		-- wrong length
	mustFail( testUuidString, nil )
	mustFail( testUuidString, 'ad9932ce7f3e473398a968ea7cbxbdec' )
											-- illegal character 'x'
	mustFail( testUuidString, '1C060124698A414580D34D3778F4AED0' )
											-- must be lower case
	mustFail( testUuidString, '733D23B0-1D37-499C-A929-9C1AD55B60E7' )
											-- "normal" UUIDs not allowed
	mustFail( testUuidString, 'ad9932ce7f3e473398a968ea7cbxbdec' )

	mustFail( testOptionalUuidString, {} )
	mustFail( testOptionalUuidString, 42 )
	mustFail( testOptionalUuidString, '' )			-- empty string not allowed
	mustFail( testOptionalUuidString, '12345' )		-- wrong length
	mustFail( testOptionalUuidString, 'ad9932ce7f3e473398a968ea7cbxbdec' )
											-- illegal character 'x'
	mustFail( testOptionalUuidString, '1C060124698A414580D34D3778F4AED0' )
											-- must be lower case
	mustFail( testOptionalUuidString, '733D23B0-1D37-499C-A929-9C1AD55B60E7' )
											-- "normal" UUIDs not allowed
	mustFail( testOptionalUuidString, 'ad9932ce7f3e473398a968ea7cbxbdec' )

end

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

return WFArguments_uuidTest
