'OHRRPGCE - rbtest helper
'(C) Copyright 1997-2020 James Paige, Ralph Versteegen, and the OHRRPGCE Developers
'Dual licensed under the GNU GPL v2+ and MIT Licenses. Read LICENSE.txt for terms and disclaimer of liability.
'
' This is part of rbtest, for testing multiple .rbas source files

extern errorpos as integer
extern errorfile as string
#define fail errorfile = __FILE__ : errorpos = __LINE__ : return 1

extern unexpected_warns as integer
declare sub count_unexpected_warnings (msg as string)

function otherFileTests(byval root as nodeptr) as integer
	# warn_func = count_unexpected_warnings
	unexpected_warns = 0

	if root."mixed files"."foo".exists = NO then fail
	dim nod as NodePtr = root."mixed files".ptr

	readnode nod, default
		if nod."_nested"."_nested2" <> 1001 then fail
	end readnode

	AppendChildNode(nod, "sharedname", 10001)
	AppendChildNode(nod, "uniquename", 10002)
end function

function testAddingNodeNames1() as integer
	dim newdoc as Docptr
	newdoc = CreateDocument()
	if newdoc = null then fail
	
	dim root as NodePtr = CreateNode(newdoc, "root")
	if root = null then fail
	SetRootNode(newdoc, root)
	AppendChildNode(root, "vlad", 41)

	# warn_func = count_unexpected_warnings
	unexpected_warns = 0

	'Force a BuildNameIndexTable call
	readnode root
	end readnode
	if unexpected_warns <> 1 then fail

	'Make sure #strings in the string table > RB_NUM_NAMES
	for i as integer = 0 to 49
		AppendChildNode(root, "totally unique name" & i)
	next

	unexpected_warns = 0
	dim as integer test1
	readnode root
		test1 = root."vlad"
	end readnode
	if unexpected_warns <> 50 then fail
	if test1 <> 41 then fail

	FreeDocument(newdoc)
end function
