Created
December 22, 2016 19:09
-
-
Save dcsan/6975c84389ceac19d6677389d910506d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const debug = require('debug')("test:RoomData"); | |
// var test = require('tape'); | |
const test = require('tape-async'); | |
test('join regex', (t) => { | |
let pairs = [ | |
{ | |
msg: '"$invitee😀" joined the group chat via the QR Code shared by "$invitee😀"', | |
regex: /"(.*)" joined the group chat via the QR Code shared by "(.*)"/i | |
}, | |
{ | |
msg: '"$invitee😀" joined the group chat via your shared QR code"', | |
regex: /"(.*)" joined the group chat via your .*/i | |
} | |
] | |
pairs.map( pair => { | |
let res = pair.msg.match(pair.regex) | |
t.notEqual(res, false) | |
t.equal(res[1], '$invitee😀') // without double quotes | |
}) | |
t.end(); | |
}); | |
test('invite regex', (t) => { | |
let pairs = [ | |
// single invite from someone else | |
// could extend this to match and get inviter as well | |
{ | |
msg: '"😀inviter" invited "$invitee😀" to the group chat', | |
regex: /.* invited "(.*)" to the group chat/i, | |
expect: "$invitee😀" | |
}, | |
// multiple at once from someone else | |
// for chinese names they are surrouned by quotes | |
// for english, no quotes? | |
{ | |
msg: '"😀inviter" invited "$invitee😀, $invitee2, $invitee3" to the group chat', | |
regex: /.* invited "(.*)" to the group chat/i, | |
expect: "$invitee😀, $invitee2, $invitee3" | |
// regex: /"(.*)" invited "(.*)" to the group chat/i | |
}, | |
// you invite one person | |
{ | |
msg: 'You\'ve invited "$invitee😀" to the group chat Revoke', | |
regex: /You\'ve invited "(.*)" to the group chat.*/i, | |
expect: "$invitee😀" | |
}, | |
// multiples sometimes have quotes - maybe if chinese names are mixed in? | |
// | |
{ | |
msg: 'You\'ve invited Person Name one, Person name two to join the group chat', | |
regex: /You\'ve invited (.*) to join the group chat/i, | |
expect: "Person Name one, Person name two" | |
}, | |
{ | |
msg: 'You\'ve invited "Quoted name, Person name two" to join the group chat', | |
regex: /You\'ve invited (.*) to join the group chat/i, | |
expect: '"Quoted name, Person name two"' | |
} | |
] | |
pairs.map( pair => { | |
let res = pair.msg.match(pair.regex) | |
t.notEqual(res, false) | |
debug("res", res, pair); | |
t.equal(res[1], pair.expect, pair) // without double quotes | |
}) | |
t.end(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment