<commit_before>var test = require('tape');
var fs   = require('fs');
var path = require('path');

var parse = require('../');

test('throws errors using invalid params', function(is) {
  is.plan(4);

  is.throws(parse, 'throws without params');
  is.throws(function() {
    parse('');
  }, 'throws without object name');
  is.throws(function() {
    parse('has-dash');
  }, 'throws if object name has dashes');
  is.throws(function() {
    parse('test');
  }, 'throws without ocss');
});

var cases = fs.readdirSync(path.join(__dirname, 'cases'));

cases.forEach(function(name) {

  test(name, function(is) {
    var dir    = path.join(__dirname, 'cases', name);
    var source = path.join(dir, 'test.ocss');
    var ast    = path.join(dir, 'ast.json');

    var actual = parse('test', readFile(source));
    var expected = JSON.parse(readFile(ast));

    is.same(actual, expected, name);
    is.end();
  });

});

function readFile(file) {
  var src = fs.readFileSync(file, 'utf8');
  src = src.replace(/\r\n/, '\n'); // normalize line endings
  return src;
}<commit_msg>add too much indentation test<commit_after>var test = require('tape');
var fs   = require('fs');
var path = require('path');

var parse = require('../');

test('params', function(is) {
  is.plan(4);

  is.throws(parse, 'throws without params');
  is.throws(function() {
    parse('');
  }, 'throws without object name');
  is.throws(function() {
    parse('has-dash');
  }, 'throws if object name has dashes');
  is.throws(function() {
    parse('test');
  }, 'throws without ocss');
});

test('indentation', function(is) {
  is.plan(1);

  is.throws(function() {
    parse('test', 'element\n\t\tdisplay: block');
  }, 'too much indentation');
});

var cases = fs.readdirSync(path.join(__dirname, 'cases'));

cases.forEach(function(name) {

  test(name, function(is) {
    var dir    = path.join(__dirname, 'cases', name);
    var source = path.join(dir, 'test.ocss');
    var ast    = path.join(dir, 'ast.json');

    var actual = parse('test', readFile(source));
    var expected = JSON.parse(readFile(ast));

    is.same(actual, expected, name);
    is.end();
  });

});

function readFile(file) {
  var src = fs.readFileSync(file, 'utf8');
  src = src.replace(/\r\n/, '\n'); // normalize line endings
  return src;
}
{'fraction_non_alphanumeric': 0.19764397905759162, 'fraction_numerical': 0.002181500872600349, 'mean_word_length': 3.737603305785124, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '293104', 'n_tokens_mistral': 781, 'n_tokens_neox': 767, 'n_words': 184}