UNPKG

tprompter

Version:
49 lines (48 loc) 2.66 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { PromptsEngine } from './PromptEngine.js'; describe(PromptsEngine.name, () => { describe('compile', () => { it('example 1', () => __awaiter(void 0, void 0, void 0, function* () { const fn = PromptsEngine.compile('Hello, ${name}!'); expect(fn({ name: 'world' })).resolves.toEqual('Hello, world!'); })); it('example 2', () => __awaiter(void 0, void 0, void 0, function* () { const fn = PromptsEngine.compile('Hello'); expect(fn()).resolves.toEqual('Hello'); })); it('example 3', () => __awaiter(void 0, void 0, void 0, function* () { const fn = PromptsEngine.compile('${callable("world")}'); expect(fn({ callable: (name) => `Hello, ${name}!` })).resolves.toEqual('Hello, world!'); })); it('example 4', () => __awaiter(void 0, void 0, void 0, function* () { const fn = PromptsEngine.compile('${callable(3 + 5)}'); expect(fn({ callable: (a) => a })).resolves.toEqual('8'); })); it('multiple components', () => __awaiter(void 0, void 0, void 0, function* () { const fn = PromptsEngine.compile('${a} ${b} ${c}!'); expect(fn({ a: 'Hello', b: 'world', c: '!' })).resolves.toEqual('Hello world !!'); })); it('empty template', () => __awaiter(void 0, void 0, void 0, function* () { const fn = PromptsEngine.compile(''); expect(fn()).resolves.toEqual(''); })); it('empty template', () => __awaiter(void 0, void 0, void 0, function* () { const fn = PromptsEngine.compile('${+new Date(0)}'); expect(fn()).resolves.toEqual('0'); })); it('empty template', () => __awaiter(void 0, void 0, void 0, function* () { const fn = PromptsEngine.compile('${a()}'); expect(yield fn({ a: () => Promise.resolve(1), })).toEqual('1'); })); }); });