UNPKG

7.38 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3// *****************************************************************************
4// Copyright (C) 2017 TypeFox and others.
5//
6// This program and the accompanying materials are made available under the
7// terms of the Eclipse Public License v. 2.0 which is available at
8// http://www.eclipse.org/legal/epl-2.0.
9//
10// This Source Code may also be made available under the following Secondary
11// Licenses when the conditions for such availability set forth in the Eclipse
12// Public License v. 2.0 are satisfied: GNU General Public License, version 2
13// with the GNU Classpath Exception which is available at
14// https://www.gnu.org/software/classpath/license.html.
15//
16// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
17// *****************************************************************************
18const label_parser_1 = require("./label-parser");
19const common_1 = require("./../common");
20const inversify_1 = require("inversify");
21const chai_1 = require("chai");
22let statusBarEntryUtility;
23before(() => {
24 const testContainer = new inversify_1.Container();
25 testContainer.bind(label_parser_1.LabelParser).toSelf().inSingletonScope();
26 testContainer.bind(common_1.CommandService).toDynamicValue(ctx => ({
27 executeCommand() {
28 return Promise.resolve(undefined);
29 }
30 })).inSingletonScope();
31 statusBarEntryUtility = testContainer.get(label_parser_1.LabelParser);
32});
33describe('StatusBarEntryUtility', () => {
34 let text;
35 it('should create an empty array.', () => {
36 text = '';
37 const iconArr = statusBarEntryUtility.parse(text);
38 (0, chai_1.expect)(iconArr).to.have.lengthOf(0);
39 });
40 it('should create a string array with one entry.', () => {
41 text = 'foo bar';
42 const iconArr = statusBarEntryUtility.parse(text);
43 (0, chai_1.expect)(iconArr).to.have.lengthOf(1);
44 (0, chai_1.expect)(iconArr[0]).equals('foo bar');
45 });
46 it('should create a string array with one entry - text contains an $.', () => {
47 text = 'foo $ bar';
48 const iconArr = statusBarEntryUtility.parse(text);
49 (0, chai_1.expect)(iconArr).to.have.lengthOf(1);
50 (0, chai_1.expect)(iconArr[0]).equals('foo $ bar');
51 });
52 it('should create a string array with one entry - text contains an $( which does not close.', () => {
53 text = 'foo $(bar';
54 const iconArr = statusBarEntryUtility.parse(text);
55 (0, chai_1.expect)(iconArr).to.have.lengthOf(1);
56 (0, chai_1.expect)(iconArr[0]).equals('foo $(bar');
57 });
58 it('should create a string array with two entries. Second is a simple StatusBarIcon.', () => {
59 text = 'foo $(bar)';
60 const iconArr = statusBarEntryUtility.parse(text);
61 (0, chai_1.expect)(iconArr).to.have.lengthOf(2);
62 (0, chai_1.expect)(iconArr[0]).equals('foo ');
63 (0, chai_1.expect)(iconArr[1]).has.property('name');
64 (0, chai_1.expect)(iconArr[1]).has.property('animation');
65 (0, chai_1.expect)(iconArr[1].name).equals('bar');
66 (0, chai_1.expect)(iconArr[1].animation).to.be.undefined;
67 });
68 it('should create a string array with two entries. Second is a StatusBarIcon with an animation.', () => {
69 text = 'foo $(bar~baz)';
70 const iconArr = statusBarEntryUtility.parse(text);
71 (0, chai_1.expect)(iconArr).to.have.lengthOf(2);
72 (0, chai_1.expect)(iconArr[0]).equals('foo ');
73 (0, chai_1.expect)(iconArr[1]).has.property('name');
74 (0, chai_1.expect)(iconArr[1]).has.property('animation');
75 (0, chai_1.expect)(iconArr[1].name).equals('bar');
76 (0, chai_1.expect)(iconArr[1].animation).equals('baz');
77 });
78 it("should create string array of 'foo $(icon1) bar $(icon2) baz $(icon3)'", () => {
79 text = 'foo $(icon1) bar $(icon2) baz $(icon3)';
80 const iconArr = statusBarEntryUtility.parse(text);
81 (0, chai_1.expect)(iconArr).to.have.lengthOf(6);
82 (0, chai_1.expect)(iconArr[0]).equals('foo ');
83 (0, chai_1.expect)(iconArr[2]).equals(' bar ');
84 });
85 it("should create string array of '$(icon1) foo bar $(icon2) baz $(icon3)'", () => {
86 text = '$(icon1) foo bar $(icon2~ani1) baz $(icon3)';
87 const iconArr = statusBarEntryUtility.parse(text);
88 (0, chai_1.expect)(iconArr).to.have.lengthOf(5);
89 (0, chai_1.expect)(iconArr[0]).has.property('name');
90 (0, chai_1.expect)(iconArr[0].name).equals('icon1');
91 (0, chai_1.expect)(iconArr[2]).has.property('animation');
92 (0, chai_1.expect)(iconArr[2].animation).equals('ani1');
93 });
94 it("should create an array with one element of '$(icon1)'", () => {
95 text = '$(icon1)';
96 const iconArr = statusBarEntryUtility.parse(text);
97 (0, chai_1.expect)(iconArr).to.have.lengthOf(1);
98 (0, chai_1.expect)(iconArr[0]).has.property('name');
99 (0, chai_1.expect)(iconArr[0].name).equals('icon1');
100 });
101 it("should create an array of '$(icon1)$(icon2) (icon3)'", () => {
102 text = '$(icon1)$(icon2) $(icon3)';
103 const iconArr = statusBarEntryUtility.parse(text);
104 (0, chai_1.expect)(iconArr).to.have.lengthOf(4);
105 (0, chai_1.expect)(iconArr[0]).has.property('name');
106 (0, chai_1.expect)(iconArr[0].name).equals('icon1');
107 (0, chai_1.expect)(iconArr[1]).has.property('name');
108 (0, chai_1.expect)(iconArr[1].name).equals('icon2');
109 (0, chai_1.expect)(iconArr[2]).equals(' ');
110 (0, chai_1.expect)(iconArr[3]).has.property('name');
111 (0, chai_1.expect)(iconArr[3].name).equals('icon3');
112 });
113 it('should strip nothing from an empty string', () => {
114 text = '';
115 const stripped = statusBarEntryUtility.stripIcons(text);
116 (0, chai_1.expect)(stripped).to.be.equal(text);
117 });
118 it('should strip nothing from an string containing no icons', () => {
119 // Deliberate double space to verify not concatenating these words
120 text = 'foo bar';
121 const stripped = statusBarEntryUtility.stripIcons(text);
122 (0, chai_1.expect)(stripped).to.be.equal(text);
123 });
124 it("should strip a medial '$(icon)' from a string", () => {
125 text = 'foo $(icon) bar';
126 const stripped = statusBarEntryUtility.stripIcons(text);
127 (0, chai_1.expect)(stripped).to.be.equal('foo bar');
128 });
129 it("should strip a terminal '$(icon)' from a string", () => {
130 // Deliberate double space to verify not concatenating these words
131 text = 'foo bar $(icon)';
132 const stripped = statusBarEntryUtility.stripIcons(text);
133 (0, chai_1.expect)(stripped).to.be.equal('foo bar');
134 });
135 it("should strip an initial '$(icon)' from a string", () => {
136 // Deliberate double space to verify not concatenating these words
137 text = '$(icon) foo bar';
138 const stripped = statusBarEntryUtility.stripIcons(text);
139 (0, chai_1.expect)(stripped).to.be.equal('foo bar');
140 });
141 it("should strip multiple '$(icon)' specifiers from a string", () => {
142 text = '$(icon1) foo $(icon2)$(icon3) bar $(icon4) $(icon5)';
143 const stripped = statusBarEntryUtility.stripIcons(text);
144 (0, chai_1.expect)(stripped).to.be.equal('foo bar');
145 });
146});
147//# sourceMappingURL=label-parser.spec.js.map
\No newline at end of file