UNPKG

1.44 kBPlain TextView Raw
1import { convertTsToLiquid } from '../src/transformers/convert';
2import { convertTemplateLiteralsToTags } from '../src/functions/content-to-liquid';
3
4const stripWhitespace = (str: string) => str.replace(/\s/g, '');
5
6const tsToLiquid = (str: string) => convertTemplateLiteralsToTags(convertTsToLiquid(str));
7
8test('Simple expression', async () => {
9 const result = tsToLiquid('foo.bar');
10 expect(result.trim()).toEqual('foo.bar');
11});
12
13test('Tripe to double equals', async () => {
14 const result = tsToLiquid('foo === bar');
15 expect(result.trim()).toEqual('foo == bar');
16});
17
18test('&& to ternary', async () => {
19 const result = tsToLiquid('foo && bar');
20 expect(result.trim()).toEqual('{% if foo %} {{ bar }} {% else %} {{ "" }} {% endif %}');
21});
22
23test('|| to or', async () => {
24 const result = tsToLiquid('foo || bar');
25 expect(result.trim()).toEqual('foo or bar');
26});
27
28test('Undefined to ""', async () => {
29 const result = tsToLiquid('undefined');
30 expect(result.trim()).toEqual('""');
31});
32
33test('Ternary to {% if %}', async () => {
34 const result = tsToLiquid('foo && bar ? bar : baz');
35 expect(stripWhitespace(result)).toEqual(
36 stripWhitespace('{% if foo and bar %} {{bar}} {% else %} {{baz}} {% endif %}')
37 );
38});
39
40test('Expressions to filters', async () => {
41 const result = tsToLiquid('"$" + price / 100');
42 expect(stripWhitespace(result)).toEqual(stripWhitespace('"$" | append: price | divided_by: 100'));
43});