File: main.coffee

package info (click to toggle)
node-external-editor 2.0.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 140 kB
  • ctags: 8
  • sloc: makefile: 10; sh: 2
file content (48 lines) | stat: -rw-r--r-- 1,212 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
assert = require('chai').assert
readFileSync = require('fs').readFileSync
ExternalEditor = require('../../src')

describe 'main', ->
  before ->
    @previous_visual = process.env.VISUAL
    process.env.VISUAL = 'truncate --size 1'

  beforeEach ->
    @editor = new ExternalEditor 'XXX'

  afterEach ->
    @editor.cleanup()

  after ->
    process.env.VISUAL = @previous_visual

  it 'convenience method ".edit"', ->
    text = ExternalEditor.edit 'XXX'
    assert.equal text, 'X'

  it 'convenience method ".editAsync"', (cb) ->
    ExternalEditor.editAsync 'XXX', (e, text) ->
      assert.equal text, 'X'
      cb()

  it 'writes original text to file', ->
    contents = readFileSync this.editor.temp_file
    assert.equal contents, 'XXX'

  it 'run() returns correctly', ->
    text = @editor.run()
    assert.equal text, 'X'

  it 'runAsync() callbacks correctly', (cb) ->
    @editor.runAsync (e, text) ->
      assert.equal text, 'X'
      cb()

  it 'run() returns text same as editor.text', ->
    text = @editor.run()
    assert.equal text, @editor.text

  it 'runAsync() callback text same as editor.text', (cb) ->
    @editor.runAsync (e, text) =>
      assert.equal text, @editor.text
      cb()