Set max line length to 120
This commit is contained in:
parent
79453750e7
commit
a390ec62ee
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"printWidth": 120
|
||||
}
|
||||
|
|
@ -21,11 +21,7 @@ const generateRangeInterval = (
|
|||
};
|
||||
};
|
||||
|
||||
const generateSteadyStateInterval = ({
|
||||
duration,
|
||||
intensity,
|
||||
cadence,
|
||||
}: Interval): xml.XmlObject => {
|
||||
const generateSteadyStateInterval = ({ duration, intensity, cadence }: Interval): xml.XmlObject => {
|
||||
return {
|
||||
SteadyState: [
|
||||
{
|
||||
|
|
@ -50,12 +46,7 @@ const generateInterval = (interval: Interval): xml.XmlObject => {
|
|||
}
|
||||
};
|
||||
|
||||
export const generateZwo = ({
|
||||
name,
|
||||
author,
|
||||
description,
|
||||
intervals,
|
||||
}: Workout): string => {
|
||||
export const generateZwo = ({ name, author, description, intervals }: Workout): string => {
|
||||
return xml(
|
||||
{
|
||||
workout_file: [
|
||||
|
|
|
|||
|
|
@ -122,23 +122,16 @@ Cooldown: 5:30 70%..45%
|
|||
`);
|
||||
});
|
||||
|
||||
const parseInterval = (interval: string) =>
|
||||
parse(`Name: My Workout\n${interval}`).intervals[0];
|
||||
const parseInterval = (interval: string) => parse(`Name: My Workout\n${interval}`).intervals[0];
|
||||
|
||||
it("requires duration and power parameters to be specified", () => {
|
||||
expect(() =>
|
||||
parseInterval("Interval: 50%")
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
expect(() => parseInterval("Interval: 50%")).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Duration not specified at line 2 char 1"`
|
||||
);
|
||||
expect(() =>
|
||||
parseInterval("Interval: 30:00")
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
expect(() => parseInterval("Interval: 30:00")).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Power not specified at line 2 char 1"`
|
||||
);
|
||||
expect(() =>
|
||||
parseInterval("Interval: 10rpm")
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
expect(() => parseInterval("Interval: 10rpm")).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Duration not specified at line 2 char 1"`
|
||||
);
|
||||
});
|
||||
|
|
@ -180,8 +173,7 @@ Cooldown: 5:30 70%..45%
|
|||
});
|
||||
|
||||
it("allows whitespace between interval parameters", () => {
|
||||
expect(parseInterval("Interval: 50% 00:10 100rpm"))
|
||||
.toMatchInlineSnapshot(`
|
||||
expect(parseInterval("Interval: 50% 00:10 100rpm")).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"cadence": 100,
|
||||
"duration": 10,
|
||||
|
|
@ -192,8 +184,7 @@ Cooldown: 5:30 70%..45%
|
|||
"type": "Interval",
|
||||
}
|
||||
`);
|
||||
expect(parseInterval("Interval: \t 50% \t 00:10 \t\t 100rpm \t"))
|
||||
.toMatchInlineSnapshot(`
|
||||
expect(parseInterval("Interval: \t 50% \t 00:10 \t\t 100rpm \t")).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"cadence": 100,
|
||||
"duration": 10,
|
||||
|
|
@ -218,50 +209,34 @@ Cooldown: 5:30 70%..45%
|
|||
});
|
||||
|
||||
it("throws error for incorrect duration formats", () => {
|
||||
expect(() =>
|
||||
parseInterval("Interval: 10 50%")
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
expect(() => parseInterval("Interval: 10 50%")).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Unrecognized interval parameter \\"10\\" at line 2 char 11"`
|
||||
);
|
||||
expect(() =>
|
||||
parseInterval("Interval: :10 50%")
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
expect(() => parseInterval("Interval: :10 50%")).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Unrecognized interval parameter \\":10\\" at line 2 char 11"`
|
||||
);
|
||||
expect(() =>
|
||||
parseInterval("Interval: 0:100 50%")
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
expect(() => parseInterval("Interval: 0:100 50%")).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Unrecognized interval parameter \\"0:100\\" at line 2 char 11"`
|
||||
);
|
||||
expect(() =>
|
||||
parseInterval("Interval: 00:00:00:10 50%")
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
expect(() => parseInterval("Interval: 00:00:00:10 50%")).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Unrecognized interval parameter \\"00:00:00:10\\" at line 2 char 11"`
|
||||
);
|
||||
});
|
||||
|
||||
it("throws error for unexpected interval parameter", () => {
|
||||
expect(() =>
|
||||
parseInterval("Interval: 10:00 50% foobar")
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
expect(() => parseInterval("Interval: 10:00 50% foobar")).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Unrecognized interval parameter \\"foobar\\" at line 2 char 21"`
|
||||
);
|
||||
expect(() =>
|
||||
parseInterval("Interval: 10:00 50% 123blah")
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
expect(() => parseInterval("Interval: 10:00 50% 123blah")).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Unrecognized interval parameter \\"123blah\\" at line 2 char 21"`
|
||||
);
|
||||
expect(() =>
|
||||
parseInterval("Interval: 10:00 50% ^*&")
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
expect(() => parseInterval("Interval: 10:00 50% ^*&")).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Unrecognized interval parameter \\"^*&\\" at line 2 char 21"`
|
||||
);
|
||||
});
|
||||
|
||||
it("throws error for unexpected type of interval", () => {
|
||||
expect(() =>
|
||||
parseInterval("Interval: 30:00 5% \n CustomInterval: 15:00 10%")
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
expect(() => parseInterval("Interval: 30:00 5% \n CustomInterval: 15:00 10%")).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Unexpected token [text CustomInterval: 15:00 10%] at line 3 char 1"`
|
||||
);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -51,10 +51,7 @@ const parseHeader = (tokens: Token[]): [Header, Token[]] => {
|
|||
|
||||
type IntervalData = Omit<Interval, "type">;
|
||||
|
||||
const parseIntervalParams = (
|
||||
tokens: Token[],
|
||||
loc: SourceLocation
|
||||
): [IntervalData, Token[]] => {
|
||||
const parseIntervalParams = (tokens: Token[], loc: SourceLocation): [IntervalData, Token[]] => {
|
||||
const data: Partial<IntervalData> = {};
|
||||
|
||||
while (tokens[0]) {
|
||||
|
|
@ -92,10 +89,7 @@ const parseIntervals = (tokens: Token[]): Interval[] => {
|
|||
while (tokens[0]) {
|
||||
const token = tokens.shift() as Token;
|
||||
if (token.type === "label" && isIntervalLabelTokenValue(token.value)) {
|
||||
const [{ duration, intensity, cadence }, rest] = parseIntervalParams(
|
||||
tokens,
|
||||
token.loc
|
||||
);
|
||||
const [{ duration, intensity, cadence }, rest] = parseIntervalParams(tokens, token.loc);
|
||||
intervals.push({
|
||||
type: token.value,
|
||||
duration,
|
||||
|
|
@ -106,10 +100,7 @@ const parseIntervals = (tokens: Token[]): Interval[] => {
|
|||
} else if (token.type === "text" && token.value === "") {
|
||||
// Ignore empty lines
|
||||
} else {
|
||||
throw new ParseError(
|
||||
`Unexpected token [${token.type} ${token.value}]`,
|
||||
token.loc
|
||||
);
|
||||
throw new ParseError(`Unexpected token [${token.type} ${token.value}]`, token.loc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -120,10 +111,7 @@ export const parseTokens = (tokens: Token[]): Workout => {
|
|||
const [header, intervalTokens] = parseHeader(tokens);
|
||||
|
||||
if (header.name === undefined) {
|
||||
throw new ParseError(
|
||||
"Workout is missing a name. Use `Name:` to declare one.",
|
||||
{ row: 0, col: 0 }
|
||||
);
|
||||
throw new ParseError("Workout is missing a name. Use `Name:` to declare one.", { row: 0, col: 0 });
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1,21 +1,13 @@
|
|||
import { ParseError } from "./ParseError";
|
||||
|
||||
export type HeaderLabelTokenValue = "Name" | "Author" | "Description";
|
||||
export type IntervalLabelTokenValue =
|
||||
| "Warmup"
|
||||
| "Rest"
|
||||
| "Interval"
|
||||
| "Cooldown";
|
||||
export type IntervalLabelTokenValue = "Warmup" | "Rest" | "Interval" | "Cooldown";
|
||||
export type LabelTokenValue = HeaderLabelTokenValue | IntervalLabelTokenValue;
|
||||
|
||||
export const isHeaderLabelTokenValue = (
|
||||
value: string
|
||||
): value is HeaderLabelTokenValue => {
|
||||
export const isHeaderLabelTokenValue = (value: string): value is HeaderLabelTokenValue => {
|
||||
return ["Name", "Author", "Description"].includes(value);
|
||||
};
|
||||
export const isIntervalLabelTokenValue = (
|
||||
value: string
|
||||
): value is IntervalLabelTokenValue => {
|
||||
export const isIntervalLabelTokenValue = (value: string): value is IntervalLabelTokenValue => {
|
||||
return ["Warmup", "Rest", "Interval", "Cooldown"].includes(value);
|
||||
};
|
||||
export const isLabelTokenValue = (value: string): value is LabelTokenValue => {
|
||||
|
|
@ -78,11 +70,7 @@ const tokenizeValueParam = (text: string, loc: SourceLocation): Token => {
|
|||
throw new ParseError(`Unrecognized interval parameter "${text}"`, loc);
|
||||
};
|
||||
|
||||
const tokenizeParams = (
|
||||
type: LabelTokenValue,
|
||||
text: string,
|
||||
loc: SourceLocation
|
||||
): Token[] => {
|
||||
const tokenizeParams = (type: LabelTokenValue, text: string, loc: SourceLocation): Token[] => {
|
||||
switch (type) {
|
||||
case "Name":
|
||||
case "Author":
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import { pluck, sum } from "ramda";
|
||||
import { Interval } from "../ast";
|
||||
|
||||
export const totalDuration = (intervals: Interval[]) =>
|
||||
sum(pluck("duration", intervals));
|
||||
export const totalDuration = (intervals: Interval[]) => sum(pluck("duration", intervals));
|
||||
|
|
|
|||
Loading…
Reference in New Issue