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