feat(fls): topology of a .fls file as Java loads it
readTopology maps the decoded JavaBeans graph to devices, cables and documentation items the way SzenarioVerwaltung.netzwerkLaden does: the kind from the Java class (the palette label is not file data), devices without bounds at 0,0, interface values through Java's setters. All 23 corpus files match Java field by field. Found on the way: - listItems mixed a constructor's elements with added ones; a router's second interface was lost. Lists now replay add/set in order after the elements the constructor made. - The first 0 of a file may be SwingConstants.CENTER; measured like the getter defaults. - IP.ipCheck (javaIp.ts) measured on 46 cases: empty tokens skipped, signs, leading zeros and BMP digits of any script accepted. - The Java oracle took lower-case MACs in a file for random ones (8 interfaces); it now compares case-insensitively and reports the host name flags. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
// IP.ipCheck as Java FILIUS runs it: every case in ip-check.cases.txt was run
|
||||
// through Java (ip-check.java.json, tools/java-oracle) and must come out the
|
||||
// same here.
|
||||
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { javaIpCheck, javaParseInt } from '../src/javaIp.js';
|
||||
|
||||
const here = dirname(fileURLToPath(import.meta.url));
|
||||
const measured = JSON.parse(readFileSync(join(here, 'ip-check.java.json'), 'utf8')) as [string, string | null][];
|
||||
|
||||
/** The cases file's escapes: a backslash, `u` and four hex digits for one UTF-16 unit. */
|
||||
function unescape(line: string): string {
|
||||
return line.replace(/\\u([0-9a-fA-F]{4})/g, (_, hex: string) => String.fromCharCode(Number.parseInt(hex, 16)));
|
||||
}
|
||||
|
||||
describe('javaIpCheck against Java', () => {
|
||||
it('covers every line of the cases file', () => {
|
||||
const lines = readFileSync(join(here, 'ip-check.cases.txt'), 'ascii').split('\n').slice(0, -1);
|
||||
expect(measured.map(([line]) => line)).toEqual(lines);
|
||||
});
|
||||
|
||||
for (const [line, expected] of measured) {
|
||||
it(JSON.stringify(line), () => {
|
||||
expect(javaIpCheck(unescape(line))).toBe(expected);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe('javaParseInt', () => {
|
||||
it('keeps to the int range', () => {
|
||||
expect(javaParseInt('2147483647')).toBe(2147483647);
|
||||
expect(javaParseInt('-2147483648')).toBe(-2147483648);
|
||||
expect(javaParseInt('2147483648')).toBeUndefined();
|
||||
expect(javaParseInt('-2147483649')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user