more cleanups, some tests
This commit is contained in:
parent
6055320aa2
commit
0137b44689
41
packages/squiggle-lang/__tests__/SqError_test.res
Normal file
41
packages/squiggle-lang/__tests__/SqError_test.res
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
open Jest
|
||||||
|
open Expect
|
||||||
|
|
||||||
|
describe("SqError.Message", () => {
|
||||||
|
test("toString", () =>
|
||||||
|
expect(SqError.Message.REOther("test error")->SqError.Message.toString)->toBe(
|
||||||
|
"Error: test error",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("SqError", () => {
|
||||||
|
test("fromMessage", () =>
|
||||||
|
expect(SqError.Message.REOther("test error")->SqError.fromMessage->SqError.toString)->toBe(
|
||||||
|
"Error: test error",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
test("toStringWithStackTrace with empty stacktrace", () =>
|
||||||
|
expect(
|
||||||
|
SqError.Message.REOther("test error")->SqError.fromMessage->SqError.toStringWithStackTrace,
|
||||||
|
)->toBe("Error: test error")
|
||||||
|
)
|
||||||
|
|
||||||
|
test("toStringWithStackTrace", () => {
|
||||||
|
let frameStack =
|
||||||
|
Reducer_FrameStack.make()
|
||||||
|
->Reducer_FrameStack.extend("frame1", None)
|
||||||
|
->Reducer_FrameStack.extend("frame2", None)
|
||||||
|
|
||||||
|
expect(
|
||||||
|
SqError.Message.REOther("test error")
|
||||||
|
->SqError.fromMessageWithFrameStack(frameStack)
|
||||||
|
->SqError.toStringWithStackTrace,
|
||||||
|
)->toBe(`Error: test error
|
||||||
|
Stack trace:
|
||||||
|
frame2
|
||||||
|
frame1
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
})
|
|
@ -43,8 +43,6 @@ export class SqFrame {
|
||||||
}
|
}
|
||||||
|
|
||||||
location() {
|
location() {
|
||||||
console.log(RSFrameStack);
|
|
||||||
console.log(RSFrameStack.Frame);
|
|
||||||
return RSFrameStack.Frame.getLocation(this._value);
|
return RSFrameStack.Frame.getLocation(this._value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ module Frame = {
|
||||||
name ++
|
name ++
|
||||||
switch location {
|
switch location {
|
||||||
| Some(location) =>
|
| Some(location) =>
|
||||||
` at line ${location.start.line->Js.Int.toString}, column ${location.start.column->Js.Int.toString}`
|
` at line ${location.start.line->Js.Int.toString}, column ${location.start.column->Js.Int.toString}` // TODO - source id?
|
||||||
| None => ""
|
| None => ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,9 +27,11 @@ let extend = (t: t, name: string, location: option<Reducer_Peggy_Parse.location>
|
||||||
location: location,
|
location: location,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// this is useful for SyntaxErrors
|
||||||
let makeSingleFrameStack = (location: Reducer_Peggy_Parse.location): t =>
|
let makeSingleFrameStack = (location: Reducer_Peggy_Parse.location): t =>
|
||||||
make()->extend(Reducer_T.topFrameName, Some(location))
|
make()->extend(Reducer_T.topFrameName, Some(location))
|
||||||
|
|
||||||
|
// this includes the left offset because it's mostly used in SqError.toStringWithStackTrace
|
||||||
let toString = (t: t) =>
|
let toString = (t: t) =>
|
||||||
t
|
t
|
||||||
->Belt.List.map(s => " " ++ s->Frame.toString ++ "\n")
|
->Belt.List.map(s => " " ++ s->Frame.toString ++ "\n")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user