forked from DanielXMoore/Civet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parses and transpiles object comprehension syntax proposed in issue DanielXMoore#439 Tested only in limited contexts, of the 4 tests added one is failing
- Loading branch information
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
{ testCase } from ./helper.civet | ||
|
||
describe "object comprehensions", -> | ||
testCase """ | ||
1 | ||
--- | ||
{ | ||
for x of [1, 2, 3] | ||
[x]: 2 * x | ||
[x * 2]: 4 * x | ||
} | ||
--- | ||
(()=>{const _results = {}; | ||
for (const x of [1, 2, 3]) { | ||
Object.assign(_results, { | ||
[x]: 2 * x | ||
,[x * 2]: 4 * x | ||
, | ||
})}; return _results})() | ||
""" | ||
|
||
testCase """ | ||
scoping | ||
--- | ||
{ | ||
for _results of [1] | ||
[_results]: 2 * _results | ||
[_results * 2]: 4 * _results | ||
} | ||
--- | ||
(()=>{const _results = {}; | ||
for (const _results of [1]) { | ||
Object.assign(_results, { | ||
[_results]: 2 * _results | ||
,[_results * 2]: 4 * _results | ||
, | ||
})}; return _results})() | ||
""" | ||
|
||
testCase """ | ||
spacing 1 | ||
--- | ||
{ for x of [1] | ||
[x]: 2 * x | ||
[x * 2]: 4 * x | ||
} | ||
--- | ||
(()=>{const _results = {}; | ||
for (const x of [1]) { | ||
Object.assign(_results, { | ||
[x]: 2 * x | ||
,[x * 2]: 4 * x | ||
, | ||
})}; return _results})() | ||
""" | ||
|
||
testCase """ | ||
spacing 2: indentation | ||
--- | ||
{ for x of [1] | ||
[x]: 2 * x | ||
[x * 2]: 4 * x | ||
} | ||
--- | ||
(()=>{const _results = {}; | ||
for (const x of [1]) { | ||
Object.assign(_results, { | ||
[x]: 2 * x | ||
,[x * 2]: 4 * x | ||
, | ||
})}; return _results})() | ||
""" |