-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnumber.spec.ts
48 lines (39 loc) · 1.21 KB
/
number.spec.ts
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
import test from "ava";
import makeParser from "../src/parser";
import select = require("unist-util-select");
import { loadFixture } from "./util";
import { Text } from "../src/types";
const BASIC_FIXTURE = loadFixture("basic.hcl");
test("base-10 numbers", t => {
const parser = makeParser();
parser.feed("my_number = 42.356");
const [ast] = parser.results;
const node = select(ast, 'Key[name="my_number"] + Number')[0];
t.is(node.rawValue, "42.356");
t.is(node.value, 42.356);
t.is(node.base, 10);
});
test("hexadecimal numbers", t => {
const parser = makeParser();
parser.feed("my_number = 0x99BEEF");
const [ast] = parser.results;
const node = select(ast, 'Key[name="my_number"] + Number')[0];
t.is(node.rawValue, "0x99BEEF");
t.is(node.value, 0x99beef);
t.is(node.base, 16);
});
test("octal numbers", t => {
const parser = makeParser();
parser.feed("permissions = 0777");
const [ast] = parser.results;
const node = select(ast, 'Key[name="permissions"] + Number')[0];
t.is(node.rawValue, "0777");
t.is(node.value, 0o777);
t.is(node.base, 8);
});
test("should throw if invalid octal", t => {
const parser = makeParser();
t.throws(() => {
parser.feed("permissions = 0797");
});
});