Skip to content

Commit fde5bb6

Browse files
Test_m2json: add test cases for string control character escaping
1 parent 345b653 commit fde5bb6

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

‎plotly/plotly_aux/Test_m2json.m‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,5 +164,47 @@ function testNestedCell1RowAs2dArray(tc)
164164
expected = "[[1, 2, 3]]";
165165
tc.verifyEqual(m2json(value), expected);
166166
end
167+
168+
function testStringWithNewline(tc)
169+
value = sprintf('Hello\nWorld');
170+
expected = '"Hello\nWorld"';
171+
tc.verifyEqual(m2json(value), expected);
172+
end
173+
174+
function testStringWithTab(tc)
175+
value = sprintf('Hello\tWorld');
176+
expected = '"Hello\tWorld"';
177+
tc.verifyEqual(m2json(value), expected);
178+
end
179+
180+
function testStringWithCarriageReturn(tc)
181+
value = sprintf('Hello\rWorld');
182+
expected = '"Hello\rWorld"';
183+
tc.verifyEqual(m2json(value), expected);
184+
end
185+
186+
function testStringWithBackspace(tc)
187+
value = sprintf('Hello\bWorld');
188+
expected = '"Hello\bWorld"';
189+
tc.verifyEqual(m2json(value), expected);
190+
end
191+
192+
function testStringWithFormFeed(tc)
193+
value = sprintf('Hello\fWorld');
194+
expected = '"Hello\fWorld"';
195+
tc.verifyEqual(m2json(value), expected);
196+
end
197+
198+
function testStringWithControlCharacters(tc)
199+
value = ['hello', char(1), 'world'];
200+
expected = '"hello\u0001world"';
201+
tc.verifyEqual(m2json(value), expected);
202+
end
203+
204+
function testCellWithControlCharacters(tc)
205+
value = {sprintf('Line 1\nLine 2'), sprintf('Col 1\tCol 2')};
206+
expected = '["Line 1\nLine 2", "Col 1\tCol 2"]';
207+
tc.verifyEqual(m2json(value), expected);
208+
end
167209
end
168210
end

0 commit comments

Comments
 (0)