Skip to content

Commit

Permalink
Fix mode tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tjvr committed May 12, 2017
1 parent d747dc2 commit 824f14d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 deletions editor/mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ CodeMirror.defineMode('tosh', module.exports = function(cfg, modeCfg) {
constructor(column, indent) {
this.column = column
this.line = []
this.indent = indent
this.indent = indent || 0
}

// TODO does this actually get called after every \n ?
Expand Down Expand Up @@ -130,7 +130,7 @@ CodeMirror.defineMode('tosh', module.exports = function(cfg, modeCfg) {
completer.highlight(startCol, endCol, (className, token) => {
const text = line.substr(token.offset, token.size)
if (text === '{') { this.indent++ }
if (text === '}') { this.indent--; }
if (text === '}') { this.indent-- }
ranges.push({
className: (className && className.trim()) || null,
text: text,
Expand Down Expand Up @@ -176,6 +176,7 @@ CodeMirror.defineMode('tosh', module.exports = function(cfg, modeCfg) {
indent: function(state, textAfter) {
var indent = state.indent
if (/^\s*\}\s*$/.test(textAfter)) indent--
if (isNaN(cfg.indentUnit)) { throw new Error('oh bother') }
return cfg.indentUnit * indent
},

Expand Down
9 changes: 6 additions & 3 deletions test/mode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const testMode = (function() {

var observedOutput = highlight(text, mode)

expect(observedOutput.indentFailures).toBe(undefined)
expect(observedOutput).toEqual(expectedOutput)
}

Expand All @@ -111,10 +112,9 @@ const testMode = (function() {

//const mode = CodeMirror.getMode({indentUnit: 2}, 'tosh')
const modeCfg = Editor.prototype.cmOptions.mode
const cfg = {tabSize: 2}
const cfg = {tabSize: 2, indentUnit: 2}
const mode = Mode(cfg, modeCfg)

function MT(name) { testMode(name, mode, Array.prototype.slice.call(arguments, 1)); }

describe('State', () => {

Expand Down Expand Up @@ -145,8 +145,11 @@ describe('State', () => {

})


describe('highlight', () => {

function MT(name) { testMode(name, mode, Array.prototype.slice.call(arguments, 1)); }

MT('one line',
'[s-pen stamp]')

Expand All @@ -173,7 +176,7 @@ describe('highlight', () => {

MT('full c block',
'[s-control forever] [s-control {]',
'[s-pen stamp]',
' [s-pen stamp]',
'[s-control }]')

})
Expand Down

0 comments on commit 824f14d

Please sign in to comment.