Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. var assert = require('assert')
  2. var clone = require('../');
  3. describe('regexp-clone', function(){
  4. function hasEqualSource (a, b) {
  5. assert.ok(a !== b);
  6. assert.equal(a.source, b.source);
  7. }
  8. function isInsensitive (a) {
  9. assert.ok(a.ignoreCase);
  10. }
  11. function isGlobal (a) {
  12. assert.ok(a.global);
  13. }
  14. function isMultiline (a) {
  15. assert.ok(a.multiline);
  16. }
  17. function insensitiveFlag (a) {
  18. var b = clone(a);
  19. hasEqualSource(a, b);
  20. isInsensitive(a);
  21. isInsensitive(b);
  22. }
  23. function globalFlag (a) {
  24. var b = clone(a);
  25. hasEqualSource(a, b);
  26. isGlobal(a);
  27. isGlobal(b);
  28. }
  29. function multilineFlag (a) {
  30. var b = clone(a);
  31. hasEqualSource(a, b);
  32. isMultiline(a);
  33. isMultiline(b);
  34. }
  35. describe('literals', function(){
  36. it('insensitive flag', function(done){
  37. var a = /hello/i;
  38. insensitiveFlag(a);
  39. done();
  40. })
  41. it('global flag', function(done){
  42. var a = /hello/g;
  43. globalFlag(a);
  44. done();
  45. })
  46. it('multiline flag', function(done){
  47. var a = /hello/m;
  48. multilineFlag(a);
  49. done();
  50. })
  51. it('no flags', function(done){
  52. var a = /hello/;
  53. var b = clone(a);
  54. hasEqualSource(a, b);
  55. assert.ok(!a.insensitive);
  56. assert.ok(!a.global);
  57. assert.ok(!a.global);
  58. done();
  59. })
  60. it('all flags', function(done){
  61. var a = /hello/gim;
  62. insensitiveFlag(a);
  63. globalFlag(a);
  64. multilineFlag(a);
  65. done();
  66. })
  67. })
  68. describe('instances', function(){
  69. it('insensitive flag', function(done){
  70. var a = new RegExp('hello', 'i');
  71. insensitiveFlag(a);
  72. done();
  73. })
  74. it('global flag', function(done){
  75. var a = new RegExp('hello', 'g');
  76. globalFlag(a);
  77. done();
  78. })
  79. it('multiline flag', function(done){
  80. var a = new RegExp('hello', 'm');
  81. multilineFlag(a);
  82. done();
  83. })
  84. it('no flags', function(done){
  85. var a = new RegExp('hmm');
  86. var b = clone(a);
  87. hasEqualSource(a, b);
  88. assert.ok(!a.insensitive);
  89. assert.ok(!a.global);
  90. assert.ok(!a.global);
  91. done();
  92. })
  93. it('all flags', function(done){
  94. var a = new RegExp('hello', 'gim');
  95. insensitiveFlag(a);
  96. globalFlag(a);
  97. multilineFlag(a);
  98. done();
  99. })
  100. })
  101. })