1 var assert = require(
'assert');
2 var fs = require(
'fs');
3 var
OpenCC = require(
'./opencc');
16 var testSync =
function (config, done) {
17 var inputName =
'test/testcases/' + config +
'.in';
18 var outputName =
'test/testcases/' + config +
'.ans';
19 var configName = config +
'.ini';
20 var opencc =
new OpenCC(configName);
21 fs.readFile(inputName,
'utf-8',
function (err, text) {
22 if (err)
return done(err);
23 var converted = opencc.convertSync(text);
24 fs.readFile(outputName,
'utf-8',
function (err, answer) {
25 if (err)
return done(err);
26 assert.equal(converted, answer);
32 var testAsync =
function (config, done) {
33 var inputName =
'test/testcases/' + config +
'.in';
34 var outputName =
'test/testcases/' + config +
'.ans';
35 var configName = config +
'.ini';
36 var opencc =
new OpenCC(configName);
37 fs.readFile(inputName,
'utf-8',
function (err, text) {
38 if (err)
return done(err);
39 opencc.convert(text,
function (err, converted) {
40 if (err)
return done(err);
41 fs.readFile(outputName,
'utf-8',
function (err, answer) {
42 if (err)
return done(err);
43 assert.equal(converted, answer);
50 describe(
'Sync API',
function () {
51 configs.forEach(
function (config) {
52 it(config,
function (done) {
53 testSync(config, done);
58 describe(
'Async API',
function () {
59 configs.forEach(
function (config) {
60 it(config,
function (done) {
61 testAsync(config, done);