2019-08-06 21:44:55 +08:00
|
|
|
const chalk = require('chalk');
|
2019-08-07 17:30:37 +08:00
|
|
|
const RULES = require('../packages/www/src/RULES');
|
|
|
|
let failGroup = [];
|
|
|
|
|
|
|
|
|
2019-08-06 21:44:55 +08:00
|
|
|
RULES.forEach(RULE => {
|
|
|
|
testOne(RULE);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function testOne(one) {
|
2019-08-07 17:30:37 +08:00
|
|
|
const {
|
|
|
|
rule,
|
|
|
|
examples,
|
|
|
|
title,
|
|
|
|
counterExamples
|
|
|
|
} = one;
|
|
|
|
examples.forEach(example => {
|
|
|
|
const isSuccess = rule.test(example);
|
2019-08-06 21:44:55 +08:00
|
|
|
if (isSuccess) {
|
2019-08-07 17:30:37 +08:00
|
|
|
console.log(chalk.green(`成功: ${title}, 用例: ${example}`));
|
2019-08-06 21:44:55 +08:00
|
|
|
} else {
|
2019-08-07 17:30:37 +08:00
|
|
|
failGroup.push({title, example, is:'正例'});
|
|
|
|
|
|
|
|
console.log(chalk.red(`失败: ${title}, 用例: ${example}`));
|
2019-08-06 21:44:55 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-08-07 17:30:37 +08:00
|
|
|
if (counterExamples) {
|
|
|
|
counterExamples.forEach(example => {
|
|
|
|
const isFail = !rule.test(example);
|
2019-08-06 21:44:55 +08:00
|
|
|
if (isFail) {
|
2019-08-07 17:30:37 +08:00
|
|
|
console.log(chalk.green(`反例成功(counterExamples): ${title}`));
|
2019-08-06 21:44:55 +08:00
|
|
|
} else {
|
2019-08-07 17:30:37 +08:00
|
|
|
failGroup.push({title, example, is: '反例'});
|
|
|
|
console.log(chalk.red(`反例失败(counterExamples): ${title}, 用例: ${example}`));
|
2019-08-06 21:44:55 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-08-07 17:30:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if(0 === failGroup.length) {
|
2019-11-07 08:55:40 +08:00
|
|
|
console.log(chalk.green('\r\n🚀 全部测试通过!'))
|
2019-08-07 17:30:37 +08:00
|
|
|
} else {
|
2019-11-07 08:55:40 +08:00
|
|
|
console.log(chalk.red('='.repeat(30) + '🔥 未通过测试' + '='.repeat(30)));
|
2019-08-06 21:44:55 +08:00
|
|
|
|
2019-08-07 17:30:37 +08:00
|
|
|
// 失败列表
|
|
|
|
failGroup.forEach(item=>{
|
|
|
|
const str = `${item.title}[${item.is}]: ${item.example}`;
|
|
|
|
console.log(chalk.red(str));
|
|
|
|
});
|
|
|
|
}
|