Skip to content

Commit d1e0c23

Browse files
authored
Expanded variable RVR regex to be more strict and account for north american style METAR (fixes #115) (#116)
1 parent b88801c commit d1e0c23

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/command/metar/RunwayCommand.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import { ICommand } from "../metar";
1212

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

@@ -63,7 +64,10 @@ export class RunwayCommand implements ICommand {
6364

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

66-
const trend = matches[4] ? as(matches[4], RunwayInfoTrend) : undefined;
67+
const trend = (() => {
68+
if (matches[6]) return as(matches[6], RunwayInfoTrend);
69+
if (matches[4]) return as(matches[4], RunwayInfoTrend);
70+
})();
6771
const unit = matches[5]
6872
? as(matches[5], RunwayInfoUnit)
6973
: RunwayInfoUnit.Meters;

tests/command/metar/RunwayCommand.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,30 @@ describe("RunwayCommand", () => {
9898
});
9999
})();
100100

101+
(() => {
102+
const code = "R08L/1400V1800FT/N"; // runway info range north america style
103+
const metar = { runwaysInfo: [] } as unknown as IMetar;
104+
105+
describe(code, () => {
106+
test("canParse", () => {
107+
expect(command.canParse(code)).toBe(true);
108+
});
109+
110+
test("parse", () => {
111+
command.execute(metar, code);
112+
113+
expect(metar.runwaysInfo).toHaveLength(1);
114+
expect(metar.runwaysInfo[0]).toEqual({
115+
name: "08L",
116+
minRange: 1400,
117+
maxRange: 1800,
118+
unit: RunwayInfoUnit.Feet,
119+
trend: RunwayInfoTrend.NoSignificantChange,
120+
});
121+
});
122+
});
123+
})();
124+
101125
(() => {
102126
const code = "R01L/0800FT"; // runway info range feet simple
103127
const metar = { runwaysInfo: [] } as unknown as IMetar;

0 commit comments

Comments
 (0)