UNPKG

node-wad

Version:
52 lines (44 loc) 2.01 kB
// Generated by CoffeeScript 1.12.6 var MapEdit, WAD, fs, w; fs = require('fs'); WAD = require('../src/wad.js'); MapEdit = require("../src/map.js"); w = WAD.read(fs.readFileSync('test.wad')); QUnit.test('WAD reading', function(assert) { assert.strictEqual(w.ptype, "PWAD", "PWAD/IWAD detection"); assert.strictEqual(w.lumps[0].name.toString('ascii'), "TESTNAME", "lumpname reading"); assert.strictEqual(w.lumps[0].data.length, 12, "lump data reading: offsets and length"); return assert.strictEqual(w.lumps[0].data.toString('ascii'), "Hello World!", "lump data reading: content"); }); QUnit.test('WAD writing', function(assert) { if ((w != null) && (w.write != null)) { return assert.strictEqual(w.write().toString('hex'), fs.readFileSync('test.wad', { encoding: 'hex' }), "WAD serializing"); } }); QUnit.test('Map writing', function(assert) { var ed, w2; ed = new MapEdit("MAP01"); w2 = new WAD(true); ed.buildSector([[0, 0], [0, 128], [128, 128], [128, 0]], { floorTex: "FLAT5_4", lighting: 192 }, { lowTex: "BROWN144" }); ed.addThing(64, 96, 1, 270, 0x7); assert.strictEqual(ed.sectors.length, 1, "sector count"); assert.strictEqual(ed.linedefs.length, 4, "linedef count"); assert.strictEqual(ed.sidedefs.length, 4, "sidedef count"); assert.strictEqual(ed.vertexes.length, 4, "vertex count"); assert.strictEqual(ed.sectors[0].floorTex, "FLAT5_4", "sector data application 1/2"); assert.strictEqual(ed.sectors[0].floorHeight, 0, "sector data application 2/2"); assert.strictEqual(ed.sidedefs[0].midtex, "STARTAN2", "line data application 1/2"); assert.strictEqual(ed.sidedefs[0].lowtex, "BROWN144", "line data application 2/2"); ed.toLumps(w2); assert.strictEqual(w2.lumps.length, 6, "map lumpcount"); assert.strictEqual(w2.lumps[0].name, "MAP01", "mapname"); assert.strictEqual(w2.write().toString("hex"), fs.readFileSync("test2.wad", "hex"), "map exporting"); return fs.writeFileSync("test2out.wad", w2.write()); });