123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- var assert = require('assert')
- var clone = require('../');
- describe('regexp-clone', function(){
- function hasEqualSource (a, b) {
- assert.ok(a !== b);
- assert.equal(a.source, b.source);
- }
- function isInsensitive (a) {
- assert.ok(a.ignoreCase);
- }
- function isGlobal (a) {
- assert.ok(a.global);
- }
- function isMultiline (a) {
- assert.ok(a.multiline);
- }
- function insensitiveFlag (a) {
- var b = clone(a);
- hasEqualSource(a, b);
- isInsensitive(a);
- isInsensitive(b);
- }
- function globalFlag (a) {
- var b = clone(a);
- hasEqualSource(a, b);
- isGlobal(a);
- isGlobal(b);
- }
- function multilineFlag (a) {
- var b = clone(a);
- hasEqualSource(a, b);
- isMultiline(a);
- isMultiline(b);
- }
- describe('literals', function(){
- it('insensitive flag', function(done){
- var a = /hello/i;
- insensitiveFlag(a);
- done();
- })
- it('global flag', function(done){
- var a = /hello/g;
- globalFlag(a);
- done();
- })
- it('multiline flag', function(done){
- var a = /hello/m;
- multilineFlag(a);
- done();
- })
- it('no flags', function(done){
- var a = /hello/;
- var b = clone(a);
- hasEqualSource(a, b);
- assert.ok(!a.insensitive);
- assert.ok(!a.global);
- assert.ok(!a.global);
- done();
- })
- it('all flags', function(done){
- var a = /hello/gim;
- insensitiveFlag(a);
- globalFlag(a);
- multilineFlag(a);
- done();
- })
- })
- describe('instances', function(){
- it('insensitive flag', function(done){
- var a = new RegExp('hello', 'i');
- insensitiveFlag(a);
- done();
- })
- it('global flag', function(done){
- var a = new RegExp('hello', 'g');
- globalFlag(a);
- done();
- })
- it('multiline flag', function(done){
- var a = new RegExp('hello', 'm');
- multilineFlag(a);
- done();
- })
- it('no flags', function(done){
- var a = new RegExp('hmm');
- var b = clone(a);
- hasEqualSource(a, b);
- assert.ok(!a.insensitive);
- assert.ok(!a.global);
- assert.ok(!a.global);
- done();
- })
- it('all flags', function(done){
- var a = new RegExp('hello', 'gim');
- insensitiveFlag(a);
- globalFlag(a);
- multilineFlag(a);
- done();
- })
- })
- })
|