<commit_before>var assert = require("assert");
var parse = require("./index");

describe("json-template", function() {

  describe("strings", function() {

    it("should compute template for a string with a single parameter", function() {
      var template = parse("{{foo}}");
      assert.equal(template({ foo: "bar" }), "bar");
      assert.deepEqual(template.parameters, [{ key: "foo" }]);
    });

    it("should compute template for strings with no parameters", function() {
      [
        "foo",
        "{{}}",
        "}}{{",
        "}}foo{{"
      ].forEach(function (value){
        var template = parse(value);
        assert.equal(template(), value);
        assert.deepEqual(template.parameters, []);
      });
    });

    it("should compute template with default for a string", function() {
      var template = parse("{{foo:bar}}");
      assert.equal(template(), "bar");
      assert.equal(template({ foo: "baz" }), "baz");
      assert.equal(template({ unknownParam: "baz" }), "bar");
      assert.deepEqual(template.parameters, [
        {
          key: "foo",
          defaultValue: "bar"
        }
      ]);
    });

  });


  describe("objects", function() {

    it("should compute template with an object", function() {
      var template = parse({ title: "{{foo}}"});
      assert.deepEqual(template({ foo: "bar" }), { title: "bar" });
      assert.deepEqual(template.parameters, [{ key: "foo" }]);
    });

  });
});

// "{{}}"
// "}}{{"
// "}}foo{{"
// "{{foo:bar:baz}}"

//
//var template = parse({ "PersonName": "{{person}}" });
//expect(template.parameters).to.equal(
//  [
//    {
//      key: "person",
//      path: ["PersonName"]
//    }
//  ]
//);
//expect(template({ person: "Susanna" })).to.equal(
//  { "PersonName": "Susanna" }
//);
//
//{ "PersonName": "{{person:Bob}}" }
//
//[
//  {
//    key: "person",
//    defaultValue: "Bob",
//    path: ["PersonName"]
//  }
//]
//
//{ "gte": "{{startDate:now-24h}}" }
//{ "index": "{{index}}" }


<commit_msg>Add test with nested objects<commit_after>var assert = require("assert");
var parse = require("./index");

describe("json-template", function() {

  describe("strings", function() {

    it("should compute template for a string with a single parameter", function() {
      var template = parse("{{foo}}");
      assert.equal(template({ foo: "bar" }), "bar");
      assert.deepEqual(template.parameters, [{ key: "foo" }]);
    });

    it("should compute template for strings with no parameters", function() {
      [
        "foo",
        "{{}}",
        "}}{{",
        "}}foo{{"
      ].forEach(function (value){
        var template = parse(value);
        assert.equal(template(), value);
        assert.deepEqual(template.parameters, []);
      });
    });

    it("should compute template with default for a string", function() {
      var template = parse("{{foo:bar}}");
      assert.equal(template(), "bar");
      assert.equal(template({ foo: "baz" }), "baz");
      assert.equal(template({ unknownParam: "baz" }), "bar");
      assert.deepEqual(template.parameters, [
        {
          key: "foo",
          defaultValue: "bar"
        }
      ]);
    });

  });


  describe("objects", function() {

    it("should compute template with an object", function() {
      var template = parse({ title: "{{foo}}"});
      assert.deepEqual(template({ foo: "bar" }), { title: "bar" });
      assert.deepEqual(template.parameters, [{ key: "foo" }]);
    });

    it("should compute template with nested objects", function() {
      var template = parse({
        body: {
          title: "{{foo}}"
        }
      });
      assert.deepEqual(template({ foo: "bar" }), { body: { title: "bar" }});
      assert.deepEqual(template.parameters, [{ key: "foo" }]);
    });

  });
});

// "{{}}"
// "}}{{"
// "}}foo{{"
// "{{foo:bar:baz}}"

//
//var template = parse({ "PersonName": "{{person}}" });
//expect(template.parameters).to.equal(
//  [
//    {
//      key: "person",
//      path: ["PersonName"]
//    }
//  ]
//);
//expect(template({ person: "Susanna" })).to.equal(
//  { "PersonName": "Susanna" }
//);
//
//{ "PersonName": "{{person:Bob}}" }
//
//[
//  {
//    key: "person",
//    defaultValue: "Bob",
//    path: ["PersonName"]
//  }
//]
//
//{ "gte": "{{startDate:now-24h}}" }
//{ "index": "{{index}}" }



{'fraction_non_alphanumeric': 0.23650683344915452, 'fraction_numerical': 0.000926569376882094, 'mean_word_length': 2.5364455364455365, 'pattern_counts': {'":': 10, '<': 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': '2412866', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1363, 'n_words': 284}