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 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. const assert = require('assert')
  2. const 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 isIgnoreCase (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 isDotAll (a) {
  18. assert.ok(a.dotAll);
  19. }
  20. function isUnicode (a) {
  21. assert.ok(a.unicode);
  22. }
  23. function isSticky(a) {
  24. assert.ok(a.sticky);
  25. }
  26. function testFlag (a, method) {
  27. const b = clone(a);
  28. hasEqualSource(a, b);
  29. method(a);
  30. method(b);
  31. }
  32. function lastIndex(a) {
  33. a.test('this string hi there');
  34. assert.strictEqual(a.lastIndex, 3);
  35. const b = clone(a);
  36. assert.strictEqual(b.lastIndex, 3);
  37. assert.strictEqual(a.lastIndex, 3);
  38. b.test('this string hi there');
  39. assert.strictEqual(b.lastIndex, 14);
  40. assert.strictEqual(a.lastIndex, 3);
  41. }
  42. function allFlags(a) {
  43. const b = clone(a);
  44. hasEqualSource(a, b);
  45. testFlag(b, isIgnoreCase);
  46. testFlag(b, isGlobal);
  47. testFlag(b, isMultiline);
  48. testFlag(b, isDotAll);
  49. testFlag(b, isUnicode);
  50. testFlag(b, isSticky);
  51. }
  52. function noFlags(a) {
  53. const b = clone(a);
  54. hasEqualSource(a, b);
  55. assert.ok(!b.ignoreCase);
  56. assert.ok(!b.global);
  57. assert.ok(!b.multiline);
  58. assert.ok(!b.dotAll);
  59. assert.ok(!b.unicode);
  60. assert.ok(!b.sticky);
  61. }
  62. describe('literals', function(){
  63. it('ignoreCase flag', function(done){
  64. const a = /hello/i;
  65. testFlag(a, isIgnoreCase);
  66. done();
  67. })
  68. it('global flag', function(done){
  69. const a = /hello/g;
  70. testFlag(a, isGlobal);
  71. done();
  72. })
  73. it('multiline flag', function(done){
  74. const a = /hello/m;
  75. testFlag(a, isMultiline);
  76. done();
  77. })
  78. it('dotAll flag', function(done){
  79. const a = /hello/s;
  80. testFlag(a, isDotAll);
  81. done();
  82. })
  83. it('unicode flag', function(done){
  84. const a = /hello/u;
  85. testFlag(a, isUnicode);
  86. done();
  87. })
  88. it('sticky flag', function(done){
  89. const a = /hello/y;
  90. testFlag(a, isSticky);
  91. done();
  92. })
  93. it('no flags', function(done){
  94. const a = /hello/;
  95. noFlags(a);
  96. done();
  97. })
  98. it('all flags', function(done){
  99. const a = /hello/gimsuy;
  100. allFlags(a);
  101. done();
  102. })
  103. it('lastIndex', function(done) {
  104. const a = /hi/g;
  105. lastIndex(a);
  106. done();
  107. })
  108. })
  109. describe('instances', function(){
  110. it('ignoreCase flag', function(done){
  111. const a = new RegExp('hello', 'i');
  112. testFlag(a, isIgnoreCase);
  113. done();
  114. })
  115. it('global flag', function(done){
  116. const a = new RegExp('hello', 'g');
  117. testFlag(a, isGlobal);
  118. done();
  119. })
  120. it('multiline flag', function(done){
  121. const a = new RegExp('hello', 'm');
  122. testFlag(a, isMultiline);
  123. done();
  124. })
  125. it('dotAll flag', function(done){
  126. const a = new RegExp('hello', 's');
  127. testFlag(a, isDotAll);
  128. done();
  129. })
  130. it('unicode flag', function(done){
  131. const a = new RegExp('hello', 'u');
  132. testFlag(a, isUnicode);
  133. done();
  134. })
  135. it('sticky flag', function(done){
  136. const a = new RegExp('hello', 'y');
  137. testFlag(a, isSticky);
  138. done();
  139. })
  140. it('no flags', function(done){
  141. const a = new RegExp('hmm');
  142. noFlags(a);
  143. done();
  144. })
  145. it('all flags', function(done){
  146. const a = new RegExp('hello', 'misguy');
  147. allFlags(a);
  148. done();
  149. })
  150. it('lastIndex', function(done) {
  151. const a = new RegExp('hi', 'g');
  152. lastIndex(a);
  153. done();
  154. })
  155. })
  156. })