From 0ce3db7760b6caae5cf59553bc60322a84bf5f3e Mon Sep 17 00:00:00 2001 From: opussf Date: Sat, 27 Jan 2024 07:54:36 -1000 Subject: [PATCH] TOC tests. Treat xml files as xml --- src/wowStubs.lua | 20 +++++++++++++------- test/test.lua | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/wowStubs.lua b/src/wowStubs.lua index e5d967a..bb99f94 100644 --- a/src/wowStubs.lua +++ b/src/wowStubs.lua @@ -1733,6 +1733,7 @@ end ----------------------------------------- -- XML functions function ParseXML( xmlFile ) + print("parse: "..xmlFile ) end ----------------------------------------- @@ -1755,7 +1756,9 @@ function ParseTOC( tocFile, useRequire ) if( hash ) then addonData[ hashKey ] = hashValue elseif( lua ) then - table.insert( tocFileTable, luaFile ) + table.insert( tocFileTable, { "lua", luaFile } ) + elseif( xml ) then + table.insert( tocFileTable, { "xml", xmlFile } ) end tocContents = string.sub( tocContents, lineend+1 ) else @@ -1774,15 +1777,18 @@ function ParseTOC( tocFile, useRequire ) --add to the include package.path package.path = includePath.."?.lua;" .. package.path end - sharedTable = {} for _,f in pairs( tocFileTable ) do - if( useRequire ) then - require( f ) - else - local loadedfile = assert( loadfile( includePath..f..".lua" ) ) - loadedfile( addonName, sharedTable ) + if( f[1] == "lua" ) then + if( useRequire ) then + require( f[2] ) + else + local loadedfile = assert( loadfile( includePath..f[2]..".lua" ) ) + loadedfile( addonName, sharedTable ) + end + elseif( f[1] == "xml" ) then + ParseXML( includePath..f[2]..".xml" ) end end end diff --git a/test/test.lua b/test/test.lua index 6029420..2201f95 100644 --- a/test/test.lua +++ b/test/test.lua @@ -1044,6 +1044,29 @@ end ----- ----- TOC tests +function CreateFile( filename, contents ) + pathSeparator = string.sub( package.config, 1, 1 ) -- first character of this string (http://www.lua.org/manual/5.2/manual.html#pdf-package.config) + filePathTable = { + os.getenv( "PWD" ), + "target", + filename, + } + tocFile = table.concat( filePathTable, pathSeparator ) + file, err = io.open( tocFile, "w" ) + if err then + print( err ) + else + file:write( contents ) + io.close( file ) + end + return tocFile +end +function test.testTOC_() + CreateFile( "test.xml", "\n\n" ) + CreateFile( "test.lua", "print(\"hi\")\n") + generatedFile = CreateFile( "test.toc", "test.lua\ntest.xml\n" ) + ParseTOC( generatedFile ) +end ----------------------------------