"""Compile AVA2 text utilities and the legacy shop-label input guard.""" from pathlib import Path import subprocess import tempfile import unittest ROOT=Path(__file__).resolve().parents[2] class Arguments(unittest.TestCase): def test_tab_compression_preserves_spaces_and_empty_edges(self): source=(ROOT/'src/server/game/src/utils.cpp').read_text(encoding='latin1') body=source[source.index('// AVA2 search files'):source.index('static int global_time_gap')] code=r''' #include #include #include using WORD=uint16_t;using BYTE=uint8_t; #define ENABLE_SHOP_SEARCH_SYSTEM #define ENABLE_OFFLINESHOP_SYSTEM #include "src/server/game/src/utils.h" '''+body+r''' int main(){ assert(getInjectText(nullptr)); assert(!getInjectText("SELECT dragon") && !getInjectText("\xe9\xbe\x99")); assert(getInjectText("a'b") && getInjectText("a\\b") && getInjectText("a; DROP")); assert(getInjectText("a\n") && getInjectText("a\x7f")); std::string longLabel(256,'a');assert(getInjectText(longLabel.c_str())); std::vector args; split_argument_special("1\t\tpet\t20",args,"\t");assert((args==std::vector{"1","pet","20"})); split_argument_special("\tlong pet name\t",args,"\t");assert((args==std::vector{"","long pet name",""})); split_argument_special(nullptr,args,"\t");assert(args.size()==1 && args[0].empty()); split_argument_special("\t\t",args,"\t");assert(args.size()==2 && args[0].empty() && args[1].empty()); split_argument_special("a|b||c;",args,"|;");assert((args==std::vector{"a","b","c",""})); split_argument_special("a b",args,"");assert(args.size()==1 && args[0]=="a b"); } ''' with tempfile.TemporaryDirectory() as tmp: src=Path(tmp)/'probe.cpp';exe=Path(tmp)/'probe';src.write_text(code) subprocess.run(['c++','-std=c++23','-fsanitize=undefined,address','-fno-sanitize-recover=all','-I'+str(ROOT),str(src),'-o',str(exe)],check=True) subprocess.run([str(exe)],check=True) if __name__=='__main__':unittest.main()