test of utils.rx

This commit is contained in:
jysperm
2014-10-22 22:36:03 +08:00
parent 537b5904b0
commit e6fa3fd905
3 changed files with 33 additions and 8 deletions

View File

@@ -9,15 +9,38 @@ describe 'utils', ->
utils.rx.username.test('184300584').should.not.be.ok
utils.rx.username.test('jysperm@gmail.com').should.not.be.ok
it 'email'
it 'email', ->
utils.rx.email.test('jysperm@gmail.com').should.be.ok
utils.rx.email.test('').should.not.be.ok
utils.rx.email.test('jysperm').should.not.be.ok
utils.rx.email.test('jysperm@').should.not.be.ok
utils.rx.email.test('@gmail.com').should.not.be.ok
it 'password'
it 'password', ->
utils.rx.password.test('passwd').should.be.ok
utils.rx.password.test('').should.not.be.ok
it 'domain'
it 'domain', ->
utils.rx.domain.test('jysperm.me').should.be.ok
utils.rx.domain.test('*.jysperm.me').should.be.ok
utils.rx.domain.test('www.jysperm.me').should.be.ok
utils.rx.domain.test('0-ms.org').should.be.ok
utils.rx.domain.test('localhost').should.be.ok
utils.rx.domain.test('.jysperm.me').should.not.be.ok
utils.rx.domain.test('-jysperm').should.not.be.ok
utils.rx.domain.test('jy sperm').should.not.be.ok
utils.rx.domain.test('jysperm.').should.not.be.ok
it 'filename'
it 'filename', ->
utils.rx.filename.test('filename').should.be.ok
utils.rx.filename.test('').should.not.be.ok
utils.rx.filename.test('"filename').should.not.be.ok
utils.rx.filename.test('file\name').should.not.be.ok
it 'url'
it 'url', ->
utils.rx.url.test('http://jysperm.me').should.be.ok
utils.rx.url.test('https://jysperm.me/about').should.be.ok
utils.rx.url.test('ssh://jysperm.me').should.not.be.ok
it 'sha256'

View File

@@ -5,8 +5,8 @@ exports.rx =
username: /^[a-z][0-9a-z_]{2,23}$/
email: /^\w+([-+.]\w+)*@\w+([-+.]\w+)*$/
password: /^.+$/
domain: /(\*\.)?[A-Za-z0-9]+(\-[A-Za-z0-9]+)*(\.[A-Za-z0-9]+(\-[A-Za-z0-9]+)*)*/
filename: /[A-Za-z0-9_\-\.]+/
domain: /^(\*\.)?[A-Za-z0-9]+(\-[A-Za-z0-9]+)*(\.[A-Za-z0-9]+(\-[A-Za-z0-9]+)*)*$/
filename: /^[A-Za-z0-9_\-\.]+$/
url: /^https?:\/\/[^\s;]*$/
exports.sha256 = (data) ->

View File

@@ -14,4 +14,6 @@ global.deepmerge = require 'deepmerge'
global.client = require './client'
require("chai").should()
chai = require 'chai'
chai.should()
chai.Assertion.includeStack = true