aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.prettierignore1
-rw-r--r--package.json2
-rw-r--r--src/types.ts2
-rw-r--r--src/util.ts7
-rw-r--r--stdlib/test.ts11
-rw-r--r--tests/builtins.spec.ts156
-rw-r--r--yarn.lock5
7 files changed, 116 insertions, 68 deletions
diff --git a/.prettierignore b/.prettierignore
new file mode 100644
index 0000000..849ddff
--- /dev/null
+++ b/.prettierignore
@@ -0,0 +1 @@
+dist/
diff --git a/package.json b/package.json
index ee05696..73b52e1 100644
--- a/package.json
+++ b/package.json
@@ -11,6 +11,7 @@
},
"scripts": {
"build": "tsc",
+ "format": "prettier --write ./**/*.ts",
"postinstall": "yarn build",
"cli": "ts-node src/index.ts"
},
@@ -23,6 +24,7 @@
"uuid": "^9.0.0"
},
"devDependencies": {
+ "prettier": "^2.8.3",
"ts-node": "^10.9.1"
}
}
diff --git a/src/types.ts b/src/types.ts
index 55d2cce..7be4c98 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -14,7 +14,7 @@ export interface Ctx {
getTypeValue: (ty: Type | undefined) => any
createResult: (ty: string) => [string, Node | undefined]
- removeResult: (key?: string) => void,
+ removeResult: (key?: string) => void
getResultExpr: (key?: string) => string
printResultNode: () => void
diff --git a/src/util.ts b/src/util.ts
index 2746746..a486294 100644
--- a/src/util.ts
+++ b/src/util.ts
@@ -14,7 +14,11 @@ export const evalList = async (ctx: Ctx, effectTyps: Type[]) => {
return effectResults
}
-export const applyFunc = (ctx: Ctx, fn: Type | undefined, val: string): Type => {
+export const applyFunc = (
+ ctx: Ctx,
+ fn: Type | undefined,
+ val: string
+): Type => {
const resultType = (() => {
const baseTypes = fn
?.getBaseTypes()
@@ -73,4 +77,3 @@ export const applyFunc = (ctx: Ctx, fn: Type | undefined, val: string): Type =>
return resultType
}
-
diff --git a/stdlib/test.ts b/stdlib/test.ts
index 86ed6a9..fd1045b 100644
--- a/stdlib/test.ts
+++ b/stdlib/test.ts
@@ -9,16 +9,15 @@ export interface Config {
export interface Assert<_B extends boolean> extends Effect {}
-export interface Test<_m extends string, _effs extends Effect[]> extends Effect {}
+export interface Test<_m extends string, _effs extends Effect[]>
+ extends Effect {}
-export interface ShowAssertionError<_L extends unknown, _R extends unknown> extends Effect {}
+export interface ShowAssertionError<_L extends unknown, _R extends unknown>
+ extends Effect {}
export type AssertEquals<Left, Right> = Try<
Assert<Equals<Left, Right>>,
- <m>() => Do<[
- ShowAssertionError<Left, Right>,
- Throw<m>,
- ]>
+ <m>() => Do<[ShowAssertionError<Left, Right>, Throw<m>]>
>
export interface AssertEqualsK<Right extends unknown> extends Kind1 {
diff --git a/tests/builtins.spec.ts b/tests/builtins.spec.ts
index cbac0d3..31e2cc0 100644
--- a/tests/builtins.spec.ts
+++ b/tests/builtins.spec.ts
@@ -4,7 +4,8 @@ import { PutStringLn } from '../stdlib/stdio'
import { DefineEffect, JsExpr, SetEvalEnvironment } from '../stdlib/sys'
import { Test, AssertEqualsK, AssertEquals } from '../stdlib/test'
-interface MyEffect<_a extends number, _b extends string, _c extends unknown> extends Effect {}
+interface MyEffect<_a extends number, _b extends string, _c extends unknown>
+ extends Effect {}
export type main = [
SetEvalEnvironment<'test.node'>,
@@ -13,84 +14,121 @@ export type main = [
PutStringLn<'=== Running tests ==='>,
PutStringLn<'=====================\n\n'>,
- Do<[
- PutStringLn<'Bind & BindTo'>,
+ Do<
+ [
+ PutStringLn<'Bind & BindTo'>,
- Test<'should bind value to function and kind', [
- Bind<Pure<[1,2,3]>, <val extends number[]>() =>
- AssertEquals<val, [1, 2, 3]>>,
+ Test<
+ 'should bind value to function and kind',
+ [
+ Bind<
+ Pure<[1, 2, 3]>,
+ <val extends number[]>() => AssertEquals<val, [1, 2, 3]>
+ >,
- Bind<Pure<[1,2,3]>, AssertEqualsK<[1,2,3]>>,
- ]>,
+ Bind<Pure<[1, 2, 3]>, AssertEqualsK<[1, 2, 3]>>
+ ]
+ >,
- Test<'should bind label correctly', [
- BindTo<"value", Pure<{ a: 'b', c: { d: 1 } }>>,
+ Test<
+ 'should bind label correctly',
+ [
+ BindTo<'value', Pure<{ a: 'b'; c: { d: 1 } }>>,
- Bind<Label<"value">, AssertEqualsK<{ a: 'b', c: { d: 1 } }>>,
- ]>,
+ Bind<Label<'value'>, AssertEqualsK<{ a: 'b'; c: { d: 1 } }>>
+ ]
+ >,
- Test<'should bind only inside Do scope', [
- Do<[
- BindTo<"value", Pure<"some value">>,
- Bind<Label<"value">, AssertEqualsK<"some value">>,
- ]>,
+ Test<
+ 'should bind only inside Do scope',
+ [
+ Do<
+ [
+ BindTo<'value', Pure<'some value'>>,
+ Bind<Label<'value'>, AssertEqualsK<'some value'>>
+ ]
+ >,
- Bind<
- Try<Label<"value">, <_>() => Pure<"none">>,
- AssertEqualsK<"none">
+ Bind<
+ Try<Label<'value'>, <_>() => Pure<'none'>>,
+ AssertEqualsK<'none'>
+ >
+ ]
>,
- ]>,
- Test<'should bind only inside Bind scope', [
- Bind<
- BindTo<"value", Pure<"some value">>,
- <_>() => Bind<Label<"value">, AssertEqualsK<"some value">>
- >,
+ Test<
+ 'should bind only inside Bind scope',
+ [
+ Bind<
+ BindTo<'value', Pure<'some value'>>,
+ <_>() => Bind<Label<'value'>, AssertEqualsK<'some value'>>
+ >,
- Bind<
- Try<Label<"value">, <_>() => Pure<"none">>,
- AssertEqualsK<"none">
- >,
- ]>,
- ]>,
+ Bind<
+ Try<Label<'value'>, <_>() => Pure<'none'>>,
+ AssertEqualsK<'none'>
+ >
+ ]
+ >
+ ]
+ >,
- Do<[
- PutStringLn<'Try/Throw'>,
+ Do<
+ [
+ PutStringLn<'Try/Throw'>,
- Test<'should return the result of effect', [
- Bind<Try<Pure<20>, <_>() => Pure<0>>,
- AssertEqualsK<20>>,
- ]>,
+ Test<
+ 'should return the result of effect',
+ [Bind<Try<Pure<20>, <_>() => Pure<0>>, AssertEqualsK<20>>]
+ >,
- Test<'should return the result of error handler', [
- Bind<Try<Do<[ Throw<"wow">, Pure<20> ]>, <_>() => Pure<0>>,
- AssertEqualsK<0>>,
+ Test<
+ 'should return the result of error handler',
+ [
+ Bind<
+ Try<Do<[Throw<'wow'>, Pure<20>]>, <_>() => Pure<0>>,
+ AssertEqualsK<0>
+ >,
- Bind<Try<Do<[ Throw<"wow">, Pure<20> ]>, <e>() => Pure<e>>,
- AssertEqualsK<"wow">>,
- ]>,
- ]>,
+ Bind<
+ Try<Do<[Throw<'wow'>, Pure<20>]>, <e>() => Pure<e>>,
+ AssertEqualsK<'wow'>
+ >
+ ]
+ >
+ ]
+ >,
- Do<[
- PutStringLn<'FFI'>,
+ Do<
+ [
+ PutStringLn<'FFI'>,
- Test<'should return the result of js expression', [
- Bind<JsExpr<'69 * 420'>, AssertEqualsK<28980>>,
- ]>,
+ Test<
+ 'should return the result of js expression',
+ [Bind<JsExpr<'69 * 420'>, AssertEqualsK<28980>>]
+ >,
- Test<'should test custom effect', [
- DefineEffect<'MyEffect', `([a, b, c], ctx) => {
+ Test<
+ 'should test custom effect',
+ [
+ DefineEffect<
+ 'MyEffect',
+ `([a, b, c], ctx) => {
return [
ctx.getTypeValue(a) * 2,
ctx.getTypeValue(b) + '!',
[...ctx.getTypeValue(c), 'wow'],
]
- }`>,
- Bind<MyEffect<4, "hey", [1, 2]>, AssertEqualsK<[
- 8, "hey!", [1, 2, 'wow'],
- ]>>,
- ]>,
- ]>,
+ }`
+ >,
+ Bind<
+ MyEffect<4, 'hey', [1, 2]>,
+ AssertEqualsK<[8, 'hey!', [1, 2, 'wow']]>
+ >
+ ]
+ >
+ ]
+ >,
- PutStringLn<"">,
+ PutStringLn<''>
]
diff --git a/yarn.lock b/yarn.lock
index ddf2f69..fdc0425 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -231,6 +231,11 @@ picomatch@^2.3.1:
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==
+prettier@^2.8.3:
+ version "2.8.3"
+ resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.3.tgz#ab697b1d3dd46fb4626fbe2f543afe0cc98d8632"
+ integrity sha512-tJ/oJ4amDihPoufT5sM0Z1SKEuKay8LfVAMlbbhnnkvt6BUserZylqo2PN+p9KeljLr0OHa2rXHU1T8reeoTrw==
+
queue-microtask@^1.2.2:
version "1.2.3"
resolved "https://registry.yarnpkg.com/queue-microtask/-/queue-microtask-1.2.3.tgz#4929228bbc724dfac43e0efb058caf7b6cfb6243"