Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 8cc24f1

Browse files
Antonio ScandurraNathan Sobo
Antonio Scandurra
authored and
Nathan Sobo
committed
Get an initial test harness in place
Signed-off-by: Nathan Sobo <[email protected]>
1 parent 613b965 commit 8cc24f1

File tree

6 files changed

+47045
-7
lines changed

6 files changed

+47045
-7
lines changed

.gitignore

-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
11
node_modules
2-
*.swp
3-
lib
42
npm-debug.log
5-
.coffee
6-
api.json

lib/transceiver.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports =
2+
class Transceiver {
3+
constructor (buffer, channel) {
4+
buffer.onDidChangeText(this.didChangeText.bind(this))
5+
channel.didReceive = this.didReceive.bind(this)
6+
}
7+
8+
didReceive (operation) {
9+
10+
}
11+
12+
didChangeText (changes) {
13+
// transform
14+
15+
// for (const transformedOperation of transformedOperations) {
16+
// this.channel.send(transformedOperation)
17+
// }
18+
}
19+
}

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
"devDependencies": {
1818
"electron": "1.6",
1919
"mocha": "^3.4.1",
20+
"random-seed": "^0.3.0",
21+
"text-buffer": "^13.0.0-0",
2022
"yargs": "^8.0.1"
2123
}
2224
}

test/helpers/random.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const WORDS = require('./words')
2+
const {Point, Range} = require('text-buffer')
3+
4+
exports.getRandomBufferRange = function getRandomBufferRange (random, buffer) {
5+
const endRow = random(buffer.getLineCount())
6+
const startRow = random.intBetween(0, endRow)
7+
const startColumn = random(buffer.lineForRow(startRow).length + 1)
8+
const endColumn = random(buffer.lineForRow(endRow).length + 1)
9+
return Range(Point(startRow, startColumn), Point(endRow, endColumn))
10+
}
11+
12+
exports.buildRandomLines = function buildRandomLines (random, maxLines) {
13+
const lines = []
14+
15+
for (let i = 0; i < random(maxLines); i++) {
16+
lines.push(buildRandomLine(random))
17+
}
18+
19+
return lines.join('\n')
20+
}
21+
22+
function buildRandomLine (random) {
23+
const line = []
24+
25+
for (let i = 0; i < random(5); i++) {
26+
const n = random(10)
27+
28+
if (n < 2) {
29+
line.push('\t')
30+
} else if (n < 4) {
31+
line.push(' ')
32+
} else {
33+
if (line.length > 0 && !/\s/.test(line[line.length - 1])) {
34+
line.push(' ')
35+
}
36+
37+
line.push(WORDS[random(WORDS.length)])
38+
}
39+
}
40+
41+
return line.join('')
42+
}

0 commit comments

Comments
 (0)