<commit_before><commit_msg>Add some tests using Mocha.<commit_after>var ManifestParser = require('../manifest-parser.js');
var assert = require('assert');

describe('Manifest Parser', function() {
  it('should not parse empty string input', function() {
    ManifestParser.parse('');
    assert.equal(false, ManifestParser.success());
  });

  it('has empty values when parsing empty manifest', function() {
    ManifestParser.parse('');
    assert.equal(null, ManifestParser.manifest().name);
    assert.equal(null, ManifestParser.manifest().short_name);
    assert.equal(null, ManifestParser.manifest().start_url);
    assert.equal(null, ManifestParser.manifest().display);
    assert.equal(null, ManifestParser.manifest().orientation);
    assert.equal(null, ManifestParser.manifest().theme_color);
    assert.equal(null, ManifestParser.manifest().background_color);
  });

  it('accepts empty dictionary', function() {
    ManifestParser.parse('{}');
    assert.equal(true, ManifestParser.success());
    assert.equal(null, ManifestParser.manifest().name);
    assert.equal(null, ManifestParser.manifest().short_name);
    assert.equal(null, ManifestParser.manifest().start_url);
    assert.equal(null, ManifestParser.manifest().display);
    assert.equal(null, ManifestParser.manifest().orientation);
    assert.equal(null, ManifestParser.manifest().theme_color);
    assert.equal(null, ManifestParser.manifest().background_color);
    // TODO:
    // icons
    // related_applications
    // prefer_related_applications
  });

  it('accepts unknown values', function() {
    ManifestParser.parse('{}');
    assert.equal(true, ManifestParser.success());
    assert.equal(null, ManifestParser.manifest().name);
    assert.equal(null, ManifestParser.manifest().short_name);
    assert.equal(null, ManifestParser.manifest().start_url);
    assert.equal(null, ManifestParser.manifest().display);
    assert.equal(null, ManifestParser.manifest().orientation);
    assert.equal(null, ManifestParser.manifest().theme_color);
    assert.equal(null, ManifestParser.manifest().background_color);
  });

  describe('name parsing', function() {
    it('it parses basic string', function() {
      ManifestParser.parse('{"name":"foo"}')
      assert.equal(true, ManifestParser.success());
      assert.equal('foo', ManifestParser.manifest().name);
    });

    it('it trims whitespaces', function() {
      ManifestParser.parse('{"name":" foo "}')
      assert.equal(true, ManifestParser.success());
      assert.equal('foo', ManifestParser.manifest().name);
    });

    it('doesn\'t parse non-string', function() {
      ManifestParser.parse('{"name": {} }')
      assert.equal(true, ManifestParser.success());
      assert.equal(null, ManifestParser.manifest().name);

      ManifestParser.parse('{"name": 42 }')
      assert.equal(true, ManifestParser.success());
      assert.equal(null, ManifestParser.manifest().name);
    });
  });

  describe('short_name parsing', function() {
    it('it parses basic string', function() {
      ManifestParser.parse('{"short_name":"foo"}')
      assert.equal(true, ManifestParser.success());
      assert.equal('foo', ManifestParser.manifest().short_name);
    });

    it('it trims whitespaces', function() {
      ManifestParser.parse('{"short_name":" foo "}')
      assert.equal(true, ManifestParser.success());
      assert.equal('foo', ManifestParser.manifest().short_name);
    });

    it('doesn\'t parse non-string', function() {
      ManifestParser.parse('{"short_name": {} }')
      assert.equal(true, ManifestParser.success());
      assert.equal(null, ManifestParser.manifest().short_name);

      ManifestParser.parse('{"short_name": 42 }')
      assert.equal(true, ManifestParser.success());
      assert.equal(null, ManifestParser.manifest().short_name);
    });
  });
});
{'fraction_non_alphanumeric': 0.16893305439330544, 'fraction_numerical': 0.0010460251046025104, 'mean_word_length': 4.440967283072546, 'pattern_counts': {'":': 8, '<': 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': '5501437', 'n_tokens_mistral': 1140, 'n_tokens_neox': 1084, 'n_words': 168}