Add tests for encoding short lists of strings
- ID
8bcdaa9- date
2025-01-15 06:47:09+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
679ae0f- message
Add tests for encoding short lists of strings- changed files
1 file, 27 additions
Changed files
tests/test_encoder.py (1698) → tests/test_encoder.py (2541)
diff --git a/tests/test_encoder.py b/tests/test_encoder.py
index de2951b..16163ca 100644
--- a/tests/test_encoder.py
+++ b/tests/test_encoder.py
@@ -2,6 +2,8 @@
Tests for ``javascript_data_files.encoder``.
"""
+import string
+
from javascript_data_files.encoder import encode_as_json
@@ -44,3 +46,28 @@ def test_a_list_of_long_ints_is_indented_and_split() -> None:
"\n 90,\n 91,\n 92,\n 93,\n 94,\n 95,\n 96,\n 97,\n 98,\n 99"
"\n]"
)
+
+
+def test_a_list_of_strings_is_not_split_over_multiple_lines() -> None:
+ """
+ If there's a list of small strings, they're printed on one line
+ rather than across multiple lines.
+ """
+ assert encode_as_json(["a", "b", "c"]) == '["a", "b", "c"]'
+
+
+def test_a_list_of_long_strings_is_indented_and_split() -> None:
+ """
+ If there's a list with more strings than a sensible line length,
+ they're split across multiple lines.
+ """
+ json_string = encode_as_json(list(string.ascii_lowercase))
+
+ assert json_string == (
+ "["
+ '\n "a",\n "b",\n "c",\n "d",\n "e",\n "f",\n "g",\n "h",'
+ '\n "i",\n "j",\n "k",\n "l",\n "m",\n "n",\n "o",\n "p",'
+ '\n "q",\n "r",\n "s",\n "t",\n "u",\n "v",\n "w",\n "x",'
+ '\n "y",\n "z"'
+ "\n]"
+ )