2012-01-05 23:13:55 +04:00
|
|
|
Buffer = require 'buffer'
|
2011-12-16 02:13:34 +04:00
|
|
|
Editor = require 'editor'
|
|
|
|
$ = require 'jquery'
|
2011-12-17 02:42:38 +04:00
|
|
|
fs = require 'fs'
|
2011-12-16 02:13:34 +04:00
|
|
|
|
2012-01-17 07:23:27 +04:00
|
|
|
describe "Editor", ->
|
2012-01-17 05:17:36 +04:00
|
|
|
buffer = null
|
2011-12-17 04:25:33 +04:00
|
|
|
editor = null
|
2011-12-16 02:13:34 +04:00
|
|
|
|
|
|
|
beforeEach ->
|
2012-01-17 05:17:36 +04:00
|
|
|
buffer = new Buffer(require.resolve('fixtures/sample.js'))
|
2011-12-29 23:12:13 +04:00
|
|
|
editor = Editor.build()
|
2011-12-16 02:13:34 +04:00
|
|
|
|
2012-01-17 05:17:36 +04:00
|
|
|
describe ".setBuffer", ->
|
|
|
|
it "creates a pre element for each line in the buffer", ->
|
2012-01-06 04:33:53 +04:00
|
|
|
editor.setBuffer(buffer)
|
2012-01-17 05:17:36 +04:00
|
|
|
expect(editor.lines.find('pre').length).toEqual(buffer.numLines())
|
2012-01-11 07:16:46 +04:00
|
|
|
|
2012-01-17 05:17:36 +04:00
|
|
|
it "sets the cursor to the beginning of the file", ->
|
|
|
|
expect(editor.getPosition()).toEqual(row: 0, col: 0)
|
2012-01-11 07:16:46 +04:00
|
|
|
|
2012-01-17 07:23:27 +04:00
|
|
|
fdescribe ".setPosition({row, col})", ->
|
|
|
|
it "moves the cursor to cover the character at the given row and column", ->
|
|
|
|
editor.attachToDom()
|
|
|
|
editor.setBuffer(buffer)
|
|
|
|
editor.setPosition(row: 2, col: 2)
|
|
|
|
|
|
|
|
expect(editor.cursor.position().top).toBe(2 * editor.lineHeight())
|
|
|
|
expect(editor.cursor.position().left).toBe(2 * editor.charWidth())
|
|
|
|
|