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