Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/database/search-utils.test.js
// @flow | // @flow | ||||
import { segmentAndStem, stopwords } from './search-utils.js'; | |||||
import { | |||||
segmentAndStem, | |||||
stopwords, | |||||
processQueryForSearch, | |||||
} from './search-utils.js'; | |||||
const alphaNumericRegex = /^[A-Za-z0-9 ]*$/; | const alphaNumericRegex = /^[A-Za-z0-9 ]*$/; | ||||
const lowerCaseRegex = /^[a-z ]*$/; | const lowerCaseRegex = /^[a-z ]*$/; | ||||
describe('segmentAndStem(message: string)', () => { | describe('segmentAndStem(message: string)', () => { | ||||
it('should remove punctuation', () => { | it('should remove punctuation', () => { | ||||
expect(segmentAndStem("o'clock")).toMatch(alphaNumericRegex); | expect(segmentAndStem("o'clock")).toMatch(alphaNumericRegex); | ||||
expect(segmentAndStem('test@example')).toMatch(alphaNumericRegex); | expect(segmentAndStem('test@example')).toMatch(alphaNumericRegex); | ||||
Show All 34 Lines | describe('segmentAndStem(message: string)', () => { | ||||
it('should leave + < = > ^ ` | ~', () => { | it('should leave + < = > ^ ` | ~', () => { | ||||
const notRemovedASCIIPunctuation = '+ < = > ^ ` | ~'; | const notRemovedASCIIPunctuation = '+ < = > ^ ` | ~'; | ||||
expect(segmentAndStem(notRemovedASCIIPunctuation)).toBe( | expect(segmentAndStem(notRemovedASCIIPunctuation)).toBe( | ||||
notRemovedASCIIPunctuation, | notRemovedASCIIPunctuation, | ||||
); | ); | ||||
}); | }); | ||||
}); | }); | ||||
describe('processQueryForSearch(query: string)', () => { | |||||
it('should add + before every word', () => { | |||||
expect(processQueryForSearch('test')).toBe('+test'); | |||||
expect(processQueryForSearch('test hello')).toBe('+test +hello'); | |||||
expect(processQueryForSearch('test \nhello')).toBe('+test +hello'); | |||||
}); | |||||
it('should remove + < > ~ from the query', () => { | |||||
expect(processQueryForSearch('+ < > ~')).toBe(''); | |||||
}); | |||||
}); |