pulsar/spec/atom/editor-spec.coffee

31 lines
939 B
CoffeeScript
Raw Normal View History

2012-01-05 23:13:55 +04:00
Buffer = require 'buffer'
Editor = require 'editor'
$ = require 'jquery'
fs = require 'fs'
2012-01-17 07:23:27 +04:00
describe "Editor", ->
2012-01-17 05:17:36 +04:00
buffer = null
editor = null
beforeEach ->
2012-01-17 05:17:36 +04:00
buffer = new Buffer(require.resolve('fixtures/sample.js'))
editor = Editor.build()
2012-01-17 05:17:36 +04:00
describe ".setBuffer", ->
it "creates a pre element for each line in the buffer", ->
editor.setBuffer(buffer)
2012-01-17 05:17:36 +04:00
expect(editor.lines.find('pre').length).toEqual(buffer.numLines())
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)
describe ".setPosition({row, col})", ->
2012-01-17 07:23:27 +04:00
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())