add extended variable checking

This commit is contained in:
2017-05-01 16:57:53 +02:00
parent 4967bd6a60
commit 2b50191093
17 changed files with 415 additions and 118 deletions

1
test/test.d.ts vendored
View File

@ -1 +0,0 @@
import 'typings-test';

View File

@ -1,17 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("typings-test");
const smarthbs = require("../dist/index");
const path = require("path");
let testHbsDir = path.join(__dirname, 'hbs_testfiles');
let testPartialDir = path.join(testHbsDir, 'partials');
let testResultDir = path.join(__dirname, 'testresult');
describe('smarthbs', function () {
it('should create partials', function () {
smarthbs.registerPartialDir(testPartialDir);
});
it('should compile a directory', function () {
smarthbs.compileDirectory(testHbsDir, testResultDir, 'data.json');
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSx3QkFBcUI7QUFDckIsMENBQXlDO0FBQ3pDLDZCQUE0QjtBQUU1QixJQUFJLFVBQVUsR0FBRyxJQUFJLENBQUMsSUFBSSxDQUFDLFNBQVMsRUFBRSxlQUFlLENBQUMsQ0FBQTtBQUN0RCxJQUFJLGNBQWMsR0FBRyxJQUFJLENBQUMsSUFBSSxDQUFDLFVBQVUsRUFBRSxVQUFVLENBQUMsQ0FBQTtBQUN0RCxJQUFJLGFBQWEsR0FBRyxJQUFJLENBQUUsSUFBSSxDQUFDLFNBQVMsRUFBRSxZQUFZLENBQUMsQ0FBQTtBQUN2RCxRQUFRLENBQUMsVUFBVSxFQUFFO0lBRWpCLEVBQUUsQ0FBQyx3QkFBd0IsRUFBRTtRQUN6QixRQUFRLENBQUMsa0JBQWtCLENBQUMsY0FBYyxDQUFDLENBQUE7SUFDL0MsQ0FBQyxDQUFDLENBQUE7SUFFRixFQUFFLENBQUMsNEJBQTRCLEVBQUU7UUFDN0IsUUFBUSxDQUFDLGdCQUFnQixDQUFDLFVBQVUsRUFBRSxhQUFhLEVBQUUsV0FBVyxDQUFDLENBQUE7SUFDckUsQ0FBQyxDQUFDLENBQUE7QUFFTixDQUFDLENBQUMsQ0FBQSJ9

View File

@ -1,18 +1,38 @@
import 'typings-test'
import { expect, tap } from 'tapbundle'
import * as smarthbs from '../dist/index'
import * as path from 'path'
let testHbsDir = path.join(__dirname, 'hbs_testfiles')
let testPartialDir = path.join(testHbsDir, 'partials')
let testResultDir = path .join(__dirname, 'testresult')
describe('smarthbs', function() {
it('should create partials', function(){
smarthbs.registerPartialDir(testPartialDir)
})
let testResultDir = path.join(__dirname, 'testresult')
tap.test('smarthbs -> should create partials', async () => {
await smarthbs.registerPartialDir(testPartialDir)
})
it('should compile a directory', function() {
smarthbs.compileDirectory(testHbsDir, testResultDir, 'data.json')
})
tap.test('smarthbs -> should compile a directory', async () => {
smarthbs.compileDirectory(testHbsDir, testResultDir, 'data.json')
})
})
tap.test('', async () => {
let templateString = '{{{firstVar}}} {{secondVar}}'
let templateVars = await smarthbs.findVarsInHbsString(templateString)
expect(templateVars).to.include('firstVar')
expect(templateVars).to.include('secondVar')
})
tap.test('', async () => {
let templateString = '{{{firstVar}}} {{secondVar}} {{thirdVar}} {{fourthVar}} {{fourthVar.someKey}} {{fourthVar.otherKey.nextKey}}'
let missingVars = await smarthbs.checkVarsSatisfaction(templateString, {
firstVar: 'hi',
secondVar: 'hello',
fourthVar: {
otherKey: {
nextKey: 'wow'
}
}
})
expect(missingVars).to.contain('thirdVar', 'fourthVar.someKey')
expect(missingVars).to.not.contain('secondVar', 'fourthVar.otherKey.nextKey')
})
tap.start()