diff --git a/lib/elixir_script/module_systems/namespace.ex b/lib/elixir_script/module_systems/namespace.ex index c98eee87..663110af 100644 --- a/lib/elixir_script/module_systems/namespace.ex +++ b/lib/elixir_script/module_systems/namespace.ex @@ -47,7 +47,7 @@ defmodule ElixirScript.ModuleSystems.Namespace do exports = [JS.return_statement(JS.identifier("__exports"))] make = JS.member_expression( - Helpers.call( + Helpers.call_sync( build_namespace(), [JS.identifier("Elixir"), JS.literal(Enum.join(["Elixir"] ++ Module.split(module_name), "."))] ), diff --git a/lib/elixir_script/passes/output/js_module.ex b/lib/elixir_script/passes/output/js_module.ex index 9277d826..f40b5bc4 100644 --- a/lib/elixir_script/passes/output/js_module.ex +++ b/lib/elixir_script/passes/output/js_module.ex @@ -21,7 +21,7 @@ defmodule ElixirScript.Output.JSModule do J.identifier("Elixir"), J.identifier("start") ), - Helpers.function( + Helpers.arrow_function( [J.identifier(:app), J.identifier(:args)], J.block_statement([ Helpers.call( @@ -48,7 +48,7 @@ defmodule ElixirScript.Output.JSModule do J.identifier("Elixir"), J.identifier("load") ), - Helpers.function( + Helpers.arrow_function( [J.identifier(:module)], J.block_statement([ J.return_statement( diff --git a/lib/elixir_script/passes/translate/form.ex b/lib/elixir_script/passes/translate/form.ex index 3f580783..9412e492 100644 --- a/lib/elixir_script/passes/translate/form.ex +++ b/lib/elixir_script/passes/translate/form.ex @@ -145,17 +145,17 @@ defmodule ElixirScript.Translate.Form do end def compile({:case, _, [condition, [do: clauses]]}, state) do - func = Helpers.call( + ast = Helpers.call( J.member_expression( - Helpers.patterns(), - J.identifier("defmatch") + Helpers.special_forms(), + J.identifier("_case") ), - Enum.map(clauses, fn x -> Clause.compile(x, state) |> elem(0) end) |> List.flatten - ) - - ast = Helpers.call( - J.member_expression( func, J.identifier("call")), - [J.identifier(:this), compile!(condition, state)] + [ + compile!(condition, state), + Enum.map(clauses, fn x -> Clause.compile(x, state) |> elem(0) end) + |> List.flatten + |> J.array_expression() + ] ) { ast, state } diff --git a/lib/elixir_script/passes/translate/forms/pattern/patterns.ex b/lib/elixir_script/passes/translate/forms/pattern/patterns.ex index eb873149..206297b4 100644 --- a/lib/elixir_script/passes/translate/forms/pattern/patterns.ex +++ b/lib/elixir_script/passes/translate/forms/pattern/patterns.ex @@ -40,56 +40,56 @@ defmodule ElixirScript.Translate.Forms.Pattern.Patterns do ) def parameter() do - Helpers.call( + Helpers.call_sync( @parameter, [] ) end def parameter(name) do - Helpers.call( + Helpers.call_sync( @parameter, [name] ) end def head_tail(headParameter, tailParameter) do - Helpers.call( + Helpers.call_sync( @head_tail, [headParameter, tailParameter] ) end def starts_with(prefix) do - Helpers.call( + Helpers.call_sync( @starts_with, [J.literal(prefix)] ) end def capture(value) do - Helpers.call( + Helpers.call_sync( @capture, [value] ) end def bound(value) do - Helpers.call( + Helpers.call_sync( @bound, [value] ) end def type(prototype, value) do - Helpers.call( + Helpers.call_sync( @_type, [prototype, value] ) end def bitstring_match(values) do - Helpers.call( + Helpers.call_sync( @bitstring_match, values ) diff --git a/lib/elixir_script/passes/translate/forms/try.ex b/lib/elixir_script/passes/translate/forms/try.ex index 249d8f9b..a00d9d7d 100644 --- a/lib/elixir_script/passes/translate/forms/try.ex +++ b/lib/elixir_script/passes/translate/forms/try.ex @@ -70,7 +70,7 @@ defmodule ElixirScript.Translate.Forms.Try do Helpers.call( JS.member_expression( Helpers.patterns(), - JS.identifier("defmatch") + JS.identifier("defmatchAsync") ), processed_clauses ) diff --git a/lib/elixir_script/passes/translate/function.ex b/lib/elixir_script/passes/translate/function.ex index 23888453..490928bc 100644 --- a/lib/elixir_script/passes/translate/function.ex +++ b/lib/elixir_script/passes/translate/function.ex @@ -102,7 +102,7 @@ defmodule ElixirScript.Translate.Function do match_or_default_call = Helpers.call( J.member_expression( Helpers.patterns(), - J.identifier("match_or_default") + J.identifier("match_or_default_async") ), [J.array_expression(patterns), J.identifier("__function_args__"), guards] ) @@ -141,7 +141,7 @@ defmodule ElixirScript.Translate.Function do |> Clause.return_last_statement |> update_last_call(state) - declaration = Helpers.declare_let(params, J.identifier("__arg_matches__")) + declaration = Helpers.declare(params, J.identifier("__arg_matches__")) body = [declaration] ++ body {patterns, params, guard, body} diff --git a/lib/elixir_script/passes/translate/helpers.ex b/lib/elixir_script/passes/translate/helpers.ex index 227eab39..4f88f0b9 100644 --- a/lib/elixir_script/passes/translate/helpers.ex +++ b/lib/elixir_script/passes/translate/helpers.ex @@ -19,18 +19,26 @@ defmodule ElixirScript.Translate.Helpers do ) end - def call(callee, arguments) do + def call_sync(callee, arguments) do J.call_expression( callee, arguments ) end + def call(callee, arguments) do + call_sync(callee, arguments) + |> J.await_expression() + end + def arrow_function(params, body) do J.arrow_function_expression( params, [], - body + body, + false, + false, + true ) end @@ -39,7 +47,10 @@ defmodule ElixirScript.Translate.Helpers do name, params, [], - body + body, + false, + false, + true ) end diff --git a/lib/elixir_script/passes/translate/protocol.ex b/lib/elixir_script/passes/translate/protocol.ex index cfaf4912..34bfeb11 100644 --- a/lib/elixir_script/passes/translate/protocol.ex +++ b/lib/elixir_script/passes/translate/protocol.ex @@ -18,7 +18,7 @@ defmodule ElixirScript.Translate.Protocol do declaration = Helpers.declare( "protocol", - Helpers.call( + Helpers.call_sync( J.member_expression( Helpers.functions(), J.identifier(:defprotocol) @@ -44,12 +44,12 @@ defmodule ElixirScript.Translate.Protocol do Enum.map(impls, fn({impl, impl_for}) -> members = ["Elixir"] ++ Module.split(impl) ++ ["__load"] - ast = Helpers.call( + ast = Helpers.call_sync( Identifier.make_namespace_members(members), [J.identifier("Elixir")] ) - Helpers.call( + Helpers.call_sync( J.member_expression( Helpers.functions(), J.identifier(:defimpl) diff --git a/src/javascript/lib/core/erlang_compat/lists.js b/src/javascript/lib/core/erlang_compat/lists.js index 066f903a..c4ed3901 100644 --- a/src/javascript/lib/core/erlang_compat/lists.js +++ b/src/javascript/lib/core/erlang_compat/lists.js @@ -5,8 +5,10 @@ function reverse(list) { return [...list].reverse(); } -function foreach(fun, list) { - list.forEach(x => fun(x)); +async function foreach(fun, list) { + for (const x of list) { + await fun(x); + } return Symbol.for('ok'); } @@ -33,11 +35,17 @@ function flatten(deepList, tail = []) { return val.concat(tail); } -function foldl(fun, acc0, list) { - return list.reduce((acc, value) => fun(value, acc), acc0); +async function foldl(fun, acc0, list) { + let acc = acc0; + + for (const value of list) { + acc = await fun(value, acc); + } + + return acc; } -function foldr(fun, acc0, list) { +async function foldr(fun, acc0, list) { return foldl(fun, acc0, reverse(list)); } @@ -124,12 +132,12 @@ function keytake(key, n, tupleList) { return false; } -function mapfoldl(fun, acc0, list1) { +async function mapfoldl(fun, acc0, list1) { const listResult = []; let accResult = acc0; for (const item of list1) { - const tuple = fun(item, accResult); + const tuple = await fun(item, accResult); listResult.push(tuple.get(0)); accResult = tuple.get(1); } @@ -141,19 +149,35 @@ function concat(things) { return things.map(v => v.toString()).join(); } -function map(fun, list) { - return list.map(value => fun(value)); +async function map(fun, list) { + const reList = []; + + for (const value of list) { + const result = await fun(value); + reList.push(result); + } + + return reList; } -function filter(pred, list1) { - return list1.filter(x => pred(x)); +async function filter(pred, list1) { + const reList = []; + + for (const value of list1) { + const result = await pred(value); + if (result === true) { + reList.push(value); + } + } + + return reList; } -function filtermap(fun, list1) { +async function filtermap(fun, list1) { const list2 = []; for (const item of list1) { - const value = fun(item); + const value = await fun(item); if (value === true) { list2.push(item); @@ -175,9 +199,9 @@ function member(elem, list) { return false; } -function all(pred, list) { +async function all(pred, list) { for (const item of list) { - if (pred(item) === false) { + if ((await pred(item)) === false) { return false; } } @@ -185,9 +209,9 @@ function all(pred, list) { return true; } -function any(pred, list) { +async function any(pred, list) { for (const item of list) { - if (pred(item) === true) { + if ((await pred(item)) === true) { return true; } } @@ -195,7 +219,7 @@ function any(pred, list) { return false; } -function splitwith(pred, list) { +async function splitwith(pred, list) { let switchToList2 = false; const list1 = []; const list2 = []; @@ -203,7 +227,7 @@ function splitwith(pred, list) { for (const item of list) { if (switchToList2 === true) { list2.push(item); - } else if (pred(item) === true) { + } else if ((await pred(item)) === true) { list1.push(item); } else { switchToList2 = true; @@ -214,7 +238,7 @@ function splitwith(pred, list) { return new ErlangTypes.Tuple(list1, list2); } -function sort(...args) { +async function sort(...args) { if (args.length === 1) { const list2 = [...args[0]]; return list2.sort(); @@ -223,15 +247,17 @@ function sort(...args) { const fun = args[0]; const list2 = [...args[1]]; - return list2.sort((a, b) => { - const result = fun(a, b); + const result = list2.sort(async (a, b) => { + const sortResult = await fun(a, b); - if (result === true) { + if (sortResult === true) { return -1; } return 1; }); + + return Promise.all(result); } export default { diff --git a/src/javascript/lib/core/erlang_compat/maps.js b/src/javascript/lib/core/erlang_compat/maps.js index ec8b4e79..ec0f3518 100644 --- a/src/javascript/lib/core/erlang_compat/maps.js +++ b/src/javascript/lib/core/erlang_compat/maps.js @@ -88,11 +88,11 @@ function find(key, map) { return ERROR; } -function fold(fun, init, map) { +async function fold(fun, init, map) { let acc = init; for (const [key, value] of map.entries()) { - acc = fun(key, value, acc); + acc = await fun(key, value, acc); } return acc; diff --git a/src/javascript/lib/core/functions.js b/src/javascript/lib/core/functions.js index 86d84a65..fee14752 100644 --- a/src/javascript/lib/core/functions.js +++ b/src/javascript/lib/core/functions.js @@ -4,7 +4,7 @@ import Core from '../core'; import proplists from './erlang_compat/proplists'; import erlang from './erlang_compat/erlang'; -function call_property(item, property) { +async function call_property(item, property) { if (!property) { if (item instanceof Function || typeof item === 'function') { return item(); @@ -156,11 +156,11 @@ class Recurse { } } -function trampoline(f) { +async function trampoline(f) { let currentValue = f; while (currentValue && currentValue instanceof Recurse) { - currentValue = currentValue.func(); + currentValue = await currentValue.func(); } return currentValue; diff --git a/src/javascript/lib/core/protocol.js b/src/javascript/lib/core/protocol.js index 15466ed8..b7aec13a 100644 --- a/src/javascript/lib/core/protocol.js +++ b/src/javascript/lib/core/protocol.js @@ -7,7 +7,7 @@ class Protocol { this.fallback = null; function createFun(funName) { - return function (...args) { + return async function (...args) { const thing = args[0]; let fun = null; @@ -37,7 +37,7 @@ class Protocol { } if (fun != null) { - const retval = fun.apply(this, args); + const retval = await fun.apply(this, args); return retval; } diff --git a/src/javascript/lib/core/special_forms.js b/src/javascript/lib/core/special_forms.js index 8caa2dfe..7a498194 100644 --- a/src/javascript/lib/core/special_forms.js +++ b/src/javascript/lib/core/special_forms.js @@ -1,10 +1,10 @@ import Core from '../core'; -function _case(condition, clauses) { - return Core.Patterns.defmatch(...clauses)(condition); +async function _case(condition, clauses) { + return Core.Patterns.defmatchAsync(...clauses)(condition); } -function cond(...clauses) { +async function cond(...clauses) { for (const clause of clauses) { if (clause[0]) { return clause[1](); @@ -35,17 +35,17 @@ function run_list_generators(generator, generators) { return run_list_generators(next_gen, generators); } -function _for(expression, generators, collectable_protocol, into = []) { +async function _for(expression, generators, collectable_protocol, into = []) { const [result, fun] = collectable_protocol.into(into); let accumulatingResult = result; const generatedValues = run_list_generators(generators.pop()(), generators); for (const value of generatedValues) { - if (expression.guard.apply(this, value)) { - accumulatingResult = fun( + if (await expression.guard.apply(this, value)) { + accumulatingResult = await fun( accumulatingResult, - new Core.Tuple(Symbol.for('cont'), expression.fn.apply(this, value)), + new Core.Tuple(Symbol.for('cont'), await expression.fn.apply(this, value)), ); } } @@ -53,17 +53,17 @@ function _for(expression, generators, collectable_protocol, into = []) { return fun(accumulatingResult, Symbol.for('done')); } -function _try(do_fun, rescue_function, catch_fun, else_function, after_function) { +async function _try(do_fun, rescue_function, catch_fun, else_function, after_function) { let result = null; try { - result = do_fun(); + result = await do_fun(); } catch (e) { let ex_result = null; if (rescue_function) { try { - ex_result = rescue_function(e); + ex_result = await rescue_function(e); return ex_result; } catch (ex) { if (ex instanceof Core.Patterns.MatchError) { @@ -74,7 +74,7 @@ function _try(do_fun, rescue_function, catch_fun, else_function, after_function) if (catch_fun) { try { - ex_result = catch_fun(e); + ex_result = await catch_fun(e); return ex_result; } catch (ex) { if (ex instanceof Core.Patterns.MatchError) { @@ -86,7 +86,7 @@ function _try(do_fun, rescue_function, catch_fun, else_function, after_function) throw e; } finally { if (after_function) { - after_function(); + await after_function(); } } @@ -105,7 +105,7 @@ function _try(do_fun, rescue_function, catch_fun, else_function, after_function) } } -function _with(...args) { +async function _with(...args) { let argsToPass = []; let successFunction = null; let elseFunction = null; @@ -119,9 +119,9 @@ function _with(...args) { for (let i = 0; i < args.length; i++) { const [pattern, func] = args[i]; - const result = func(...argsToPass); + const result = await func(...argsToPass); - const patternResult = Core.Patterns.match_or_default(pattern, result); + const patternResult = await Core.Patterns.match_or_default_async(pattern, result); if (patternResult == null) { if (elseFunction) { diff --git a/src/javascript/tests/case.spec.js b/src/javascript/tests/case.spec.js index 8715ae11..b48d3304 100644 --- a/src/javascript/tests/case.spec.js +++ b/src/javascript/tests/case.spec.js @@ -5,7 +5,7 @@ const Patterns = Core.Patterns; const SpecialForms = Core.SpecialForms; const Tuple = Core.Tuple; -test('case', (t) => { +test('case', async (t) => { const clauses = [ Patterns.clause( [new Tuple(Symbol.for('selector'), Patterns.variable(), Patterns.variable())], @@ -15,7 +15,7 @@ test('case', (t) => { Patterns.clause([Patterns.variable()], value => value), ]; - const result = SpecialForms._case('thing', clauses); + const result = await SpecialForms._case('thing', clauses); t.is(result, 'thing'); }); diff --git a/src/javascript/tests/cond.spec.js b/src/javascript/tests/cond.spec.js index f1a09736..4ee5afb8 100644 --- a/src/javascript/tests/cond.spec.js +++ b/src/javascript/tests/cond.spec.js @@ -3,14 +3,14 @@ import Core from '../lib/core'; const SpecialForms = Core.SpecialForms; -test('cond', (t) => { +test('cond', async (t) => { const clauses = [ [1 + 1 === 1, () => 'This will never match'], [2 * 2 !== 4, () => 'Nor this'], [true, () => 'This will'], ]; - const result = SpecialForms.cond(...clauses); + const result = await SpecialForms.cond(...clauses); t.is(result, 'This will'); }); diff --git a/src/javascript/tests/core/erlang_compat/lists_spec.js b/src/javascript/tests/core/erlang_compat/lists_spec.js index 7e943b73..c7d4622f 100644 --- a/src/javascript/tests/core/erlang_compat/lists_spec.js +++ b/src/javascript/tests/core/erlang_compat/lists_spec.js @@ -16,12 +16,12 @@ test('flatten', (t) => { t.deepEqual(Core.lists.flatten([1, [[2], 3]]), [1, 2, 3]); }); -test('foldl', (t) => { - t.deepEqual(Core.lists.foldl((v, acc) => acc + v, 0, [1, 2, 3]), 6); +test('foldl', async (t) => { + t.deepEqual(await Core.lists.foldl((v, acc) => acc + v, 0, [1, 2, 3]), 6); }); -test('foldr', (t) => { - t.deepEqual(Core.lists.foldr((v, acc) => acc + v.toString(), '', [1, 2, 3]), '321'); +test('foldr', async (t) => { + t.deepEqual(await Core.lists.foldr((v, acc) => acc + v.toString(), '', [1, 2, 3]), '321'); }); test('member/2', (t) => { diff --git a/src/javascript/tests/core/erlang_compat/maps_spec.js b/src/javascript/tests/core/erlang_compat/maps_spec.js index 1a504227..7e1d1539 100644 --- a/src/javascript/tests/core/erlang_compat/maps_spec.js +++ b/src/javascript/tests/core/erlang_compat/maps_spec.js @@ -23,9 +23,9 @@ test('find', (t) => { t.deepEqual(result.values, [Symbol.for('ok'), 'b']); }); -test('fold', (t) => { +test('fold', async (t) => { const myMap = new Map([['a', 1], ['b', 2]]); - const result = Core.maps.fold((k, v, acc) => acc + v, 0, myMap); + const result = await Core.maps.fold((k, v, acc) => acc + v, 0, myMap); t.is(result, 3); }); diff --git a/src/javascript/tests/core/functions.spec.js b/src/javascript/tests/core/functions.spec.js index d3ed14e1..f56d312d 100644 --- a/src/javascript/tests/core/functions.spec.js +++ b/src/javascript/tests/core/functions.spec.js @@ -3,15 +3,15 @@ import Core from '../../lib/core'; const Functions = Core.Functions; -test('call_property', (t) => { - t.is(Functions.call_property(1, 'toString'), '1'); - t.is(Functions.call_property([], 'toString'), ''); - t.is(Functions.call_property([], 'length'), 0); - t.is(Functions.call_property('', 'toString'), ''); - t.is(Functions.call_property('', 'length'), 0); - t.is(Functions.call_property(Symbol('test'), 'toString'), 'Symbol(test)'); - t.is(Functions.call_property({ completed: false }, 'completed'), false); - t.is(Functions.call_property({ id: 0 }, 'id'), 0); +test('call_property', async (t) => { + t.is(await Functions.call_property(1, 'toString'), '1'); + t.is(await Functions.call_property([], 'toString'), ''); + t.is(await Functions.call_property([], 'length'), 0); + t.is(await Functions.call_property('', 'toString'), ''); + t.is(await Functions.call_property('', 'length'), 0); + t.is(await Functions.call_property(Symbol('test'), 'toString'), 'Symbol(test)'); + t.is(await Functions.call_property({ completed: false }, 'completed'), false); + t.is(await Functions.call_property({ id: 0 }, 'id'), 0); }); test('split_at', (t) => { diff --git a/src/javascript/tests/for.spec.js b/src/javascript/tests/for.spec.js index 9bcd1894..5f5c2e60 100644 --- a/src/javascript/tests/for.spec.js +++ b/src/javascript/tests/for.spec.js @@ -15,8 +15,8 @@ const collectable = { [ $, Patterns.type(Tuple, { - values: [Symbol.for('cont'), Patterns.variable()], - }), + values: [Symbol.for('cont'), Patterns.variable()] + }) ], (list, x) => list.concat([x]), ), @@ -24,22 +24,37 @@ const collectable = { ); return new Tuple([], fun); - }, + } }; +<<<<<<< HEAD +test('simple for', async t => { + const gen = Patterns.list_generator($, [1, 2, 3, 4]); + const result = await SpecialForms._for( + Patterns.clause([$], x => x * 2), + [gen], + collectable + ); +======= test('simple for', (t) => { const gen = Patterns.list_generator($, [1, 2, 3, 4]); const result = SpecialForms._for(Patterns.clause([$], x => x * 2), [gen], collectable); +>>>>>>> master t.deepEqual(result, [2, 4, 6, 8]); }); +<<<<<<< HEAD +test('for with multiple generators', async t => { + //for x <- [1, 2], y <- [2, 3], do: x*y +======= test('for with multiple generators', (t) => { // for x <- [1, 2], y <- [2, 3], do: x*y +>>>>>>> master const gen = Patterns.list_generator($, [1, 2]); const gen2 = Patterns.list_generator($, [2, 3]); - const result = SpecialForms._for( + const result = await SpecialForms._for( Patterns.clause([$, $], (x, y) => x * y), [gen, gen2], collectable, @@ -48,10 +63,15 @@ test('for with multiple generators', (t) => { t.deepEqual(result, [2, 3, 4, 6]); }); +<<<<<<< HEAD +test('for with filter', async t => { + //for n <- [1, 2, 3, 4, 5, 6], rem(n, 2) == 0, do: n +======= test('for with filter', (t) => { // for n <- [1, 2, 3, 4, 5, 6], rem(n, 2) == 0, do: n +>>>>>>> master const gen = Patterns.list_generator($, [1, 2, 3, 4, 5, 6]); - const result = SpecialForms._for( + const result = await SpecialForms._for( Patterns.clause([$], x => x, x => x % 2 === 0), [gen], collectable, @@ -60,17 +80,30 @@ test('for with filter', (t) => { t.deepEqual(result, [2, 4, 6]); }); +<<<<<<< HEAD +test('for with pattern matching', async t => { + //for {:user, name} <- [user: "john", admin: "john", user: "meg"], do +======= test('for with pattern matching', (t) => { // for {:user, name} <- [user: "john", admin: "john", user: "meg"], do +>>>>>>> master // String.upcase(name) // end const gen = Patterns.list_generator( [Symbol.for('user'), $], +<<<<<<< HEAD + [ + [Symbol.for('user'), 'john'], + [Symbol.for('admin'), 'john'], + [Symbol.for('user'), 'meg'] + ] +======= [[Symbol.for('user'), 'john'], [Symbol.for('admin'), 'john'], [Symbol.for('user'), 'meg']], +>>>>>>> master ); - const result = SpecialForms._for( + const result = await SpecialForms._for( Patterns.clause([[Symbol.for('user'), $]], name => name.toUpperCase()), [gen], collectable, @@ -79,8 +112,8 @@ test('for with pattern matching', (t) => { t.deepEqual(result, ['JOHN', 'MEG']); }); -test('for with bitstring', (t) => { - // for <> >>, do: {r, g, b} +test('for with bitstring', async t => { + //for <> >>, do: {r, g, b} const gen = Patterns.bitstring_generator( Patterns.bitStringMatch( @@ -109,18 +142,23 @@ test('for with bitstring', (t) => { Patterns.bitStringMatch( BitString.integer({ value: $ }), BitString.integer({ value: $ }), +<<<<<<< HEAD + BitString.integer({ value: $ }) + ) +======= BitString.integer({ value: $ }), ), +>>>>>>> master ], (r, g, b) => new Tuple(r, g, b), ); - const result = SpecialForms._for(expression, [gen], collectable); + const result = await SpecialForms._for(expression, [gen], collectable); t.deepEqual(result, [ new Tuple(213, 45, 132), new Tuple(64, 76, 32), new Tuple(76, 0, 0), - new Tuple(234, 32, 15), + new Tuple(234, 32, 15) ]); }); diff --git a/src/javascript/tests/try.spec.js b/src/javascript/tests/try.spec.js index 97150618..0c604de8 100644 --- a/src/javascript/tests/try.spec.js +++ b/src/javascript/tests/try.spec.js @@ -4,7 +4,11 @@ import Core from '../lib/core'; const Patterns = Core.Patterns; const SpecialForms = Core.SpecialForms; +<<<<<<< HEAD +test('try', async t => { +======= test('try', (t) => { +>>>>>>> master /* try do 1 / x @@ -19,8 +23,10 @@ test('try', (t) => { const x = 1; - const value = SpecialForms._try( - () => 1 / x, + const value = await SpecialForms._try( + () => { + return 1 / x; + }, null, null, Patterns.defmatch( diff --git a/src/javascript/tests/with.spec.js b/src/javascript/tests/with.spec.js index 0ac09ced..c143d2ad 100644 --- a/src/javascript/tests/with.spec.js +++ b/src/javascript/tests/with.spec.js @@ -16,7 +16,11 @@ function map_fetch(map, key) { return Symbol.for('error'); } +<<<<<<< HEAD +test('with', async t => { +======= test('with', (t) => { +>>>>>>> master /* opts = %{width: 10, height: 15} @@ -29,7 +33,7 @@ test('with', (t) => { const opts = { width: 10, height: 15 }; - const value = SpecialForms._with( + const value = await SpecialForms._with( [new Tuple(Symbol.for('ok'), $), () => map_fetch(opts, 'width')], [new Tuple(Symbol.for('ok'), $), width => map_fetch(opts, 'height')], (width, height) => new Tuple(Symbol.for('ok'), width * height), @@ -38,7 +42,11 @@ test('with', (t) => { t.deepEqual(value, new Tuple(Symbol.for('ok'), 150)); }); +<<<<<<< HEAD +test('with without match', async t => { +======= test('with without match', (t) => { +>>>>>>> master /* opts = %{width: 10} @@ -51,7 +59,7 @@ test('with without match', (t) => { const opts = { width: 10 }; - const value = SpecialForms._with( + const value = await SpecialForms._with( [new Tuple(Symbol.for('ok'), $), () => map_fetch(opts, 'width')], [new Tuple(Symbol.for('ok'), $), () => map_fetch(opts, 'height')], (width, height) => new Tuple(Symbol.for('ok'), width * height), @@ -60,7 +68,11 @@ test('with without match', (t) => { t.deepEqual(value, Symbol.for('error')); }); +<<<<<<< HEAD +test('with bare expression', async t => { +======= test('with bare expression', (t) => { +>>>>>>> master /* opts = %{width: 10} @@ -74,7 +86,7 @@ test('with bare expression', (t) => { const opts = { width: 10, height: 15 }; - const value = SpecialForms._with( + const value = await SpecialForms._with( [new Tuple(Symbol.for('ok'), $), () => map_fetch(opts, 'width')], [$, width => width * 2], [new Tuple(Symbol.for('ok'), $), () => map_fetch(opts, 'height')], @@ -84,7 +96,11 @@ test('with bare expression', (t) => { t.deepEqual(value, new Tuple(Symbol.for('ok'), 300)); }); +<<<<<<< HEAD +test('with else', async t => { +======= test('with else', (t) => { +>>>>>>> master /* opts = %{width: 10} @@ -100,7 +116,7 @@ test('with else', (t) => { const opts = { width: 10 }; - const value = SpecialForms._with( + const value = await SpecialForms._with( [new Tuple(Symbol.for('ok'), $), () => map_fetch(opts, 'width')], [new Tuple(Symbol.for('ok'), $), () => map_fetch(opts, 'height')], (width, height) => new Tuple(Symbol.for('ok'), width * height), @@ -115,7 +131,7 @@ test('with else', (t) => { t.deepEqual(value, new Tuple(Symbol.for('error'), Symbol.for('wrong_data'))); }); -test('with else that don`t match', (t) => { +test('with else that don`t match', async t => { /* opts = %{width: 10} @@ -131,8 +147,7 @@ test('with else that don`t match', (t) => { const opts = { width: 10 }; - const withFunction = SpecialForms._with.bind( - null, + const withFunctionPromise = SpecialForms._with( [new Tuple(Symbol.for('ok'), $), () => map_fetch(opts, 'width')], [new Tuple(Symbol.for('ok'), $), () => map_fetch(opts, 'height')], (width, height) => new Tuple(Symbol.for('ok'), width * height), @@ -144,5 +159,5 @@ test('with else that don`t match', (t) => { ), ); - t.throws(withFunction, MatchError); + await t.throws(withFunctionPromise, MatchError); });