local p = require( 'Module:UnitTests' )

local WL = require( 'Module:Work license' )

local function makeQidLink( qid )
	return '[[wikidata:' .. qid .. '|' .. qid .. ']]'
end

local CASES = {
	{
		-- In Memoriam: pub 1850, author died 1892 -> PD everywhere
		qid = 'Q19065684',
		pd = true
	},
    {
    	-- The Coin Collector's Survival Manual (Revised Seventh Edition)
    	-- pub. 2015, definitely copyrighted
    	qid = 'Q107605306',
    	pd = false
    },
    {
    	-- US Federal gov work
    	qid = 'Q19095438',
    	pd = true
    }
}


function p:test_pd_work_global()
	
	for _, case in pairs(CASES) do
		local qid = case.qid 
		local qidLink = makeQidLink( qid )
		local wl = WL.newWorkLicense( qid )
	
		self:equals( qidLink .. ': Check entity and ID', wl.entity.id, qid )
		self:equals( qidLink .. ': Check PD status', wl.isPublicDomain, case.pd )
	end
end

--[=[
Test the raw license data extraction
]=]
function p:test_get_licenses()
	
	local cases = {
		{
			-- a work that's published over 95 years ago
			-- and by an author who died > 100 years ago
			name = 'PD-US + pma 100+',
			qid = 'Q19025618',
			licDataUs = {
				nature = 'pub-date',
				date = 1751
			},
			licDataOther = {
				nature = 'pma',
				date = 1723,
			},
		}
	}
	
	for _, case in pairs(cases) do
		local qid = case.qid 
		local qidLink = makeQidLink( qid )
		local wl = WL.newWorkLicense( qid )
		
		local actualLic = wl.licenseData
	
		self:equals_deep( makeQidLink( case.qid ) .. ': ' .. case.name .. ' - US',
			actualLic.us, case.licDataUs )
	end
end

return p