reel-of-js-fortune/test/util/gin.test.ts

81 lines
No EOL
1.8 KiB
TypeScript

import { describe, it, expect } from 'bun:test'
import { Gin } from '../../src/util/gin'
describe('Gin template porting test', () => {
it('parse', async () => {
const example =
`Dear {{.Name}},
{{if .Attended}}
It was a pleasure to see you at the wedding.
{{- else}}
It is a shame you couldn't make it to the wedding.
{{- end}}
{{with .Gift -}}
Thank you for the lovely {{.}}.
{{end}}
Best wishes,
Josie`;
const template = {
name: 'example',
root: Gin.parse(example)
};
const data = [
{
Name: 'Aunt Mildred',
Gift: 'bone china tea set',
Attended: true,
},
{
Name: 'Uncle John',
Gift: 'moleskin pants',
Attended: false,
},
{
Name: 'Cousin Rodney',
Gift: '',
Attended: false,
},
]
const expected =
`Dear Aunt Mildred,
It was a pleasure to see you at the wedding.
Thank you for the lovely bone china tea set.
Best wishes,
Josie
Dear Uncle John,
It is a shame you couldn't make it to the wedding.
Thank you for the lovely moleskin pants.
Best wishes,
Josie
Dear Cousin Rodney,
It is a shame you couldn't make it to the wedding.
Best wishes,
Josie`
const actual = data.map(r => Gin.execute(template, r)).join('\n');
console.log(actual)
expect(actual).toEqual(expected);
})
// it('parseGlob', async () => {
// const gin = new Gin();
// const paths = await gin.parseGlob('public/**/*html');
// })
// it('parseHTML', async () => {
// const gin = new Gin();
// const text = await gin.parseHTML('public/pages/movie.html');
// console.log(text);
// })
})