• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2024 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
16import { LEVEL, SIZE, TESTTYPE } from '../../Constant';
17
18class ClassFilter {
19    constructor(suiteName, itName, params) {
20        this.suiteName = suiteName;
21        this.itName = itName;
22        this.params = params;
23    }
24
25    filterSuite() {
26        return !this.params.split(',').map(item => item.split('#')[0]).map(item => item == this.suiteName).reduce((pre, cur) => pre || cur, false);
27    }
28
29    filterIt() {
30        let classArray = this.params.split(',') || [];
31        let suiteFilterResult = classArray.filter(item => !item.includes('#')).map(item => item == this.suiteName).reduce((pre, cur) => pre || cur, false);
32        let itFilterResult = classArray.filter(item => item.includes('#')).map(item => item == (this.suiteName + '#' + this.itName)).reduce((pre, cur) => pre || cur, false);
33        return !(suiteFilterResult || itFilterResult);
34    }
35}
36
37class NotClassFilter {
38    constructor(suiteName, itName, params) {
39        this.suiteName = suiteName;
40        this.itName = itName;
41        this.params = params;
42    }
43
44    filterSuite() {
45        return this.params.split(',').map(item => item == this.suiteName).reduce((pre, cur) => pre || cur, false);
46    }
47
48    filterIt() {
49        return this.params.split(',').some(item => item == (this.suiteName + '#' + this.itName));
50    }
51}
52
53class SuiteAndItNameFilter {
54    constructor(suiteName, itName, params) {
55        this.suiteName = suiteName;
56        this.itName = itName;
57        this.params = params;
58    }
59
60    filterSuite() {
61        return !this.params.split(',').map(item => item == this.suiteName).reduce((pre, cur) => pre || cur, false);
62    }
63
64    filterIt() {
65        return !this.params.split(',').map(item => item == this.itName).reduce((pre, cur) => pre || cur, false);
66    }
67}
68
69
70class TestTypesFilter {
71    constructor(suiteName, itName, fi, params) {
72        this.suiteName = suiteName;
73        this.itName = itName;
74        this.params = params;
75        this.fi = fi;
76    }
77
78    filterIt() {
79        return !((this.params === (this.fi & this.params)) || this.fi === 0);
80    }
81}
82
83class NestFilter {
84    filterNestName(targetSuiteArray, targetSpecArray, suiteStack, desc) {
85        let targetSuiteName = '';
86        for (let key in suiteStack) {
87            targetSuiteName = targetSuiteName + '.' + suiteStack[key].description;
88        }
89        targetSuiteName = targetSuiteName.substring(2);
90        const targetSpecName = targetSuiteName + '#' + desc;
91        let isFilter = true;
92        if (targetSpecArray.includes(targetSpecName)) {
93            return false;
94        }
95        for (let index in targetSuiteArray) {
96            if (targetSuiteName.startsWith(targetSuiteArray[index])) {
97                return false;
98            }
99        }
100        return isFilter;
101    }
102
103    filterNotClass(notClass, suiteStack, desc) {
104        let filterNotClass = false;
105        if (notClass != null) {
106            let notClassArray = notClass.split(',');
107            let targetSuiteName = '';
108            for (let key in suiteStack) {
109                targetSuiteName = targetSuiteName + '.' + suiteStack[key].description;
110            }
111            targetSuiteName = targetSuiteName.substring(2);
112            const targetSpecName = targetSuiteName + '#' + desc;
113            if (notClassArray.includes(targetSpecName) || notClassArray.some(key => targetSpecName.startsWith(key))) {
114                filterNotClass = true;
115            }
116        }
117        return filterNotClass;
118    }
119
120    filterLevelOrSizeOrTestType(level, size, testType, filter) {
121        let result = false;
122        if (filter === 0 || filter === '0') {
123            return result;
124        }
125        if (level == null && size == null && testType == null) {
126            return result;
127        }
128        if (level != null) {
129            let levelFilter = LEVEL[`${level}`];
130            result = result || filter === levelFilter;
131        }
132        if (size != null) {
133            let sizeFilter = SIZE[`${size}`];
134            result = result || filter === sizeFilter;
135        }
136        if (testType != null) {
137            let testTypeFilter = TESTTYPE[`${testType}`];
138            result = result || filter === testTypeFilter;
139        }
140        return !result;
141    }
142}
143export { ClassFilter, NotClassFilter, SuiteAndItNameFilter, TestTypesFilter, NestFilter };
144