Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
416898e
Scope usage of editor.nonWordCharacters
benogle Oct 3, 2014
339cb02
Scope editor.tabLength
benogle Oct 3, 2014
8cd217e
Handle changes to the tabLength setting
benogle Oct 3, 2014
857fd5e
Retokenize when setTabLength() was called.
benogle Oct 6, 2014
fbcaaba
Fix weird spec
benogle Oct 6, 2014
938f216
Scope softWrap, softWrapAtPreferredLineLength, preferredLineLength
benogle Oct 6, 2014
c1ff53b
getCurrentScopeDescriptor -> getGrammarScopeDescriptor
benogle Oct 6, 2014
237c668
Scope editor.invisibles and editor.showInvisibles
benogle Oct 6, 2014
6958e0a
Scope editor.normalizeIndentOnPaste
benogle Oct 7, 2014
ca4c409
Scope editor.autoIndent
benogle Oct 7, 2014
fbe4cf5
Invisibles will be set in a call to updateInvisibles()
benogle Oct 7, 2014
2605044
Scope editor.showIndentGuide
benogle Oct 7, 2014
d3b00f6
Fix spec
benogle Oct 7, 2014
f662b3d
:lipstick: Normalize the names of related subscription things
benogle Oct 7, 2014
b44a5dd
Use jasmine json
benogle Oct 7, 2014
a3bbbc1
Read and write scoped settings from the user’s config
benogle Oct 7, 2014
2a73d70
:lipstick: Clean up spec names
benogle Oct 7, 2014
26524e8
:lipstick: tests
benogle Oct 8, 2014
c315631
Remove scopeDescriptor from getTabLength
benogle Oct 8, 2014
8910dd1
Update to not new format from propertiesForSource
benogle Oct 8, 2014
d7cd0de
Upgrade scoped-property-store
benogle Oct 8, 2014
f2d480f
getGrammarScopeDescriptor -> getRootScopeDescriptor
benogle Oct 8, 2014
841412b
Fix spec
benogle Oct 8, 2014
c2081fa
:lipstick: test
benogle Oct 8, 2014
a28fed8
:memo: Expose TextEditor::observeGrammar
benogle Oct 8, 2014
c154b8f
:lipstick: edit spec descriptions
benogle Oct 8, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"git-utils": "^2.1.5",
"grim": "0.12.0",
"guid": "0.0.10",
"jasmine-json": "~0.0",
"jasmine-tagged": "^1.1.2",
"less-cache": "0.15.0",
"mixto": "^1",
Expand All @@ -50,7 +51,7 @@
"reactionary-atom-fork": "^1.0.0",
"runas": "1.0.1",
"scandal": "1.0.2",
"scoped-property-store": "^0.11.0",
"scoped-property-store": "^0.12.0",
"scrollbar-style": "^1.0.2",
"season": "^1.0.2",
"semver": "1.1.4",
Expand Down
109 changes: 93 additions & 16 deletions spec/config-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ describe "Config", ->

expect(CSON.writeFileSync.argsForCall[0][0]).toBe(path.join(atom.config.configDirPath, "atom.config.json"))
writtenConfig = CSON.writeFileSync.argsForCall[0][1]
expect(writtenConfig).toBe atom.config.settings
expect(writtenConfig).toEqual global: atom.config.settings

describe "when ~/.atom/config.json doesn't exist", ->
it "writes any non-default properties to ~/.atom/config.cson", ->
Expand All @@ -214,9 +214,29 @@ describe "Config", ->
atom.config.save()

expect(CSON.writeFileSync.argsForCall[0][0]).toBe(path.join(atom.config.configDirPath, "atom.config.cson"))
CoffeeScript = require 'coffee-script'
writtenConfig = CSON.writeFileSync.argsForCall[0][1]
expect(writtenConfig).toEqual atom.config.settings
expect(writtenConfig).toEqual global: atom.config.settings

describe "when scoped settings are defined", ->
it 'writes out explicitly set config settings', ->
atom.config.set('.source.ruby', 'foo.bar', 'ruby')
atom.config.set('.source.ruby', 'foo.omg', 'wow')
atom.config.set('.source.coffee', 'foo.bar', 'coffee')

CSON.writeFileSync.reset()
atom.config.save()

writtenConfig = CSON.writeFileSync.argsForCall[0][1]
expect(writtenConfig).toEqualJson
global:
atom.config.settings
'.ruby.source':
foo:
bar: 'ruby'
omg: 'wow'
'.coffee.source':
foo:
bar: 'coffee'

describe ".setDefaults(keyPath, defaults)", ->
it "assigns any previously-unassigned keys to the object at the key path", ->
Expand Down Expand Up @@ -356,6 +376,23 @@ describe "Config", ->
afterEach ->
fs.removeSync(dotAtomPath)

describe "when the config file contains scoped settings", ->
beforeEach ->
fs.writeFileSync atom.config.configFilePath, """
global:
foo:
bar: 'baz'

'.source.ruby':
foo:
bar: 'more-specific'
"""
atom.config.loadUserConfig()

it "updates the config data based on the file contents", ->
expect(atom.config.get("foo.bar")).toBe 'baz'
expect(atom.config.get(['.source.ruby'], "foo.bar")).toBe 'more-specific'

describe "when the config file contains valid cson", ->
beforeEach ->
fs.writeFileSync(atom.config.configFilePath, "foo: bar: 'baz'")
Expand Down Expand Up @@ -430,7 +467,15 @@ describe "Config", ->
atom.config.configDirPath = dotAtomPath
atom.config.configFilePath = path.join(atom.config.configDirPath, "atom.config.cson")
expect(fs.existsSync(atom.config.configDirPath)).toBeFalsy()
fs.writeFileSync(atom.config.configFilePath, "foo: bar: 'baz'")
fs.writeFileSync atom.config.configFilePath, """
global:
foo:
bar: 'baz'
scoped: false
'.source.ruby':
foo:
scoped: true
"""
atom.config.loadUserConfig()
atom.config.observeUserConfig()
updatedHandler = jasmine.createSpy("updatedHandler")
Expand Down Expand Up @@ -474,6 +519,38 @@ describe "Config", ->
expect(atom.config.get('foo.bar')).toEqual ['baz', 'ok']
expect(atom.config.get('foo.omg')).toBe 'another'

describe 'when scoped settings are used', ->
it "fires a change event for scoped settings that are removed", ->
atom.config.onDidChange ['.source.ruby'], 'foo.scoped', scopedSpy = jasmine.createSpy()

fs.writeFileSync atom.config.configFilePath, """
global:
foo:
scoped: false
"""
waitsFor 'update event', -> updatedHandler.callCount > 0
runs ->
expect(scopedSpy).toHaveBeenCalled()
expect(atom.config.get(['.source.ruby'], 'foo.scoped')).toBe false

it "does not fire a change event for paths that did not change", ->
atom.config.onDidChange ['.source.ruby'], 'foo.scoped', noChangeSpy = jasmine.createSpy()

fs.writeFileSync atom.config.configFilePath, """
global:
foo:
bar: 'baz'
'.source.ruby':
foo:
scoped: true
"""
waitsFor 'update event', -> updatedHandler.callCount > 0
runs ->
expect(noChangeSpy).not.toHaveBeenCalled()
expect(atom.config.get(['.source.ruby'], 'foo.bar')).toBe 'baz'
expect(atom.config.get(['.source.ruby'], 'foo.scoped')).toBe true


describe "when the config file changes to omit a setting with a default", ->
it "resets the setting back to the default", ->
fs.writeFileSync(atom.config.configFilePath, "foo: { baz: 'new'}")
Expand Down Expand Up @@ -866,18 +943,18 @@ describe "Config", ->
describe "scoped settings", ->
describe ".get(scopeDescriptor, keyPath)", ->
it "returns the property with the most specific scope selector", ->
atom.config.addScopedSettings(".source.coffee .string.quoted.double.coffee", foo: bar: baz: 42)
atom.config.addScopedSettings(".source .string.quoted.double", foo: bar: baz: 22)
atom.config.addScopedSettings(".source", foo: bar: baz: 11)
atom.config.addScopedSettings("config", ".source.coffee .string.quoted.double.coffee", foo: bar: baz: 42)
atom.config.addScopedSettings("config", ".source .string.quoted.double", foo: bar: baz: 22)
atom.config.addScopedSettings("config", ".source", foo: bar: baz: 11)

expect(atom.config.get([".source.coffee", ".string.quoted.double.coffee"], "foo.bar.baz")).toBe 42
expect(atom.config.get([".source.js", ".string.quoted.double.js"], "foo.bar.baz")).toBe 22
expect(atom.config.get([".source.js", ".variable.assignment.js"], "foo.bar.baz")).toBe 11
expect(atom.config.get([".text"], "foo.bar.baz")).toBeUndefined()

it "favors the most recently added properties in the event of a specificity tie", ->
atom.config.addScopedSettings(".source.coffee .string.quoted.single", foo: bar: baz: 42)
atom.config.addScopedSettings(".source.coffee .string.quoted.double", foo: bar: baz: 22)
atom.config.addScopedSettings("config", ".source.coffee .string.quoted.single", foo: bar: baz: 42)
atom.config.addScopedSettings("config", ".source.coffee .string.quoted.double", foo: bar: baz: 22)

expect(atom.config.get([".source.coffee", ".string.quoted.single"], "foo.bar.baz")).toBe 42
expect(atom.config.get([".source.coffee", ".string.quoted.single.double"], "foo.bar.baz")).toBe 22
Expand All @@ -889,9 +966,9 @@ describe "Config", ->

describe ".set(scope, keyPath, value)", ->
it "sets the value and overrides the others", ->
atom.config.addScopedSettings(".source.coffee .string.quoted.double.coffee", foo: bar: baz: 42)
atom.config.addScopedSettings(".source .string.quoted.double", foo: bar: baz: 22)
atom.config.addScopedSettings(".source", foo: bar: baz: 11)
atom.config.addScopedSettings("config", ".source.coffee .string.quoted.double.coffee", foo: bar: baz: 42)
atom.config.addScopedSettings("config", ".source .string.quoted.double", foo: bar: baz: 22)
atom.config.addScopedSettings("config", ".source", foo: bar: baz: 11)

expect(atom.config.get([".source.coffee", ".string.quoted.double.coffee"], "foo.bar.baz")).toBe 42

Expand All @@ -917,11 +994,11 @@ describe "Config", ->
expect(changeSpy).toHaveBeenCalledWith(12)
changeSpy.reset()

disposable1 = atom.config.addScopedSettings(".source .string.quoted.double", foo: bar: baz: 22)
disposable1 = atom.config.addScopedSettings("a", ".source .string.quoted.double", foo: bar: baz: 22)
expect(changeSpy).toHaveBeenCalledWith(22)
changeSpy.reset()

disposable2 = atom.config.addScopedSettings("a", ".source.coffee .string.quoted.double.coffee", foo: bar: baz: 42)
disposable2 = atom.config.addScopedSettings("b", ".source.coffee .string.quoted.double.coffee", foo: bar: baz: 42)
expect(changeSpy).toHaveBeenCalledWith(42)
changeSpy.reset()

Expand All @@ -946,11 +1023,11 @@ describe "Config", ->
expect(changeSpy).toHaveBeenCalledWith({oldValue: undefined, newValue: 12, keyPath})
changeSpy.reset()

disposable1 = atom.config.addScopedSettings(".source .string.quoted.double", foo: bar: baz: 22)
disposable1 = atom.config.addScopedSettings("a", ".source .string.quoted.double", foo: bar: baz: 22)
expect(changeSpy).toHaveBeenCalledWith({oldValue: 12, newValue: 22, keyPath})
changeSpy.reset()

disposable2 = atom.config.addScopedSettings("a", ".source.coffee .string.quoted.double.coffee", foo: bar: baz: 42)
disposable2 = atom.config.addScopedSettings("b", ".source.coffee .string.quoted.double.coffee", foo: bar: baz: 42)
expect(changeSpy).toHaveBeenCalledWith({oldValue: 22, newValue: 42, keyPath})
changeSpy.reset()

Expand Down
1 change: 1 addition & 0 deletions spec/spec-helper.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ require '../src/window'
atom.initialize()
atom.restoreWindowDimensions()

require 'jasmine-json'
require '../vendor/jasmine-jquery'
path = require 'path'
_ = require 'underscore-plus'
Expand Down
147 changes: 140 additions & 7 deletions spec/text-editor-component-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,6 @@ describe "TextEditorComponent", ->
foldedLineNode = component.lineNodeForScreenRow(4)
expect(foldedLineNode.querySelector('.fold-marker')).toBeFalsy()

getLeafNodes = (node) ->
if node.children.length > 0
flatten(toArray(node.children).map(getLeafNodes))
else
[node]

describe "gutter rendering", ->
[gutter] = []

Expand Down Expand Up @@ -2214,7 +2208,6 @@ describe "TextEditorComponent", ->
it "does not render invisible characters", ->
atom.config.set('editor.invisibles', eol: 'E')
atom.config.set('editor.showInvisibles', true)
nextAnimationFrame()
expect(component.lineNodeForScreenRow(0).textContent).toBe 'var quicksort = function () {'

it "does not assign an explicit line-height on the editor contents", ->
Expand Down Expand Up @@ -2268,6 +2261,140 @@ describe "TextEditorComponent", ->

expect(editor.getCursorBufferPosition()).toEqual [0, 1]

describe 'scoped config settings', ->
[coffeeEditor, coffeeComponent] = []

beforeEach ->
waitsForPromise ->
atom.packages.activatePackage('language-coffee-script')
waitsForPromise ->
atom.project.open('coffee.coffee', autoIndent: false).then (o) -> coffeeEditor = o

afterEach: ->
atom.packages.deactivatePackages()
atom.packages.unloadPackages()

describe 'soft wrap settings', ->
beforeEach ->
atom.config.set '.source.coffee', 'editor.softWrap', true
atom.config.set '.source.coffee', 'editor.preferredLineLength', 17
atom.config.set '.source.coffee', 'editor.softWrapAtPreferredLineLength', true

editor.setEditorWidthInChars(20)
coffeeEditor.setEditorWidthInChars(20)

it "wraps lines when editor.softWrap is true for a matching scope", ->
expect(editor.lineTextForScreenRow(2)).toEqual ' if (items.length <= 1) return items;'
expect(coffeeEditor.lineTextForScreenRow(3)).toEqual ' return items '

it 'updates the wrapped lines when editor.preferredLineLength changes', ->
atom.config.set '.source.coffee', 'editor.preferredLineLength', 20
expect(coffeeEditor.lineTextForScreenRow(2)).toEqual ' return items if '

it 'updates the wrapped lines when editor.softWrapAtPreferredLineLength changes', ->
atom.config.set '.source.coffee', 'editor.softWrapAtPreferredLineLength', false
expect(coffeeEditor.lineTextForScreenRow(2)).toEqual ' return items if '

it 'updates the wrapped lines when editor.softWrap changes', ->

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly here, why not just test the isSoftWrapped property. We presumably have tests for when that property changes elsewhere? Though you could confirm.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was actually no observation of editor.softWrap before this PR, so this is a new test.

atom.config.set '.source.coffee', 'editor.softWrap', false
expect(coffeeEditor.lineTextForScreenRow(2)).toEqual ' return items if items.length <= 1'

atom.config.set '.source.coffee', 'editor.softWrap', true
expect(coffeeEditor.lineTextForScreenRow(3)).toEqual ' return items '

it 'updates the wrapped lines when the grammar changes', ->
editor.setGrammar(coffeeEditor.getGrammar())
expect(editor.isSoftWrapped()).toBe true
expect(editor.lineTextForScreenRow(0)).toEqual 'var quicksort = '

describe '::isSoftWrapped()', ->
it 'returns the correct value based on the scoped settings', ->
expect(editor.isSoftWrapped()).toBe false
expect(coffeeEditor.isSoftWrapped()).toBe true

describe 'invisibles settings', ->
[jsInvisibles, coffeeInvisibles] = []
beforeEach ->
jsInvisibles =
eol: 'J'
space: 'A'
tab: 'V'
cr: 'A'

coffeeInvisibles =
eol: 'C'
space: 'O'
tab: 'F'
cr: 'E'

atom.config.set '.source.js', 'editor.showInvisibles', true
atom.config.set '.source.js', 'editor.invisibles', jsInvisibles

atom.config.set '.source.coffee', 'editor.showInvisibles', false
atom.config.set '.source.coffee', 'editor.invisibles', coffeeInvisibles

editor.setText " a line with tabs\tand spaces \n"
nextAnimationFrame()

it "renders the invisibles when editor.showInvisibles is true for a given grammar", ->
expect(component.lineNodeForScreenRow(0).textContent).toBe "#{jsInvisibles.space}a line with tabs#{jsInvisibles.tab}and spaces#{jsInvisibles.space}#{jsInvisibles.eol}"

it "does not render the invisibles when editor.showInvisibles is false for a given grammar", ->
editor.setGrammar(coffeeEditor.getGrammar())
nextAnimationFrame()
expect(component.lineNodeForScreenRow(0).textContent).toBe " a line with tabs and spaces "

it "re-renders the invisibles when the invisible settings change", ->
jsGrammar = editor.getGrammar()
editor.setGrammar(coffeeEditor.getGrammar())
atom.config.set '.source.coffee', 'editor.showInvisibles', true
nextAnimationFrame()
expect(component.lineNodeForScreenRow(0).textContent).toBe "#{coffeeInvisibles.space}a line with tabs#{coffeeInvisibles.tab}and spaces#{coffeeInvisibles.space}#{coffeeInvisibles.eol}"

newInvisibles =
eol: 'N'
space: 'E'
tab: 'W'
cr: 'I'
atom.config.set '.source.coffee', 'editor.invisibles', newInvisibles
nextAnimationFrame()
expect(component.lineNodeForScreenRow(0).textContent).toBe "#{newInvisibles.space}a line with tabs#{newInvisibles.tab}and spaces#{newInvisibles.space}#{newInvisibles.eol}"

editor.setGrammar(jsGrammar)
nextAnimationFrame()
expect(component.lineNodeForScreenRow(0).textContent).toBe "#{jsInvisibles.space}a line with tabs#{jsInvisibles.tab}and spaces#{jsInvisibles.space}#{jsInvisibles.eol}"

describe 'editor.showIndentGuide', ->
beforeEach ->
atom.config.set '.source.js', 'editor.showIndentGuide', true
atom.config.set '.source.coffee', 'editor.showIndentGuide', false

it "has an 'indent-guide' class when scoped editor.showIndentGuide is true, but not when scoped editor.showIndentGuide is false", ->
line1LeafNodes = getLeafNodes(component.lineNodeForScreenRow(1))
expect(line1LeafNodes[0].textContent).toBe ' '
expect(line1LeafNodes[0].classList.contains('indent-guide')).toBe true
expect(line1LeafNodes[1].classList.contains('indent-guide')).toBe false

editor.setGrammar(coffeeEditor.getGrammar())

line1LeafNodes = getLeafNodes(component.lineNodeForScreenRow(1))
expect(line1LeafNodes[0].textContent).toBe ' '
expect(line1LeafNodes[0].classList.contains('indent-guide')).toBe false
expect(line1LeafNodes[1].classList.contains('indent-guide')).toBe false

it "removes the 'indent-guide' class when editor.showIndentGuide to false", ->
line1LeafNodes = getLeafNodes(component.lineNodeForScreenRow(1))
expect(line1LeafNodes[0].textContent).toBe ' '
expect(line1LeafNodes[0].classList.contains('indent-guide')).toBe true
expect(line1LeafNodes[1].classList.contains('indent-guide')).toBe false

atom.config.set '.source.js', 'editor.showIndentGuide', false

line1LeafNodes = getLeafNodes(component.lineNodeForScreenRow(1))
expect(line1LeafNodes[0].textContent).toBe ' '
expect(line1LeafNodes[0].classList.contains('indent-guide')).toBe false
expect(line1LeafNodes[1].classList.contains('indent-guide')).toBe false

buildMouseEvent = (type, properties...) ->
properties = extend({bubbles: true, cancelable: true}, properties...)
properties.detail ?= 1
Expand Down Expand Up @@ -2304,3 +2431,9 @@ describe "TextEditorComponent", ->

lineHasClass = (screenRow, klass) ->
component.lineNodeForScreenRow(screenRow).classList.contains(klass)

getLeafNodes = (node) ->
if node.children.length > 0
flatten(toArray(node.children).map(getLeafNodes))
else
[node]
Loading