Skip to content

Commit

Permalink
Merge pull request #52 from ndr-brt/issue-29
Browse files Browse the repository at this point in the history
Make initTidal understand code blocks
  • Loading branch information
ndr-brt authored Oct 20, 2019
2 parents 7114576 + 54e75cd commit fc8ad4d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
npm-debug.log
node_modules
*.tidal
.idea
16 changes: 12 additions & 4 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,18 @@ export default class REPL {

initTidal() {
const bootPath = this.getBootTidalPath();
var commands = fs.readFileSync(bootPath).toString().split('\n');
for (var i = 0; i < commands.length; i++) {
this.tidalSendLine(commands[i]);
}
const blocks = fs.readFileSync(bootPath)
.toString()
.split('\n\n')
.map(block => block.replace(":{", "").replace(":}", ""));

blocks.forEach(block => {
if (block.startsWith(":set")) {
block.split("\n").forEach(row => this.tidalSendLine(row))
} else {
this.tidalSendExpression(block);
}
});
}

stdinWrite(command) {
Expand Down
31 changes: 31 additions & 0 deletions spec/repl-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const REPL = require('../lib/repl.js')

describe('repl', () => {
it('should load code blocks on boot', () => {
let repl = new REPL()
spyOn(repl, 'getBootTidalPath').andReturn("lib/BootTidal.hs")
spyOn(repl, 'tidalSendLine')
spyOn(repl, 'tidalSendExpression')

repl.initTidal()

expect(repl.tidalSendLine.callCount).toBe(5)
expect(repl.tidalSendExpression.callCount).toBe(4)
expect(repl.tidalSendLine.calls[0].args[0]).toBe(':set -XOverloadedStrings')
expect(repl.tidalSendExpression.calls[1].args[0]).toBe('-- total latency = oLatency + cFrameTimespan\ntidal <- startTidal (superdirtTarget {oLatency = 0.1, oAddress = "127.0.0.1", oPort = 57120}) (defaultConfig {cFrameTimespan = 1/20})')
})

it('should send :set lines as single lines on boot', () => {
let repl = new REPL()
spyOn(repl, 'getBootTidalPath').andReturn("lib/BootTidal.hs")
spyOn(repl, 'tidalSendLine')
spyOn(repl, 'tidalSendExpression')

repl.initTidal()

expect(repl.tidalSendLine.calls[0].args[0]).toBe(':set -XOverloadedStrings')
expect(repl.tidalSendLine.calls[1].args[0]).toBe(':set prompt ""')
expect(repl.tidalSendLine.calls[2].args[0]).toBe(':set prompt-cont ""')
expect(repl.tidalSendLine.calls[3].args[0]).toBe(':set prompt "tidal> "')
})
})

0 comments on commit fc8ad4d

Please sign in to comment.