-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from argonui/fix_core_script
Fix luascript bunding from root config
- Loading branch information
Showing
4 changed files
with
157 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package mod | ||
|
||
import ( | ||
"ModCreator/tests" | ||
"ModCreator/types" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/google/go-cmp/cmp/cmpopts" | ||
) | ||
|
||
func TestGenerate(t *testing.T) { | ||
for _, tc := range []struct { | ||
name string | ||
inputRoot types.J | ||
inputModSettings map[string]interface{} | ||
inputOjbs map[string]types.J | ||
inputLuaSrc map[string]string | ||
inputObjTexts map[string]string | ||
want map[string]interface{} | ||
}{ | ||
{ | ||
name: "LuaScript", | ||
inputRoot: map[string]interface{}{ | ||
"LuaScript": "require(\"core/Global\")", | ||
}, | ||
inputLuaSrc: map[string]string{ | ||
"core/Global.ttslua": "var a = 42", | ||
}, | ||
want: map[string]interface{}{ | ||
"LuaScript": "-- Bundled by luabundle {\"version\":\"1.6.0\"}\nlocal __bundle_require, __bundle_loaded, __bundle_register, __bundle_modules = (function(superRequire)\n\tlocal loadingPlaceholder = {[{}] = true}\n\n\tlocal register\n\tlocal modules = {}\n\n\tlocal require\n\tlocal loaded = {}\n\n\tregister = function(name, body)\n\t\tif not modules[name] then\n\t\t\tmodules[name] = body\n\t\tend\n\tend\n\n\trequire = function(name)\n\t\tlocal loadedModule = loaded[name]\n\n\t\tif loadedModule then\n\t\t\tif loadedModule == loadingPlaceholder then\n\t\t\t\treturn nil\n\t\t\tend\n\t\telse\n\t\t\tif not modules[name] then\n\t\t\t\tif not superRequire then\n\t\t\t\t\tlocal identifier = type(name) == 'string' and '\\\"' .. name .. '\\\"' or tostring(name)\n\t\t\t\t\terror('Tried to require ' .. identifier .. ', but no such module has been registered')\n\t\t\t\telse\n\t\t\t\t\treturn superRequire(name)\n\t\t\t\tend\n\t\t\tend\n\n\t\t\tloaded[name] = loadingPlaceholder\n\t\t\tloadedModule = modules[name](require, loaded, register, modules)\n\t\t\tloaded[name] = loadedModule\n\t\tend\n\n\t\treturn loadedModule\n\tend\n\n\treturn require, loaded, register, modules\nend)(nil)\n__bundle_register(\"__root\", function(require, _LOADED, __bundle_register, __bundle_modules)\nrequire(\"core/Global\")\nend)\n__bundle_register(\"core/Global\", function(require, _LOADED, __bundle_register, __bundle_modules)\nvar a = 42\nend)\nreturn __bundle_require(\"__root\")", | ||
"CameraStates": nil, | ||
"ComponentTags": nil, | ||
"MusicPlayer": nil, | ||
"Sky": "", | ||
"TabStates": nil, | ||
"Note": "", | ||
"ObjectStates": []interface{}{}, | ||
"SaveName": "", | ||
"Table": "", | ||
"LuaScriptState": "", | ||
"SnapPoints": nil, | ||
"XmlUI": "", | ||
"Turns": nil, | ||
"VersionNumber": "", | ||
"GameMode": "", | ||
"GameType": "", | ||
"Hands": nil, | ||
"Grid": nil, | ||
"Lighting": nil, | ||
"GameComplexity": "", | ||
"Decals": nil, | ||
"CustomUIAssets": nil, | ||
"DecalPallet": nil, | ||
}, | ||
}, | ||
} { | ||
t.Run(tc.name, func(t *testing.T) { | ||
rootff := &tests.FakeFiles{ | ||
Data: map[string]types.J{ | ||
"config.json": tc.inputRoot, | ||
}, | ||
} | ||
luaReadff := &tests.FakeFiles{ | ||
Fs: tc.inputLuaSrc, | ||
} | ||
msff := &tests.FakeFiles{} | ||
objs := &tests.FakeFiles{ | ||
Data: tc.inputOjbs, | ||
Fs: tc.inputObjTexts, | ||
} | ||
m := Mod{ | ||
RootRead: rootff, | ||
RootWrite: rootff, | ||
Lua: luaReadff, | ||
Modsettings: msff, | ||
Objs: objs, | ||
Objdirs: objs, | ||
} | ||
err := m.GenerateFromConfig() | ||
if err != nil { | ||
t.Fatalf("Error reading config %v", err) | ||
} | ||
err = m.Print() | ||
if err != nil { | ||
t.Fatalf("Error printing config %v", err) | ||
} | ||
got, err := rootff.ReadObj("output.json") | ||
if err != nil { | ||
t.Fatalf("Error reading output: %v", err) | ||
} | ||
|
||
ignoreUnpredictable := func(k string, v interface{}) bool { | ||
if k == "Date" || k == "EpochTime" { | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
if diff := cmp.Diff(tc.want, got, cmpopts.IgnoreMapEntries(ignoreUnpredictable)); diff != "" { | ||
t.Errorf("want != got:\n%v\n", diff) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"CameraStates": [], | ||
"ComponentTags": {}, | ||
"CustomUIAssets": [], | ||
"Date": "", | ||
"DecalPallet": [], | ||
"Decals": [], | ||
"GameComplexity": "", | ||
"GameMode": "", | ||
"GameType": "", | ||
"Grid": {}, | ||
"Hands": {}, | ||
"Lighting": {}, | ||
"LuaScript": "-- Bundled by luabundle {\"version\":\"1.6.0\"}\nlocal __bundle_require, __bundle_loaded, __bundle_register, __bundle_modules = (function(superRequire)\n\tlocal loadingPlaceholder = {[{}] = true}\n\n\tlocal register\n\tlocal modules = {}\n\n\tlocal require\n\tlocal loaded = {}\n\n\tregister = function(name, body)\n\t\tif not modules[name] then\n\t\t\tmodules[name] = body\n\t\tend\n\tend\n\n\trequire = function(name)\n\t\tlocal loadedModule = loaded[name]\n\n\t\tif loadedModule then\n\t\t\tif loadedModule == loadingPlaceholder then\n\t\t\t\treturn nil\n\t\t\tend\n\t\telse\n\t\t\tif not modules[name] then\n\t\t\t\tif not superRequire then\n\t\t\t\t\tlocal identifier = type(name) == 'string' and '\\\"' .. name .. '\\\"' or tostring(name)\n\t\t\t\t\terror('Tried to require ' .. identifier .. ', but no such module has been registered')\n\t\t\t\telse\n\t\t\t\t\treturn superRequire(name)\n\t\t\t\tend\n\t\t\tend\n\n\t\t\tloaded[name] = loadingPlaceholder\n\t\t\tloadedModule = modules[name](require, loaded, register, modules)\n\t\t\tloaded[name] = loadedModule\n\t\tend\n\n\t\treturn loadedModule\n\tend\n\n\treturn require, loaded, register, modules\nend)(nil)\n__bundle_register(\"__root\", function(require, _LOADED, __bundle_register, __bundle_modules)\nrequire(\"core/Global\")\nend)\n__bundle_register(\"core/Global\", function(require, _LOADED, __bundle_register, __bundle_modules)\n\r\nfunction urldecode(str)\r\n str = string.gsub(str, \"%%(%x%x)\",\r\n function (h) return string.char(tonumber(h, 16)) end)\r\n return str\r\nend\r\n\nend)\nreturn __bundle_require(\"__root\")", | ||
"LuaScriptState": "", | ||
"MusicPlayer": {}, | ||
"Note": "", | ||
"ObjectStates": [], | ||
"SaveName": "", | ||
"Sky": "", | ||
"SnapPoints": [], | ||
"TabStates": {}, | ||
"Table": "", | ||
"Turns": {}, | ||
"VersionNumber": "", | ||
"XmlUI": "" | ||
} |