Skip to content

Commit 5e0b519

Browse files
committed
refactor(memory-parser): collapse duplicated operand formatting
1 parent e2dd76d commit 5e0b519

3 files changed

Lines changed: 400 additions & 345 deletions

File tree

.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/utils/memory-parser.test.ts

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,4 +1170,190 @@ describe("Util: memory-parser", () => {
11701170
expect(result.groups[2]).toHaveLength(1);
11711171
});
11721172
});
1173+
1174+
// Characterization snapshots that pin the asymmetric edge-case behavior
1175+
// baked into the three parse paths. If any of these break, the refactor
1176+
// changed observable behavior.
1177+
describe("parseMemory characterization", () => {
1178+
const cases: Array<[string, ParsedRequirement]> = [
1179+
[
1180+
"f-100=0",
1181+
{
1182+
flag: "",
1183+
lType: "f",
1184+
lSize: "",
1185+
lMemory: "-100",
1186+
cmp: "=",
1187+
rType: "",
1188+
rSize: "",
1189+
rMemVal: "0",
1190+
hits: "0",
1191+
},
1192+
],
1193+
[
1194+
"0xH1234=f-100",
1195+
{
1196+
flag: "",
1197+
lType: "",
1198+
lSize: "0xh",
1199+
lMemory: "1234",
1200+
cmp: "=",
1201+
rType: "f",
1202+
rSize: "",
1203+
rMemVal: "-100",
1204+
hits: "0",
1205+
},
1206+
],
1207+
[
1208+
"0xH1234-5",
1209+
{
1210+
flag: "",
1211+
lType: "m",
1212+
lSize: "0xh",
1213+
lMemory: "0x1234-5",
1214+
cmp: "=",
1215+
rType: "v",
1216+
rSize: "",
1217+
rMemVal: "",
1218+
hits: "0",
1219+
},
1220+
],
1221+
[
1222+
"K:{recall}==5",
1223+
{
1224+
flag: "k",
1225+
lType: "recall",
1226+
lSize: "",
1227+
lMemory: "",
1228+
cmp: "==",
1229+
rType: "v",
1230+
rSize: "",
1231+
rMemVal: "0x000005",
1232+
hits: "",
1233+
},
1234+
],
1235+
[
1236+
"K:{recall}+false",
1237+
{
1238+
flag: "k",
1239+
lType: "recall",
1240+
lSize: "",
1241+
lMemory: "",
1242+
cmp: "+",
1243+
rType: "v",
1244+
rSize: "",
1245+
rMemVal: "false",
1246+
hits: "",
1247+
},
1248+
],
1249+
[
1250+
"H1234=5",
1251+
{
1252+
flag: "",
1253+
lType: "v",
1254+
lSize: "",
1255+
lMemory: "0x001234",
1256+
cmp: "=",
1257+
rType: "v",
1258+
rSize: "",
1259+
rMemVal: "0x000005",
1260+
hits: "0",
1261+
},
1262+
],
1263+
[
1264+
"I:0xG0045ba18+{recall}",
1265+
{
1266+
flag: "i",
1267+
lType: "m",
1268+
lSize: "0xg",
1269+
lMemory: "0x0045ba18",
1270+
cmp: "+",
1271+
rType: "recall",
1272+
rSize: "",
1273+
rMemVal: "",
1274+
hits: "0",
1275+
},
1276+
],
1277+
[
1278+
"K:{varname}+2",
1279+
{
1280+
flag: "k",
1281+
lType: "variable",
1282+
lSize: "",
1283+
lMemory: "varname",
1284+
cmp: "+",
1285+
rType: "v",
1286+
rSize: "",
1287+
rMemVal: "0x000002",
1288+
hits: "",
1289+
},
1290+
],
1291+
[
1292+
"K:{recall}+-100",
1293+
{
1294+
flag: "k",
1295+
lType: "recall",
1296+
lSize: "",
1297+
lMemory: "",
1298+
cmp: "+",
1299+
rType: "v",
1300+
rSize: "",
1301+
rMemVal: "0x000-64",
1302+
hits: "",
1303+
},
1304+
],
1305+
[
1306+
"I:-100+{recall}",
1307+
{
1308+
flag: "i",
1309+
lType: "v",
1310+
lSize: "",
1311+
lMemory: "0x000-64",
1312+
cmp: "+",
1313+
rType: "recall",
1314+
rSize: "",
1315+
rMemVal: "",
1316+
hits: "0",
1317+
},
1318+
],
1319+
[
1320+
"K:{varname}+-100",
1321+
{
1322+
flag: "k",
1323+
lType: "variable",
1324+
lSize: "",
1325+
lMemory: "varname",
1326+
cmp: "+",
1327+
rType: "v",
1328+
rSize: "",
1329+
rMemVal: "0x000-64",
1330+
hits: "",
1331+
},
1332+
],
1333+
[
1334+
"A:{varname}",
1335+
{
1336+
flag: "a",
1337+
lType: "variable",
1338+
lSize: "",
1339+
lMemory: "varname",
1340+
cmp: "",
1341+
rType: "",
1342+
rSize: "",
1343+
rMemVal: "",
1344+
hits: "0",
1345+
},
1346+
],
1347+
];
1348+
1349+
for (const [input, expected] of cases) {
1350+
it(`pins ${input}`, () => {
1351+
// ACT
1352+
const result = parseMemory(input);
1353+
1354+
// ASSERT
1355+
expect(result.groups[0]?.[0]).toEqual(expected);
1356+
});
1357+
}
1358+
});
11731359
});

0 commit comments

Comments
 (0)