Add test for a multi-step walk into a parent context.

This test proves that the dynamic scoping does not add the intermediate steps when doing a multi-step walk.
This commit is contained in:
Tom Alexander 2020-05-03 16:32:29 -04:00
parent 45facfed0d
commit 2b6c3990a9
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 49 additions and 1 deletions

View File

@ -31,3 +31,36 @@ After walk "foo":
``` ```
This appears to be using dynamic scoping instead of lexical scoping. For example, in lexical scoping a read of "b1" would fail after that final walk because you're inside the "foo" context which does not have any "b1" in or above it, however, since this is using dynamic scoping its using the invocations to build a scope tree rather than their original position. This appears to be using dynamic scoping instead of lexical scoping. For example, in lexical scoping a read of "b1" would fail after that final walk because you're inside the "foo" context which does not have any "b1" in or above it, however, since this is using dynamic scoping its using the invocations to build a scope tree rather than their original position.
Itermediate scopes appear to not be added. For example:
```js
{
"globals": {
"item": "pencil",
"things": {"color": "purple"}
},
"people": [
{"name": "Dave"},
{"name": "Emily", "item": "pen"}
]
}
```
If we walk into people and then into globals.things in one step, globals will not be added to the dynamic scope:
```
(attempts to read from the context in-order starting with the first line)
Starting access context:
{"globals":{"item":"pencil","things":{"color":"purple"}},"people":[{"name":"Dave"},{"name":"Emily","item":"pen"}]}
After walk "people":
[{"name":"Dave"},{"name":"Emily","item":"pen"}]
{"globals":{"item":"pencil","things":{"color":"purple"}},"people":[{"name":"Dave"},{"name":"Emily","item":"pen"}]}
After walk globals.things
{"color":"purple"}
[{"name":"Dave"},{"name":"Emily","item":"pen"}]
{"globals":{"item":"pencil","things":{"color":"purple"}},"people":[{"name":"Dave"},{"name":"Emily","item":"pen"}]}
```
So if we were on the "Dave" iteration in people and I attempted to read "item" it would not find a value despite "item" being a key in the lexical context above `globals.things`.

View File

@ -7,5 +7,13 @@
{"name": "Alice", "job": "Chief Swinger"}, {"name": "Alice", "job": "Chief Swinger"},
{"name": "Bob", "job": "Chief Swayer"}, {"name": "Bob", "job": "Chief Swayer"},
{"name": "Chris", "job": "Barista", "company": "GenericCoffee", "email": "thecoffeeguy@generic.coffee"} {"name": "Chris", "job": "Barista", "company": "GenericCoffee", "email": "thecoffeeguy@generic.coffee"}
],
"deep_globals": {
"item": "pencil",
"things": {"color": "purple"}
},
"deep_people": [
{"name": "Dave"},
{"name": "Emily", "item": "pen"}
] ]
} }

View File

@ -3,3 +3,10 @@ Directory for {company}:{~n}
{name}: {job} at {company} (email: {globals.email}){~n} {name}: {job} at {company} (email: {globals.email}){~n}
Testing walking after entering a parent context {#globals}job: {job}, email: {email}, company: {company}{/globals}{~n} Testing walking after entering a parent context {#globals}job: {job}, email: {email}, company: {company}{/globals}{~n}
{/people} {/people}
Doing a deep walk to see if intermediate steps are added to the dynamic context.{~n}
{#deep_people}
{#deep_globals.things}
{name} has a {color} {item}{~n}
{/deep_globals.things}
{/deep_people}