Skip to content

Commit

Permalink
tests: new type system test
Browse files Browse the repository at this point in the history
  • Loading branch information
nbrugger-tgm committed Mar 16, 2022
1 parent 704957e commit f91726e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 36 deletions.
4 changes: 2 additions & 2 deletions m/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}
42 changes: 8 additions & 34 deletions m/impl/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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"))
Expand All @@ -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"))
Expand Down
52 changes: 52 additions & 0 deletions tests/transpiler/type_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package transpiler

import (
"github.com/Vilsol/go-mlog/m"
"testing"
)

Expand All @@ -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)
}

0 comments on commit f91726e

Please sign in to comment.