Answer stability round 1: 1 🔴, 1 🟡 (0 misread); a fix that drops a test file's declaration gets the planted file, and any file may stand beside or under its declarer
This commit is contained in:
@@ -7,7 +7,7 @@ import unittest
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from task_bench import rust_test_modules
|
||||
from task_bench.rust_test_modules import tells_apart
|
||||
from task_bench.rust_test_modules import homes, tells_apart
|
||||
|
||||
LIB = textwrap.dedent("""\
|
||||
pub fn add(a: i32, b: i32) -> i32 {
|
||||
@@ -118,15 +118,20 @@ class DeclaredTest(unittest.TestCase):
|
||||
source = '// #[cfg(test)]\n// mod a;\n/* #[cfg(test)] mod b; */\nconst C: &str = "#[cfg(test)] mod c;";\nconst D: &str = r#"#[cfg(test)] mod d;"#;\n'
|
||||
self.assertEqual(declared(source), [])
|
||||
|
||||
def test_cannot_tell_where_a_declaration_moves_its_file_with_a_path_attribute(self):
|
||||
self.assertIsNone(declared('#[cfg(test)]\n#[path = "elsewhere.rs"]\nmod tests;\n'))
|
||||
|
||||
def test_cannot_tell_where_a_string_or_comment_is_never_closed(self):
|
||||
for source in ("#[cfg(test)]\nmod tests;\nconst A: &str = \"\n", "/* open\n#[cfg(test)]\nmod tests;\n"):
|
||||
with self.subTest(source=source):
|
||||
self.assertIsNone(declared(source))
|
||||
|
||||
|
||||
class HomesTest(unittest.TestCase):
|
||||
def test_lists_where_the_file_of_a_declared_module_may_stand(self):
|
||||
self.assertEqual(homes("src/pick.rs", "tests"), ["src/tests.rs", "src/tests/mod.rs", "src/pick/tests.rs", "src/pick/tests/mod.rs"])
|
||||
|
||||
def test_lists_the_places_by_the_path_from_the_top_of_a_file_there(self):
|
||||
self.assertEqual(homes("lib.rs", "t"), ["t.rs", "t/mod.rs", "lib/t.rs", "lib/t/mod.rs"])
|
||||
|
||||
|
||||
class TellsApartTest(unittest.TestCase):
|
||||
def test_tells_the_modules_of_a_rust_file_apart_where_they_can_be(self):
|
||||
self.assertEqual([tells_apart("lib.rs", b"fn a() {}"), tells_apart("lib.rs", b"fn a() {")], [True, False])
|
||||
@@ -136,6 +141,16 @@ class TellsApartTest(unittest.TestCase):
|
||||
|
||||
|
||||
class WithTestsOfTest(unittest.TestCase):
|
||||
def test_takes_the_planted_file_where_the_fix_dropped_a_declaration_of_a_test_file(self):
|
||||
planted = "fn a() { 1 }\n#[cfg(test)]\nmod tests;\n#[cfg(test)]\nmod more;\n"
|
||||
for name, fixed in {"dropped": "fn a() { 2 }\n", "one of two kept": "fn a() { 2 }\n#[cfg(test)]\nmod more;\n", "string never closed": 'fn a() { "\n#[cfg(test)]\nmod tests;\n#[cfg(test)]\nmod more;\n'}.items():
|
||||
with self.subTest(name):
|
||||
self.assertEqual(with_tests_of(planted, fixed), planted)
|
||||
|
||||
def test_takes_the_fixed_file_where_it_keeps_each_declaration_and_adds_one(self):
|
||||
fixed = "fn a() { 2 }\n#[cfg(test)]\nmod more;\n#[cfg(test)]\nmod tests;\n"
|
||||
self.assertEqual(with_tests_of("fn a() { 1 }\n#[cfg(test)]\nmod tests;\n", fixed), fixed)
|
||||
|
||||
def test_takes_the_code_as_fixed_and_the_tests_as_planted(self):
|
||||
planted = LIB.replace("a + b", "a - b")
|
||||
fixed = LIB.replace("assert_eq!(add(1, 2), 3);", "assert_eq!(add(1, 2), 0);")
|
||||
|
||||
Reference in New Issue
Block a user