UNPKG

1.26 kBJavaScriptView Raw
1// Copyright (c) 2016-2020 Electric Imp
2// This file is licensed under the MIT License
3// http://opensource.org/licenses/MIT
4
5'use strict';
6
7const Builder = require('../src');
8const Machine = require('../src/Machine');
9const path = require('path');
10
11const contextPath = path.resolve(__dirname, './..').replace(/\\/g, '/');
12const filePath = path.join(contextPath, 'main').replace(/\\/g, '/');
13
14describe('Builder', () => {
15
16 let builder;
17
18 beforeEach(() => {
19 builder = new Builder();
20 builder.machine.readers.github.token = process.env.SPEC_GITHUB_TOKEN;
21 });
22
23 it('should build something', () => {
24 expect(builder.machine instanceof Machine).toBeTruthy();
25 builder.machine.generateLineControlStatements = true;
26 expect(builder.machine.execute('@{__FILE__}:@{__LINE__}'))
27 .toBe('#line 1 "' + filePath + '"\nmain:1');
28 });
29
30 it('should execute "escape" filter', () => {
31 expect(builder.machine instanceof Machine).toBeTruthy();
32 const res = builder.machine.execute(`"@{'"'|escape}"`);
33 expect(res).toBe(`"\\""`);
34 });
35
36 it('should execute "base64" filter', () => {
37 expect(builder.machine instanceof Machine).toBeTruthy();
38 const res = builder.machine.execute(`@{"abc"|base64}`);
39 expect(res).toBe(`YWJj`);
40 });
41
42});