This repository has been archived by the owner on Nov 23, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
893e46d
commit 41666f7
Showing
35 changed files
with
146 additions
and
94 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 was deleted.
Oops, something went wrong.
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,85 @@ | ||
describe('compiler', function(){ | ||
var roy = require('../src/compile'), | ||
fs = require('fs'), | ||
path = require('path'), | ||
child_process = require('child_process'), | ||
processBin = process.argv[0]; | ||
|
||
function compilerOutput(s) { | ||
return roy.compile(s, {}, {}, {nodejs: true}).output; | ||
} | ||
|
||
function fixtureCompilerOutput(s) { | ||
return compilerOutput(fs.readFileSync(path.join('test', 'fixtures', s + '.roy'), 'utf8')); | ||
} | ||
|
||
function fixtureExpectedOutput(s) { | ||
return fs.readFileSync(path.join('test', 'fixtures', s + '.out'), 'utf8'); | ||
} | ||
|
||
function expectExecutionToHaveExpectedOutput(s) { | ||
var expected = fixtureExpectedOutput(s); | ||
var compiled = fixtureCompilerOutput(s); | ||
|
||
var child = child_process.spawn(processBin); | ||
child.stdin.write(compiled, 'utf8'); | ||
child.stdin.end(); | ||
child.stdout.setEncoding('utf8'); | ||
|
||
var actual = ''; | ||
asyncSpecWait(); | ||
child.stdout.on('data', function(d) { | ||
actual += d; | ||
}); | ||
child.stdout.on('end', function() { | ||
expect(actual).toEqual(expected); | ||
asyncSpecDone(); | ||
}); | ||
} | ||
|
||
it('should preserve comments', function(){ | ||
expect(compilerOutput('// HELLO')).toEqual('// HELLO\n'); | ||
}); | ||
|
||
describe('should execute', function() { | ||
it('accessors.roy with expected output', function() { | ||
expectExecutionToHaveExpectedOutput('good/accessors'); | ||
}); | ||
it('coercing_native_to_any.roy with expected output', function() { | ||
expectExecutionToHaveExpectedOutput('good/coercing_native_to_any'); | ||
}); | ||
it('conditionals.roy with expected output', function() { | ||
expectExecutionToHaveExpectedOutput('good/conditionals'); | ||
}); | ||
it('deep_matching.roy with expected output', function() { | ||
expectExecutionToHaveExpectedOutput('good/deep_matching'); | ||
}); | ||
it('functions.roy with expected output', function() { | ||
expectExecutionToHaveExpectedOutput('good/functions'); | ||
}); | ||
it('map.roy with expected output', function() { | ||
expectExecutionToHaveExpectedOutput('good/map'); | ||
}); | ||
it('monoid.roy with expected output', function() { | ||
expectExecutionToHaveExpectedOutput('good/monoid'); | ||
}); | ||
it('option_monad.roy with expected output', function() { | ||
expectExecutionToHaveExpectedOutput('good/option_monad'); | ||
}); | ||
it('primitive_types.roy with expected output', function() { | ||
expectExecutionToHaveExpectedOutput('good/primitive_types'); | ||
}); | ||
it('tagged_unions.roy with expected output', function() { | ||
expectExecutionToHaveExpectedOutput('good/tagged_unions'); | ||
}); | ||
it('trace_monad.roy with expected output', function() { | ||
expectExecutionToHaveExpectedOutput('good/trace_monad'); | ||
}); | ||
it('unicode.roy with expected output', function() { | ||
expectExecutionToHaveExpectedOutput('good/unicode'); | ||
}); | ||
it('where.roy with expected output', function() { | ||
expectExecutionToHaveExpectedOutput('good/where'); | ||
}); | ||
}); | ||
}); |
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,52 @@ | ||
describe('tarjan', function(){ | ||
var tarjan = require('../src/tarjan.js'), | ||
stronglyConnectedComponents = tarjan.stronglyConnectedComponents, | ||
_ = require('underscore'); | ||
|
||
it('should identify strongly connected components', function() { | ||
var a = {id: "a"}; | ||
var b = {id: "b"}; | ||
var c = {id: "c"}; | ||
var d = {id: "d"}; | ||
var e = {id: "e"}; | ||
var f = {id: "f"}; | ||
var g = {id: "g"}; | ||
var h = {id: "h"}; | ||
var vertices = [a, b, c, d, e, f, g, h]; | ||
var edges = { | ||
"a": [b], | ||
"b": [c, e, f], | ||
"c": [d, g], | ||
"d": [c, h], | ||
"e": [a, f], | ||
"f": [g], | ||
"g": [f], | ||
"h": [d, g] | ||
}; | ||
|
||
var components = stronglyConnectedComponents({vertices: vertices, edges: edges}); | ||
|
||
var sortedComponents = _.map(components, function(component) { | ||
return _.sortBy(component, function(vertex) { | ||
return vertex.id; | ||
}); | ||
}); | ||
|
||
expect(sortedComponents).toEqual([ | ||
[ | ||
{id: 'f'}, | ||
{id: 'g'} | ||
], | ||
[ | ||
{id: 'c'}, | ||
{id: 'd'}, | ||
{id: 'h'}, | ||
], | ||
[ | ||
{id: 'a'}, | ||
{id: 'b'}, | ||
{id: 'e'} | ||
] | ||
]); | ||
}); | ||
}); |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
test/deep_matching.roy → test/fixtures/good/deep_matching.roy
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,5 @@ | ||
data Either a b = Left a | Right b | ||
|
||
let xor e = match e | ||
case (Left (Left n)) = 0 | ||
case (Left (Right n)) = n | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,4 +1,4 @@ | ||
// Uses `Option a` from stdlib | ||
data Option a = Some a | None | ||
|
||
let optionMonad = { | ||
return: λx → | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
|
@@ -29,5 +29,5 @@ where | |
id x = x | ||
data Even = Zero | SuccEven Odd | ||
data Odd = SuccOdd Even | ||
|
||
console.log (g 0) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.