Skip to content

Commit

Permalink
test: add another test for let tag
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Aug 10, 2023
1 parent a76e7ac commit 8cca7d7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
18 changes: 18 additions & 0 deletions fixtures/eval-tag-push-to-array/compiled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
let out = "";
let $lineNumber = 1;
let $filename = "{{__dirname}}index.edge";
try {
state.users.push({
username: 'romain'
});
$lineNumber = 2;
template.loop(state.users, function (user) {
out += "\n";
out += " - ";
$lineNumber = 3;
out += `${template.escape(user.username)}`;
});
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
return out;
4 changes: 4 additions & 0 deletions fixtures/eval-tag-push-to-array/index.edge
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@eval(users.push({ username: 'romain' }))
@each(user in users)
- {{ user.username }}
@end
3 changes: 3 additions & 0 deletions fixtures/eval-tag-push-to-array/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"users": [{ "username": "virk" }]
}
2 changes: 2 additions & 0 deletions fixtures/eval-tag-push-to-array/index.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- virk
- romain
12 changes: 6 additions & 6 deletions tests/fixtures.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ test.group('Fixtures', (group) => {
* Render output
*/
const out = readFileSync(join(dirBasePath, 'index.txt'), 'utf-8')
const state = JSON.parse(readFileSync(join(dirBasePath, 'index.json'), 'utf-8'))
const output = template.render(`${dir}/index.edge`, state) as string
const state = readFileSync(join(dirBasePath, 'index.json'), 'utf-8')
const output = template.render(`${dir}/index.edge`, JSON.parse(state)) as string
const outputRaw = template.renderRaw<string>(
readFileSync(join(dirBasePath, 'index.edge'), 'utf-8'),
state
JSON.parse(state)
)
assert.stringEqual(output.trim(), out)
assert.stringEqual(outputRaw.trim(), out)
Expand Down Expand Up @@ -144,11 +144,11 @@ test.group('Fixtures | Cache', (group) => {
* Render output
*/
const out = readFileSync(join(dirBasePath, 'index.txt'), 'utf-8')
const state = JSON.parse(readFileSync(join(dirBasePath, 'index.json'), 'utf-8'))
const output = template.render(`${dir}/index.edge`, state) as string
const state = readFileSync(join(dirBasePath, 'index.json'), 'utf-8')
const output = template.render(`${dir}/index.edge`, JSON.parse(state)) as string
const outputRaw = template.renderRaw<string>(
readFileSync(join(dirBasePath, 'index.edge'), 'utf-8'),
state
JSON.parse(state)
)
assert.stringEqual(output.trim(), out)
assert.stringEqual(outputRaw.trim(), out)
Expand Down

0 comments on commit 8cca7d7

Please sign in to comment.