Skip to content

Commit

Permalink
Expanded variable RVR regex to be more strict and account for north a…
Browse files Browse the repository at this point in the history
…merican style METAR (fixes #115)
  • Loading branch information
fkrauthan committed Jan 6, 2025
1 parent b88801c commit 7232560
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/command/metar/RunwayCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { ICommand } from "../metar";

export class RunwayCommand implements ICommand {
#genericRegex = /^(R\d{2}\w?\/)/;
#runwayMaxRangeRegex = /^R(\d{2}\w?)\/(\d{4})V(\d{3,4})([UDN])?(FT)?/;
#runwayMaxRangeRegex =
/^R(\d{2}\w?)\/(\d{4})V(\d{3,4})(?:([UDN])|(FT)(?:\/([UDN]))?)$/;
#runwayRegex = /^R(\d{2}\w?)\/([MP])?(\d{4})(?:([UDN])|(FT)(?:\/([UDN]))?)$/;
#runwayDepositRegex = /^R(\d{2}\w?)\/([/\d])([/\d])(\/\/|\d{2})(\/\/|\d{2})$/;

Expand Down Expand Up @@ -63,7 +64,10 @@ export class RunwayCommand implements ICommand {

if (!matches) throw new UnexpectedParseError("Should be able to parse");

const trend = matches[4] ? as(matches[4], RunwayInfoTrend) : undefined;
const trend = (() => {
if (matches[6]) return as(matches[6], RunwayInfoTrend);
if (matches[4]) return as(matches[4], RunwayInfoTrend);
})();
const unit = matches[5]
? as(matches[5], RunwayInfoUnit)
: RunwayInfoUnit.Meters;
Expand Down
24 changes: 24 additions & 0 deletions tests/command/metar/RunwayCommand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,30 @@ describe("RunwayCommand", () => {
});
})();

(() => {
const code = "R08L/1400V1800FT/N"; // runway info range north america style
const metar = { runwaysInfo: [] } as unknown as IMetar;

describe(code, () => {
test("canParse", () => {
expect(command.canParse(code)).toBe(true);
});

test("parse", () => {
command.execute(metar, code);

expect(metar.runwaysInfo).toHaveLength(1);
expect(metar.runwaysInfo[0]).toEqual({
name: "08L",
minRange: 1400,
maxRange: 1800,
unit: RunwayInfoUnit.Feet,
trend: RunwayInfoTrend.NoSignificantChange,
});
});
});
})();

(() => {
const code = "R01L/0800FT"; // runway info range feet simple
const metar = { runwaysInfo: [] } as unknown as IMetar;
Expand Down

0 comments on commit 7232560

Please sign in to comment.