|
| 1 | +import { generate } from '../../src/ts' |
| 2 | +import { readFile, validateSyntax } from '../utils' |
| 3 | + |
| 4 | +test('simple', async () => { |
| 5 | + const { source } = await readFile('./fixtures/codegen/simple.ts') |
| 6 | + const { code } = generate(source, { |
| 7 | + sourceMap: true, |
| 8 | + env: 'development' |
| 9 | + }) |
| 10 | + |
| 11 | + expect(validateSyntax(code)).toBe(true) |
| 12 | + expect(code).toMatchInlineSnapshot(` |
| 13 | + "const resource = { |
| 14 | + "hi": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize(["hi there!"])};fn.source="hi there!";return fn;})(), |
| 15 | + "hello": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize(["hello world!"])};fn.source="hello world!";return fn;})(), |
| 16 | + "named": (()=>{const fn=(ctx) => {const { normalize: _normalize, interpolate: _interpolate, named: _named } = ctx;return _normalize(["hi, ", _interpolate(_named("name")), " !"])};fn.source="hi, {name} !";return fn;})(), |
| 17 | + "list": (()=>{const fn=(ctx) => {const { normalize: _normalize, interpolate: _interpolate, list: _list } = ctx;return _normalize(["hi, ", _interpolate(_list(0)), " !"])};fn.source="hi, {0} !";return fn;})(), |
| 18 | + "literal": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize(["hi, ", "kazupon", " !"])};fn.source="hi, { 'kazupon' } !";return fn;})(), |
| 19 | + "linked": (()=>{const fn=(ctx) => {const { normalize: _normalize, linked: _linked, type: _type } = ctx;return _normalize(["hi, ", _linked("name", undefined, _type), " !"])};fn.source="hi, @:name !";return fn;})(), |
| 20 | + "plural": (()=>{const fn=(ctx) => {const { normalize: _normalize, linked: _linked, type: _type, interpolate: _interpolate, list: _list, named: _named, plural: _plural } = ctx;return _plural([_normalize([_linked("no apples", "caml", _type)]), _normalize([_interpolate(_list(0)), " apple"]), _normalize([_interpolate(_named("n")), " apples"])])};fn.source="@.caml:{'no apples'} | {0} apple | {n} apples";return fn;})() |
| 21 | + } |
| 22 | + export default resource" |
| 23 | + `) |
| 24 | +}) |
0 commit comments