Skip to content

Commit

Permalink
Fix parsing of "calm wind" (#81)
Browse files Browse the repository at this point in the history
* fix: correctly parse calm wind

* test: ensure correct wind unit is parsed

* test: ensure visibility is not mistaken for wind speed

* style: apply formatting
  • Loading branch information
SkySails authored Jan 26, 2024
1 parent 6fa7302 commit 283e92f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/command/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class MainVisibilityCommand implements ICommand {
}

export class WindCommand implements ICommand {
#regex = /^(VRB|00|[0-3]\d{2})(\d{2})G?(\d{2,3})?(KT|MPS|KM\/H)?/;
#regex = /^(VRB|000|[0-3]\d{2})(\d{2})G?(\d{2,3})?(KT|MPS|KM\/H)?/;

canParse(windString: string): boolean {
return this.#regex.test(windString);
Expand Down
28 changes: 27 additions & 1 deletion tests/parser/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ describe("MetarParser", () => {

test("wind of 0000KT should not parse as minVisibility", () => {
const metar = new MetarParser(en).parse(
"KATW 022045Z 0000KT 10SM SCT120 00/M08 A2996"
"KATW 022045Z 00000KT 10SM SCT120 00/M08 A2996"
);

expect(metar.wind).toStrictEqual({
Expand All @@ -400,6 +400,32 @@ describe("MetarParser", () => {
expect(metar.visibility?.min).toBeUndefined();
});

test("wind of 00000MPS should parse with correct unit", () => {
const metar = new MetarParser(en).parse("KATL 270200Z 00000MPS");

expect(metar.wind).toStrictEqual({
degrees: 0,
speed: 0,
unit: "MPS",
gust: undefined,
direction: "N",
});
});

test("visibility should not parse as wind speed", () => {
const metar = new MetarParser(en).parse("VIDP 270200Z 00000MPS 0050");

expect(metar.wind).toStrictEqual({
degrees: 0,
speed: 0,
unit: "MPS",
gust: undefined,
direction: "N",
});

expect(metar.visibility).toStrictEqual({ unit: "m", value: 50 });
});

test("wind variation", () => {
const metar = new MetarParser(en).parse("LFPG 161430Z 24015G25KT 180V300");

Expand Down

0 comments on commit 283e92f

Please sign in to comment.