Make it easier to write test cases for read_js
- ID
35491bb- date
2024-08-17 20:01:49+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
64e2d6c- message
Make it easier to write test cases for `read_js`- changed files
1 file, 10 additions, 10 deletions
Changed files
tests/test_javascript.py (4431) → tests/test_javascript.py (4363)
diff --git a/tests/test_javascript.py b/tests/test_javascript.py
index e6639a0..a07d420 100644
--- a/tests/test_javascript.py
+++ b/tests/test_javascript.py
@@ -7,11 +7,17 @@ from javascript import append_to_js_array, read_js, write_js
class TestReadJs:
- def test_can_read_file(self, tmp_path: pathlib.Path) -> None:
+ @pytest.mark.parametrize(
+ "text",
+ [
+ 'const redPentagon = {\n "sides": 5,\n "colour": "red"\n};\n',
+ 'const redPentagon = {\n "sides": 5,\n "colour": "red"\n};',
+ 'const redPentagon = {\n "sides": 5,\n "colour": "red"\n}',
+ ],
+ )
+ def test_can_read_file(self, tmp_path: pathlib.Path, text: str) -> None:
js_path = tmp_path / "shape.js"
- js_path.write_text(
- 'const redPentagon = {\n "sides": 5,\n "colour": "red"\n};\n'
- )
+ js_path.write_text(text)
assert read_js(js_path, varname="redPentagon") == {"sides": 5, "colour": "red"}
@@ -37,12 +43,6 @@ class TestReadJs:
):
read_js(js_path, varname="blueTriangle")
- def test_allows_trailing_semicolon(self, tmp_path: pathlib.Path) -> None:
- js_path = tmp_path / "shape.js"
- js_path.write_text('const redPentagon = {\n "sides": 5,\n "colour": "red"\n}')
-
- assert read_js(js_path, varname="redPentagon") == {"sides": 5, "colour": "red"}
-
class TestWriteJs:
def test_can_write_file(self, tmp_path: pathlib.Path) -> None: