react / wstein / node_modules / browserify / node_modules / browser-pack / 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(prefix, suffix) {9rx.lastIndex = 0;10return rx.test(prefix + 'sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJmdW5jdGlvbiBmb28oKSB7XG4gY29uc29sZS5sb2coXCJoZWxsbyBJIGFtIGZvb1wiKTtcbiBjb25zb2xlLmxvZyhcIndobyBhcmUgeW91XCIpO1xufVxuXG5mb28oKTtcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9' + suffix)11}1213function commentWithCharSet(prefix, suffix, sep) {14sep = sep || ':';15rx.lastIndex = 0;16return rx.test(prefix + 'sourceMappingURL=data:application/json;charset' + sep +'utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJmdW5jdGlvbiBmb28oKSB7XG4gY29uc29sZS5sb2coXCJoZWxsbyBJIGFtIGZvb1wiKTtcbiBjb25zb2xlLmxvZyhcIndobyBhcmUgeW91XCIpO1xufVxuXG5mb28oKTtcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9' + suffix)17}1819// Source Map v2 Tests20test('comment regex old spec - @', function (t) {21[22'//@ ',23' //@ ', // with leading space24'\t//@ ', // with leading tab25'//@ ', // with leading text26'/*@ ', // multi line style27' /*@ ', // multi line style with leading spaces28'\t/*@ ', // multi line style with leading tab29'/*@ ', // multi line style with leading text30].forEach(function (x) {31t.ok(comment(x, ''), 'matches ' + x)32t.ok(commentWithCharSet(x, ''), 'matches ' + x + ' with charset')33t.ok(commentWithCharSet(x, '', '='), 'matches ' + x + ' with charset')34});3536[37' @// @',38' @/* @',39].forEach(function (x) { t.ok(!comment(x, ''), 'should not match ' + x) })4041t.end()42})4344test('comment regex new spec - #', function (t) {45[46' //# ', // with leading spaces47'\t//# ', // with leading tab48'//# ', // with leading text49'/*# ', // multi line style50' /*# ', // multi line style with leading spaces51'\t/*# ', // multi line style with leading tab52'/*# ', // multi line style with leading text53].forEach(function (x) {54t.ok(comment(x, ''), 'matches ' + x)55t.ok(commentWithCharSet(x, ''), 'matches ' + x + ' with charset')56t.ok(commentWithCharSet(x, '', '='), 'matches ' + x + ' with charset')57});5859[60' #// #',61' #/* #',62].forEach(function (x) { t.ok(!comment(x, ''), 'should not match ' + x) })6364t.end()65})6667function mapFileCommentWrap(s1, s2) {68mapFileRx.lastIndex = 0;69return mapFileRx.test(s1 + 'sourceMappingURL=foo.js.map' + s2)70}7172test('mapFileComment regex old spec - @', function (t) {7374[75['//@ ', ''],76[' //@ ', ''], // with leading spaces77['\t//@ ', ''], // with a leading tab78['///@ ', ''], // with a leading text79[';//@ ', ''], // with a leading text80['return//@ ', ''], // with a leading text81].forEach(function (x) { t.ok(mapFileCommentWrap(x[0], x[1]), 'matches ' + x.join(' :: ')) });8283[84[' @// @', ''],85['var sm = "//@ ', '"'], // not inside a string86['var sm = \'//@ ', '\''], // not inside a string87['var sm = \' //@ ', '\''], // not inside a string88].forEach(function (x) { t.ok(!mapFileCommentWrap(x[0], x[1]), 'does not match ' + x.join(' :: ')) })89t.end()90})9192test('mapFileComment regex new spec - #', function (t) {93[94['//# ', ''],95[' //# ', ''], // with leading space96['\t//# ', ''], // with leading tab97['///# ', ''], // with leading text98[';//# ', ''], // with leading text99['return//# ', ''], // with leading text100].forEach(function (x) { t.ok(mapFileCommentWrap(x[0], x[1]), 'matches ' + x.join(' :: ')) });101102[103[' #// #', ''],104['var sm = "//# ', '"'], // not inside a string105['var sm = \'//# ', '\''], // not inside a string106['var sm = \' //# ', '\''], // not inside a string107].forEach(function (x) { t.ok(!mapFileCommentWrap(x[0], x[1]), 'does not match ' + x.join(' :: ')) })108t.end()109})110111test('mapFileComment regex /* */ old spec - @', function (t) {112[ [ '/*@ ', '*/' ]113, [' /*@ ', ' */ ' ] // with leading spaces114, [ '\t/*@ ', ' \t*/\t '] // with a leading tab115, [ 'leading string/*@ ', '*/' ] // with a leading string116, [ '/*@ ', ' \t*/\t '] // with trailing whitespace117].forEach(function (x) { t.ok(mapFileCommentWrap(x[0], x[1]), 'matches ' + x.join(' :: ')) });118119[ ['/*@ ', ' */ */ ' ], // not the last thing on its line120['/*@ ', ' */ more text ' ] // not the last thing on its line121].forEach(function (x) { t.ok(!mapFileCommentWrap(x[0], x[1]), 'does not match ' + x.join(' :: ')) });122t.end()123})124125test('mapFileComment regex /* */ new spec - #', function (t) {126[ [ '/*# ', '*/' ]127, [' /*# ', ' */ ' ] // with leading spaces128, [ '\t/*# ', ' \t*/\t '] // with a leading tab129, [ 'leading string/*# ', '*/' ] // with a leading string130, [ '/*# ', ' \t*/\t '] // with trailing whitespace131].forEach(function (x) { t.ok(mapFileCommentWrap(x[0], x[1]), 'matches ' + x.join(' :: ')) });132133[ ['/*# ', ' */ */ ' ], // not the last thing on its line134['/*# ', ' */ more text ' ] // not the last thing on its line135].forEach(function (x) { t.ok(!mapFileCommentWrap(x[0], x[1]), 'does not match ' + x.join(' :: ')) });136t.end()137})138139140