forked from Wilfred/difftastic
-
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.
fix: compare with 'in' operator (Wilfred#15)
* fix: compare with 'in' operator * fix: use field in object for loop * test: add examples from Wilfred#13 as tests * test: update test case following suggestion in Wilfred#13
- Loading branch information
Showing
4 changed files
with
314 additions
and
14 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,155 @@ | ||
=============================== | ||
Resolve expr in fieldname key 1 | ||
=============================== | ||
|
||
local a = 'a'; | ||
{ [a]: 'a' } | ||
|
||
--- | ||
|
||
(document | ||
(expr | ||
(local_bind | ||
(local) | ||
(bind | ||
(id) | ||
(expr | ||
(string | ||
(string_start) | ||
(string_content) | ||
(string_end)))) | ||
(expr | ||
(member | ||
(field | ||
(fieldname | ||
(expr | ||
(id))) | ||
(expr | ||
(string | ||
(string_start) | ||
(string_content) | ||
(string_end))))))))) | ||
|
||
=============================== | ||
Resolve expr in fieldname key 2 | ||
=============================== | ||
|
||
local prefix = 'Happy Hour '; | ||
{ | ||
[prefix + 'Mimosa']: 'Champagne', | ||
} | ||
|
||
--- | ||
|
||
(document | ||
(expr | ||
(local_bind | ||
(local) | ||
(bind | ||
(id) | ||
(expr | ||
(string | ||
(string_start) | ||
(string_content) | ||
(string_end)))) | ||
(expr | ||
(member | ||
(field | ||
(fieldname | ||
(expr | ||
(expr (id)) | ||
(expr | ||
(string | ||
(string_start) | ||
(string_content) | ||
(string_end))))) | ||
(expr | ||
(string | ||
(string_start) | ||
(string_content) | ||
(string_end))))))))) | ||
|
||
=============================== | ||
Resolve expr in fieldname key 3 | ||
=============================== | ||
|
||
local Margarita(salted) = { | ||
[if salted then 'garnish']: 'Salt', | ||
ingredients: [ | ||
{ kind: 'Tequila Blanco', qty: 2 }, | ||
], | ||
}; | ||
{ | ||
Margarita: Margarita(true), | ||
'Margarita Unsalted': Margarita(false), | ||
} | ||
|
||
--- | ||
|
||
(document | ||
(expr | ||
(local_bind | ||
(local) | ||
(bind | ||
function: (id) | ||
params: | ||
(params | ||
(param | ||
identifier: (id))) | ||
body: (expr | ||
(member | ||
(field | ||
(fieldname | ||
(expr | ||
condition: (expr (id)) | ||
consequence: | ||
(expr | ||
(string | ||
(string_start) | ||
(string_content) | ||
(string_end))))) | ||
(expr | ||
(string | ||
(string_start) | ||
(string_content) | ||
(string_end))))) | ||
(member | ||
(field | ||
(fieldname (id)) | ||
(expr | ||
(expr | ||
(member | ||
(field | ||
(fieldname (id)) | ||
(expr | ||
(string | ||
(string_start) | ||
(string_content) | ||
(string_end))))) | ||
(member | ||
(field | ||
(fieldname | ||
(id)) | ||
(expr | ||
(number)))))))) | ||
)) | ||
(expr | ||
(member | ||
(field | ||
(fieldname (id)) | ||
(expr | ||
(expr (id)) | ||
(args | ||
(expr (true)))))) | ||
(member | ||
(field | ||
(fieldname | ||
(string | ||
(string_start) | ||
(string_content) | ||
(string_end))) | ||
(expr | ||
(expr (id)) | ||
(args | ||
(expr | ||
(false)))))))))) |
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,78 @@ | ||
====================== | ||
For loop in array | ||
====================== | ||
|
||
[ | ||
i | ||
for i in std.range(0,10) | ||
] | ||
|
||
--- | ||
|
||
(document | ||
(expr | ||
(expr (id)) | ||
(forspec | ||
(id) | ||
(expr (expr (expr (id)) (id)) | ||
(args (expr (number)) (expr (number))))))) | ||
|
||
====================== | ||
For loop in object | ||
====================== | ||
|
||
{ | ||
['item' + i]: i | ||
for i in std.range(0,10) | ||
} | ||
|
||
--- | ||
|
||
(document | ||
(expr | ||
(field | ||
(fieldname | ||
(expr | ||
(expr | ||
(string | ||
(string_start) | ||
(string_content) | ||
(string_end))) | ||
(expr (id)))) | ||
(expr (id))) | ||
(forspec | ||
(id) | ||
(expr (expr (expr (id)) (id)) | ||
(args (expr (number)) (expr (number))))))) | ||
|
||
================================ | ||
For loop in object with function | ||
================================ | ||
|
||
{ | ||
['item' + i](v): i + v | ||
for i in std.range(0,10) | ||
} | ||
|
||
--- | ||
|
||
(document | ||
(expr | ||
(field | ||
(fieldname | ||
(expr | ||
(expr | ||
(string | ||
(string_start) | ||
(string_content) | ||
(string_end))) | ||
(expr (id)))) | ||
(params | ||
(param (id))) | ||
(expr | ||
(expr (id)) | ||
(expr (id)))) | ||
(forspec | ||
(id) | ||
(expr (expr (expr (id)) (id)) | ||
(args (expr (number)) (expr (number))))))) |
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,68 @@ | ||
====================== | ||
In operator on object | ||
====================== | ||
|
||
local obj = { a: null }; | ||
'a' in obj | ||
|
||
--- | ||
|
||
(document | ||
(expr | ||
(local_bind | ||
(local) | ||
(bind | ||
(id) | ||
(expr | ||
(member | ||
(field | ||
(fieldname | ||
(id)) | ||
(expr | ||
(null)))))) | ||
(expr | ||
(expr | ||
(string | ||
(string_start) | ||
(string_content) | ||
(string_end))) | ||
(expr | ||
(id)))))) | ||
|
||
====================== | ||
In operator on super | ||
====================== | ||
|
||
local obj = { a: null }; | ||
obj + { b: 'a' in super } | ||
|
||
--- | ||
|
||
(document | ||
(expr | ||
(local_bind | ||
(local) | ||
(bind | ||
(id) | ||
(expr | ||
(member | ||
(field | ||
(fieldname | ||
(id)) | ||
(expr | ||
(null)))))) | ||
(expr | ||
(expr | ||
(id)) | ||
(expr | ||
(member | ||
(field | ||
(fieldname | ||
(id)) | ||
(expr | ||
(expr | ||
(string | ||
(string_start) | ||
(string_content) | ||
(string_end))) | ||
(super))))))))) |