36 lines
2.1 KiB
Python
36 lines
2.1 KiB
Python
"""Exercise actual Core alias, integer parsing and settings-boundary bodies.
|
|
Native dispatch/storage and remote ownership remain separate tests.
|
|
"""
|
|
from policy_harness import ROOT,body,run
|
|
admin=ROOT/'addons/core/Scripts/Game/ERR/ERR_AdminService.c'
|
|
settings=ROOT/'addons/core/Scripts/Game/ERR/ERR_Settings.c'
|
|
rules='\n'.join(body(path,sig) for path,sig in ((admin,'static string CoreSetting('),(admin,'static bool Integer('),(settings,'static bool Valid(')))
|
|
rules=(rules.replace('string ', 'std::string ').replace('out int ', 'int& ')
|
|
.replace('text.Length()', 'int(text.size())').replace('.IsEmpty()', '.empty()')
|
|
.replace('.Substring(', '.substr(').replace('"0123456789".IndexOf(', 'std::string("0123456789").find(')
|
|
.replace(' < 0) return false;', ' == std::string::npos) return false;').replace('text.ToInt()', 'std::stoi(text)'))
|
|
run('#include <cassert>\n#include <string>\n'+rules+r'''
|
|
int main(){
|
|
assert(CoreSetting("intel","reveal")=="intelRevealChancePercent");
|
|
assert(CoreSetting("mission","radio")=="radioDefenceSeconds");
|
|
for(std::string section:{"", "hq", "mission", "intel", "unknown"})
|
|
for(std::string option:{"", "interval", "carrying", "radio", "reveal", "unknown"}){
|
|
bool recognized=(section=="intel"&&option=="reveal")||(section=="mission"&&option=="radio");
|
|
assert(CoreSetting(section,option).empty()==!recognized);
|
|
}
|
|
int parsed=-1;
|
|
for(std::string malformed:{"", "-1", "+1", "1.0", "10junk", "1e2", "0x10", " 50", "50 ", "1234567"})
|
|
assert(!Integer(malformed,parsed));
|
|
for(int value=0;value<=101;++value){
|
|
assert(Integer(std::to_string(value),parsed)&&parsed==value);
|
|
assert(Valid(CoreSetting("intel","reveal"),parsed)==(value<=100));
|
|
}
|
|
assert(Integer("000050",parsed)&&parsed==50);
|
|
assert(Integer("999999",parsed)&&!Valid("intelRevealChancePercent",parsed));
|
|
assert(!Valid("intelRevealChancePercent",-1));
|
|
assert(Valid("radioDefenceSeconds",30)&&Valid("radioDefenceSeconds",1800));
|
|
assert(!Valid("radioDefenceSeconds",29)&&!Valid("radioDefenceSeconds",1801));
|
|
}
|
|
''')
|
|
print('PASS: Core document-discovery alias, companion-only alias exclusion, strict integer parsing and setting boundaries')
|