@@ -297,4 +297,128 @@ describe("NormalModule", function() {
297297 } ) ;
298298 } ) ;
299299 } ) ;
300+
301+ describe ( "#applyNoParseRule" , function ( ) {
302+ let rule ;
303+ let content ;
304+ describe ( "given a string as rule" , function ( ) {
305+ beforeEach ( function ( ) {
306+ rule = "some-rule" ;
307+ } ) ;
308+ describe ( "and the content starting with the string specified in rule" , function ( ) {
309+ beforeEach ( function ( ) {
310+ content = rule + "some-content" ;
311+ } ) ;
312+ it ( "returns true" , function ( ) {
313+ normalModule . preventParsing ( rule , content ) . should . eql ( true ) ;
314+ } ) ;
315+ } ) ;
316+ describe ( "and the content does not start with the string specified in rule" , function ( ) {
317+ beforeEach ( function ( ) {
318+ content = "some-content" ;
319+ } ) ;
320+ it ( "returns false" , function ( ) {
321+ normalModule . preventParsing ( rule , content ) . should . eql ( false ) ;
322+ } ) ;
323+ } ) ;
324+ } ) ;
325+ describe ( "given a regex as rule" , function ( ) {
326+ beforeEach ( function ( ) {
327+ rule = / s o m e - r u l e / ;
328+ } ) ;
329+ describe ( "and the content matches the rule" , function ( ) {
330+ beforeEach ( function ( ) {
331+ content = rule + "some-content" ;
332+ } ) ;
333+ it ( "returns true" , function ( ) {
334+ normalModule . preventParsing ( rule , content ) . should . eql ( true ) ;
335+ } ) ;
336+ } ) ;
337+ describe ( "and the content does not match the rule" , function ( ) {
338+ beforeEach ( function ( ) {
339+ content = "some-content" ;
340+ } ) ;
341+ it ( "returns false" , function ( ) {
342+ normalModule . preventParsing ( rule , content ) . should . eql ( false ) ;
343+ } ) ;
344+ } ) ;
345+ } ) ;
346+ } ) ;
347+
348+ describe ( "#preventParsing" , function ( ) {
349+ let applyNoParseRuleSpy ;
350+ beforeEach ( function ( ) {
351+ applyNoParseRuleSpy = sinon . stub ( ) ;
352+ normalModule . applyNoParseRule = applyNoParseRuleSpy ;
353+ } ) ;
354+ describe ( "given no noParseRule" , function ( ) {
355+ it ( "returns false" , function ( ) {
356+ normalModule . preventParsing ( ) . should . eql ( false ) ;
357+ applyNoParseRuleSpy . callCount . should . eql ( 0 ) ;
358+ } ) ;
359+ } ) ;
360+ describe ( "given a noParseRule" , function ( ) {
361+ let returnValOfSpy ;
362+ beforeEach ( function ( ) {
363+ returnValOfSpy = Math . random ( ) >= 0.5 ? true : false ;
364+ applyNoParseRuleSpy . returns ( returnValOfSpy ) ;
365+ } ) ;
366+ describe ( "that is a string" , function ( ) {
367+ it ( "calls and returns whatever applyNoParseRule returns" , function ( ) {
368+ normalModule . preventParsing ( "some rule" ) . should . eql ( returnValOfSpy ) ;
369+ applyNoParseRuleSpy . callCount . should . eql ( 1 ) ;
370+ } ) ;
371+ } ) ;
372+ describe ( "that is a regex" , function ( ) {
373+ it ( "calls and returns whatever applyNoParseRule returns" , function ( ) {
374+ normalModule . preventParsing ( "some rule" ) . should . eql ( returnValOfSpy ) ;
375+ applyNoParseRuleSpy . callCount . should . eql ( 1 ) ;
376+ } ) ;
377+ } ) ;
378+ describe ( "that is an array" , function ( ) {
379+ describe ( "of strings and or regexs" , function ( ) {
380+ let someRules ;
381+ beforeEach ( function ( ) {
382+ someRules = [
383+ Math . random ( ) >= 0.5 ? "some rule" : / s o m e r u l e / ,
384+ Math . random ( ) >= 0.5 ? "some rule1" : / s o m e r u l e 1 / ,
385+ Math . random ( ) >= 0.5 ? "some rule2" : / s o m e r u l e 2 / ,
386+ ] ;
387+ } ) ;
388+ describe ( "and none of them match" , function ( ) {
389+ beforeEach ( function ( ) {
390+ returnValOfSpy = false ;
391+ applyNoParseRuleSpy . returns ( returnValOfSpy ) ;
392+ } ) ;
393+ it ( "returns false" , function ( ) {
394+ normalModule . preventParsing ( someRules ) . should . eql ( returnValOfSpy ) ;
395+ applyNoParseRuleSpy . callCount . should . eql ( 3 ) ;
396+ } ) ;
397+ } ) ;
398+ describe ( "and the first of them matches" , function ( ) {
399+ beforeEach ( function ( ) {
400+ returnValOfSpy = true ;
401+ applyNoParseRuleSpy . returns ( returnValOfSpy ) ;
402+ } ) ;
403+ it ( "returns true" , function ( ) {
404+ normalModule . preventParsing ( someRules ) . should . eql ( returnValOfSpy ) ;
405+ applyNoParseRuleSpy . callCount . should . eql ( 1 ) ;
406+ } ) ;
407+ } ) ;
408+ describe ( "and the last of them matches" , function ( ) {
409+ beforeEach ( function ( ) {
410+ returnValOfSpy = true ;
411+ applyNoParseRuleSpy . onCall ( 0 ) . returns ( false ) ;
412+ applyNoParseRuleSpy . onCall ( 1 ) . returns ( false ) ;
413+ applyNoParseRuleSpy . onCall ( 2 ) . returns ( true ) ;
414+ } ) ;
415+ it ( "returns true" , function ( ) {
416+ normalModule . preventParsing ( someRules ) . should . eql ( returnValOfSpy ) ;
417+ applyNoParseRuleSpy . callCount . should . eql ( 3 ) ;
418+ } ) ;
419+ } ) ;
420+ } ) ;
421+ } ) ;
422+ } ) ;
423+ } ) ;
300424} ) ;
0 commit comments