UNPKG

3.83 kBJavaScriptView Raw
1import fs from 'fs';
2import path from 'path';
3import { interpreter, Time } from '../src';
4
5const EXPECTATIONS_DIR = path.join(__dirname, 'data/interpreter-test-suite/format_decision_rules');
6
7// List the expectations file
8const expectationsFiles = fs.readdirSync(EXPECTATIONS_DIR);
9
10describe('interpreter.formatDecisionRules', () => {
11 _.each(expectationsFiles, (expectationsFile) => {
12 describe(`"${expectationsFile}"`, function() {
13 // Load the tree
14 const expectations = require(path.join(EXPECTATIONS_DIR, expectationsFile));
15
16 _.each(expectations, ({ title, expectation, rules }) => {
17 it(title, function() {
18 if (expectation.error) {
19 expect(() => interpreter.formatDecisionRules(rules)).to.throw();
20 }
21 else {
22 expect(interpreter.formatDecisionRules(rules)).to.be.deep.equal(expectation.string);
23 }
24 });
25 });
26 });
27 });
28});
29describe('interpreter.formatProperty', () => {
30 describe('on generated date types, works from a Time instance', () => {
31 it('From \'2018-08-07T16:06:06+0200\'', () => {
32 const date = new Time('2018-08-07T16:06:06+0200');
33 expect(interpreter.formatProperty('month_of_year', date)).to.be.equal('Aug');
34 expect(interpreter.formatProperty('day_of_month', date)).to.be.equal('07');
35 expect(interpreter.formatProperty('day_of_week', date)).to.be.equal('Tue');
36 expect(interpreter.formatProperty('time_of_day', date)).to.be.equal('16:06:06');
37 });
38 it('From \'2018-08-06T08:32:58.000Z\'', () => {
39 const date = new Time('2018-08-06T08:32:58.000Z');
40 expect(interpreter.formatProperty('month_of_year', date)).to.be.equal('Aug');
41 expect(interpreter.formatProperty('day_of_month', date)).to.be.equal('06');
42 expect(interpreter.formatProperty('day_of_week', date)).to.be.equal('Mon');
43 expect(interpreter.formatProperty('time_of_day', date)).to.be.equal('08:32:58');
44 });
45 it('From \'2017-10-03T09:13-0800\'', () => {
46 const date = new Time('2017-10-03T09:13-0800');
47 expect(interpreter.formatProperty('month_of_year', date)).to.be.equal('Oct');
48 expect(interpreter.formatProperty('day_of_month', date)).to.be.equal('03');
49 expect(interpreter.formatProperty('day_of_week', date)).to.be.equal('Tue');
50 expect(interpreter.formatProperty('time_of_day', date)).to.be.equal('09:13');
51 });
52 it('From \'2017-12-03T02:03+0500\' on tz \'-02:00\'', () => {
53 const date = new Time('2017-12-03T02:03+0500', '-02:00');
54 expect(interpreter.formatProperty('month_of_year', date)).to.be.equal('Dec');
55 expect(interpreter.formatProperty('day_of_month', date)).to.be.equal('02');
56 expect(interpreter.formatProperty('day_of_week', date)).to.be.equal('Sat');
57 expect(interpreter.formatProperty('time_of_day', date)).to.be.equal('19:03');
58 });
59 it('From \'2017-07-01T04:20:00.000Z\' on tz \'+02:00\'', () => {
60 const date = new Time('2017-07-01T04:20:00.000Z', '+02:00');
61 expect(interpreter.formatProperty('month_of_year', date)).to.be.equal('Jul');
62 expect(interpreter.formatProperty('day_of_month', date)).to.be.equal('01');
63 expect(interpreter.formatProperty('day_of_week', date)).to.be.equal('Sat');
64 expect(interpreter.formatProperty('time_of_day', date)).to.be.equal('06:20');
65 });
66 it('From \'2007-12-01T17:23:00.000Z\' on tz \'+01:00\'', () => {
67 const date = new Time('2007-12-01T17:23:00.000Z', '+01:00');
68 expect(interpreter.formatProperty('month_of_year', date)).to.be.equal('Dec');
69 expect(interpreter.formatProperty('day_of_month', date)).to.be.equal('01');
70 expect(interpreter.formatProperty('day_of_week', date)).to.be.equal('Sat');
71 expect(interpreter.formatProperty('time_of_day', date)).to.be.equal('18:23');
72 });
73 });
74});