1/* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16class ClassFilter { 17 constructor(suiteName, itName, params) { 18 this.suiteName = suiteName; 19 this.itName = itName; 20 this.params = params; 21 } 22 23 filterSuite() { 24 return !this.params.split(',').map(item => item.split('#')[0]).map(item => item == this.suiteName).reduce((pre, cur) => pre || cur, false); 25 } 26 27 filterIt() { 28 let classArray = this.params.split(',') || []; 29 let suiteFilterResult = classArray.filter(item => !item.includes('#')).map(item => item == this.suiteName).reduce((pre, cur) => pre || cur, false); 30 let itFilterResult = classArray.filter(item => item.includes('#')).map(item => item == (this.suiteName + '#' + this.itName)).reduce((pre, cur) => pre || cur, false); 31 return !(suiteFilterResult || itFilterResult); 32 } 33} 34 35class NotClassFilter { 36 constructor(suiteName, itName, params) { 37 this.suiteName = suiteName; 38 this.itName = itName; 39 this.params = params; 40 } 41 42 filterSuite() { 43 return this.params.split(',').map(item => item == this.suiteName).reduce((pre, cur) => pre || cur, false); 44 } 45 46 filterIt() { 47 return this.params.split(',').some(item => item == (this.suiteName + '#' + this.itName)); 48 } 49} 50 51class SuiteAndItNameFilter { 52 constructor(suiteName, itName, params) { 53 this.suiteName = suiteName; 54 this.itName = itName; 55 this.params = params; 56 } 57 58 filterSuite() { 59 return !this.params.split(',').map(item => item == this.suiteName).reduce((pre, cur) => pre || cur, false); 60 } 61 62 filterIt() { 63 return !this.params.split(',').map(item => item == this.itName).reduce((pre, cur) => pre || cur, false); 64 } 65} 66 67 68class TestTypesFilter { 69 constructor(suiteName, itName, fi, params) { 70 this.suiteName = suiteName; 71 this.itName = itName; 72 this.params = params; 73 this.fi = fi; 74 } 75 76 filterIt() { 77 return !((this.params === (this.fi & this.params)) || this.fi === 0); 78 } 79} 80 81export {ClassFilter, NotClassFilter, SuiteAndItNameFilter, TestTypesFilter}; 82