Merge branch 'master' into mb-tree-sitter-parsers

This commit is contained in:
Max Brunsfeld
2017-12-06 14:56:09 -08:00
10 changed files with 121 additions and 36 deletions

View File

@@ -9,34 +9,41 @@ ipcHelpers = require '../src/ipc-helpers'
formatStackTrace = (spec, message='', stackTrace) ->
return stackTrace unless stackTrace
# at ... (.../jasmine.js:1:2)
jasminePattern = /^\s*at\s+.*\(?.*[/\\]jasmine(-[^/\\]*)?\.js:\d+:\d+\)?\s*$/
firstJasmineLinePattern = /^\s*at [/\\].*[/\\]jasmine(-[^/\\]*)?\.js:\d+:\d+\)?\s*$/
# at jasmine.Something... (.../jasmine.js:1:2)
firstJasmineLinePattern = /^\s*at\s+jasmine\.[A-Z][^\s]*\s+\(?.*[/\\]jasmine(-[^/\\]*)?\.js:\d+:\d+\)?\s*$/
lines = []
for line in stackTrace.split('\n')
lines.push(line) unless jasminePattern.test(line)
break if firstJasmineLinePattern.test(line)
lines.push(line) unless jasminePattern.test(line)
# Remove first line of stack when it is the same as the error message
errorMatch = lines[0]?.match(/^Error: (.*)/)
lines.shift() if message.trim() is errorMatch?[1]?.trim()
for line, index in lines
# Remove prefix of lines matching: at jasmine.Spec.<anonymous> (path:1:2)
prefixMatch = line.match(/at jasmine\.Spec\.<anonymous> \(([^)]+)\)/)
line = "at #{prefixMatch[1]}" if prefixMatch
lines = lines.map (line) ->
# Only format actual stacktrace lines
if /^\s*at\s/.test(line)
# Needs to occur before path relativization
if process.platform is 'win32' and /file:\/\/\//.test(line)
# file:///C:/some/file -> C:\some\file
line = line.replace('file:///', '').replace(///#{path.posix.sep}///g, path.win32.sep)
# Relativize locations to spec directory
if process.platform is 'win32'
line = line.replace('file:///', '').replace(///#{path.posix.sep}///g, path.win32.sep)
line = line.replace("at #{spec.specDirectory}#{path.sep}", 'at ')
lines[index] = line.replace("(#{spec.specDirectory}#{path.sep}", '(') # at step (path:1:2)
line = line.trim()
# at jasmine.Spec.<anonymous> (path:1:2) -> at path:1:2
.replace(/^at jasmine\.Spec\.<anonymous> \(([^)]+)\)/, 'at $1')
# at it (path:1:2) -> at path:1:2
.replace(/^at f*it \(([^)]+)\)/, 'at $1')
# at spec/file-test.js -> at file-test.js
.replace(spec.specDirectory + path.sep, '')
return line
lines = lines.map (line) -> line.trim()
lines.join('\n').trim()
module.exports =
class AtomReporter
constructor: ->
@element = document.createElement('div')
@element.classList.add('spec-reporter-container')

View File

@@ -70,6 +70,19 @@ describe('TextEditorElement', () => {
expect(element.getModel().isLineNumberGutterVisible()).toBe(false)
})
it("honors the 'readonly' attribute", async function() {
jasmineContent.innerHTML = "<atom-text-editor readonly>"
const element = jasmineContent.firstChild
expect(element.getComponent().isInputEnabled()).toBe(false)
element.removeAttribute('readonly')
expect(element.getComponent().isInputEnabled()).toBe(true)
element.setAttribute('readonly', true)
expect(element.getComponent().isInputEnabled()).toBe(false)
})
it('honors the text content', () => {
jasmineContent.innerHTML = '<atom-text-editor>testing</atom-text-editor>'
const element = jasmineContent.firstChild

View File

@@ -86,6 +86,23 @@ describe('TextEditor', () => {
})
})
describe('when the editor is readonly', () => {
it('overrides TextBuffer.isModified to return false', async () => {
const editor = await atom.workspace.open(null, {readOnly: true})
editor.setText('I am altering the buffer, pray I do not alter it any further')
expect(editor.isModified()).toBe(false)
editor.setReadOnly(false)
expect(editor.isModified()).toBe(true)
})
it('clears the readonly status when saved', async () => {
const editor = await atom.workspace.open(null, {readOnly: true})
editor.setText('I am altering the buffer, pray I do not alter it any further')
expect(editor.isReadOnly()).toBe(true)
await editor.saveAs(temp.openSync('was-readonly').path)
expect(editor.isReadOnly()).toBe(false)
})
})
describe('.copy()', () => {
it('returns a different editor with the same initial state', () => {
expect(editor.getAutoHeight()).toBeFalsy()

View File

@@ -1,5 +1,7 @@
const path = require('path')
const temp = require('temp').track()
const dedent = require('dedent')
const TextBuffer = require('text-buffer')
const TextEditor = require('../src/text-editor')
const Workspace = require('../src/workspace')
const Project = require('../src/project')
@@ -932,6 +934,18 @@ describe('Workspace', () => {
})
})
})
describe('when opening an editor with a buffer that isn\'t part of the project', () => {
it('adds the buffer to the project', async () => {
const buffer = new TextBuffer()
const editor = new TextEditor({buffer})
await atom.workspace.open(editor)
expect(atom.project.getBuffers().map(buffer => buffer.id)).toContain(buffer.id)
expect(buffer.getLanguageMode().getLanguageId()).toBe('text.plain.null-grammar')
})
})
})
describe('finding items in the workspace', () => {
@@ -1206,8 +1220,8 @@ describe('Workspace', () => {
})
})
describe('::onDidStopChangingActivePaneItem()', function () {
it('invokes observers when the active item of the active pane stops changing', function () {
describe('::onDidStopChangingActivePaneItem()', () => {
it('invokes observers when the active item of the active pane stops changing', () => {
const pane1 = atom.workspace.getCenter().getActivePane()
const pane2 = pane1.splitRight({items: [document.createElement('div'), document.createElement('div')]});
atom.workspace.getLeftDock().getActivePane().addItem(document.createElement('div'))
@@ -1364,7 +1378,7 @@ describe('Workspace', () => {
describe('::getActiveTextEditor()', () => {
describe("when the workspace center's active pane item is a text editor", () => {
describe('when the workspace center has focus', function () {
describe('when the workspace center has focus', () => {
it('returns the text editor', () => {
const workspaceCenter = workspace.getCenter()
const editor = new TextEditor()
@@ -1375,7 +1389,7 @@ describe('Workspace', () => {
})
})
describe('when a dock has focus', function () {
describe('when a dock has focus', () => {
it('returns the text editor', () => {
const workspaceCenter = workspace.getCenter()
const editor = new TextEditor()
@@ -1536,11 +1550,10 @@ describe('Workspace', () => {
waitsForPromise(() => atom.workspace.open('sample.coffee'))
runs(function () {
atom.workspace.getActiveTextEditor().setText(`\
i = /test/; #FIXME\
`
)
runs(() => {
atom.workspace.getActiveTextEditor().setText(dedent `
i = /test/; #FIXME\
`)
const atom2 = new AtomEnvironment({applicationDelegate: atom.applicationDelegate})
atom2.initialize({
@@ -2867,4 +2880,6 @@ i = /test/; #FIXME\
})
})
const escapeStringRegex = str => str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')
function escapeStringRegex (string) {
return string.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')
}