-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updated Roster List and Item commands Changed from `<J>` to `<JR>` * Updated Roster Item parser Changed from `<j>` to `<jR>` * Added Roster List Parser This includes reworking the Roster Item Parser to handle the commands correctly
- Loading branch information
1 parent
73708fb
commit b4fc37c
Showing
14 changed files
with
183 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './rosterItemParser.js' | ||
export * from './rosterListParser.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Command, parseCommand } from '../../utils/index.js' | ||
import { FunctionName, ParserResult, ParserStatus } from '../../types/index.js' | ||
import { ParserKeyError } from '../errors/index.js' | ||
|
||
interface RosterListParams { | ||
cabIds: number[] | ||
} | ||
|
||
export type RosterListResult = ParserResult<RosterListParams> | ||
const rosterListParserKey = 'jR' | ||
|
||
const parseFromCommand: (params: Command) => RosterListResult = ({ key, attributes }) => { | ||
const possibleCabIds = attributes | ||
|
||
if (key !== rosterListParserKey) { | ||
throw new ParserKeyError('rosterListParser', key) | ||
} | ||
|
||
const cabIds = possibleCabIds.map(cabIdString => { | ||
const cabId = parseInt(cabIdString) | ||
if (!isNaN(cabId) && isFinite(cabId)) { | ||
return cabId | ||
} | ||
|
||
throw new Error(`Cab ID ${cabIdString} is not a number`) | ||
}) | ||
|
||
return { | ||
key: rosterListParserKey, | ||
parser: FunctionName.ROSTER_LIST, | ||
status: ParserStatus.SUCCESS, | ||
params: { | ||
cabIds | ||
} | ||
} | ||
} | ||
|
||
export const rosterListParser: (command: string) => RosterListResult = (command) => { | ||
const commandParams = parseCommand(command) | ||
return parseFromCommand(commandParams) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './makeCommand.js' | ||
export * from './parseAddress.js' | ||
export * from './parseCommand.js' | ||
export * from './removeQuotes.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function removeDoubleQuotes (str: string): string { | ||
return str.replaceAll('"', '') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { | ||
FunctionName, | ||
ParserKeyError, | ||
ParserStatus, | ||
rosterListParser, | ||
RosterListResult | ||
} from '../../../../src' | ||
|
||
describe('rosterListParser()', function () { | ||
describe('without any Roster Items', function () { | ||
it('parses `<jR>`', () => { | ||
const result = rosterListParser('<jR>') | ||
|
||
const expected: RosterListResult = { | ||
key: 'jR', | ||
parser: FunctionName.ROSTER_LIST, | ||
params: { | ||
cabIds: [] | ||
}, | ||
status: ParserStatus.SUCCESS | ||
} | ||
expect(result).toEqual(expected) | ||
}) | ||
}) | ||
|
||
describe('with Roster Items', function () { | ||
it('parses `<jR 1 22 333 4444>`', () => { | ||
const result = rosterListParser('<jR 1 22 333 4444>') | ||
|
||
const expected: RosterListResult = { | ||
key: 'jR', | ||
parser: FunctionName.ROSTER_LIST, | ||
params: { | ||
cabIds: [ | ||
1, | ||
22, | ||
333, | ||
4444 | ||
] | ||
}, | ||
status: ParserStatus.SUCCESS | ||
} | ||
expect(result).toEqual(expected) | ||
}) | ||
}) | ||
|
||
describe('with incorrect key', function () { | ||
it('throws a ParserKeyError', function () { | ||
expect(() => { | ||
rosterListParser('<incorrect-key>') | ||
}).toThrowError(ParserKeyError) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters