Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toPoint throws an error if a blank string is passed in #37

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions mgrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ export function inverse(mgrs) {
}

export function toPoint(mgrs) {
if (mgrs === '') {
throw (`toPoint received a blank string`);
DanielJDufour marked this conversation as resolved.
Show resolved Hide resolved
}
const bbox = UTMtoLL(decode(mgrs.toUpperCase()));
if (bbox.lat && bbox.lon) {
return [bbox.lon, bbox.lat];
Expand Down
7 changes: 7 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ describe ('third mgrs set', () => {

describe ('data validation', () => {
describe('forward function', () => {
it('toPoint throws an error when a blank string is passed in', () => {
try {
mgrs.toPoint('');
} catch (error) {
error.should.equal('toPoint received a blank string');
}
});
it('forward throws an error when array of strings passed in', () => {
try {
mgrs.forward(['40', '40']);
Expand Down