-
Notifications
You must be signed in to change notification settings - Fork 0
/
isEmail.js
108 lines (90 loc) · 2.76 KB
/
isEmail.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
/* eslint-disable */
const {isEmail} = require("../functions/isEmail");
const fs = require("fs");
function generateImageBadgeURL(label, value, passed) {
return `https://img.shields.io/badge/${encodeURIComponent(label)}-${value}-${passed === 0 ? '13b285' : 'ff69b4'}`;}
function generateTestBadge(functionName, numberOfPassed, numberOfFailed) {
const url = generateImageBadgeURL(functionName + '()', encodeURIComponent(numberOfPassed + ' passed, ' + numberOfFailed + ' failed.'), numberOfFailed);
return '\n\n### Tests for ' + functionName + '\n\n' + '![' + functionName + '](' + url + ')';}
function addToReadme(str) {fs.appendFile('./README.md', str, function (err) {if (err) throw err;console.log('String added to the file');});}/**
* Test function for isEmail.
*/
function testIsEmail() {
const name_of_function = "isEmail";
let number_of_tests_passed = 0;
let number_of_tests_failed = 0;
try {
if (result) {
number_of_tests_passed++;
} else {
number_of_tests_failed++;
}
} catch (err) {
number_of_tests_failed++;
}
try {
if (result) {
number_of_tests_passed++;
} else {
number_of_tests_failed++;
}
} catch (err) {
number_of_tests_failed++;
}
try {
if (result) {
number_of_tests_passed++;
} else {
number_of_tests_failed++;
}
} catch (err) {
number_of_tests_failed++;
}
try {
if (result) {
number_of_tests_passed++;
} else {
number_of_tests_failed++;
}
} catch (err) {
number_of_tests_failed++;
}
try {
const result = isEmail("johndoe@例子.测试");
if (result) {
number_of_tests_passed++;
} else {
number_of_tests_failed++;
}
} catch (err) {
number_of_tests_failed++;
}
try {
const result = isEmail("");
if (!result) {
number_of_tests_passed++;
} else {
number_of_tests_failed++;
}
} catch (err) {
number_of_tests_failed++;
}
try {
const result = isEmail(" ");
if (!result) {
number_of_tests_passed++;
} else {
number_of_tests_failed++;
}
} catch (err) {
number_of_tests_failed++;
}
addToReadme(generateTestBadge(name_of_function, number_of_tests_passed, number_of_tests_failed));
}
module.exports = {
testIsEmail
};