-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(types): add types of expressions, close #28
- Loading branch information
Showing
8 changed files
with
101 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const la = require('lazy-ass') | ||
const is = require('check-more-types') | ||
const instrument = require('../src/instrument-source') | ||
const R = require('ramda') | ||
|
||
describe.only('composed types', () => { | ||
const source = ` | ||
const R = require('ramda') | ||
const pipe = R.pipe( | ||
R.inc, //:: | ||
R.multiply(10) //> | ||
) | ||
pipe(-4) | ||
` | ||
let emitter | ||
|
||
beforeEach(() => { | ||
emitter = global.instrument | ||
delete global.__instrumenter | ||
}) | ||
|
||
it('finds the special comments', () => { | ||
const starts = [] | ||
emitter.on('comment', c => starts.push(c.commentStart)) | ||
instrument(source) | ||
la(R.equals(['::', '>'], starts), starts) | ||
}) | ||
|
||
it('evaluates original source', () => { | ||
const result = eval(source) | ||
la(result === -30, result) | ||
}) | ||
|
||
it('evaluates instrumented source', () => { | ||
const s = instrument(source) | ||
const result = eval(s) | ||
la(result === -30, result) | ||
la(global.__instrumenter.comments.length === 2, | ||
global.__instrumenter.comments) | ||
}) | ||
|
||
it('keeps type for first comment', () => { | ||
const s = instrument(source) | ||
const result = eval(s) | ||
const first = global.__instrumenter.comments[0] | ||
la(first.find === 'type', 'should find type', first) | ||
la(first.type === 'number', 'found type', first) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
// set type of any variable | ||
// by using the "// name::" syntax | ||
const foo = 'f' + 'o' + 'o' | ||
// foo:: "string" | ||
const life = 42 | ||
// life:: "number" | ||
// type of preceding expression | ||
const add = (a, b) => a + b | ||
add(2, 3) // :: number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
// type of preceding expression | ||
const add = (a, b) => a + b | ||
add(2, 3) // :: 5 | ||
add(2, 3) // :: number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters