react / wstein / node_modules / browserify / node_modules / insert-module-globals / node_modules / combine-source-map / node_modules / convert-source-map / test / comment-regex.js
80556 views'use strict';1/*jshint asi: true */23var test = require('tap').test4, generator = require('inline-source-map')5, rx = require('..').commentRegex6, mapFileRx = require('..').mapFileCommentRegex78function comment(s) {9rx.lastIndex = 0;10return rx.test(s + 'sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJmdW5jdGlvbiBmb28oKSB7XG4gY29uc29sZS5sb2coXCJoZWxsbyBJIGFtIGZvb1wiKTtcbiBjb25zb2xlLmxvZyhcIndobyBhcmUgeW91XCIpO1xufVxuXG5mb28oKTtcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9')11}1213test('comment regex old spec - @', function (t) {14[ '//@ '15, ' //@ '16, '\t//@ '17].forEach(function (x) { t.ok(comment(x), 'matches ' + x) });1819[ '///@ '20, '}}//@ '21, ' @// @'22].forEach(function (x) { t.ok(!comment(x), 'does not match ' + x) })23t.end()24})2526test('comment regex new spec - #', function (t) {27[ '//# '28, ' //# '29, '\t//# '30].forEach(function (x) { t.ok(comment(x), 'matches ' + x) });3132[ '///# '33, '}}//# '34, ' #// #'35].forEach(function (x) { t.ok(!comment(x), 'does not match ' + x) })36t.end()37})3839function mapFileComment(s) {40mapFileRx.lastIndex = 0;41return mapFileRx.test(s + 'sourceMappingURL=foo.js.map')42}4344test('mapFileComment regex old spec - @', function (t) {45[ '//@ '46, ' //@ '47, '\t//@ '48].forEach(function (x) { t.ok(mapFileComment(x), 'matches ' + x) });4950[ '///@ '51, '}}//@ '52, ' @// @'53].forEach(function (x) { t.ok(!mapFileComment(x), 'does not match ' + x) })54t.end()55})5657test('mapFileComment regex new spec - #', function (t) {58[ '//# '59, ' //# '60, '\t//# '61].forEach(function (x) { t.ok(mapFileComment(x), 'matches ' + x) });6263[ '///# '64, '}}//# '65, ' #// #'66].forEach(function (x) { t.ok(!mapFileComment(x), 'does not match ' + x) })67t.end()68})6970function mapFileCommentWrap(s1, s2) {71mapFileRx.lastIndex = 0;72return mapFileRx.test(s1 + 'sourceMappingURL=foo.js.map' + s2)73}7475test('mapFileComment regex /* */ old spec - @', function (t) {76[ [ '/*@ ', '*/' ]77, [' /*@ ', ' */ ' ]78, [ '\t/*@ ', ' \t*/\t ']79].forEach(function (x) { t.ok(mapFileCommentWrap(x[0], x[1]), 'matches ' + x.join(' :: ')) });8081[ [ '/*/*@ ', '*/' ]82, ['}}/*@ ', ' */ ' ]83, [ ' @/*@ ', ' \t*/\t ']84].forEach(function (x) { t.ok(!mapFileCommentWrap(x[0], x[1]), 'does not match ' + x.join(' :: ')) });85t.end()86})8788test('mapFileComment regex /* */ new spec - #', function (t) {89[ [ '/*# ', '*/' ]90, [' /*# ', ' */ ' ]91, [ '\t/*# ', ' \t*/\t ']92].forEach(function (x) { t.ok(mapFileCommentWrap(x[0], x[1]), 'matches ' + x.join(' :: ')) });9394[ [ '/*/*# ', '*/' ]95, ['}}/*# ', ' */ ' ]96, [ ' #/*# ', ' \t*/\t ']97].forEach(function (x) { t.ok(!mapFileCommentWrap(x[0], x[1]), 'does not match ' + x.join(' :: ')) });98t.end()99})100101102