{"size": 1633, "ext": "js", "max_stars_repo_path": "lib/__tests__/template_string.test.js", "max_stars_repo_name": "vandium-io/vandium-utils", "max_stars_repo_stars_event_min_datetime": "2017-10-03T19:16:55.000Z", "max_stars_repo_stars_event_max_datetime": "2017-10-03T19:16:55.000Z", "max_issues_repo_path": "lib/__tests__/template_string.test.js", "max_issues_repo_name": "vandium-io/vandium-utils", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/__tests__/template_string.test.js", "max_forks_repo_name": "vandium-io/vandium-utils", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 40.825, "max_line_length": 115, "alphanum_fraction": 0.538273117}
'use strict';

/*jshint expr: true*/

var expect = require( 'chai' ).expect;

var templateString = require( '../template_string' );

describe( 'lib/template_string', function() {

    [
        [ 'basic case', 'Hello ${name}', { name: 'Fred' }, 'Hello Fred' ],
        [ 'basic case with spaces', 'Hello ${ name }', { name: 'Fred' }, 'Hello Fred' ],
        [ 'template string only', '${name}', { name: 'Fred' }, 'Fred' ],
        [ 'multiple values', '${last}, ${first}', { first: 'Fred', last: 'Smith' }, 'Smith, Fred' ],
        [ 'multiple values, via container object', '${user.last}, ${user.first}',
            { user: { first: 'Fred', last: 'Smith' } }, 'Smith, Fred' ],
        [ 'non-string values', 'I am ${age} years old', { age: 42 }, 'I am 42 years old' ],
        [ 'missing value, simple case', 'Hello ${name}', { person: 'Fred' }, 'Hello undefined' ],
        [ 'missing value, object case', 'Hello ${person.name}', { person: { first: 'Fred' } }, 'Hello undefined' ],
        [ 'missing value, value is not object', 'Hello ${person.name}', { person: 'Fred' }, 'Hello undefined' ],
        [ 'escaped case', 'Hello \\${name}', { name: 'Fred' }, 'Hello \\${name}' ],
        [ 'missing state object', 'Hello ${name}', undefined, 'Hello undefined' ],

    ].forEach( function( testCase ) {

        it( testCase[0], function() {

            let result = templateString( testCase[1], testCase[2] );

            expect( result ).to.equal( testCase[3] );
        });
    });

    it( 'missing string case', function() {

        expect( templateString( undefined, { name: 'Fred' } ) ).to.equal( undefined );
    });
});
