adjust spacing on test examples

This commit is contained in:
Nate 2024-09-17 15:40:35 -07:00
parent 9850288e39
commit 1aef8e71fb
6 changed files with 80 additions and 95 deletions

View file

@ -1,7 +1,7 @@
import fs from "node:fs";
// @ts-ignore no typings available
import { changed, diff as myersDiff } from "myers-diff";
import { diff as myersDiff } from "myers-diff";
import path from "node:path";
import { DiffLine, DiffLineType } from "../..";
import { dedent } from "../../util";
@ -36,25 +36,11 @@ async function collectDiffs(
return { ourDiffs, myersDiffs };
}
function getMyersDiffType(diff: any): MyersDiffTypes | undefined {
if (changed(diff.rhs) && !changed(diff.lhs)) {
return "new";
}
if (!changed(diff.rhs) && changed(diff.lhs)) {
return "old";
}
if (changed(diff.rhs) && changed(diff.lhs)) {
return "modification";
}
return undefined;
}
function displayDiff(diff: DiffLine[]) {
return diff
.map(({ type, line }) => `${UNIFIED_DIFF_SYMBOLS[type]} ${line}`)
.map(({ type, line }) =>
type === "same" ? line : `${UNIFIED_DIFF_SYMBOLS[type]} ${line}`,
)
.join("\n");
}
@ -129,19 +115,19 @@ describe("deterministicApplyLazyEdit(", () => {
expect(myersDiffs).toEqual([]);
});
test("fastapi", async () => {
test.skip("fastapi", async () => {
await expectDiff("fastapi.py");
});
test("calculator exp", async () => {
test.skip("calculator exp", async () => {
await expectDiff("calculator-exp.js");
});
test.only("calculator exp2", async () => {
test("calculator exp2", async () => {
await expectDiff("calculator-exp2.js");
});
test("calculator comments", async () => {
test.skip("calculator comments", async () => {
await expectDiff("calculator-comments.js");
});
});

View file

@ -86,7 +86,7 @@ function nodesAreSimilar(a: Parser.SyntaxNode, b: Parser.SyntaxNode): boolean {
}
if (
a.children[0]?.text === b.children[0]?.text &&
a.namedChildren[0]?.text === b.namedChildren[0]?.text &&
a.children[1]?.text === b.children[1]?.text
) {
return true;
@ -96,7 +96,7 @@ function nodesAreSimilar(a: Parser.SyntaxNode, b: Parser.SyntaxNode): boolean {
const lineOneB = b.text.split("\n")[0];
const levDist = distance(lineOneA, lineOneB);
return levDist / Math.min(lineOneA.length, lineOneB.length) <= 0.25;
return levDist / Math.min(lineOneA.length, lineOneB.length) <= 0.2;
}
function nodesAreExact(a: Parser.SyntaxNode, b: Parser.SyntaxNode): boolean {
@ -149,7 +149,6 @@ function diffNodes(
// Enter "lazy mode"
isLazy = true;
currentLazyBlockNode = R;
R.startIndex;
rightChildren.shift();
continue;
}

View file

@ -83,47 +83,47 @@ class Calculator {
---
class Calculator {
constructor() {
this.result = 0;
}
class Calculator {
constructor() {
this.result = 0;
}
+ // Adds the given number to the result
add(number) {
this.result += number;
return this;
}
add(number) {
this.result += number;
return this;
}
+ // Subtracts the given number from the result
subtract(number) {
this.result -= number;
return this;
}
subtract(number) {
this.result -= number;
return this;
}
+ // Multiplies the result by the given number
multiply(number) {
this.result *= number;
return this;
}
multiply(number) {
this.result *= number;
return this;
}
+ // Divides the result by the given number
+ // Throws an error if attempting to divide by zero
divide(number) {
if (number === 0) {
throw new Error("Cannot divide by zero");
}
this.result /= number;
return this;
}
divide(number) {
if (number === 0) {
throw new Error("Cannot divide by zero");
}
this.result /= number;
return this;
}
+ // Returns the current result
getResult() {
return this.result;
}
getResult() {
return this.result;
}
+ // Resets the result to zero
reset() {
this.result = 0;
return this;
}
}
reset() {
this.result = 0;
return this;
}
}

View file

@ -55,45 +55,45 @@ class Calculator {
---
class Calculator {
constructor() {
this.result = 0;
}
class Calculator {
constructor() {
this.result = 0;
}
add(number) {
this.result += number;
return this;
}
add(number) {
this.result += number;
return this;
}
subtract(number) {
this.result -= number;
return this;
}
subtract(number) {
this.result -= number;
return this;
}
multiply(number) {
this.result *= number;
return this;
}
multiply(number) {
this.result *= number;
return this;
}
divide(number) {
if (number === 0) {
throw new Error("Cannot divide by zero");
}
this.result /= number;
return this;
}
divide(number) {
if (number === 0) {
throw new Error("Cannot divide by zero");
}
this.result /= number;
return this;
}
+
+ exp(a) {
+ this.result = Math.pow(this.result, a);
+ return this;
+ }
getResult() {
return this.result;
}
getResult() {
return this.result;
}
reset() {
this.result = 0;
return this;
}
}
reset() {
this.result = 0;
return this;
}
}

View file

@ -86,8 +86,8 @@ class Calculator {
return this;
}
+
+ exp(a) {
+ this.result = Math.pow(this.result, a);
+ exp(number) {
+ this.result = Math.pow(this.result, number);
+ return this;
+ }
}

View file

@ -25,13 +25,13 @@ def read_landing_page():
- from fastapi import FastAPI
+ from fastapi import FastAPI, HTTPException
app = FastAPI()
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/landing")
def read_landing_page():
@app.get("/landing")
def read_landing_page():
- return {"message": "Welcome to the landing page"}
+ raise HTTPException(status_code=404, detail="Page not found")