Skip to content

Commit 9b72eaf

Browse files
refactor(matlab): rename ctoon.* functions to package‑scoped names
- Updated MATLAB bindings in `+ctoon` folder: removed the `ctoon.` prefix from `decode`, `encode`, and `read` function definitions. - Adjusted corresponding test file name (`test_ctoon_mex.m` → `test_ctoon.m`) and updated all test calls to use the new function names. - Ensures functions follow MATLAB package conventions, providing a cleaner API without redundant naming.
1 parent fe03854 commit 9b72eaf

4 files changed

Lines changed: 34 additions & 34 deletions

File tree

src/bindings/matlab/+ctoon/decode.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function value = ctoon.decode(str)
1+
function value = decode(str)
22
%DECODE Decode a TOON-format string into a MATLAB value.
33
%
44
% VALUE = DECODE(STR)

src/bindings/matlab/+ctoon/encode.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function str = ctoon.encode(value)
1+
function str = encode(value)
22
%ENCODE Encode a MATLAB value to a TOON-format string.
33
%
44
% STR = ENCODE(VALUE)

src/bindings/matlab/+ctoon/read.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function value = ctoon.read(filepath)
1+
function value = read(filepath)
22
%READ Read and decode a TOON file into a MATLAB value.
33
%
44
% VALUE = READ(FILEPATH)
Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
%% Main function
2-
function tests = test_ctoon_mex
2+
function tests = test_ctoon
33
tests = functiontests(localfunctions);
44
end
55

@@ -14,56 +14,56 @@ function teardownOnce(~)
1414
end
1515

1616
%% -------------------------------------------------------------------------
17-
% ctoon_decode — scalar primitives
17+
% ctoon.decode — scalar primitives
1818
%% -------------------------------------------------------------------------
1919

2020
function testDecodeNull(testCase)
21-
v = ctoon_decode('null');
21+
v = ctoon.decode('null');
2222
verifyEmpty(testCase, v);
2323
verifyClass(testCase, v, 'double');
2424
end
2525

2626
function testDecodeTrue(testCase)
27-
v = ctoon_decode('true');
27+
v = ctoon.decode('true');
2828
verifyClass(testCase, v, 'logical');
2929
verifyTrue(testCase, v);
3030
end
3131

3232
function testDecodeFalse(testCase)
33-
v = ctoon_decode('false');
33+
v = ctoon.decode('false');
3434
verifyClass(testCase, v, 'logical');
3535
verifyFalse(testCase, v);
3636
end
3737

3838
function testDecodeUint(testCase)
39-
v = ctoon_decode('42');
39+
v = ctoon.decode('42');
4040
verifyEqual(testCase, double(v), 42);
4141
end
4242

4343
function testDecodeSint(testCase)
44-
v = ctoon_decode('-7');
44+
v = ctoon.decode('-7');
4545
verifyEqual(testCase, double(v), -7);
4646
end
4747

4848
function testDecodeReal(testCase)
49-
v = ctoon_decode('3.14');
49+
v = ctoon.decode('3.14');
5050
verifyClass(testCase, v, 'double');
5151
verifyEqual(testCase, v, 3.14, 'AbsTol', 1e-10);
5252
end
5353

5454
function testDecodeString(testCase)
5555
% Bare string (no quotes needed in TOON)
56-
v = ctoon_decode('hello');
56+
v = ctoon.decode('hello');
5757
verifyEqual(testCase, v, 'hello');
5858
end
5959

6060
%% -------------------------------------------------------------------------
61-
% ctoon_decode — composite types
61+
% ctoon.decode — composite types
6262
%% -------------------------------------------------------------------------
6363

6464
function testDecodeArray(testCase)
6565
% TOON array syntax: [n]: v1,v2,...
66-
v = ctoon_decode('[3]: 1,2,3');
66+
v = ctoon.decode('[3]: 1,2,3');
6767
verifyClass(testCase, v, 'cell');
6868
verifyEqual(testCase, numel(v), 3);
6969
verifyEqual(testCase, double(v{1}), 1);
@@ -74,7 +74,7 @@ function testDecodeArray(testCase)
7474
function testDecodeObject(testCase)
7575
% TOON object syntax: key: value (newline separated)
7676
toon = sprintf('name: Alice\nage: 30\nactive: true');
77-
v = ctoon_decode(toon);
77+
v = ctoon.decode(toon);
7878
verifyClass(testCase, v, 'struct');
7979
verifyEqual(testCase, v.name, 'Alice');
8080
verifyEqual(testCase, double(v.age), 30);
@@ -85,7 +85,7 @@ function testDecodeObject(testCase)
8585
function testDecodeNestedObject(testCase)
8686
% Nested object via indentation
8787
toon = sprintf('person:\n name: Bob\n age: 25');
88-
v = ctoon_decode(toon);
88+
v = ctoon.decode(toon);
8989
verifyClass(testCase, v, 'struct');
9090
verifyClass(testCase, v.person, 'struct');
9191
verifyEqual(testCase, v.person.name, 'Bob');
@@ -94,7 +94,7 @@ function testDecodeNestedObject(testCase)
9494

9595
function testDecodeObjectWithArray(testCase)
9696
toon = sprintf('name: Alice\nage: 30\nactive: true\ntags[3]: programming,c++,serialization');
97-
v = ctoon_decode(toon);
97+
v = ctoon.decode(toon);
9898
verifyEqual(testCase, v.name, 'Alice');
9999
verifyEqual(testCase, double(v.age), 30);
100100
verifyTrue(testCase, v.active);
@@ -103,50 +103,50 @@ function testDecodeObjectWithArray(testCase)
103103
end
104104

105105
%% -------------------------------------------------------------------------
106-
% ctoon_encode / ctoon_decode round-trip
106+
% ctoon.encode / ctoon.decode round-trip
107107
%% -------------------------------------------------------------------------
108108

109109
function testRoundTripReal(testCase)
110110
% Use non-integer double to avoid uint64 promotion
111111
original = 3.14159;
112-
v = ctoon_decode(ctoon_encode(original));
112+
v = ctoon.decode(ctoon.encode(original));
113113
verifyClass(testCase, v, 'double');
114114
verifyEqual(testCase, v, original, 'AbsTol', 1e-10);
115115
end
116116

117117
function testRoundTripString(testCase)
118118
original = 'world';
119-
v = ctoon_decode(ctoon_encode(original));
119+
v = ctoon.decode(ctoon.encode(original));
120120
verifyEqual(testCase, v, original);
121121
end
122122

123123
function testRoundTripLogicalTrue(testCase)
124-
v = ctoon_decode(ctoon_encode(true));
124+
v = ctoon.decode(ctoon.encode(true));
125125
verifyClass(testCase, v, 'logical');
126126
verifyTrue(testCase, v);
127127
end
128128

129129
function testRoundTripLogicalFalse(testCase)
130-
v = ctoon_decode(ctoon_encode(false));
130+
v = ctoon.decode(ctoon.encode(false));
131131
verifyClass(testCase, v, 'logical');
132132
verifyFalse(testCase, v);
133133
end
134134

135135
function testRoundTripInt64(testCase)
136136
original = int64(-999);
137-
v = ctoon_decode(ctoon_encode(original));
137+
v = ctoon.decode(ctoon.encode(original));
138138
verifyEqual(testCase, double(v), double(original));
139139
end
140140

141141
function testRoundTripUint64(testCase)
142142
original = uint64(2^40);
143-
v = ctoon_decode(ctoon_encode(original));
143+
v = ctoon.decode(ctoon.encode(original));
144144
verifyEqual(testCase, double(v), double(original));
145145
end
146146

147147
function testRoundTripCell(testCase)
148148
original = {1.5, 'abc', false};
149-
v = ctoon_decode(ctoon_encode(original));
149+
v = ctoon.decode(ctoon.encode(original));
150150
verifyClass(testCase, v, 'cell');
151151
verifyEqual(testCase, numel(v), numel(original));
152152
end
@@ -156,7 +156,7 @@ function testRoundTripStruct(testCase)
156156
original.x = 1.5;
157157
original.label = 'point';
158158
original.flag = false;
159-
v = ctoon_decode(ctoon_encode(original));
159+
v = ctoon.decode(ctoon.encode(original));
160160
verifyClass(testCase, v, 'struct');
161161
verifyEqual(testCase, v.x, original.x, 'AbsTol', 1e-10);
162162
verifyEqual(testCase, v.label, original.label);
@@ -165,13 +165,13 @@ function testRoundTripStruct(testCase)
165165
end
166166

167167
%% -------------------------------------------------------------------------
168-
% ctoon_read / ctoon_write — file I/O
168+
% ctoon.read / ctoon.write — file I/O
169169
%% -------------------------------------------------------------------------
170170

171171
function testReadSample1(testCase)
172172
sample = fullfile(testCase.TestData.DataDir, 'sample1_user.toon');
173173
assumeTrue(testCase, isfile(sample), 'Test data file not found — skipping.');
174-
v = ctoon_read(sample);
174+
v = ctoon.read(sample);
175175
verifyClass(testCase, v, 'struct');
176176
verifyEqual(testCase, v.name, 'Alice');
177177
verifyEqual(testCase, double(v.age), 30);
@@ -187,9 +187,9 @@ function testWriteReadRoundTrip(testCase)
187187
original.pi = 3.14159;
188188
original.label = 'round-trip';
189189
original.ok = true;
190-
ctoon_write(original, tmp);
190+
ctoon.write(original, tmp);
191191
verifyTrue(testCase, isfile(tmp));
192-
v = ctoon_read(tmp);
192+
v = ctoon.read(tmp);
193193
verifyClass(testCase, v, 'struct');
194194
verifyEqual(testCase, v.pi, original.pi, 'AbsTol', 1e-10);
195195
verifyEqual(testCase, v.label, original.label);
@@ -203,19 +203,19 @@ function testWriteReadRoundTrip(testCase)
203203

204204
function testDecodeInvalidToon(testCase)
205205
% Empty string produces CTOON_READ_ERROR_EMPTY_CONTENT
206-
verifyError(testCase, @() ctoon_decode(''), 'ctoon:decodeError');
206+
verifyError(testCase, @() ctoon.decode(''), 'ctoon:decodeError');
207207
end
208208

209209
function testReadMissingFile(testCase)
210-
verifyError(testCase, @() ctoon_read('/no/such/file.toon'), 'ctoon:readError');
210+
verifyError(testCase, @() ctoon.read('/no/such/file.toon'), 'ctoon:readError');
211211
end
212212

213213
function testDecodeNonString(testCase)
214-
verifyError(testCase, @() ctoon_decode(42), 'ctoon:badArg');
214+
verifyError(testCase, @() ctoon.decode(42), 'ctoon:badArg');
215215
end
216216

217217
function testWriteInvalidPath(testCase)
218-
verifyError(testCase, @() ctoon_write(struct('x', 1.5), '/no/such/dir/out.toon'), ...
218+
verifyError(testCase, @() ctoon.write(struct('x', 1.5), '/no/such/dir/out.toon'), ...
219219
'ctoon:writeError');
220220
end
221221

0 commit comments

Comments
 (0)