This repository was archived by the owner on Jan 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
53 lines (50 loc) · 1.29 KB
/
Copy pathtest.js
File metadata and controls
53 lines (50 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* test.js
*
* Used for message parsing tests
* IRC messages to test are listed in test.txt file
* and after running the script the results will be
* shown in the test.out.txt file
*/
'use strict';
const fs = require('fs'),
Message = require('./includes/msg.js');
/**
* Writes output to file
* @param {String} text Text to write into the file
*/
function write(text) {
fs.writeFile('test.out.txt', text, function(err) {
if (err) {
console.error(
'An error occurred while writing to the output file!',
err
);
}
});
}
/**
* Reads the test file
*/
function read() {
let output = '';
fs.readFile('test.txt', function(err, data) {
if (err) {
console.error('An error occurred while reading test.txt!', err);
return;
}
data.toString().split('\n').forEach(function(line) {
const msg = new Message(line.trim());
if (msg.type) {
for (const i in msg) {
output += `${i}: ${JSON.stringify(msg[i])}\n`;
}
} else {
output += `Couldn't parse line: ${line}\n`;
}
output += '--------------------\n';
});
write(output);
});
}
read();