Skip to content
Open
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
28 changes: 12 additions & 16 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"lint": "eslint \"**/{src,test,examples,scripts,dtslint}/**/*.{ts,mjs}\"",
"lint-fix": "pnpm lint --fix",
"test": "bun test",
"vitest": "vitest",
"coverage": "bun test --coverage",
"repl": " bun src/services/cli.ts repl",
"dev": "vite dev",
Expand Down Expand Up @@ -52,7 +53,7 @@
"@effect/build-utils": "0.7.8",
"@effect/eslint-plugin": "0.2.0",
"@effect/language-service": "0.2.0",
"@effect/vitest": "0.17.3",
"@effect/vitest": "0.19.0",
"@eslint/compat": "1.2.5",
"@eslint/eslintrc": "3.2.0",
"@eslint/js": "9.19.0",
Expand All @@ -73,7 +74,7 @@
"tsx": "4.19.2",
"typescript": "5.7.3",
"vite": "^6.1.0",
"vitest": "3.0.4"
"vitest": "3.0.7"
},
"effect": {
"generateExports": {
Expand Down
7 changes: 5 additions & 2 deletions src/services/object/builtins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,11 @@ export const builtInFnMap = {
const firstArg = args[0];

return yield* Match.value(firstArg).pipe(
Match.tag("StringObj", (strObj) =>
Effect.succeed(IntegerObj.make({ value: strObj.value.length })),
Match.tag("StringObj", ({ value }) =>
Effect.succeed(IntegerObj.make({ value: value.length })),
),
Match.tag("ArrayObj", ({ elements }) =>
Effect.succeed(IntegerObj.make({ value: elements.length })),
),
Match.orElse(() =>
Effect.succeed(
Expand Down
44 changes: 44 additions & 0 deletions src/tests/property/eval/eval.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { BooleanObj } from "@/schemas/objs/bool";
import { IntegerObj } from "@/schemas/objs/int";
import { Evaluator } from "@/services/evaluator";
import { OPERATOR_TO_FUNCTION_MAP } from "@/services/evaluator/constants";
import { it } from "@effect/vitest";
import { Effect, Schema } from "effect";
import { logDebug } from "effect/Effect";

// Testing a successful division
it.prop(
"prefix operator",
[
Schema.Number.pipe(Schema.int()),
Schema.Literal("+"),
Schema.Number.pipe(Schema.int()),
],
([left, operator, right]) =>
Effect.gen(function* () {
const evaluator = yield* Evaluator;
const evaluation = yield* evaluator.run(`${left} ${operator} ${right}`);
const { value } = yield* Schema.decodeUnknown(
Schema.Union(IntegerObj, BooleanObj),
)(evaluation);
yield* logDebug("value", value);
const jsValue = OPERATOR_TO_FUNCTION_MAP[operator](left, right);
yield* logDebug("jsValue", jsValue);
return true;
// if (value !== jsValue)
// throw new Error(`expected ${jsValue}, got ${value}`);
}),
);

SELECT
co.status,
co.company,
co.affiliateComission
FROM
`cartorder` co
LEFT JOIN `account` a ON co.`accountId` = a.`accountId`
LEFT JOIN customer c ON c.customerId = a.customerId
WHERE
co.`referringAffiliateId` = 4016
AND c.customerId = 48994
AND co.wc_status = 'completed'
43 changes: 43 additions & 0 deletions src/tests/property/pbt/pbt.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { it } from "@effect/vitest";
import { Schema } from "effect";

class Letter extends Schema.Class<Letter>("Letter")({
name: Schema.String.pipe(
Schema.minLength(1),
Schema.filter((s) => s.match(/^[a-z]+$/) !== null),
),
age: Schema.Int.pipe(Schema.between(1, 77)),
}) {
static Array = Schema.Array(this);
}

function sortLetters(letters: Schema.Schema.Type<typeof Letter.Array>) {
const clonedLetters = [...letters];
return clonedLetters.sort(
(la, lb) =>
la.age - lb.age || la.name.codePointAt(0)! - lb.name.codePointAt(0)!,
);
}

it.prop(
"day #1: should properly sort letters",
[Letter.Array],
([unsortedLetters]) => {
const letters = sortLetters(unsortedLetters);
for (let i = 1; i < letters.length; ++i) {
const prev = letters[i - 1];
const curr = letters[i];
if (prev.age < curr.age) continue; // properly ordered
if (prev.age > curr.age) throw new Error("Invalid on age");
if (prev.name > curr.name) throw new Error("Invalid on name");
}
},
{
fails: false,
fastCheck: {
seed: 1485455336,
path: "352:3:7:9:9:13:12:11",
endOnFailure: true,
},
},
);
32 changes: 16 additions & 16 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import path from "path"
import { defineConfig } from "vitest/config"
import path from "node:path";
import { defineConfig } from "vitest/config";

export default defineConfig({
plugins: [
],
test: {
setupFiles: [path.join(__dirname, "setupTests.ts")],
include: ["./test/**/*.test.ts"],
globals: true
},
resolve: {
alias: {
"@template/basic/test": path.join(__dirname, "test"),
"@template/basic": path.join(__dirname, "src")
}
}
})
plugins: [],
test: {
// setupFiles: [path.join(__dirname, "setupTests.ts")],
include: ["./src/tests/property/**/*.test.ts"],
globals: true,
},
resolve: {
alias: {
"@template/basic/test": path.join(__dirname, "test"),
"@template/basic": path.join(__dirname, "src"),
"@": path.resolve(__dirname, "./src"),
},
},
});