'use strict';
// Tests for HTML comments;
const decomment = require('../lib');
const os = require('os');
const LB = os.EOL;
describe('HTML:', function () {
describe('empty html', function () {
it('must be intact', function () {
expect(decomment('<>/*hello*/')).toBe('<>/*hello*/');
expect(decomment('//something')).toBe('//something');
});
});
describe('single-line comment', function () {
it('must be gone', function () {
expect(decomment('')).toBe('');
expect(decomment('' + LB)).toBe('');
// note: spaces and tabs are removed from empty lines;
expect(decomment('\t \t ' + LB)).toBe('');
});
});
describe('multi-line comment', function () {
it('must be gone', function () {
expect(decomment('')).toBe('');
});
});
describe('unclosed comment', function () {
it('must be gone', function () {
expect(decomment('text')).toBe('text');
expect(decomment('\ttext')).toBe('\ttext');
});
});
describe('with prefix text', function () {
it('only the text must be left', function () {
expect(decomment('prefix')).toBe('prefix');
expect(decomment('prefix' + LB)).toBe('prefix' + LB);
});
});
describe('with space=true', function () {
it('must return the preceding text', function () {
expect(decomment.html('Text', {space: true})).toBe('Text');
expect(decomment.html(LB + 'Text', {space: true})).toBe(LB + 'Text');
expect(decomment.html('Text' + LB + '', {space: true})).toBe('Text' + LB);
expect(decomment.html('Text' + LB + 'Here', {space: true})).toBe('Text' + LB + 'Here');
});
});
describe('with preceding text', function () {
it('must return the preceding text', function () {
expect(decomment.html('Text')).toBe('Text');
expect(decomment.html(LB + 'Text')).toBe(LB + 'Text');
expect(decomment.html('Text' + LB + '')).toBe('Text' + LB);
expect(decomment.html('Text' + LB + 'Here')).toBe('Text' + LB + 'Here');
});
});
describe('Explicit HTML call', function () {
it('must process it as HTML always', function () {
expect(decomment.html('text')).toBe('text');
});
});
describe('starting comments suffixed by spaces', function () {
it('must remove comment and spaces', function () {
expect(decomment(' ' + LB + 'next')).toBe('next');
expect(decomment(' ' + LB + 'next')).toBe('next');
expect(decomment(' \t ' + LB + 'next')).toBe('next');
expect(decomment(' \t \t ' + LB + 'next')).toBe('next');
});
});
describe('starting comments suffixed by text, space=false', function () {
it('must remove comment and preserve the suffix', function () {
expect(decomment('text' + LB + 'next')).toBe('text' + LB + 'next');
});
});
describe('starting comments suffixed by text, space=true', function () {
it('must replace comment with white spaces and preserve the suffix', function () {
expect(decomment('text' + LB + 'next', {space: true})).toBe(' text' + LB + 'next');
});
});
describe('across lines, with space=false', function () {
it('must delete all lines', function () {
expect(decomment('')).toBe('');
expect(decomment('text')).toBe('text');
expect(decomment.html('prefix-suffix')).toBe('prefix-suffix');
});
});
describe('across lines, with space=true', function () {
it('must replace deleted lines with line break', function () {
expect(decomment.html('prefixsuffix', {space: true})).toBe('prefix suffix');
expect(decomment('text' + LB, {space: true})).toBe(LB + LB + ' text' + LB);
expect(decomment('\ttext', {space: true})).toBe(LB + LB + ' \ttext');
expect(decomment('', {space: true})).toBe(LB + LB);
expect(decomment('text', {space: true})).toBe(LB + LB + ' text');
expect(decomment.html('prefixsuffix', {space: true})).toBe('prefix' + LB + LB + ' suffix');
});
});
});
describe('HTML-IE', function () {
describe('Safe', function () {
it('must keep all IE comments', function () {
expect(decomment('', {safe: true})).toBe('');
expect(decomment('', {safe: true})).toBe('');
});
});
describe('Not Safe', function () {
it('must delete all IE comments', function () {
expect(decomment('')).toBe('');
expect(decomment('')).toBe('');
expect(decomment.html(' prefix ' + LB + '' + ' suffix ')).toBe(' prefix ' + LB + ' suffix ');
});
});
});