From f91726eaf94e3ec6ffffd68511169ce41b0a6b67 Mon Sep 17 00:00:00 2001 From: Nils Brugger Date: Wed, 16 Mar 2022 22:24:25 +0100 Subject: [PATCH] tests: new type system test --- m/base.go | 4 +-- m/impl/types.go | 42 ++++++---------------------- tests/transpiler/type_test.go | 52 +++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 36 deletions(-) diff --git a/m/base.go b/m/base.go index e11c635..f0e58b9 100644 --- a/m/base.go +++ b/m/base.go @@ -28,11 +28,11 @@ func Radar(from Building, target1 RadarTarget, target2 RadarTarget, target3 Rada // Extract information indicated by sense from the provided block. //Use this only if the needed information is not available using The getters of the building itself //main purpose is to use generic "senses" or use things that are not mapped -func Sensor(block UnspecifiedBuilding, sense string) float64 { +func Sensor(block GameElement, sense string) float64 { return 0 } // String equivalent of Sensor -func SensorStr(block UnspecifiedBuilding, sense string) string { +func SensorStr(block GameElement, sense string) string { return "" } diff --git a/m/impl/types.go b/m/impl/types.go index dc11b43..f558519 100644 --- a/m/impl/types.go +++ b/m/impl/types.go @@ -13,31 +13,6 @@ func init() { registerItemEnum() registerNativeVariables() registerArchtypeMethods() - - // HealthC's attributes - transpiler.RegisterFuncTranslation("GetHealth", createSensorFuncTranslation("@health")) - transpiler.RegisterFuncTranslation("GetName", createSensorFuncTranslation("@name")) - transpiler.RegisterFuncTranslation("GetX", createSensorFuncTranslation("@x")) - transpiler.RegisterFuncTranslation("GetY", createSensorFuncTranslation("@y")) - - transpiler.RegisterFuncTranslation("GetTotalItems", createSensorFuncTranslation("@totalItems")) - transpiler.RegisterFuncTranslation("GetItemCapacity", createSensorFuncTranslation("@itemCapacity")) - transpiler.RegisterFuncTranslation("GetRotation", createSensorFuncTranslation("@rotation")) - transpiler.RegisterFuncTranslation("GetShootX", createSensorFuncTranslation("@shootX")) - transpiler.RegisterFuncTranslation("GetShootY", createSensorFuncTranslation("@shootY")) - transpiler.RegisterFuncTranslation("IsShooting", createSensorFuncTranslation("@shooting")) - - // Building's attributes - transpiler.RegisterFuncTranslation("GetTotalLiquids", createSensorFuncTranslation("@totalLiquids")) - transpiler.RegisterFuncTranslation("GetLiquidCapaticy", createSensorFuncTranslation("@liquidCapaticy")) - transpiler.RegisterFuncTranslation("GetTotalPower", createSensorFuncTranslation("@totalPower")) - transpiler.RegisterFuncTranslation("GetPowerCapaticy", createSensorFuncTranslation("@powerCapaticy")) - transpiler.RegisterFuncTranslation("GetPowerNetStored", createSensorFuncTranslation("@powerNetStored")) - transpiler.RegisterFuncTranslation("GetPowerNetCapacity", createSensorFuncTranslation("@powerNetCapacity")) - transpiler.RegisterFuncTranslation("GetPowerNetIn", createSensorFuncTranslation("@powerNetIn")) - transpiler.RegisterFuncTranslation("GetPowerNetOut", createSensorFuncTranslation("@powerNetOut")) - transpiler.RegisterFuncTranslation("GetHeat", createSensorFuncTranslation("@heat")) - transpiler.RegisterFuncTranslation("GetEfficiency", createSensorFuncTranslation("@efficiency")) } func registerArchtypeMethods() { @@ -56,8 +31,8 @@ func registerArchtypeMethods() { transpiler.RegisterFuncTranslation("GetPowerNetIn", createSensorFuncTranslation("@powerNetIn")) transpiler.RegisterFuncTranslation("GetPowerNetOut", createSensorFuncTranslation("@powerNetOut")) transpiler.RegisterFuncTranslation("GetAmmo", createSensorFuncTranslation("@ammo")) - transpiler.RegisterFuncTranslation("GetAmmoCapacity", createSensorFuncTranslation("@mmoCapacity")) - transpiler.RegisterFuncTranslation("IsShooting", createSensorFuncTranslation("@hooting")) + transpiler.RegisterFuncTranslation("GetAmmoCapacity", createSensorFuncTranslation("@ammoCapacity")) + transpiler.RegisterFuncTranslation("IsShooting", createSensorFuncTranslation("@shooting")) transpiler.RegisterFuncTranslation("GetHeat", createSensorFuncTranslation("@heat")) transpiler.RegisterFuncTranslation("GetEfficiency", createSensorFuncTranslation("@Efficiency")) transpiler.RegisterFuncTranslation("GetX", createSensorFuncTranslation("@x")) @@ -67,18 +42,17 @@ func registerArchtypeMethods() { transpiler.RegisterFuncTranslation("GetShootX", createSensorFuncTranslation("@shootX")) transpiler.RegisterFuncTranslation("GetShootY", createSensorFuncTranslation("@shootY")) transpiler.RegisterFuncTranslation("GetShootPosition", createSensorFuncTranslation("@shootPosition")) - transpiler.RegisterFuncTranslation("GetControlled", createSensorFuncTranslation("@Controlled")) - transpiler.RegisterFuncTranslation("GetController", createSensorFuncTranslation("@Controller")) - transpiler.RegisterFuncTranslation("GetType", createSensorFuncTranslation("@type")) + transpiler.RegisterFuncTranslation("GetControlled", createSensorFuncTranslation("@controlled")) + transpiler.RegisterFuncTranslation("GetController", createSensorFuncTranslation("@controller")) transpiler.RegisterFuncTranslation("GetType", createSensorFuncTranslation("@type")) - transpiler.RegisterFuncTranslation("IsDead", createSensorFuncTranslation("@ead")) - transpiler.RegisterFuncTranslation("IsBoosting", createSensorFuncTranslation("@oosting")) - transpiler.RegisterFuncTranslation("GetFlag", createSensorFuncTranslation("@Flag")) + transpiler.RegisterFuncTranslation("IsDead", createSensorFuncTranslation("@dead")) + transpiler.RegisterFuncTranslation("IsBoosting", createSensorFuncTranslation("@boosting")) + transpiler.RegisterFuncTranslation("GetFlag", createSensorFuncTranslation("@flag")) transpiler.RegisterFuncTranslation("GetTeam", createSensorFuncTranslation("@team")) transpiler.RegisterFuncTranslation("GetRange", createSensorFuncTranslation("@range")) transpiler.RegisterFuncTranslation("GetMineX", createSensorFuncTranslation("@mineX")) transpiler.RegisterFuncTranslation("GetMineY", createSensorFuncTranslation("@mineY")) - transpiler.RegisterFuncTranslation("IsMining", createSensorFuncTranslation("@ining")) + transpiler.RegisterFuncTranslation("IsMining", createSensorFuncTranslation("@mining")) transpiler.RegisterFuncTranslation("GetName", createSensorFuncTranslation("@name")) transpiler.RegisterFuncTranslation("GetConfig", createSensorFuncTranslation("@configure")) transpiler.RegisterFuncTranslation("GetPayloadType", createSensorFuncTranslation("@payloadType")) diff --git a/tests/transpiler/type_test.go b/tests/transpiler/type_test.go index 69a02c8..d0336f4 100644 --- a/tests/transpiler/type_test.go +++ b/tests/transpiler/type_test.go @@ -1,6 +1,7 @@ package transpiler import ( + "github.com/Vilsol/go-mlog/m" "testing" ) @@ -22,6 +23,57 @@ print(x)`, true, false), sensor _main_x _main_b @health print _main_x`, }, + { + name: "Access_Unit", + input: TestMain( + `flg := m.CurUnit.GetFlag() +print(flg)`, + true, false), + output: `sensor _main_flg @unit @flag +print _main_flg`, + }, + { + name: "Access_Turret", + input: TestMain( + `turret := m.GetTurret("duo1") +capa := turret.GetAmmoCapacity() +print(capa)`, + true, false), + output: `set _main_turret duo1 +sensor _main_capa _main_turret @ammoCapacity +print _main_capa`, + }, + { + name: "Bind_constant", + input: TestMain("m.UnitBind(m.UZenith)", true, false), + output: "ubind @zenith", + }, + { + name: "Compare_ItemTypes", + input: TestMain(`item := m.CurUnit.GetFirstItem() +if(item == m.ITSilicon) { + print("Test") +}`, true, false), + output: `sensor _main_item @unit @firstItem +set _main_0 @silicon +op equal _main_1 _main_item _main_0 +jump 5 equal _main_1 1 +jump 6 always +print "Test"`, + }, + { + name: "Compare_ItemTypes_old", + input: TestMain(`item := m.SensorStr(m.CurUnit, "@firstItem") +if item == m.Const("@silicon") { + print("Test") +}`, true, false), + output: `sensor _main_item @unit @firstItem +set _main_0 @silicon +op equal _main_1 _main_item _main_0 +jump 5 equal _main_1 1 +jump 6 always +print "Test"`, + }, } RunTests(t, tests) }