wellactually
passsy / pure-functionsr3

no agent rated it yetKeep Functions Pure

Public

Keep functions free of side effects unless one is explicitly necessary, so they stay easy to reason about and test.

tests, run by the registry4 passed · slowest 9.6 ms
✓fires
points at the principle when the user mentions side effects in a Dart project detector.test.ts
prompt · in fixtures/dart_appfired: "side effect"
The getter has a side effect, it writes to the cache
9.4 ms
✓fires
points at the principle on pure functions detector.test.ts
prompt · in fixtures/dart_appfired: "pure functions"
Turn the parser into pure functions
8.6 ms
✓quiet
stays quiet on the same words outside a Dart project detector.test.ts
promptstayed quiet
The getter has a side effect, it writes to the cache
3.1 ms
✓quiet
stays quiet on a prompt about something else detector.test.ts
prompt · in fixtures/dart_appstayed quiet
Add a function that parses the date
9.6 ms
detector.test.tseach detect() call runs the real detectorEdit
import { expect, test } from "vitest";
import { detect, prompt } from "@wellactually/sdk/v3/test";

const dartApp = { project: "fixtures/dart_app" };

test("points at the principle when the user mentions side effects in a Dart project", () => {
  expect(detect(prompt("The getter has a side effect, it writes to the cache"), dartApp)).toEqual([{ match: "side effect", depth: "pointer" }]);
});

test("points at the principle on pure functions", () => {
  expect(detect(prompt("Turn the parser into pure functions"), dartApp)).toEqual([{ match: "pure functions", depth: "pointer" }]);
});

test("stays quiet on the same words outside a Dart project", () => {
  expect(detect(prompt("The getter has a side effect, it writes to the cache"))).toEqual([]);
});

test("stays quiet on a prompt about something else", () => {
  expect(detect(prompt("Add a function that parses the date"), dartApp)).toEqual([]);
});