-
Notifications
You must be signed in to change notification settings - Fork 631
/
Copy pathtest_linter_invalid_posts.rb
411 lines (337 loc) · 8.98 KB
/
test_linter_invalid_posts.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
# frozen_string_literal: true
require "helper"
require "linter"
describe Linter do
before do
chdir_tempdir
end
after do
teardown_tempdir
end
it "reports old posts with lang variable that is nil" do
content = <<~POST
---
layout: news_post
title: "Post"
author: "stomar"
lang:
---
Content
POST
create_file("en/news/_posts/2000-01-01-old-lang-variable-nil.md", content)
_(linter_output).must_match "missing or invalid lang variable"
end
it "reports old posts with translator variable that has wrong type" do
content = <<~POST
---
layout: news_post
title: "Post"
author: "stomar"
translator: 1
lang: en
---
Content
POST
create_file("en/news/_posts/2000-01-01-old-translator-variable-wrong-type.md", content)
_(linter_output).must_match "invalid translator variable"
end
it "reports old posts with date variable that is empty" do
content = <<~POST
---
layout: news_post
title: "Post"
author: "stomar"
date: ""
lang: en
---
Content
POST
create_file("en/news/_posts/2000-01-01-old-date-empty.md", content)
_(linter_output).must_match "invalid date variable"
end
it "reports old posts with filename not matching date variable" do
content = <<~POST
---
layout: news_post
title: "Post"
author: "stomar"
date: 2000-12-12 12:00:00 +0000
lang: en
---
Content
POST
create_file("en/news/_posts/2000-01-01-old-date-mismatch.md", content)
_(linter_output).must_match "filename not matching date variable"
end
it "reports posts with trailing whitespace" do
content = <<~POST
---
layout: news_post
title: "Post"
author: "stomar"
translator:
date: 2018-01-01 12:00:00 +0000
lang: en
---
Content\s
POST
create_file("en/news/_posts/2018-01-01-trailing-whitespace.md", content)
_(linter_output).must_match "trailing whitespace"
end
it "reports posts with lang variable that is nil" do
content = <<~POST
---
layout: news_post
title: "Post"
author: "stomar"
translator:
date: 2018-01-02 12:00:00 +0000
lang:
---
Content
POST
create_file("en/news/_posts/2018-01-02-lang-variable-nil.md", content)
_(linter_output).must_match "missing or invalid lang variable"
end
it "reports posts with missing author variable" do
content = <<~POST
---
layout: news_post
title: "Post"
translator:
date: 2018-01-03 12:00:00 +0000
lang: en
---
Content
POST
create_file("en/news/_posts/2018-01-03-author-variable.md", content)
_(linter_output).must_match "missing or invalid author variable"
end
it "reports posts with author variable that is nil" do
content = <<~POST
---
layout: news_post
title: "Post"
author:
translator:
date: 2018-01-04 12:00:00 +0000
lang: en
---
Content
POST
create_file("en/news/_posts/2018-01-04-author-variable-nil.md", content)
_(linter_output).must_match "missing or invalid author variable"
end
it "reports posts with author variable that is empty" do
content = <<~POST
---
layout: news_post
title: "Post"
author: ""
translator:
date: 2018-01-05 12:00:00 +0000
lang: en
---
Content
POST
create_file("en/news/_posts/2018-01-05-author-variable-empty.md", content)
_(linter_output).must_match "missing or invalid author variable"
end
it "reports posts with author variable that has wrong type" do
content = <<~POST
---
layout: news_post
title: "Post"
author: 1
translator:
date: 2018-01-06 12:00:00 +0000
lang: en
---
Content
POST
create_file("en/news/_posts/2018-01-06-author-variable-wrong-type.md", content)
_(linter_output).must_match "missing or invalid author variable"
end
it "reports posts with missing translator" do
content = <<~POST
---
layout: news_post
title: "Post"
author: stomar
date: 2018-01-07 12:00:00 +0000
lang: en
---
Content
POST
create_file("en/news/_posts/2018-01-07-translator-variable-missing.md", content)
_(linter_output).must_match "missing translator variable"
end
it "reports posts with translator variable that is empty" do
content = <<~POST
---
layout: news_post
title: "Post"
author: stomar
translator: ""
date: 2018-01-08 12:00:00 +0000
lang: en
---
Content
POST
create_file("en/news/_posts/2018-01-08-translator-variable-empty.md", content)
_(linter_output).must_match "invalid translator variable"
end
it "reports posts with missing date variable" do
content = <<~POST
---
layout: news_post
title: "Post"
author: stomar
translator:
lang: en
---
Content
POST
create_file("en/news/_posts/2018-01-09-date-variable-missing.md", content)
_(linter_output).must_match "missing date variable"
end
it "reports posts with date variable that is nil" do
content = <<~POST
---
layout: news_post
title: "Post"
author: stomar
translator:
date:
lang: en
---
Content
POST
create_file("en/news/_posts/2018-01-10-date-variable-nil.md", content)
_(linter_output).must_match "missing date variable"
end
it "reports posts with date variable that is empty" do
content = <<~POST
---
layout: news_post
title: "Post"
author: stomar
translator:
date: ""
lang: en
---
Content
POST
create_file("en/news/_posts/2018-01-11-date-variable-empty.md", content)
_(linter_output).must_match "invalid date variable"
end
it "reports posts with date variable that is of wrong type" do
content = <<~POST
---
layout: news_post
title: "Post"
author: stomar
translator:
date: 2018
lang: en
---
Content
POST
create_file("en/news/_posts/2018-01-12-date-variable-wrong-type.md", content)
_(linter_output).must_match "invalid date variable"
end
it "reports posts with date variable that has no time" do
content = <<~POST
---
layout: news_post
title: "Post"
author: stomar
translator:
date: 2018-01-13
lang: en
---
Content
POST
create_file("en/news/_posts/2018-01-13-date-variable-without-time.md", content)
_(linter_output).must_match "invalid date variable"
end
it "reports posts with date variable that has wrong offset" do
content = <<~POST
---
layout: news_post
title: "Post"
author: stomar
translator:
date: 2018-01-14 12:00:00 +0500
lang: en
---
Content
POST
create_file("en/news/_posts/2018-01-14-date-variable-wrong-offset.md", content)
_(linter_output).must_match "date variable with wrong time zone offset"
end
it "reports posts with filename not matching date variable" do
content = <<~POST
---
layout: news_post
title: "Post"
author: stomar
translator:
date: 2018-12-12 12:00:00 +0000
lang: en
---
Content
POST
create_file("en/news/_posts/2018-01-15-date-mismatch.md", content)
_(linter_output).must_match "filename not matching date variable"
end
it "reports posts with invalid SHA1 length" do
content = <<~POST
---
layout: news_post
title: "Release Post"
author: "stomar"
translator:
date: 2019-01-01 12:00:00 +0000
lang: en
---
Content
SHA1: abcdef78901234567890
POST
create_file("en/news/_posts/2019-01-01-invalid-sha1-length-released.md", content)
_(linter_output).must_match "invalid SHA1 length"
end
it "reports posts with invalid SHA256 length" do
content = <<~POST
---
layout: news_post
title: "Release Post"
author: "stomar"
translator:
date: 2019-01-02 12:00:00 +0000
lang: en
---
Content
SHA256: abcdef7890123456789012345678901234567890123456789012345678901234567890
POST
create_file("en/news/_posts/2019-01-02-invalid-sha256-length-released.md", content)
_(linter_output).must_match "invalid SHA256 length"
end
it "reports posts with invalid SHA512 length" do
content = <<~POST
---
layout: news_post
title: "Release Post"
author: "stomar"
translator:
date: 2019-01-03 12:00:00 +0000
lang: en
---
Content
SHA512: abcdef789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678
POST
create_file("en/news/_posts/2019-01-03-invalid-sha512-length-released.md", content)
_(linter_output).must_match "invalid SHA512 length"
end
end