Skip to content

Commit

Permalink
Lint fixture file from go-to-line package
Browse files Browse the repository at this point in the history
The specs needed to be updated since they depended on the actual contents
of the fixture.
  • Loading branch information
rafeca committed Feb 25, 2019
1 parent 20ec642 commit 3f1b965
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 53 deletions.
102 changes: 58 additions & 44 deletions packages/go-to-line/spec/fixtures/sample.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,84 @@
var quicksort = function () {
var sort = function(items) {
if (items.length <= 1) return items;
var pivot = items.shift(), current, left = [], right = [];
while(items.length > 0) {
current = items.shift();
current < pivot ? left.push(current) : right.push(current);
var sort = function (items) {
if (items.length <= 1) return items
var pivot = items.shift()
var current
var left = []
var right = []

while (items.length > 0) {
current = items.shift()
current < pivot ? left.push(current) : right.push(current)
}
return sort(left).concat(pivot).concat(sort(right));
};
return sort(left)
.concat(pivot)
.concat(sort(right))
}

return sort(Array.apply(this, arguments));
};
return sort(Array.apply(this, arguments))
}

// adapted from:
// https://github.com/nzakas/computer-science-in-javascript/tree/master/algorithms/sorting/merge-sort-recursive
var mergeSort = function (items){
var merge = function (left, right){
var result = [];
var il = 0;
var ir = 0;
var mergeSort = function (items) {
var merge = function (left, right) {
var result = []
var il = 0
var ir = 0

while (il < left.length && ir < right.length){
if (left[il] < right[ir]){
result.push(left[il++]);
while (il < left.length && ir < right.length) {
if (left[il] < right[ir]) {
result.push(left[il++])
} else {
result.push(right[ir++]);
result.push(right[ir++])
}
}

return result.concat(left.slice(il)).concat(right.slice(ir));
};
return result.concat(left.slice(il)).concat(right.slice(ir))
}

if (items.length < 2) {
return items;
return items
}

var middle = Math.floor(items.length / 2),
left = items.slice(0, middle),
right = items.slice(middle),
params = merge(mergeSort(left), mergeSort(right));
var middle = Math.floor(items.length / 2)
var left = items.slice(0, middle)
var right = items.slice(middle)
var params = merge(mergeSort(left), mergeSort(right))

// Add the arguments to replace everything between 0 and last item in the array
params.unshift(0, items.length);
items.splice.apply(items, params);
return items;
};
params.unshift(0, items.length)
items.splice.apply(items, params)
return items
}

// adapted from:
// https://github.com/nzakas/computer-science-in-javascript/blob/master/algorithms/sorting/bubble-sort/bubble-sort.js
var bubbleSort = function (items){
var swap = function (items, firstIndex, secondIndex){
var temp = items[firstIndex];
items[firstIndex] = items[secondIndex];
items[secondIndex] = temp;
};
var bubbleSort = function (items) {
var swap = function (items, firstIndex, secondIndex) {
var temp = items[firstIndex]
items[firstIndex] = items[secondIndex]
items[secondIndex] = temp
}

var len = items.length,
i, j, stop;
var len = items.length
var i
var j
var stop

for (i=0; i < len; i++){
for (j=0, stop=len-i; j < stop; j++){
if (items[j] > items[j+1]){
swap(items, j, j+1);
for (i = 0; i < len; i++) {
for (j = 0, stop = len - i; j < stop; j++) {
if (items[j] > items[j + 1]) {
swap(items, j, j + 1)
}
}
}

return items;
};
return items
}

module.exports = {
bubbleSort,
mergeSort,
quicksort
}
18 changes: 9 additions & 9 deletions packages/go-to-line/spec/go-to-line-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ describe('GoToLine', () => {

describe('when typing line numbers (auto-navigation)', () => {
it('automatically scrolls to the desired line', () => {
goToLine.miniEditor.insertText('13')
expect(editor.getCursorBufferPosition()).toEqual([12, 0])
goToLine.miniEditor.insertText('19')
expect(editor.getCursorBufferPosition()).toEqual([18, 0])
})
})

Expand Down Expand Up @@ -90,10 +90,10 @@ describe('GoToLine', () => {
atom.commands.dispatch(editorView, 'go-to-line:toggle')
expect(goToLine.panel.isVisible()).toBeTruthy()
expect(goToLine.miniEditor.getText()).toBe('')
goToLine.miniEditor.insertText('71')
goToLine.miniEditor.insertText('78')
atom.commands.dispatch(goToLine.miniEditor.element, 'core:confirm')
expect(goToLine.panel.isVisible()).toBeFalsy()
expect(editor.getCursorBufferPosition()).toEqual([70, 0])
expect(editor.getCursorBufferPosition()).toEqual([77, 0])
})
})

Expand All @@ -105,7 +105,7 @@ describe('GoToLine', () => {
goToLine.miniEditor.insertText('3:43')
atom.commands.dispatch(goToLine.miniEditor.element, 'core:confirm')
expect(goToLine.panel.isVisible()).toBeFalsy()
expect(editor.getCursorBufferPosition()).toEqual([2, 40])
expect(editor.getCursorBufferPosition()).toEqual([2, 39])
})
})

Expand All @@ -120,12 +120,12 @@ describe('GoToLine', () => {

describe('when the line number entered is nested within foldes', () => {
it('unfolds all folds containing the given row', () => {
expect(editor.indentationForBufferRow(6)).toEqual(3)
expect(editor.indentationForBufferRow(9)).toEqual(3)
editor.foldAll()
expect(editor.screenRowForBufferRow(6)).toEqual(0)
goToLine.miniEditor.insertText('7')
expect(editor.screenRowForBufferRow(9)).toEqual(0)
goToLine.miniEditor.insertText('10')
atom.commands.dispatch(goToLine.miniEditor.element, 'core:confirm')
expect(editor.getCursorBufferPosition()).toEqual([6, 6])
expect(editor.getCursorBufferPosition()).toEqual([9, 6])
})
})
})
Expand Down

0 comments on commit 3f1b965

Please sign in to comment.