Skip to content

Commit

Permalink
#88 ts-node working
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-zozol committed Oct 15, 2017
1 parent 83ef833 commit 598e617
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 11 deletions.
39 changes: 39 additions & 0 deletions integration-ts/assert.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export function assertArrayEquals(expected, actual, testName = "Unknown Test") {
if (!arraysEqual(expected, actual)) {
throw new Error("Prepublish error for operations - Failed " + testName +
" - . Expected " + expected + " , but != " + actual);
}
}

export function assertEquals(expected, actual, testName = "Unknown Test") {
if (expected !== actual) {
throw new Error("Prepublish error for operations - Failed " + testName +
" - . Expected " + expected + " , but != " + actual);
}
}

export function assertTrue(test, testName = "Unknown Test") {
if (!test) {
throw new Error("Prepublish error for operations - Failed " + testName);
}
}

export function assertFalse(test, testName = "Unknown Test") {
if (test) {
throw new Error("Prepublish error for operations - Failed " + testName);
}
}

function arraysEqual(a, b) {
if (a === b) return true;
if (a == null || b == null) return false;
if (a.length != b.length) return false;

// If you don't care about the order of the elements inside
// the array, you should sort both arrays here.

for (var i = 0; i < a.length; ++i) {
if (a[i] !== b[i]) return false;
}
return true;
}
4 changes: 2 additions & 2 deletions integration-ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
*/

import * as masala from './masala';
import Bundle from '../src/lib/index'
import Bundles from '@masala/parser';

// Can I get rid of this line ?
let {Stream, F, C}:masala.Bundle = Bundle;
let {Stream, F, C}:masala.Bundles = Bundles;

let stream = Stream.ofString('abc');
let parser= C.char('a');
Expand Down
12 changes: 8 additions & 4 deletions integration-ts/masala.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,14 @@ export interface CharBundle {
export interface FlowBundle {
}

export interface Bundle {
Stream: StreamFactory;
C: CharBundle;
F: FlowBundle
export interface NumberBundle {
}

export interface Bundles {
Stream?: StreamFactory;
C?: CharBundle;
F?: FlowBundle;
N?:NumberBundle;
}

//export default Bundle;
19 changes: 19 additions & 0 deletions integration-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "integration-ts",
"version": "1.0.0",
"description": "used to test npm publications",
"main": "index.js",
"dependencies": {
"@masala/parser": "0.5.0"
},
"devDependencies": {
"ts-node": "^3.3.0",
"typescript": "^2.5.3"
},
"scripts": {
"start": "ts-node ./working.ts",
"test": "ts-node ./test.ts"
},
"author": "",
"license": "ISC"
}
Empty file added integration-ts/test.ts
Empty file.
10 changes: 5 additions & 5 deletions integration-ts/working.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as masala from './masala';
import {Stream, F, C} from '../src/lib/index'
import {Stream, F, C} from '@masala/parser'

import{ assertTrue} from '../integration-npm/assert';
import{assertArrayEquals, assertEquals, assertTrue} from './assert';

let stream: masala.Stream<string> = Stream.ofString('abc');
let stream: masala.Stream<string> = Stream.ofString('ab');
let parser: masala.SingleParser<string> = C.char('a');
let arrayParser = parser.then(C.char('b'))//.map(x=>x+'yop');
let parsing = arrayParser.parse(stream);

assertTrue(['a', 2] === parsing.value[0]) ; //compiling, types are almost OK
assertArrayEquals(['a', 'b'], parsing.value) ; //compiling, types are almost OK


parser = C.char('a');
Expand All @@ -24,4 +24,4 @@ assertTrue( 'a' === singleParsing.value); //compiling, types are almost OK

parser = C.char('a');
singleParsing = parser.parse(stream);
assertTrue( ['a', 'b', 'c'] === parsing.value); //compiling, types are almost OK
assertEquals( 'a' , singleParsing.value); //compiling, types are almost OK

0 comments on commit 598e617

Please sign in to comment.