Skip to content

Commit a878d2d

Browse files
committed
test eval top-level
1 parent 9959d83 commit a878d2d

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/eval-region.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ const evalAtCursor = (view) => {
8585
return true
8686
}
8787

88-
const clearEval = (view) => {
88+
export const clearEval = (view) => {
8989
if (evalResult.length != 0) {
9090
evalResult = ""
9191
updateEditor(view, codeBeforeEval, posBeforeEval)
9292
}
9393
}
9494

95-
const evalTopLevel = (view) => {
95+
export const evalTopLevel = (view) => {
9696
posAtFormEnd = topLevelNode(view.state).to
9797
const doc = view.state.doc.toString()
9898
posBeforeEval = view.state.selection.main.head

test/lang-clojure-eval.test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {describe, expect, test, it} from 'vitest'
22
import {EditorState} from "@codemirror/state"
33
import {EditorView} from "codemirror"
44
import {evalString} from "../src/sci"
5-
import {evalCell} from '../src/eval-region'
5+
import {evalCell, clearEval, evalTopLevel} from '../src/eval-region'
66
import {clojure} from "../src/clojure"
77

88
describe('Editor state', () => {
@@ -26,4 +26,13 @@ describe('Editor state', () => {
2626
evalCell(view)
2727
expect(view.state.doc.text.join(" ")).eq("(map inc (range 5)) => (1 2 3 4 5)")
2828
})
29+
it('Clears evaluation result', () => {
30+
clearEval(view)
31+
expect(view.state.doc.text.join(" ")).eq("(map inc (range 5))")
32+
})
33+
it('Evaluates top-level form', () => {
34+
evalTopLevel(view)
35+
console.log(view.state.doc.toString())
36+
expect(view.state.doc.toString()).eq("(map inc (range 5)) => (1 2 3 4 5) ")
37+
})
2938
})

0 commit comments

Comments
 (0)