-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathwb-lang.js
44 lines (38 loc) · 1.42 KB
/
wb-lang.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
import 'should'
import { shellExec } from '#test/lib/utils'
describe('wb lang', () => {
it('should display help', async () => {
const { stdout } = await shellExec('./bin/wd.js lang')
stdout.should.containEql('Usage:')
})
it('should identify a lang from a wikidata item id', async () => {
const { stdout } = await shellExec('./bin/wd.js lang Q150')
stdout.should.equal('fr')
})
it('should identify a lang from a language code', async () => {
const { stdout } = await shellExec('./bin/wd.js lang fr')
stdout.should.equal('Q150')
})
it('should identify a lang from a string', async () => {
const { stdout } = await shellExec('./bin/wd.js lang akan')
const [ langCode, wdId, englishLabel, native ] = stdout.split(/\s+/g)
langCode.should.equal('ak')
wdId.should.equal('Q28026')
englishLabel.should.equal('Akan')
native.should.equal('Akana')
})
describe('json', () => {
it('should identify a lang from a wikidata item id', async () => {
const { stdout } = await shellExec('./bin/wd.js lang Q150 --json')
const data = JSON.parse(stdout)
data.code.should.equal('fr')
data.wd.should.equal('Q150')
})
it('should identify a lang from a language code', async () => {
const { stdout } = await shellExec('./bin/wd.js lang fr --json')
const data = JSON.parse(stdout)
data.code.should.equal('fr')
data.wd.should.equal('Q150')
})
})
})