@@ -16,13 +16,8 @@ import * as assert from "assert";
16
16
import * as Stream from "stream" ;
17
17
import {
18
18
execFileStreamOutput ,
19
- getRepositoryName ,
20
19
execSwift ,
21
20
getSwiftExecutable ,
22
- stringArrayInEnglish ,
23
- regexEscapedString ,
24
- hashString ,
25
- getErrorDescription ,
26
21
} from "../../../src/utilities/utilities" ;
27
22
28
23
suite ( "Utilities Test Suite" , ( ) => {
@@ -46,144 +41,4 @@ suite("Utilities Test Suite", () => {
46
41
assert ( result . includes ( "Swift version" ) ) ;
47
42
assert . strictEqual ( result , stdout ) ;
48
43
} ) ;
49
-
50
- suite ( "getRepositoryName" , ( ) => {
51
- test ( "regular url" , ( ) => {
52
- assert . strictEqual (
53
- getRepositoryName ( "https://github.com/swiftlang/vscode-swift.git" ) ,
54
- "vscode-swift"
55
- ) ;
56
- } ) ;
57
-
58
- test ( "url does not end in .git" , ( ) => {
59
- assert . strictEqual (
60
- getRepositoryName ( "https://github.com/swiftlang/vscode-swift" ) ,
61
- "vscode-swift"
62
- ) ;
63
- } ) ;
64
-
65
- test ( "URL contains a trailing slash" , ( ) => {
66
- assert . strictEqual (
67
- getRepositoryName ( "https://github.com/swiftlang/vscode-swift.git/" ) ,
68
- "vscode-swift"
69
- ) ;
70
- } ) ;
71
- test ( "Name contains a dot" , ( ) => {
72
- assert . strictEqual (
73
- getRepositoryName ( "https://github.com/swiftlang/vscode.swift.git" ) ,
74
- "vscode.swift"
75
- ) ;
76
- } ) ;
77
-
78
- test ( "Name contains .git" , ( ) => {
79
- assert . strictEqual (
80
- getRepositoryName ( "https://github.com/swiftlang/vscode.git.git" ) ,
81
- "vscode.git"
82
- ) ;
83
- } ) ;
84
- } ) ;
85
-
86
- suite ( "getErrorDescription" , ( ) => {
87
- test ( 'should return "No error provided" when the error is null or undefined' , ( ) => {
88
- assert . strictEqual ( getErrorDescription ( null ) , "No error provided" ) ;
89
- assert . strictEqual ( getErrorDescription ( undefined ) , "No error provided" ) ;
90
- } ) ;
91
-
92
- test ( "should return the stderr property if present" , ( ) => {
93
- const errorWithStderr = { stderr : "This is an error from stderr" } ;
94
- const result = getErrorDescription ( errorWithStderr ) ;
95
- assert . strictEqual ( result , "This is an error from stderr" ) ;
96
- } ) ;
97
-
98
- test ( "should return the error property if present" , ( ) => {
99
- const errorWithErrorProperty = { error : "This is an error message" } ;
100
- const result = getErrorDescription ( errorWithErrorProperty ) ;
101
- assert . strictEqual ( result , JSON . stringify ( "This is an error message" ) ) ;
102
- } ) ;
103
-
104
- test ( "should return the message property if the error is an instance of Error" , ( ) => {
105
- const standardError = new Error ( "This is a standard error message" ) ;
106
- const result = getErrorDescription ( standardError ) ;
107
- assert . strictEqual ( result , "This is a standard error message" ) ;
108
- } ) ;
109
-
110
- test ( "should return a stringified version of the error if it is an object without stderr or error properties" , ( ) => {
111
- const genericObjectError = { message : "Generic error" , code : 500 } ;
112
- const result = getErrorDescription ( genericObjectError ) ;
113
- assert . strictEqual ( result , JSON . stringify ( genericObjectError ) ) ;
114
- } ) ;
115
-
116
- test ( "should return a stringified version of the error if it is a string" , ( ) => {
117
- const stringError = "This is a string error" ;
118
- const result = getErrorDescription ( stringError ) ;
119
- assert . strictEqual ( result , JSON . stringify ( stringError ) ) ;
120
- } ) ;
121
-
122
- test ( "should return a stringified version of the error if it is a number" , ( ) => {
123
- const numericError = 404 ;
124
- const result = getErrorDescription ( numericError ) ;
125
- assert . strictEqual ( result , JSON . stringify ( numericError ) ) ;
126
- } ) ;
127
-
128
- test ( "should return a stringified version of an array if passed as error" , ( ) => {
129
- const arrayError = [ "Error in item 1" , "Error in item 2" ] ;
130
- const result = getErrorDescription ( arrayError ) ;
131
- assert . strictEqual ( result , JSON . stringify ( arrayError ) ) ;
132
- } ) ;
133
- } ) ;
134
-
135
- suite ( "hashString" , ( ) => {
136
- test ( "empty string" , ( ) => {
137
- assert . strictEqual ( hashString ( "" ) , 3338908027751811 ) ;
138
- } ) ;
139
-
140
- test ( "non empty string" , ( ) => {
141
- assert . strictEqual ( hashString ( "foo" ) , 6104293464250660 ) ;
142
- } ) ;
143
- } ) ;
144
-
145
- suite ( "stringArrayInEnglish" , ( ) => {
146
- test ( "should return a single element unchanged" , ( ) => {
147
- assert . strictEqual ( stringArrayInEnglish ( [ "a" ] ) , "a" ) ;
148
- } ) ;
149
-
150
- test ( "should use 'and' to concatinate two elements" , ( ) => {
151
- assert . strictEqual ( stringArrayInEnglish ( [ "a" , "b" ] ) , "a and b" ) ;
152
- } ) ;
153
-
154
- test ( "should handle three or more elements" , ( ) => {
155
- assert . strictEqual ( stringArrayInEnglish ( [ "a" , "b" , "c" ] ) , "a, b and c" ) ;
156
- } ) ;
157
- } ) ;
158
-
159
- suite ( "regexEscapedString" , ( ) => {
160
- test ( "should escape special regex characters in a string" , ( ) => {
161
- assert . strictEqual (
162
- regexEscapedString ( "a.b(c)d[e]f$g^h?i|j/k:l" ) ,
163
- "a\\.b\\(c\\)d\\[e\\]f\\$g\\^h\\?i\\|j\\/k\\:l"
164
- ) ;
165
- } ) ;
166
-
167
- test ( "should not escape characters that are not special regex characters" , ( ) => {
168
- assert . strictEqual ( regexEscapedString ( "abcde12345" ) , "abcde12345" ) ;
169
- } ) ;
170
-
171
- test ( "should escape a string that contains only special regex characters" , ( ) => {
172
- assert . strictEqual (
173
- regexEscapedString ( ".^$|()?[]/:" ) ,
174
- "\\.\\^\\$\\|\\(\\)\\?\\[\\]\\/\\:"
175
- ) ;
176
- } ) ;
177
-
178
- test ( "should escape a string that omits some characters" , ( ) => {
179
- assert . strictEqual (
180
- regexEscapedString ( ".^$|()?[]/:" , new Set ( [ "^" , "$" , "a" ] ) ) ,
181
- "\\.^$\\|\\(\\)\\?\\[\\]\\/\\:"
182
- ) ;
183
- } ) ;
184
-
185
- test ( "should return an empty string when input is an empty string" , ( ) => {
186
- assert . strictEqual ( regexEscapedString ( "" ) , "" ) ;
187
- } ) ;
188
- } ) ;
189
44
} ) ;
0 commit comments