Skip to content

Commit 816ff3a

Browse files
committed
test evalAtCursor
1 parent a878d2d commit 816ff3a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/eval-region.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export function tryEval(s) {
7272
}
7373
}
7474

75-
const evalAtCursor = (view) => {
75+
export const evalAtCursor = (view) => {
7676
const doc = view.state.doc.toString()
7777
codeBeforeEval = doc
7878
posBeforeEval = view.state.selection.main.head

test/lang-clojure-eval.test.js

Lines changed: 7 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, clearEval, evalTopLevel} from '../src/eval-region'
5+
import {evalCell, clearEval, evalTopLevel, evalAtCursor} from '../src/eval-region'
66
import {clojure} from "../src/clojure"
77

88
describe('Editor state', () => {
@@ -35,4 +35,10 @@ describe('Editor state', () => {
3535
console.log(view.state.doc.toString())
3636
expect(view.state.doc.toString()).eq("(map inc (range 5)) => (1 2 3 4 5) ")
3737
})
38+
it('Evaluates at cursor', () => {
39+
clearEval(view)
40+
view.dispatch({selection: {anchor: 18, head: 18}})
41+
evalAtCursor(view)
42+
expect(view.state.doc.toString()).eq("(map inc (range 5) => (0 1 2 3 4) )")
43+
})
3844
})

0 commit comments

Comments
 (0)