More bugfixes in comment offsets
This commit is contained in:
@@ -822,7 +822,7 @@ export class Frame implements IFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// remove altitude token from ext and advance ext for further parsing
|
// remove altitude token from ext and advance ext for further parsing
|
||||||
commentOffset += 7;
|
commentOffset += altMatch[0].length;
|
||||||
ext = ext.replace(altMatch[0], "").trimStart();
|
ext = ext.replace(altMatch[0], "").trimStart();
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -6,6 +6,26 @@ import type { PositionPayload } from "../src/frame.types";
|
|||||||
import { feetToMeters, milesToMeters } from "../src/parser";
|
import { feetToMeters, milesToMeters } from "../src/parser";
|
||||||
|
|
||||||
describe("APRS extras test vectors", () => {
|
describe("APRS extras test vectors", () => {
|
||||||
|
it("parses altitude token in the beginning of a comment and emits structure", () => {
|
||||||
|
const raw =
|
||||||
|
"DL3QP-R>APDG03,TCPIP*,qAC,T2ROMANIA:!5151.12ND00637.65E&/A=000000440 MMDVM Voice 439.40000MHz -7.6000MHz, DL3QP_Pi-Star";
|
||||||
|
const frame = Frame.fromString(raw);
|
||||||
|
const res = frame.decode(true) as { payload: PositionPayload | null; structure: Dissected };
|
||||||
|
const { payload, structure } = res;
|
||||||
|
|
||||||
|
expect(payload).not.toBeNull();
|
||||||
|
// Altitude 001234 ft -> meters
|
||||||
|
expect(payload!.position.altitude).toBe(0);
|
||||||
|
|
||||||
|
const commentSeg = structure.find((s) => /comment/i.test(String(s.name))) as Segment | undefined;
|
||||||
|
expect(commentSeg).toBeDefined();
|
||||||
|
const fieldsAlt = (commentSeg!.fields ?? []) as Field[];
|
||||||
|
const hasAlt = fieldsAlt.some((f) => f.name === "altitude");
|
||||||
|
expect(hasAlt).toBe(true);
|
||||||
|
|
||||||
|
expect(payload!.position.comment).toBe("440 MMDVM Voice 439.40000MHz -7.6000MHz, DL3QP_Pi-Star");
|
||||||
|
});
|
||||||
|
|
||||||
it("parses altitude token marker mid-comment and emits structure", () => {
|
it("parses altitude token marker mid-comment and emits structure", () => {
|
||||||
const raw = "N0CALL>APRS,WIDE1-1:!4500.00N/07000.00W#RNG0001ALT/A=001234 Your Comment Here";
|
const raw = "N0CALL>APRS,WIDE1-1:!4500.00N/07000.00W#RNG0001ALT/A=001234 Your Comment Here";
|
||||||
const frame = Frame.fromString(raw);
|
const frame = Frame.fromString(raw);
|
||||||
|
|||||||
Reference in New Issue
Block a user