Files
FreeCADWasmDev/tools/test_scheduler_source_search.py

33 lines
1.5 KiB
Python

import unittest
from pathlib import Path
from scheduler_source_search import translate
from fast_source_search import filter_globs
class ScopedSearchTests(unittest.TestCase):
def test_enumerated_paths_respect_requested_source_types_and_exclusions(self):
paths = {Path("src/native.cpp"), Path("src/native.h"), Path("src/script.py"), Path("src/generated.h")}
self.assertEqual(filter_globs(paths, ["*.cpp", "*.h", "!generated.h"]),
{Path("src/native.cpp"), Path("src/native.h")})
def test_directory_with_globs_and_multiple_paths(self):
command = translate(["-n", "IfcGlobalId|IfcPropertySets", "native.cpp", "dependency/src", "-g*.cpp", "-g*.h"])
self.assertEqual(command, ["fast_source_search.py", "--pattern", "IfcGlobalId|IfcPropertySets", "--context", "0",
"--max-count", "160", "--path", "native.cpp", "--path", "dependency/src",
"--glob", "*.cpp", "--glob", "*.h"])
def test_ignore_case_and_bounds_are_preserved(self):
command = translate(["-ni", "-m", "9000", "Wall", "module"])
self.assertIn("(?i)Wall", command)
self.assertEqual(command[command.index("--max-count") + 1], "240")
def test_fixed_pattern_remains_literal(self):
command = translate(["-F", "Part::Box", "module"])
self.assertIn("--fixed-strings", command)
self.assertIn("Part::Box", command)
if __name__ == "__main__":
unittest.main()