1 | "use strict";
|
2 |
|
3 | var assert = require("chai").assert;
|
4 | var TokenStreamTransformer = require("./helper/token-stream-transformer");
|
5 | var TestCase = require("./helper/test-case");
|
6 |
|
7 |
|
8 |
|
9 | describe("The token stream transformer",
|
10 | function () {
|
11 | it("should handle all kinds of simple transformations",
|
12 | function () {
|
13 | var tokens = [
|
14 | {type: "type", content: "content"},
|
15 | "string"
|
16 | ];
|
17 |
|
18 | var expected = [
|
19 | ["type", "content"],
|
20 | "string"
|
21 | ];
|
22 |
|
23 | assert.deepEqual(TokenStreamTransformer.simplify(tokens), expected);
|
24 | }
|
25 | );
|
26 |
|
27 |
|
28 | it("should handle nested structures",
|
29 | function () {
|
30 | var tokens = [
|
31 | {
|
32 | type: "type",
|
33 | content: [
|
34 | {
|
35 | type: "insideType", content:
|
36 | [
|
37 | {type: "insideInsideType", content: "content"}
|
38 | ]
|
39 | }
|
40 | ]
|
41 | }
|
42 | ];
|
43 |
|
44 | var expected = [
|
45 | ["type", [
|
46 | ["insideType", [
|
47 | ["insideInsideType", "content"]
|
48 | ]]
|
49 | ]]
|
50 | ];
|
51 |
|
52 | assert.deepEqual(TokenStreamTransformer.simplify(tokens), expected);
|
53 | }
|
54 | );
|
55 |
|
56 |
|
57 | it("should strip empty tokens",
|
58 | function () {
|
59 | var tokenStream = [
|
60 | "",
|
61 | "\r\n",
|
62 | "\t",
|
63 | " "
|
64 | ];
|
65 |
|
66 | var expectedSimplified = [];
|
67 |
|
68 | assert.deepEqual(TokenStreamTransformer.simplify(tokenStream), expectedSimplified);
|
69 | }
|
70 | );
|
71 |
|
72 |
|
73 | it("should strip empty token tree branches",
|
74 | function () {
|
75 | var tokenStream = [
|
76 | {
|
77 | type: "type",
|
78 | content: [
|
79 | ["", ""],
|
80 | "",
|
81 | {type: "nested", content: [""]}
|
82 | ]
|
83 | },
|
84 | [[[[[[[""]]]]]]]
|
85 | ];
|
86 |
|
87 | var expectedSimplified = [
|
88 | ["type", [
|
89 | ["nested", []]
|
90 | ]]
|
91 | ];
|
92 |
|
93 | assert.deepEqual(TokenStreamTransformer.simplify(tokenStream), expectedSimplified);
|
94 | }
|
95 | );
|
96 |
|
97 |
|
98 | it("should ignore all properties in tokens except value and content",
|
99 | function () {
|
100 |
|
101 | var tokenStream = [
|
102 | {type: "type", content: "content", alias: "alias"}
|
103 | ];
|
104 |
|
105 | var expectedSimplified = [
|
106 | ["type", "content"]
|
107 | ];
|
108 |
|
109 | assert.deepEqual(TokenStreamTransformer.simplify(tokenStream), expectedSimplified);
|
110 | }
|
111 | );
|
112 | }
|
113 | );
|
114 |
|
115 |
|
116 |
|
117 |
|
118 | describe("The language name parsing",
|
119 | function () {
|
120 | it("should use the last language as the main language if no language is specified",
|
121 | function () {
|
122 | assert.deepEqual(
|
123 | TestCase.parseLanguageNames("a"),
|
124 | {
|
125 | languages: ["a"],
|
126 | mainLanguage: "a"
|
127 | }
|
128 | );
|
129 |
|
130 | assert.deepEqual(
|
131 | TestCase.parseLanguageNames("a+b+c"),
|
132 | {
|
133 | languages: ["a", "b", "c"],
|
134 | mainLanguage: "c"
|
135 | }
|
136 | );
|
137 | }
|
138 | );
|
139 |
|
140 |
|
141 | it("should use the specified language as main language",
|
142 | function () {
|
143 | assert.deepEqual(
|
144 | TestCase.parseLanguageNames("a+b!+c"),
|
145 | {
|
146 | languages: ["a", "b", "c"],
|
147 | mainLanguage: "b"
|
148 | }
|
149 | );
|
150 | }
|
151 | );
|
152 |
|
153 |
|
154 | it("should throw an error if there are multiple main languages",
|
155 | function () {
|
156 | assert.throw(
|
157 | function () {
|
158 | TestCase.parseLanguageNames("a+b!+c!");
|
159 | },
|
160 | "There are multiple main languages defined."
|
161 | );
|
162 | }
|
163 | );
|
164 | }
|
165 | );
|
166 |
|