forked from plainheart/google-translate-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
79 lines (65 loc) · 2.01 KB
/
test.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const test = require('ava');
const Configstore = require('configstore');
const languages = require('./languages.js');
const translate = require('./index.js');
// const { HttpsProxyAgent } = require('hpagent');
const config = new Configstore('google-translate-api');
test.beforeEach(() => {
config.clear();
});
test('translate', async t => {
const res = await translate(
`你好`,
{ to: 'en', endpointFallback: true, endpoints: [], randomEndpoint: true, raw: true },
// {
// agent: {
// https: new HttpsProxyAgent({
// keepAlive: true,
// keepAliveMsecs: 1000,
// maxSockets: 256,
// maxFreeSockets: 256,
// scheduling: 'lifo',
// proxy: 'http://127.0.0.1:9633'
// })
// }
// }
)
t.is(res.text, 'Hello there');
t.false(res.from.language.didYouMean);
t.is(res.from.language.iso, 'zh-CN');
t.false(res.from.text.autoCorrected);
t.false(res.from.text.didYouMean);
})
test('test get zh code', t => {
t.false(languages.getCode('zh'));
});
test('test get zh-CN code', t => {
t.is(languages.getCode('zh-CN'), 'zh-CN');
});
test('test get zh-cn code', t => {
t.false(languages.getCode('zh-cn'));
});
test('test get zh-TW code', t => {
t.is(languages.getCode('zh-TW'), 'zh-TW');
});
test('test get zh-tw code', t => {
t.false(languages.getCode('zh-tw'));
});
test('test zh unsupported', t => {
t.false(languages.isSupported('zh'));
});
test('test zh-CN supported', t => {
t.true(languages.isSupported('zh-CN'));
});
test('test zh-cn unsupported', t => {
t.false(languages.isSupported('zh-cn'));
});
test('test zh-TW supported', t => {
t.true(languages.isSupported('zh-TW'));
});
test('test zh-tw unsupported', t => {
t.false(languages.isSupported('zh-tw'));
});
test('test zh-CN supported – by name', t => {
t.true(languages.isSupported('chinese (simplified)'));
});