Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Data can be referenced from other places in the program using lookups, like
}
```

You can drill down into the properties of looked-up values:
You can index into the properties of looked-up values:

```
{
Expand All @@ -100,7 +100,7 @@ You can drill down into the properties of looked-up values:
greeting: "Hello, World!"
}
}
greeting: :deeply.nested.greeting // or :{deeply nested greeting}
greeting: :deeply.nested.greeting
}
```

Expand Down
77 changes: 19 additions & 58 deletions src/end-to-end.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ testCases(endToEnd, code => code)('end-to-end tests', [
['{a,1:overwritten,c}', either.makeRight({ 0: 'a', 1: 'c' })],
['{overwritten,0:a,c}', either.makeRight({ 0: 'a', 1: 'c' })],
['{@check type:true value:true}', either.makeRight('true')],
['{a:A b:{@lookup {a}}}', either.makeRight({ a: 'A', b: 'A' })],
['{a:A b: :{a}}', either.makeRight({ a: 'A', b: 'A' })],
['{a:A {@lookup {a}}}', either.makeRight({ a: 'A', 0: 'A' })],
['{a:A :{a}}', either.makeRight({ a: 'A', 0: 'A' })],
['{a:A b:{@lookup a}}', either.makeRight({ a: 'A', b: 'A' })],
['{a:A b: :a}', either.makeRight({ a: 'A', b: 'A' })],
['{a:A {@lookup a}}', either.makeRight({ a: 'A', 0: 'A' })],
['{a:A :a}', either.makeRight({ a: 'A', 0: 'A' })],
['{ a: (a => :a)(A) }', either.makeRight({ a: 'A' })],
['{ a: ( a => :a )( A ) }', either.makeRight({ a: 'A' })],
['(a => :a)(A)', either.makeRight('A')],
Expand All @@ -50,7 +50,7 @@ testCases(endToEnd, code => code)('end-to-end tests', [
either.makeRight({
0: '@function',
parameter: 'a',
body: { 0: '@lookup', query: { 0: 'a' } },
body: { 0: '@lookup', key: 'a' },
}),
],
['{ success }.0', either.makeRight('success')],
Expand Down Expand Up @@ -116,7 +116,7 @@ testCases(endToEnd, code => code)('end-to-end tests', [
either.makeRight('output'),
],
[':match({ a: A })({ tag: a, value: {} })', either.makeRight('A')],
[':{atom prepend}(a)(b)', either.makeRight('ab')],
[':atom.prepend(a)(b)', either.makeRight('ab')],
[':flow({ :atom.append(a) :atom.append(b) })(z)', either.makeRight('zab')],
[
`{
Expand All @@ -126,7 +126,7 @@ testCases(endToEnd, code => code)('end-to-end tests', [
0:@runtime
function:{
0:@apply
function:{0:@lookup query:{0:object 1:lookup}}
function:{0:@index object:{0:@lookup key:object} query:{0:lookup}}
argument:"key which does not exist in runtime context"
}
}
Expand All @@ -138,63 +138,17 @@ testCases(endToEnd, code => code)('end-to-end tests', [
],
[
`{@runtime
:{object lookup}("key which does not exist in runtime context")
:object.lookup("key which does not exist in runtime context")
}`,
either.makeRight({ tag: 'none', value: {} }),
],
[
`{@runtime
{@apply
{@lookup { flow }}
{
{@apply
{@lookup { object lookup }}
environment
}
{@apply
{@lookup { match }}
{
none: "environment does not exist"
some: {@apply
{@lookup { flow }}
{
{@apply
{@lookup { object lookup }}
lookup
}
{@apply
{@lookup { match }}
{
none: "environment.lookup does not exist"
some: {@apply
{@lookup { apply }}
PATH
}
}
}
}
}
}
}
}
}
}`,
output => {
if (either.isLeft(output)) {
assert.fail(output.value.message)
}
assert(typeof output.value === 'object')
assert.deepEqual(output.value['tag'], 'some')
assert.deepEqual(typeof output.value['value'], 'string')
},
],
[
`{@runtime {@apply :flow {
{@apply :{object lookup} environment}
{@apply :object.lookup environment}
{@apply :match {
none: "environment does not exist"
some: {@apply :flow {
{@apply :{object lookup} lookup}
{@apply :object.lookup lookup}
{@apply :match {
none: "environment.lookup does not exist"
some: {@apply :apply PATH}
Expand All @@ -213,11 +167,11 @@ testCases(endToEnd, code => code)('end-to-end tests', [
],
[
`{@runtime :flow({
:{object lookup}(environment)
:object.lookup(environment)
:match({
none: "environment does not exist"
some: :flow({
:{object lookup}(lookup)
:object.lookup(lookup)
:match({
none: "environment.lookup does not exist"
some: :apply(PATH)
Expand Down Expand Up @@ -287,4 +241,11 @@ testCases(endToEnd, code => code)('end-to-end tests', [
)`,
either.makeRight('3'),
],
[
`{
true: true
false: :boolean.not(:true)
}`,
either.makeRight({ true: 'true', false: 'false' }),
],
])
80 changes: 48 additions & 32 deletions src/language/compiling/compiler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,44 @@ testCases(compile, input => `compiling \`${JSON.stringify(input)}\``)(
'compiler',
[
['Hello, world!', success('Hello, world!')],
[['@check', true, ['@lookup', ['identity']]], success('true')],
[['@check', true, ['@lookup', 'identity']], success('true')],
[
{
true1: ['@check', true, ['@lookup', ['identity']]],
true2: ['@apply', ['@lookup', ['boolean', 'not']], false],
true1: ['@check', true, ['@lookup', 'identity']],
true2: ['@apply', ['@index', ['@lookup', 'boolean'], ['not']], false],
true3: [
'@apply',
[
'@apply',
['@lookup', ['flow']],
['@lookup', 'flow'],
[
['@lookup', ['boolean', 'not']],
['@lookup', ['boolean', 'not']],
['@index', ['@lookup', 'boolean'], ['not']],
['@index', ['@lookup', 'boolean'], ['not']],
],
],
true,
],
false1: ['@check', false, ['@lookup', ['boolean', 'is']]],
false2: ['@apply', ['@lookup', ['boolean', 'is']], 'not a boolean'],
false1: ['@check', false, ['@index', ['@lookup', 'boolean'], ['is']]],
false2: [
'@apply',
['@index', ['@lookup', 'boolean'], ['is']],
'not a boolean',
],
false3: [
'@apply',
[
'@apply',
['@lookup', ['flow']],
['@lookup', 'flow'],
[
[
'@apply',
['@lookup', ['flow']],
['@lookup', 'flow'],
[
['@lookup', ['boolean', 'not']],
['@lookup', ['boolean', 'not']],
['@index', ['@lookup', 'boolean'], ['not']],
['@index', ['@lookup', 'boolean'], ['not']],
],
],
['@lookup', ['boolean', 'not']],
['@index', ['@lookup', 'boolean'], ['not']],
],
],
true,
Expand All @@ -65,29 +69,29 @@ testCases(compile, input => `compiling \`${JSON.stringify(input)}\``)(
}),
],
[
['@runtime', ['@lookup', ['identity']]],
['@runtime', ['@lookup', 'identity']],
success({
0: '@runtime',
function: { 0: '@lookup', query: { 0: 'identity' } },
function: { 0: '@lookup', key: 'identity' },
}),
],
[
[
'@runtime',
['@apply', ['@lookup', ['identity']], ['@lookup', ['identity']]],
['@apply', ['@lookup', 'identity'], ['@lookup', 'identity']],
],
success({
0: '@runtime',
function: { 0: '@lookup', query: { 0: 'identity' } },
function: { 0: '@lookup', key: 'identity' },
}),
],
[
['@check', 'not a boolean', ['@lookup', ['boolean', 'is']]],
['@check', 'not a boolean', ['@index', ['@lookup', 'boolean'], ['is']]],
output => assert(either.isLeft(output)),
],
[['@lookup', ['compose']], output => assert(either.isLeft(output))],
[['@lookup', 'compose'], output => assert(either.isLeft(output))],
[
['@runtime', ['@lookup', ['boolean', 'not']]],
['@runtime', ['@index', ['@lookup', 'boolean'], ['not']]],
output => {
assert(either.isLeft(output))
assert(output.value.kind === 'typeMismatch')
Expand All @@ -96,7 +100,11 @@ testCases(compile, input => `compiling \`${JSON.stringify(input)}\``)(
[
[
'@runtime',
['@apply', ['@lookup', ['identity']], ['@lookup', ['boolean', 'not']]],
[
'@apply',
['@lookup', 'identity'],
['@index', ['@lookup', 'boolean'], ['not']],
],
],
output => {
assert(either.isLeft(output))
Expand All @@ -108,21 +116,21 @@ testCases(compile, input => `compiling \`${JSON.stringify(input)}\``)(
'@runtime',
[
'@apply',
['@lookup', ['flow']],
['@lookup', 'flow'],
[
['@lookup', ['identity']],
['@lookup', ['identity']],
['@lookup', 'identity'],
['@lookup', 'identity'],
],
],
],
success({
0: '@runtime',
function: {
0: '@apply',
function: { 0: '@lookup', query: { 0: 'flow' } },
function: { 0: '@lookup', key: 'flow' },
argument: {
0: { 0: '@lookup', query: { 0: 'identity' } },
1: { 0: '@lookup', query: { 0: 'identity' } },
0: { 0: '@lookup', key: 'identity' },
1: { 0: '@lookup', key: 'identity' },
},
},
}),
Expand All @@ -132,10 +140,10 @@ testCases(compile, input => `compiling \`${JSON.stringify(input)}\``)(
'@runtime',
[
'@apply',
['@lookup', ['flow']],
['@lookup', 'flow'],
[
['@lookup', ['boolean', 'not']],
['@lookup', ['boolean', 'not']],
['@index', ['@lookup', 'boolean'], ['not']],
['@index', ['@lookup', 'boolean'], ['not']],
],
],
],
Expand All @@ -149,15 +157,23 @@ testCases(compile, input => `compiling \`${JSON.stringify(input)}\``)(
0: '@runtime',
function: {
0: '@apply',
function: { 0: '@lookup', query: { 0: 'object', 1: 'lookup' } },
function: {
0: '@index',
object: { 0: '@lookup', key: 'object' },
query: { 0: 'lookup' },
},
argument: 'key which does not exist in runtime context',
},
},
success({
0: '@runtime',
function: {
0: '@apply',
function: { 0: '@lookup', query: { 0: 'object', 1: 'lookup' } },
function: {
0: '@index',
object: { 0: '@lookup', key: 'object' },
query: { 0: 'lookup' },
},
argument: 'key which does not exist in runtime context',
},
}),
Expand Down
Loading