Skip to content
This repository has been archived by the owner on Nov 23, 2017. It is now read-only.

Commit

Permalink
Convert tests to Jasmine specs
Browse files Browse the repository at this point in the history
  • Loading branch information
puffnfresh committed May 13, 2012
1 parent 893e46d commit 41666f7
Show file tree
Hide file tree
Showing 35 changed files with 146 additions and 94 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ docs/guide/_build/
src/parser.js
src/typeparser.js
examples/*.js
test/*.js
!test/tarjan.js
lib/*.js
roy.brianmckenna.org
bundled-roy.js
Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ optimise-bundle:
# Tests

test: all
./roy -r run-tests.roy
./node_modules/jasmine-node/bin/jasmine-node test/spec
./node_modules/jasmine-node/bin/jasmine-node --verbose test
38 changes: 0 additions & 38 deletions run-tests.roy

This file was deleted.

85 changes: 85 additions & 0 deletions test/CompileSpec.js
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');
});
});
});
52 changes: 52 additions & 0 deletions test/TarjanSpec.js
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'}
]
]);
});
});
8 changes: 4 additions & 4 deletions test/spec/TypeInferenceSpec.js → test/TypeInferenceSpec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
describe('type inference', function(){
var typeinference = require('../../src/typeinference'),
types = require('../../src/types');
lexer = require('../../src/lexer');
parser = require('../../src/parser');
var typeinference = require('../src/typeinference'),
types = require('../src/types');
lexer = require('../src/lexer');
parser = require('../src/parser');

beforeEach(function() {
this.addMatchers({
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Expand Down
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.
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 →
Expand Down
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.
2 changes: 1 addition & 1 deletion test/where.roy → test/fixtures/good/where.roy
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ where
id x = x
data Even = Zero | SuccEven Odd
data Odd = SuccOdd Even

console.log (g 0)
11 changes: 0 additions & 11 deletions test/spec/CompileSpec.js

This file was deleted.

35 changes: 0 additions & 35 deletions test/tarjan.js

This file was deleted.

0 comments on commit 41666f7

Please sign in to comment.