passsy / pure-functionsr3
Keep Functions Pure
PublicKeep 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
✓fires9.4 ms
points at the principle when the user mentions side effects in a Dart project
prompt · in fixtures/dart_appfired: "side effect"
The getter has a side effect, it writes to the cache✓fires8.6 ms
points at the principle on pure functions
prompt · in fixtures/dart_appfired: "pure functions"
Turn the parser into pure functions✓quiet3.1 ms
stays quiet on the same words outside a Dart project
promptstayed quiet
The getter has a side effect, it writes to the cache✓quiet9.6 ms
stays quiet on a prompt about something else
prompt · in fixtures/dart_appstayed quiet
Add a function that parses the datedetector.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([]);
});