Skip to content

Commit

Permalink
fix(api): fix comparator matching
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Reed committed Aug 4, 2017
1 parent 3a243a5 commit 6897389
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/api/Comparator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ export class Comparator extends OnmsEnum<number> {

/** Whether this comparator matches the given comparator string. */
public matches(comparator: string) {
return (comparator.toLowerCase() === this.label.toLowerCase())
|| this.aliases.indexOf(comparator) >= 0;
const compareTo = comparator.toUpperCase();
return (compareTo === this.label.toUpperCase())
|| this.aliases.indexOf(compareTo) >= 0;
}
}

Expand Down
42 changes: 42 additions & 0 deletions test/api/Comparator.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
declare const describe, beforeEach, it, expect;

import {Comparator, Comparators} from '../../src/api/Comparator';

const matches = {
'=': Comparators.EQ,
'==': Comparators.EQ,
'eq': Comparators.EQ,
'!=': Comparators.NE,
'ne': Comparators.NE,
'ilike': Comparators.ILIKE,
'like': Comparators.LIKE,
'>': Comparators.GT,
'gt': Comparators.GT,
'<': Comparators.LT,
'lt': Comparators.LT,
'>=': Comparators.GE,
'ge': Comparators.GE,
'<=': Comparators.LE,
'le': Comparators.LE,
'null': Comparators.NULL,
'isnull': Comparators.NULL,
'notnull': Comparators.NOTNULL
}

describe('Comparators: Lower-Case', () => {
for (const match in matches) {
const comparator = matches[match];
it(comparator.label + ' should match ' + match.toLowerCase(), () => {
expect(comparator.matches(match.toLowerCase())).toBeTruthy();
});
}
});

describe('Comparators: Upper-Case', () => {
for (const match in matches) {
const comparator = matches[match];
it(comparator.label + ' should match ' + match.toUpperCase(), () => {
expect(comparator.matches(match.toUpperCase())).toBeTruthy();
});
}
});

0 comments on commit 6897389

Please sign in to comment.