11%% Main function
2- function tests = test_ctoon_mex
2+ function tests = test_ctoon
33tests = functiontests(localfunctions );
44end
55
@@ -14,56 +14,56 @@ function teardownOnce(~)
1414end
1515
1616%% -------------------------------------------------------------------------
17- % ctoon_decode — scalar primitives
17+ % ctoon.decode — scalar primitives
1818%% -------------------------------------------------------------------------
1919
2020function testDecodeNull(testCase )
21- v = ctoon_decode (' null' );
21+ v = ctoon .decode (' null' );
2222verifyEmpty(testCase , v );
2323verifyClass(testCase , v , ' double' );
2424end
2525
2626function testDecodeTrue(testCase )
27- v = ctoon_decode (' true' );
27+ v = ctoon .decode (' true' );
2828verifyClass(testCase , v , ' logical' );
2929verifyTrue(testCase , v );
3030end
3131
3232function testDecodeFalse(testCase )
33- v = ctoon_decode (' false' );
33+ v = ctoon .decode (' false' );
3434verifyClass(testCase , v , ' logical' );
3535verifyFalse(testCase , v );
3636end
3737
3838function testDecodeUint(testCase )
39- v = ctoon_decode (' 42' );
39+ v = ctoon .decode (' 42' );
4040verifyEqual(testCase , double(v ), 42 );
4141end
4242
4343function testDecodeSint(testCase )
44- v = ctoon_decode (' -7' );
44+ v = ctoon .decode (' -7' );
4545verifyEqual(testCase , double(v ), - 7 );
4646end
4747
4848function testDecodeReal(testCase )
49- v = ctoon_decode (' 3.14' );
49+ v = ctoon .decode (' 3.14' );
5050verifyClass(testCase , v , ' double' );
5151verifyEqual(testCase , v , 3.14 , ' AbsTol' , 1e- 10 );
5252end
5353
5454function testDecodeString(testCase )
5555% Bare string (no quotes needed in TOON)
56- v = ctoon_decode (' hello' );
56+ v = ctoon .decode (' hello' );
5757verifyEqual(testCase , v , ' hello' );
5858end
5959
6060%% -------------------------------------------------------------------------
61- % ctoon_decode — composite types
61+ % ctoon.decode — composite types
6262%% -------------------------------------------------------------------------
6363
6464function 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' );
6767verifyClass(testCase , v , ' cell' );
6868verifyEqual(testCase , numel(v ), 3 );
6969verifyEqual(testCase , double(v{1 }), 1 );
@@ -74,7 +74,7 @@ function testDecodeArray(testCase)
7474function testDecodeObject(testCase )
7575% TOON object syntax: key: value (newline separated)
7676toon = sprintf(' name: Alice\n age: 30\n active: true' );
77- v = ctoon_decode (toon );
77+ v = ctoon .decode (toon );
7878verifyClass(testCase , v , ' struct' );
7979verifyEqual(testCase , v .name, ' Alice' );
8080verifyEqual(testCase , double(v .age), 30 );
@@ -85,7 +85,7 @@ function testDecodeObject(testCase)
8585function testDecodeNestedObject(testCase )
8686% Nested object via indentation
8787toon = sprintf(' person:\n name: Bob\n age: 25' );
88- v = ctoon_decode (toon );
88+ v = ctoon .decode (toon );
8989verifyClass(testCase , v , ' struct' );
9090verifyClass(testCase , v .person, ' struct' );
9191verifyEqual(testCase , v .person.name, ' Bob' );
@@ -94,7 +94,7 @@ function testDecodeNestedObject(testCase)
9494
9595function testDecodeObjectWithArray(testCase )
9696toon = sprintf(' name: Alice\n age: 30\n active: true\n tags[3]: programming,c++,serialization' );
97- v = ctoon_decode (toon );
97+ v = ctoon .decode (toon );
9898verifyEqual(testCase , v .name, ' Alice' );
9999verifyEqual(testCase , double(v .age), 30 );
100100verifyTrue(testCase , v .active);
@@ -103,50 +103,50 @@ function testDecodeObjectWithArray(testCase)
103103end
104104
105105%% -------------------------------------------------------------------------
106- % ctoon_encode / ctoon_decode round-trip
106+ % ctoon.encode / ctoon.decode round-trip
107107%% -------------------------------------------------------------------------
108108
109109function testRoundTripReal(testCase )
110110% Use non-integer double to avoid uint64 promotion
111111original = 3.14159 ;
112- v = ctoon_decode(ctoon_encode (original ));
112+ v = ctoon .decode( ctoon .encode (original ));
113113verifyClass(testCase , v , ' double' );
114114verifyEqual(testCase , v , original , ' AbsTol' , 1e- 10 );
115115end
116116
117117function testRoundTripString(testCase )
118118original = ' world' ;
119- v = ctoon_decode(ctoon_encode (original ));
119+ v = ctoon .decode( ctoon .encode (original ));
120120verifyEqual(testCase , v , original );
121121end
122122
123123function testRoundTripLogicalTrue(testCase )
124- v = ctoon_decode(ctoon_encode (true ));
124+ v = ctoon .decode( ctoon .encode (true ));
125125verifyClass(testCase , v , ' logical' );
126126verifyTrue(testCase , v );
127127end
128128
129129function testRoundTripLogicalFalse(testCase )
130- v = ctoon_decode(ctoon_encode (false ));
130+ v = ctoon .decode( ctoon .encode (false ));
131131verifyClass(testCase , v , ' logical' );
132132verifyFalse(testCase , v );
133133end
134134
135135function testRoundTripInt64(testCase )
136136original = int64(-999 );
137- v = ctoon_decode(ctoon_encode (original ));
137+ v = ctoon .decode( ctoon .encode (original ));
138138verifyEqual(testCase , double(v ), double(original ));
139139end
140140
141141function testRoundTripUint64(testCase )
142142original = uint64(2 ^ 40 );
143- v = ctoon_decode(ctoon_encode (original ));
143+ v = ctoon .decode( ctoon .encode (original ));
144144verifyEqual(testCase , double(v ), double(original ));
145145end
146146
147147function testRoundTripCell(testCase )
148148original = {1.5 , ' abc' , false };
149- v = ctoon_decode(ctoon_encode (original ));
149+ v = ctoon .decode( ctoon .encode (original ));
150150verifyClass(testCase , v , ' cell' );
151151verifyEqual(testCase , numel(v ), numel(original ));
152152end
@@ -156,7 +156,7 @@ function testRoundTripStruct(testCase)
156156original.x = 1.5 ;
157157original.label = ' point' ;
158158original.flag = false ;
159- v = ctoon_decode(ctoon_encode (original ));
159+ v = ctoon .decode( ctoon .encode (original ));
160160verifyClass(testCase , v , ' struct' );
161161verifyEqual(testCase , v .x, original .x, ' AbsTol' , 1e- 10 );
162162verifyEqual(testCase , v .label, original .label);
@@ -165,13 +165,13 @@ function testRoundTripStruct(testCase)
165165end
166166
167167%% -------------------------------------------------------------------------
168- % ctoon_read / ctoon_write — file I/O
168+ % ctoon.read / ctoon.write — file I/O
169169%% -------------------------------------------------------------------------
170170
171171function testReadSample1(testCase )
172172sample = fullfile(testCase .TestData.DataDir, ' sample1_user.toon' );
173173assumeTrue(testCase , isfile(sample ), ' Test data file not found — skipping.' );
174- v = ctoon_read (sample );
174+ v = ctoon .read (sample );
175175verifyClass(testCase , v , ' struct' );
176176verifyEqual(testCase , v .name, ' Alice' );
177177verifyEqual(testCase , double(v .age), 30 );
@@ -187,9 +187,9 @@ function testWriteReadRoundTrip(testCase)
187187original.pi = 3.14159 ;
188188original.label = ' round-trip' ;
189189original.ok = true ;
190- ctoon_write (original , tmp );
190+ ctoon .write (original , tmp );
191191verifyTrue(testCase , isfile(tmp ));
192- v = ctoon_read (tmp );
192+ v = ctoon .read (tmp );
193193verifyClass(testCase , v , ' struct' );
194194verifyEqual(testCase , v .pi, original .pi, ' AbsTol' , 1e- 10 );
195195verifyEqual(testCase , v .label, original .label);
@@ -203,19 +203,19 @@ function testWriteReadRoundTrip(testCase)
203203
204204function 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' );
207207end
208208
209209function testReadMissingFile(testCase )
210- verifyError(testCase , @() ctoon_read (' /no/such/file.toon' ), ' ctoon:readError' );
210+ verifyError(testCase , @() ctoon .read (' /no/such/file.toon' ), ' ctoon:readError' );
211211end
212212
213213function testDecodeNonString(testCase )
214- verifyError(testCase , @() ctoon_decode (42 ), ' ctoon:badArg' );
214+ verifyError(testCase , @() ctoon .decode (42 ), ' ctoon:badArg' );
215215end
216216
217217function 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' );
220220end
221221
0 commit comments