<commit_before>goog.require('treesaver.dimensions');

$(function() {
  module("dimensions", {
    setup: function() {
      var container = $('<div id="tmpContainer"></div>')
        .appendTo('body'),
          $el;

      $el = $('<div class="px" />')
              .css({
                position: 'absolute',
                minWidth: '300px',
                maxWidth: '600px',
                minHeight: '500px',
                maxHeight: '1000px',
                marginTop: '10px',
                padding: '5px 15px'
              })
              .appendTo(container)
    },
    teardown: function () {
      $('#tmpContainer').remove();
      $('.testonly').remove();
    }
  });

  //test("sizeInfo", function() {
    //var $px = $('#tmpContainer .px'),
        //dim;

    //dim = play.sizeInfo($px[0]);
    //selectiveSame(dim, {
      //minWidth: 300,
      //width: 300,
      //maxWidth: 600,
      //minHeight: 500,
      //height: 500,
      //maxHeight: 1000,
      //outerWidth: 330,
      //outerHeight: 510,
      //marginHeight: 10,
      //marginWidth: 0
    //}, 'Pixel values');
  //});

  //test('mergeSizeRange', function () {
    //var r1 = play.mergeSizeRange(),
        //r2 = play.mergeSizeRange();

    //same(r1, {
      //width: 0,
      //height: 0,
      //maxWidth: Infinity,
      //maxHeight: Infinity
    //}, 'Default values');
    //r2.width = 100;
    //r2.height = 200;
    //r2.maxHeight = 400;
    //r1 = play.mergeSizeRange(r1, r2);
    //same(r1, {
      //width: 100,
      //height: 200,
      //maxWidth: Infinity,
      //maxHeight: 400
    //}, 'Default values');
  //});

  test('minimax', function() {
    var e = $('<div></div>').addClass('testonly').appendTo('body'),
        size = new treesaver.dimensions.Metrics(e[0]);

    equals(size.minW, 0, 'min-width is 0');
    equals(size.minH, 0, 'min-height is 0');
    equals(size.maxW, Infinity, 'max-width is set to Infinity');
    equals(size.maxH, Infinity, 'max-height is set to Infinity');

    e.css({
      minWidth: 400,
      minHeight: 200
    });

    size = new treesaver.dimensions.Metrics(e[0]);

    equals(size.minW, 400, 'min-width is 400');
    equals(size.minH, 200, 'min-height is 200');

    e.css({
      maxWidth: 800,
      maxHeight: 400
    });

    size = new treesaver.dimensions.Metrics(e[0]);

    equals(size.maxW, 800, 'max-width is set to 800');
    equals(size.maxH, 400, 'max-height is set to 400');
  });

  test('units', function () {
    var e = $('<div></div>').addClass('testonly').appendTo('body').css({
          display: 'block',
          position: 'absolute',
          fontSize: '1em',
          margin: '1em',
          padding: '2em'
        }),
        d = new treesaver.dimensions.Metrics(e[0]);

    equals(d.marginTop, 16);
    equals(d.marginBottom, 16);
    equals(d.paddingTop, 32);
    equals(d.paddingBottom, 32);
  });

  test('offsetHeight', function() {
    var e = $('<div></div>').addClass('testonly').appendTo('body').css({
          fontSize: '14px',
          lineHeight: '20px'
        }),
        h = $('<h2>Hello World</h2>').appendTo(e).css({
          margin: 0,
          padding: 0,
          fontSize: '20px'
        }),
        d = new treesaver.dimensions.Metrics(e[0]);

    equals(d.outerH, 20);
  });

  test('lineHeight', function() {
    var e = $('<div></div>').addClass('testonly').appendTo('body').css({
          fontSize: '14px',
          lineHeight: '20px'
        }),
        h = $('<h2>Hello World</h2>').appendTo(e).css({
          margin: 0,
          padding: 0,
          fontSize: '20px'
        }),
        d = new treesaver.dimensions.Metrics(e[0]);

    equals(d.lineHeight, 20);
  });

  test('helpers', function () {
    var range = {
      minW: 100,
      maxW: 200,
      minH: 300,
      maxH: 400
    };

    ok(treesaver.dimensions.inSizeRange(range, { w: 100, h: 300}), "withinSizeRange: Min boundary");
    ok(treesaver.dimensions.inSizeRange(range, { w: 200, h: 400}), "withinSizeRange: Max boundary");
    ok(!treesaver.dimensions.inSizeRange(range, { w: 20, h: 400 }), "withinSizeRange: Under width");
    ok(!treesaver.dimensions.inSizeRange(range, { w: 200, h: 4000}), "withinSizeRange: Over height");

    equals(treesaver.dimensions.toPixels(null, '40px'), 40, 'toPixels');
    ok(!treesaver.dimensions.toPixels('1em'), 'toPixels: Non-px value');
  });
});<commit_msg>Add a simple test for sub-pixels in lineHeight.<commit_after>goog.require('treesaver.dimensions');
goog.require('treesaver.capabilities');

$(function() {
  module("dimensions", {
    setup: function() {
      var container = $('<div id="tmpContainer"></div>')
        .appendTo('body'),
          $el;

      $el = $('<div class="px" />')
              .css({
                position: 'absolute',
                minWidth: '300px',
                maxWidth: '600px',
                minHeight: '500px',
                maxHeight: '1000px',
                marginTop: '10px',
                padding: '5px 15px'
              })
              .appendTo(container)
    },
    teardown: function () {
      $('#tmpContainer').remove();
      $('.testonly').remove();
    }
  });

  //test("sizeInfo", function() {
    //var $px = $('#tmpContainer .px'),
        //dim;

    //dim = play.sizeInfo($px[0]);
    //selectiveSame(dim, {
      //minWidth: 300,
      //width: 300,
      //maxWidth: 600,
      //minHeight: 500,
      //height: 500,
      //maxHeight: 1000,
      //outerWidth: 330,
      //outerHeight: 510,
      //marginHeight: 10,
      //marginWidth: 0
    //}, 'Pixel values');
  //});

  //test('mergeSizeRange', function () {
    //var r1 = play.mergeSizeRange(),
        //r2 = play.mergeSizeRange();

    //same(r1, {
      //width: 0,
      //height: 0,
      //maxWidth: Infinity,
      //maxHeight: Infinity
    //}, 'Default values');
    //r2.width = 100;
    //r2.height = 200;
    //r2.maxHeight = 400;
    //r1 = play.mergeSizeRange(r1, r2);
    //same(r1, {
      //width: 100,
      //height: 200,
      //maxWidth: Infinity,
      //maxHeight: 400
    //}, 'Default values');
  //});

  test('minimax', function() {
    var e = $('<div></div>').addClass('testonly').appendTo('body'),
        size = new treesaver.dimensions.Metrics(e[0]);

    equals(size.minW, 0, 'min-width is 0');
    equals(size.minH, 0, 'min-height is 0');
    equals(size.maxW, Infinity, 'max-width is set to Infinity');
    equals(size.maxH, Infinity, 'max-height is set to Infinity');

    e.css({
      minWidth: 400,
      minHeight: 200
    });

    size = new treesaver.dimensions.Metrics(e[0]);

    equals(size.minW, 400, 'min-width is 400');
    equals(size.minH, 200, 'min-height is 200');

    e.css({
      maxWidth: 800,
      maxHeight: 400
    });

    size = new treesaver.dimensions.Metrics(e[0]);

    equals(size.maxW, 800, 'max-width is set to 800');
    equals(size.maxH, 400, 'max-height is set to 400');
  });

  test('units', function () {
    var e = $('<div></div>').addClass('testonly').appendTo('body').css({
          display: 'block',
          position: 'absolute',
          fontSize: '1em',
          margin: '1em',
          padding: '2em'
        }),
        d = new treesaver.dimensions.Metrics(e[0]);

    equals(d.marginTop, 16);
    equals(d.marginBottom, 16);
    equals(d.paddingTop, 32);
    equals(d.paddingBottom, 32);
  });

  test('offsetHeight', function() {
    var e = $('<div></div>').addClass('testonly').appendTo('body').css({
          fontSize: '14px',
          lineHeight: '20px'
        }),
        h = $('<h2>Hello World</h2>').appendTo(e).css({
          margin: 0,
          padding: 0,
          fontSize: '20px'
        }),
        d = new treesaver.dimensions.Metrics(e[0]);

    equals(d.outerH, 20);
  });

  test('lineHeight', function() {
    var e = $('<div></div>').addClass('testonly').appendTo('body').css({
          fontSize: '14px',
          lineHeight: '20px'
        }),
        h = $('<h2>Hello World</h2>').appendTo(e).css({
          margin: 0,
          padding: 0,
          fontSize: '20px'
        }),
        d = new treesaver.dimensions.Metrics(e[0]);

    equals(d.lineHeight, 20);
  });

  test('lineHeight with subpixels', function() {
    var e = $('<div></div>').addClass('testonly').appendTo('body').css({
          fontSize: '14px',
          lineHeight: '1.45em'
        }),
        h = $('<h2>Hello World</h2>').appendTo(e).css({
          margin: 0,
          padding: 0,
          fontSize: '1.45em'
        }),
        d = new treesaver.dimensions.Metrics(e[0]);

    if (treesaver.capabilities.SUPPORTS_SUBPIXELS) {
      equals((20.3 - d.lineHeight) < 0.001, true);
    } else {
      equals(d.lineHeight, 20);
    }
  });

  test('helpers', function () {
    var range = {
      minW: 100,
      maxW: 200,
      minH: 300,
      maxH: 400
    };

    ok(treesaver.dimensions.inSizeRange(range, { w: 100, h: 300}), "withinSizeRange: Min boundary");
    ok(treesaver.dimensions.inSizeRange(range, { w: 200, h: 400}), "withinSizeRange: Max boundary");
    ok(!treesaver.dimensions.inSizeRange(range, { w: 20, h: 400 }), "withinSizeRange: Under width");
    ok(!treesaver.dimensions.inSizeRange(range, { w: 200, h: 4000}), "withinSizeRange: Over height");

    equals(treesaver.dimensions.toPixels(null, '40px'), 40, 'toPixels');
    ok(!treesaver.dimensions.toPixels('1em'), 'toPixels: Non-px value');
  });
});
{'fraction_non_alphanumeric': 0.19140791152700978, 'fraction_numerical': 0.04466184602296895, 'mean_word_length': 2.164535666218035, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 37, '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': '6300191', 'n_tokens_mistral': 3532, 'n_tokens_neox': 3117, 'n_words': 642}