-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegexTester.js
115 lines (106 loc) · 4.72 KB
/
RegexTester.js
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
var testStringsAndExpectedResults = [
["[EN] Lorem ipsum dolor sit amet", true],
["[translation] Lorem ipsum dolor sit amet", true],
["[tr] Lorem ipsum dolor sit amet", true],
["[英訳] Lorem ipsum dolor sit amet", true],
["[英訳/EN]Lorem ipsum dolor sit amet", true],
["EN: Lorem ipsum dolor sit amet", true],
["translation: Lorem ipsum dolor sit amet", true],
["tr: Lorem ipsum dolor sit amet", true],
["英訳: Lorem ipsum dolor sit amet", true],
["英訳/EN:Lorem ipsum dolor sit amet", true],
["EN : Lorem ipsum dolor sit amet", true],
["translation : Lorem ipsum dolor sit amet", true],
["tr : Lorem ipsum dolor sit amet", true],
["英訳 : Lorem ipsum dolor sit amet", true],
["英訳/EN :Lorem ipsum dolor sit amet", true],
["EN- Lorem ipsum dolor sit amet", true],
["translation- Lorem ipsum dolor sit amet", true],
["tr- Lorem ipsum dolor sit amet", true],
["英訳- Lorem ipsum dolor sit amet", true],
["英訳/EN-Lorem ipsum dolor sit amet", true],
["EN - Lorem ipsum dolor sit amet", true],
["translation - Lorem ipsum dolor sit amet", true],
["tr - Lorem ipsum dolor sit amet", true],
["英訳 - Lorem ipsum dolor sit amet", true],
["英訳/EN -Lorem ipsum dolor sit amet", true],
["EN} Lorem ipsum dolor sit amet", true],
["translation} Lorem ipsum dolor sit amet", true],
["tr} Lorem ipsum dolor sit amet", true],
["英訳} Lorem ipsum dolor sit amet", true],
["英訳/EN}Lorem ipsum dolor sit amet", true],
["EN } Lorem ipsum dolor sit amet", true],
["translation } Lorem ipsum dolor sit amet", true],
["tr } Lorem ipsum dolor sit amet", true],
["英訳 } Lorem ipsum dolor sit amet", true],
["英訳/EN }Lorem ipsum dolor sit amet", true],
["/[EN] Lorem ipsum dolor sit amet", true],
["/[translation] Lorem ipsum dolor sit amet", true],
["/[tr] Lorem ipsum dolor sit amet", true],
["/[英訳] Lorem ipsum dolor sit amet", true],
["/[英訳/EN]Lorem ipsum dolor sit amet", true],
["/EN: Lorem ipsum dolor sit amet", true],
["/translation: Lorem ipsum dolor sit amet", true],
["/tr: Lorem ipsum dolor sit amet", true],
["/英訳: Lorem ipsum dolor sit amet", true],
["/英訳/EN:Lorem ipsum dolor sit amet", true],
["/EN : Lorem ipsum dolor sit amet", true],
["/translation : Lorem ipsum dolor sit amet", true],
["/tr : Lorem ipsum dolor sit amet", true],
["/英訳 : Lorem ipsum dolor sit amet", true],
["/英訳/EN :Lorem ipsum dolor sit amet", true],
["/EN- Lorem ipsum dolor sit amet", true],
["/translation- Lorem ipsum dolor sit amet", true],
["/tr- Lorem ipsum dolor sit amet", true],
["/英訳- Lorem ipsum dolor sit amet", true],
["/英訳/EN-Lorem ipsum dolor sit amet", true],
["/EN - Lorem ipsum dolor sit amet", true],
["/translation - Lorem ipsum dolor sit amet", true],
["/tr - Lorem ipsum dolor sit amet", true],
["/英訳 - Lorem ipsum dolor sit amet", true],
["/英訳/EN -Lorem ipsum dolor sit amet", true],
["/EN} Lorem ipsum dolor sit amet", true],
["/translation} Lorem ipsum dolor sit amet", true],
["/tr} Lorem ipsum dolor sit amet", true],
["/英訳} Lorem ipsum dolor sit amet", true],
["/英訳/EN}Lorem ipsum dolor sit amet", true],
["/EN } Lorem ipsum dolor sit amet", true],
["/translation } Lorem ipsum dolor sit amet", true],
["/tr } Lorem ipsum dolor sit amet", true],
["/英訳 } Lorem ipsum dolor sit amet", true],
["/英訳/EN }Lorem ipsum dolor sit amet", true],
["EN: Lorem ipsum dolor sit amet", true],
["translation: Lorem ipsum dolor sit amet", true],
["true endingとかなんか", false],
["encounter an enemy", false],
["(EN) Loki: I am innocent!",true],
]
var regexTester = (function () {
var basePattern = "^\\/?((§)\\s?(:|-|\\})|\\[(§)\\]|\\((§)\\)|(§)\s)";
var thingsToMatch = ["英訳", "英訳\/en", "en", "tr", "translation"];
var pattern = basePattern.replace(/§/g, thingsToMatch.join('|'));
return {
isTranslation: function (txt) {
return RegExp(pattern, 'i').test(txt)
},
showPattern: function () {
return pattern;
},
}
}());
(function () {
var Assert = function (func, str, expected) {
if (func(str) === expected) {
return "PASS";
}
else {
return "FAIL: " + str;
}
}
var IsTranslation = function (str, expected) {
var result = Assert(regexTester.isTranslation, str, expected);
console.log(result);
}
console.log("Pattern: ", regexTester.showPattern());
testStringsAndExpectedResults.forEach(([testString, expectedOutput]) => IsTranslation(testString, expectedOutput));
})();