1e5c31af7Sopenharmony_ci#!/usr/bin/env python
2e5c31af7Sopenharmony_ci
3e5c31af7Sopenharmony_ci# Copyright 2020 The Amber Authors. All rights reserved.
4e5c31af7Sopenharmony_ci#
5e5c31af7Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
6e5c31af7Sopenharmony_ci# you may not use this file except in compliance with the License.
7e5c31af7Sopenharmony_ci# You may obtain a copy of the License at
8e5c31af7Sopenharmony_ci#
9e5c31af7Sopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
10e5c31af7Sopenharmony_ci#
11e5c31af7Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
12e5c31af7Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
13e5c31af7Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14e5c31af7Sopenharmony_ci# See the License for the specific language governing permissions and
15e5c31af7Sopenharmony_ci# limitations under the License.
16e5c31af7Sopenharmony_ci
17e5c31af7Sopenharmony_ci"""Unit tests for check_language.py."""
18e5c31af7Sopenharmony_ci
19e5c31af7Sopenharmony_ciimport os
20e5c31af7Sopenharmony_ciimport sys
21e5c31af7Sopenharmony_ciimport unittest
22e5c31af7Sopenharmony_ci
23e5c31af7Sopenharmony_cisys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
24e5c31af7Sopenharmony_ci
25e5c31af7Sopenharmony_ciimport check_language
26e5c31af7Sopenharmony_ci
27e5c31af7Sopenharmony_ciclass TestCheckLanguage(unittest.TestCase):
28e5c31af7Sopenharmony_ci	def testMatches(self):
29e5c31af7Sopenharmony_ci		tests = ["blacklist", "black-list", "black_list", "whitelist",
30e5c31af7Sopenharmony_ci			"white-list", "white_list", "greylist", "grey-list", "grey_list",
31e5c31af7Sopenharmony_ci			"graylist", "gray-list", "gray_list", "first class citizen",
32e5c31af7Sopenharmony_ci			"blackhat", "black-hat", "black_hat", "whitehat", "white-hat",
33e5c31af7Sopenharmony_ci			"white_hat", "greyhat", "grey-hat", "grey_hat", "grayhat",
34e5c31af7Sopenharmony_ci			"gray-hat", "gray_hat", "master", "slave", "him", "his", "she",
35e5c31af7Sopenharmony_ci			"her", "hers", "man", "woman", "he", "he'd", "he's", "he'll",
36e5c31af7Sopenharmony_ci			"he\u2019d", "he\u2019s", "he\u2019ll",
37e5c31af7Sopenharmony_ci			"grandfather", "mitm", "crazy", "insane", "blind to",
38e5c31af7Sopenharmony_ci			"flying blind", "blind eye", "cripple", "crippled", "dumb",
39e5c31af7Sopenharmony_ci			"dummy", "paranoid", "sane", "sanity", "redline", "red-line",
40e5c31af7Sopenharmony_ci			"red_line"]
41e5c31af7Sopenharmony_ci
42e5c31af7Sopenharmony_ci		for word in tests:
43e5c31af7Sopenharmony_ci			self.assertTrue(
44e5c31af7Sopenharmony_ci				check_language.check_match("", "this is a " + word + " attempt"), word)
45e5c31af7Sopenharmony_ci
46e5c31af7Sopenharmony_ci
47e5c31af7Sopenharmony_ci	def testSuppression(self):
48e5c31af7Sopenharmony_ci		self.assertFalse(check_language.check_match("", "in the man-pages"))
49e5c31af7Sopenharmony_ci		self.assertFalse(check_language.check_match("", "the MS_SLAVE test"))
50e5c31af7Sopenharmony_ci
51e5c31af7Sopenharmony_ci
52e5c31af7Sopenharmony_ci	def testMatchStartofFileWhenRequireSpace(self):
53e5c31af7Sopenharmony_ci		self.assertTrue(check_language.check_match("", "he said"))
54e5c31af7Sopenharmony_ci
55e5c31af7Sopenharmony_ci
56e5c31af7Sopenharmony_ci	def testMatchOverNewline(self):
57e5c31af7Sopenharmony_ci		self.assertTrue(check_language.check_match("", "flying\nblind"))
58e5c31af7Sopenharmony_ci
59e5c31af7Sopenharmony_ci
60e5c31af7Sopenharmony_ciif __name__ == '__main__':
61e5c31af7Sopenharmony_ci	unittest.main()
62