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:
@@ -126,18 +126,93 @@ describe('XMLDecoder rules', () => {
|
||||
|
||||
it('reads static fields, static factories, maps and arrays', () => {
|
||||
const [constant, manager, map, array] = decodeJavaBeans(
|
||||
doc(`<object class="javax.swing.SwingConstants" field="CENTER"/>
|
||||
doc(`<object class="javax.swing.SwingConstants" field="LEFT"/>
|
||||
<object class="javax.swing.ToolTipManager" method="sharedInstance"/>
|
||||
<object class="java.util.HashMap"><void method="put"><string>k</string><int>1</int></void></object>
|
||||
<array class="filius.hardware.Port" length="2"><void index="1"><string>b</string></void></array>`),
|
||||
);
|
||||
|
||||
expect(object(constant)).toMatchObject({ className: 'javax.swing.SwingConstants', staticField: 'CENTER' });
|
||||
expect(object(constant)).toMatchObject({ className: 'javax.swing.SwingConstants', staticField: 'LEFT' });
|
||||
expect(object(manager).factoryMethod).toBe('sharedInstance');
|
||||
expect(mapEntries(map)).toEqual([['k', 1]]);
|
||||
expect(listItems(array)).toEqual([null, 'b']);
|
||||
});
|
||||
|
||||
it('answers a measured static constant with its value, which later references share', () => {
|
||||
const [color, holder] = decodeJavaBeans(
|
||||
doc(`<object class="java.awt.Color" id="Color0">
|
||||
<object class="javax.swing.SwingConstants" field="CENTER" id="Integer0"/>
|
||||
<int>128</int><int>255</int>
|
||||
</object>
|
||||
<object class="java.util.ArrayList"><void method="add"><object idref="Integer0"/></void></object>`),
|
||||
);
|
||||
|
||||
expect(object(color).args).toEqual([0, 128, 255]);
|
||||
expect(listItems(holder)).toEqual([0]);
|
||||
});
|
||||
|
||||
it('keeps the elements a constructor made ahead of the ones the file adds', () => {
|
||||
// A Java router starts with one interface; the file changes it by index
|
||||
// and adds two more — three interfaces, in this order.
|
||||
const [node] = decodeJavaBeans(
|
||||
doc(`<object class="filius.hardware.knoten.Vermittlungsrechner">
|
||||
<void id="LinkedList0" property="netzwerkInterfaces">
|
||||
<void id="NetzwerkInterface0" index="0"><void property="ip"><string>10.0.0.1</string></void></void>
|
||||
<void method="add"><object class="filius.hardware.NetzwerkInterface" id="NetzwerkInterface1"/></void>
|
||||
<void method="add"><object class="filius.hardware.NetzwerkInterface" id="NetzwerkInterface2"/></void>
|
||||
</void>
|
||||
</object>`),
|
||||
);
|
||||
|
||||
const interfaces = listItems(object(node).properties.get('netzwerkInterfaces'));
|
||||
expect(interfaces.map((nic) => object(nic).id)).toEqual(['NetzwerkInterface0', 'NetzwerkInterface1', 'NetzwerkInterface2']);
|
||||
expect(object(interfaces[0]).properties.get('ip')).toBe('10.0.0.1');
|
||||
});
|
||||
|
||||
it('fills the constructed elements the file never mentions, in index order', () => {
|
||||
// A switch has 24 ports; the file names the three that carry a cable,
|
||||
// in any order.
|
||||
const [ports] = decodeJavaBeans(
|
||||
doc(`<object class="filius.hardware.knoten.Switch"><void id="LinkedList0" property="anschluesse">
|
||||
<void id="Port9" index="1"/><void id="Port10" index="0"/><void id="Port11" index="2"/>
|
||||
</void></object>`),
|
||||
);
|
||||
|
||||
const list = object(ports).properties.get('anschluesse');
|
||||
const items = listItems(list, 24);
|
||||
expect(items).toHaveLength(24);
|
||||
expect(items.slice(0, 3).map((port) => object(port).id)).toEqual(['Port10', 'Port9', 'Port11']);
|
||||
expect(object(items[3])).toMatchObject({ className: 'unknown', fromGetter: true });
|
||||
expect(listItems(list)).toHaveLength(3);
|
||||
});
|
||||
|
||||
it('replays add at an index and set by index in order', () => {
|
||||
const [list] = decodeJavaBeans(
|
||||
doc(`<object class="java.util.ArrayList">
|
||||
<void method="add"><string>a</string></void>
|
||||
<void method="add"><string>c</string></void>
|
||||
<void method="add"><int>1</int><string>b</string></void>
|
||||
<void index="2"><string>C</string></void>
|
||||
</object>`),
|
||||
);
|
||||
|
||||
expect(listItems(list)).toEqual(['a', 'b', 'C']);
|
||||
});
|
||||
|
||||
it('does not guess what an index means once the list was changed', () => {
|
||||
const [, holder] = decodeJavaBeans(
|
||||
doc(`<object class="filius.hardware.knoten.Rechner">
|
||||
<void id="LinkedList0" property="netzwerkInterfaces">
|
||||
<void method="add"><object class="filius.hardware.NetzwerkInterface"/></void>
|
||||
<void id="NetzwerkInterface5" index="3"/>
|
||||
</void>
|
||||
</object>
|
||||
<object class="java.util.ArrayList"><void method="add"><object idref="NetzwerkInterface5"/></void></object>`),
|
||||
);
|
||||
|
||||
expect(isUnresolved(listItems(holder)[0])).toBe(true);
|
||||
});
|
||||
|
||||
it('reports an idref to an id that was never defined', () => {
|
||||
const [value] = decodeJavaBeans(doc('<object idref="Missing0"/>'));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user