<commit_before>'use strict';

var assert = require('chai').assert;
var cheerio = require('cheerio');
var HTMLUglify = require('../lib/main.js');

var htmlUglify = new HTMLUglify();

describe('HTMLUglify', function() {
  describe('#isWhitelisted', function() {
    var whitelist;
    var htmlUglify;

    beforeEach(function() {
      whitelist = ['#theid', '.theclass'];
      htmlUglify = new HTMLUglify({whitelist: whitelist});
    });
    it('returns true if id is in whitelist', function() {
      var whitelisted = htmlUglify.isWhitelisted('id', 'theid')
      assert.isTrue(whitelisted);
    });
    it('returns false if id is in the whitelist but only checking for classes', function() {
      var whitelisted = htmlUglify.isWhitelisted('class', 'theid')
      assert.isFalse(whitelisted);
    });
    it('returns true if class is in whitelist', function() {
      var whitelisted = htmlUglify.isWhitelisted('class', 'theclass')
      assert.isTrue(whitelisted);
    });
  });
  describe('#rewriteStyles', function() {
    it('rewrites an id given lookups', function() {
      var lookups = { 'id=abe': 'xz' };
      var html = '<style>#abe{ color: red; }</style>';
      var $ = cheerio.load(html);
      var results = htmlUglify.rewriteStyles($, lookups).html();
      assert.equal(results, '<style>#xz{ color: red; }</style>');
    });
    it('does not rewrite an id given no lookups', function() {
      var lookups = { };
      var html = '<style>#abe{ color: red; }</style>';
      var $ = cheerio.load(html);
      var results = htmlUglify.rewriteStyles($, lookups).html();
      assert.equal(results, '<style>#abe{ color: red; }</style>');
    });
    it('rewrites an id with the same name as the element', function() {
      var lookups = { 'id=label': 'ab' };
      var html = '<style>label#label{ color: blue; }</style>';<commit_msg>Add test showing unicode id and class<commit_after>'use strict';

var assert = require('chai').assert;
var cheerio = require('cheerio');
var HTMLUglify = require('../lib/main.js');

var htmlUglify = new HTMLUglify();

describe('HTMLUglify', function() {
  describe('#isWhitelisted', function() {
    var whitelist;
    var htmlUglify;

    beforeEach(function() {
      whitelist = ['#theid', '.theclass', '#★', '.★'];
      htmlUglify = new HTMLUglify({whitelist: whitelist});
    });
    it('returns true if id is in whitelist', function() {
      var whitelisted = htmlUglify.isWhitelisted('id', 'theid')
      assert.isTrue(whitelisted);
    });
    it('returns false if id is in the whitelist but only checking for classes', function() {
      var whitelisted = htmlUglify.isWhitelisted('class', 'theid')
      assert.isFalse(whitelisted);
    });
    it('returns true if class is in whitelist', function() {
      var whitelisted = htmlUglify.isWhitelisted('class', 'theclass')
      assert.isTrue(whitelisted);
    });
    it('returns true if id is in whitelist for a unicode character', function() {
      var whitelisted = htmlUglify.isWhitelisted('id', '★')
      assert.isTrue(whitelisted);
    });
    it('returns true if class is in whitelist for a unicode character', function() {
      var whitelisted = htmlUglify.isWhitelisted('class', '★')
      assert.isTrue(whitelisted);
    });
  });
  describe('#rewriteStyles', function() {
    it('rewrites an id given lookups', function() {
      var lookups = { 'id=abe': 'xz' };
      var html = '<style>#abe{ color: red; }</style>';
      var $ = cheerio.load(html);
      var results = htmlUglify.rewriteStyles($, lookups).html();
      assert.equal(results, '<style>#xz{ color: red; }</style>');
    });
    it('does not rewrite an id given no lookups', function() {
      var lookups = { };
      var html = '<style>#abe{ color: red; }</style>';
      var $ = cheerio.load(html);
      var results = htmlUglify.rewriteStyles($, lookups).html();
      assert.equal(results, '<style>#abe{ color: red; }</style>');
    });
    it('rewrites an id with the same name as the element', function() {
      var lookups = { 'id=label': 'ab' };
      var html = '<style>label#label{ color: blue; }</style>';
{'fraction_non_alphanumeric': 0.16731517509727625, 'fraction_numerical': 0.0, 'mean_word_length': 3.4706521739130434, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6147317', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1314, 'n_words': 349}