@@ -73,8 +73,15 @@ def test_minify():
7373 assert test_output == ref_output
7474
7575
76+ def test_depth ():
77+ json_input = Path ("tests/data/test-bool.json" ).read_text ()
78+ formatter = Formatter ()
79+ test_output = formatter .reformat (json_input , 2 )
80+ assert test_output == ' { "bools": {"true": true, "false": false} }\n '
81+
82+
7683def test_exceptions ():
77- with pytest .raises (KeyError , match = "Unknown option 'non_existent_option'" ):
84+ with pytest .raises (AttributeError , match = "Unknown option 'non_existent_option'" ):
7885 _ = FracturedJsonOptions (non_existent_option = True )
7986
8087 with pytest .raises (
@@ -110,6 +117,19 @@ def test_exceptions():
110117 with pytest .raises (TypeError , match = "Must be callable" ):
111118 formatter .string_length_func = 123 # type: ignore[assignment]
112119
120+ options = FracturedJsonOptions ()
121+ with pytest .raises (
122+ AttributeError ,
123+ match = "FracturedJsonOptions has no attribute 'invalid'" ,
124+ ):
125+ _ = options .invalid
126+
127+ with pytest .raises (
128+ AttributeError ,
129+ match = "FracturedJsonOptions has no attribute 'invalid'" ,
130+ ):
131+ options .invalid = 0
132+
113133
114134def test_dll_missing (path_is_file_fails ): # noqa: ARG001
115135 if "fractured_json" in sys .modules :
@@ -142,3 +162,26 @@ def double_len(s: str) -> int:
142162 getter = formatter .string_length_func
143163 assert callable (getter )
144164 assert getter ("abc" ) == 6
165+
166+
167+ def test_formatter_options ():
168+ opts = FracturedJsonOptions (
169+ max_total_line_length = 80 ,
170+ indent_spaces = 3 ,
171+ comment_policy = "REMOVE" ,
172+ table_comma_placement = "BEFORE_PADDING_EXCEPT_NUMBERS" ,
173+ number_list_alignment = "LEFT" ,
174+ prefix_string = "::" ,
175+ use_tab_to_indent = False ,
176+ )
177+
178+ formatter = Formatter ()
179+ formatter .options = opts
180+
181+ got = formatter .options
182+ assert got .max_total_line_length == 80
183+ assert got .indent_spaces == 3
184+ assert got .comment_policy .name == "REMOVE"
185+
186+ got .max_total_line_length = 100
187+ assert got .max_total_line_length == 100
0 commit comments