Skip to content

Custom assertion #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 19, 2022
Merged
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
2 changes: 1 addition & 1 deletion src/lambda-calculus.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export function toInt(term) {
} else if ( config.numEncoding === "None" )
return term;
else
return numEncoding.toInt(term); // Custom encoding
return config.numEncoding.toInt(term); // Custom encoding
} catch (e) {
if ( config.verbosity >= "Concise" ) console.error(`toInt: ${ term } is not a number in numEncoding ${ numEncoding }`);
throw e;
Expand Down
19 changes: 17 additions & 2 deletions workspace/lc-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { readFileSync } from "fs";

export { assert, config } from "chai";
export * as LC from "@codewars/lambda-calculus";
import { assert, config } from "chai";
import * as LC from "../src/lambda-calculus.js";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work because there's no src/ in the image. @codewars/lambda-calculus is the package installed there.

To test without creating a new image, run npm install first in workspace/ to get workspace/node_modules/ then run npx mocha. If you have unreleased changes you want to test, release the package and update package.json before npm install. You can also do this temporarily locally to quickly test before releasing a new version, but don't commit the change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh of course 🤦‍♂️ I did plan to revert that but forgot


export { assert, config, LC };

const read = (path) => readFileSync(new URL(path, import.meta.url), {encoding: "utf8"});

Expand All @@ -13,3 +15,16 @@ export const getPreloaded = () => read("./preloaded.lc");

/** Return the contents of the preloaded file and the solution file combined */
export const getSolutionWithPreloaded = () => getPreloaded() + "\n_ = ()\n" + getSolution();


/** Custom assertions */

function numEql(got, exp, msg) {
if ( got?.term && got?.env ) got = LC.toInt(got);
if ( exp?.term && exp?.env ) exp = LC.toInt(exp);
return this.equal(got, exp, msg);
}

Object.assign(assert, {
numEql
});