Skip to content

Commit

Permalink
chore(update): multi line comment, remove log
Browse files Browse the repository at this point in the history
  • Loading branch information
stavares843 committed Feb 14, 2022
1 parent 9aea172 commit c153c7a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
21 changes: 11 additions & 10 deletions libraries/ui/Commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,20 +192,21 @@ describe('Commands.isArgsValid', () => {
describe('Commands.hasCommandPreview', () => {
test('0', () => {
const object: string = '/a'
// Regex is [a-z0-9], hence everything that is in these is valid.
// Other condition that we need to consider so that it passes the test is that:
// it will return true if either the string has / at the start (text.charAt(0) === commandPrefix)
// AND
// the text is valid for the regex (/^[a-z0-9]+$/i) and has a length of 1 (/ab has a length of 2).
/* Regex is [a-z0-9], hence everything that is in these is valid.
Other condition that we need to consider so that it passes the test is that:
it will return true if either the string has / at the start (text.charAt(0) === commandPrefix)
AND
the text is valid for the regex (/^[a-z0-9]+$/i) and has a length of 1 (/ab has a length of 2). */
const result: any = Commands.hasCommandPreview(object)
expect(result).toBeTruthy()
})
test('1', () => {
const object: string = 'ABC' // A-Z is in [a-z0-9] because of the `i` flag at the end of the regex (/^[a-z0-9]+$/i)
// Though what makes this string above invalid is because it does not adhere to both the condition of
// text.charAt(0) === commandPrefix && (cmd.match(/^[a-z0-9]+$/i) || text.length === 1)
// It does not have `/` at the start, hence not adhering to text.charAt(0) === commandPrefix.
// And though it adheres to `(cmd.match(/^[a-z0-9]+$/i)`, it does not adhere to `text.length === 1`
const object: string =
'ABC' /* A-Z is in [a-z0-9] because of the `i` flag at the end of the regex (/^[a-z0-9]+$/i)
Though what makes this string above invalid is because it does not adhere to both the condition of
text.charAt(0) === commandPrefix && (cmd.match(/^[a-z0-9]+$/i) || text.length === 1)
It does not have `/` at the start, hence not adhering to text.charAt(0) === commandPrefix.
And though it adheres to `(cmd.match(/^[a-z0-9]+$/i)`, it does not adhere to `text.length === 1` */
const result: any = Commands.hasCommandPreview(object)
expect(result).toBeFalsy()
})
Expand Down
8 changes: 1 addition & 7 deletions libraries/ui/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@ export const commandPrefix = '/'
*/
export function containsCommand(text: string) {
const cmd = text.split(' ')[0].replace(commandPrefix, '')
console.log(1, cmd, text)
console.log(
2,
text.charAt(0) === commandPrefix,
text.charAt(0),
commandPrefix,
)

console.log(3, cmd, text, cmd.match(/^[a-z0-9]+$/i), text.length === 1)
return (
text.charAt(0) === commandPrefix &&
Expand Down

0 comments on commit c153c7a

Please sign in to comment.