Blame Raw
· · · 177 lines (7.8 KB)
0 contributors
1import { test, expect } from '@playwright/test';
2import { testSetup } from './frontent-test-utils.js';
3
4test.describe('MacroSlashCommands', () => {
5 test.beforeEach(testSetup.awaitST);
6
7 test.describe('Parser Flags', () => {
8 test('should bypass REPLACE_GETVAR', async ({ page }) => {
9 const output = await page.evaluate(async () => {
10 const { executeSlashCommandsWithOptions } = await import('./scripts/slash-commands.js');
11 const { power_user } = await import('./scripts/power-user.js');
12
13 power_user.experimental_macro_engine = true;
14
15 return (await executeSlashCommandsWithOptions('/parser-flag REPLACE_GETVAR || /setvar key=x \\{\\{lastMessageId}} || /pass {{getvar::x}}')).pipe;
16 });
17
18 expect(output).toBe('{{lastMessageId}}');
19 });
20 });
21
22 test.describe('{{pipe}} Macro', () => {
23 test('should support {{pipe}} macro', async ({ page }) => {
24 const output = await page.evaluate(async () => {
25 const { executeSlashCommandsWithOptions } = await import('./scripts/slash-commands.js');
26 const { power_user } = await import('./scripts/power-user.js');
27
28 power_user.experimental_macro_engine = true;
29
30 return (await executeSlashCommandsWithOptions('/pass Hello World || /pass {{pipe}}')).pipe;
31 });
32
33 expect(output).toBe('Hello World');
34 });
35 });
36
37 test.describe('{{var}} Macro', () => {
38 test('should support {{var::key}} macro', async ({ page }) => {
39 const output = await page.evaluate(async () => {
40 const { executeSlashCommandsWithOptions } = await import('./scripts/slash-commands.js');
41 const { power_user } = await import('./scripts/power-user.js');
42
43 power_user.experimental_macro_engine = true;
44
45 return (await executeSlashCommandsWithOptions('/let key=greeting Hello || /pass {{var::greeting}}')).pipe;
46 });
47
48 expect(output).toBe('Hello');
49 });
50
51 test('should support {{var::key::index}} macro', async ({ page }) => {
52 const output = await page.evaluate(async () => {
53 const { executeSlashCommandsWithOptions } = await import('./scripts/slash-commands.js');
54 const { power_user } = await import('./scripts/power-user.js');
55
56 power_user.experimental_macro_engine = true;
57
58 return (await executeSlashCommandsWithOptions('/let key=list ["item1","item2","item3"] || /pass {{var::list::1}}')).pipe;
59 });
60
61 expect(output).toBe('item2');
62 });
63
64 test('should not fail on unknown variable keys', async ({ page }) => {
65 const output = await page.evaluate(async () => {
66 const { executeSlashCommandsWithOptions } = await import('./scripts/slash-commands.js');
67 const { power_user } = await import('./scripts/power-user.js');
68
69 power_user.experimental_macro_engine = true;
70 return (await executeSlashCommandsWithOptions('/pass {{var::unknownKey}}')).pipe;
71 });
72
73 expect(output).toBe('');
74 });
75
76 test('should not fail on out-of-bounds variable index', async ({ page }) => {
77 const output = await page.evaluate(async () => {
78 const { executeSlashCommandsWithOptions } = await import('./scripts/slash-commands.js');
79 const { power_user } = await import('./scripts/power-user.js');
80
81 power_user.experimental_macro_engine = true;
82
83 return (await executeSlashCommandsWithOptions('/let key=test {"key":"value"} || /pass {{var::test::error}}')).pipe;
84 });
85
86 expect(output).toBe('');
87 });
88 });
89
90 test.describe('{{arg}} Macro', () => {
91 test('should support {{arg}} macro with plain value', async ({ page }) => {
92 const output = await page.evaluate(async () => {
93 const { executeSlashCommandsWithOptions } = await import('./scripts/slash-commands.js');
94 const { power_user } = await import('./scripts/power-user.js');
95
96 power_user.experimental_macro_engine = true;
97
98 return (await executeSlashCommandsWithOptions('/qr-arg hello world || /pass {{arg::hello}}')).pipe;
99 });
100
101 expect(output).toBe('world');
102 });
103
104 test('should support {{arg}} macro with closure value', async ({ page }) => {
105 const output = await page.evaluate(async () => {
106 const { executeSlashCommandsWithOptions } = await import('./scripts/slash-commands.js');
107 const { power_user } = await import('./scripts/power-user.js');
108
109 power_user.experimental_macro_engine = true;
110
111 return (await executeSlashCommandsWithOptions('/qr-arg x {: /echo test :} || /echo {{arg::x}}')).pipe;
112 });
113
114 expect(output).toBe('[Closure]');
115 });
116
117 test('should support mixed type {{arg}} macro values', async ({ page }) => {
118 const output = await page.evaluate(async () => {
119 const { executeSlashCommandsWithOptions } = await import('./scripts/slash-commands.js');
120 const { power_user } = await import('./scripts/power-user.js');
121
122 power_user.experimental_macro_engine = true;
123
124 return (await executeSlashCommandsWithOptions('/qr-arg a simple || /qr-arg b {: /echo closure :} || /echo {{arg::a}} and {{arg::b}}')).pipe;
125 });
126
127 expect(output).toBe('simple and ,[Closure]');
128 });
129
130 test('should support wildcard {{arg}} macro', async ({ page }) => {
131 const output = await page.evaluate(async () => {
132 const { executeSlashCommandsWithOptions } = await import('./scripts/slash-commands.js');
133 const { power_user } = await import('./scripts/power-user.js');
134
135 power_user.experimental_macro_engine = true;
136
137 return (await executeSlashCommandsWithOptions('/qr-arg * wildcard || /pass {{arg::any}}')).pipe;
138 });
139
140 expect(output).toBe('wildcard');
141 });
142 });
143
144 test.describe('Custom Scope Macros', () => {
145 test('should support {{timesIndex}} in /times command', async ({ page }) => {
146 const output = await page.evaluate(async () => {
147 const { executeSlashCommandsWithOptions } = await import('./scripts/slash-commands.js');
148 const { power_user } = await import('./scripts/power-user.js');
149
150 power_user.experimental_macro_engine = true;
151
152 return (await executeSlashCommandsWithOptions('/times 1 {: /pass {{timesIndex}} :}')).pipe;
153 });
154
155 expect(output).toBe('0');
156 });
157
158 test('should support custom SlashCommandScope macros', async ({ page }) => {
159 const output = await page.evaluate(async () => {
160 const { executeSlashCommandsWithOptions } = await import('./scripts/slash-commands.js');
161 const { SlashCommandScope } = await import('./scripts/slash-commands/SlashCommandScope.js');
162 const { power_user } = await import('./scripts/power-user.js');
163
164 power_user.experimental_macro_engine = true;
165
166 // Create a custom scope with a macro
167 const customScope = new SlashCommandScope(null);
168 customScope.setMacro('uno::dos::tres', 'CUSTOM_VALUE');
169 customScope.setMacro('uno::dos::quatro', 'SHOULD_NOT_BE_USED');
170 customScope.setMacro('uno::dos::*', 'WILDCARD_VALUE');
171 return (await executeSlashCommandsWithOptions('/pass {{uno::dos::tres}}', { scope: customScope })).pipe;
172 });
173
174 expect(output).toBe('CUSTOM_VALUE');
175 });
176 });
177});