From 70fd40a1aad85c85a461bb1b99a0423ea9850dd6 Mon Sep 17 00:00:00 2001 From: Andrew Gaspar Date: Sun, 24 Mar 2013 22:52:11 -0500 Subject: [PATCH] Added default assert definition and a second definition for writeFile. Also added a basic test file. Will be expanded more later. --- node/node-tests.ts | 30 ++++++++++++++++++++++++++++++ node/node.d.ts | 6 ++++-- 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 node/node-tests.ts diff --git a/node/node-tests.ts b/node/node-tests.ts new file mode 100644 index 000000000..00e08b006 --- /dev/null +++ b/node/node-tests.ts @@ -0,0 +1,30 @@ +/// + +import assert = module("assert"); +import fs = module("fs"); + +assert(1 + 1 - 2 === 0, "The universe isn't how it should."); + +assert.deepEqual({ x: { y: 3 } }, { x: { y: 3 } }, "DEEP WENT DERP"); + +assert.equal(3, "3", "uses == comparator"); + +assert.notStrictEqual(2, "2", "uses === comparator"); + +assert.throws(() => { throw "a hammer at your face"; }, undefined, "DODGED IT"); + +assert.doesNotThrow(() => { + if (false) { throw "a hammer at your face"; } +}, undefined, "What the...*crunch*"); + + +fs.writeFile("thebible.txt", + "Do unto others as you would have them do unto you.", + assert.ifError); + +fs.writeFile("Harry Potter", + "\"You be wizzing, Harry,\" jived Dumbledore.", + { + encoding: "ascii" + }, + assert.ifError); \ No newline at end of file diff --git a/node/node.d.ts b/node/node.d.ts index 7d0cf5fbc..b247a7450 100644 --- a/node/node.d.ts +++ b/node/node.d.ts @@ -776,7 +776,8 @@ declare module "fs" { export function readFile(filename: string, callback: (err: Error, data: NodeBuffer) => void ): void; export function readFileSync(filename: string): NodeBuffer; export function readFileSync(filename: string, encoding: string): string; - export function writeFile(filename: string, data: any, encoding?: string, callback?: Function): void; + export function writeFile(filename: string, data: any, callback?: (err) => void): void; + export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: Function): void; export function writeFileSync(filename: string, data: any, encoding?: string): void; export function appendFile(filename: string, data: any, encoding?: string, callback?: Function): void; export function appendFileSync(filename: string, data: any, encoding?: string): void; @@ -1014,6 +1015,7 @@ declare module "util" { } declare module "assert" { + export function (booleanValue: bool, message?: string); export function fail(actual: any, expected: any, message: string, operator: string): void; export function assert(value: any, message: string): void; export function ok(value: any, message?: string): void; @@ -1054,4 +1056,4 @@ declare module "domain" { export function bind(cb: (er: Error, data: any) =>any): any; export function intercept(cb: (data: any) => any): any; export function dispose(): void; -} +}