forked from Lellansin/node-scanf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhex.js
More file actions
55 lines (46 loc) · 1.5 KB
/
Copy pathhex.js
File metadata and controls
55 lines (46 loc) · 1.5 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
54
55
var sscanf = require('../').sscanf;
var should = require('should');
describe('scanf', function() {
describe('#Hexadecimal', function() {
it('[%x] \t\tshould get a number 32', function(done) {
var num = sscanf('20', '%x');
should.strictEqual(num, 32);
done();
});
it('[%x] \t\tshould get a number 16', function(done) {
var num = sscanf('10 10', '%x');
should.strictEqual(num, 16);
done();
});
it('[%x] \t\tshould get a number 16', function(done) {
var num = sscanf('0xA0', '%x');
should.strictEqual(num, 160);
done();
});
it('[%x] \t\tinvalid hex number should get a null', function(done) {
var num = sscanf('0x1G0', '%x');
should.strictEqual(num, null);
done();
});
it('[a=%x] \t\tshould get a number 161', function(done) {
var num = sscanf('a=A1 456', 'a=%x');
should.strictEqual(num, 161);
done();
});
it('[%x%x] \t\tshould get an array with two numbers [16, 32]', function(done) {
var num = sscanf('10,20', '%x%x');
should.deepEqual(num, [16, 32]);
done();
});
it('[%x,%x] \tshould get an array with two numbers [16, 32]', function(done) {
var num = sscanf('0x10,0X20', '%x,%x');
should.deepEqual(num, [16, 32]);
done();
});
it('[a=%x, b=%x] \tshould get an array with two numbers [16, 32]', function(done) {
var num = sscanf('a=0x10, b=20', 'a=%x, b=%x');
should.deepEqual(num, [16, 32]);
done();
});
});
});