b8effffb12a91b13f5f4d0483698d1de791c6175
[scilab.git] / scilab / modules / data_structures / tests / nonreg_tests / bug_5588.tst
1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2010 - INRIA - Serge Steer
4 //
5 //  This file is distributed under the same license as the Scilab package.
6 // =============================================================================
7
8 // <-- CLI SHELL MODE -->
9
10 // <-- Non-regression test for bug 5588 -->
11 //
12 // <-- Bugzilla URL -->
13 // http://bugzilla.scilab.org/show_bug.cgi?id=5588
14 //
15 // <-- Short Description -->
16 // null() of a tlist() field shifts all remaining values with respect to
17 // field names.
18
19 // tlist null assignment indexed by a name
20 clear  %0_i_a %0_i_A
21 t=tlist(["a","b","c"],10,"foo");
22 if execstr("t.b=null()","errcatch")==0 then pause,end
23 function t=%0_i_a(i,void,t)
24     f=getfield(1,t);
25     k=find(f==i);
26     if k<>[] then
27         f(k)=[];
28         setfield(k,null(),t);
29         setfield(1,f,t);
30     end
31 endfunction
32 if execstr("t.b=null()","errcatch")<>0 then pause,end
33 if or(t<>tlist(["a","c"],"foo"))  then pause,end
34
35 // tlist null assignment indexed by a number
36 t=tlist(["a","b","c"],10,"foo");
37 if execstr("t(2)=null()","errcatch")<>0 then pause,end
38 if or(t<>tlist(["a","b","c"],"foo"))  then pause,end
39
40 //struct null assignment indexed by a name
41 T.x="foo";T.y=33;
42 if execstr("size(T)=null()","errcatch")==0 then pause,end
43 if execstr("T(1,1)=null()","errcatch")==0 then pause,end
44
45 if execstr("T.x=null()","errcatch")<>0 then pause,end
46 T1.y=33;
47 if or(T<>T1) then pause,end
48 T1.x="foo";
49 if execstr("T(1)=null()","errcatch")==0 then pause,end
50
51
52 //cell null assignment
53 c=makecell([1,2],1,"xyz");
54 if execstr("c(1,1)=null()","errcatch")==0 then pause,end
55 if execstr("size(c)=null()","errcatch")==0 then pause,end
56
57 //sublist null assigment indexed by a name
58 L=tlist(["foo","x","y"],mlist(["A","b","c"],10,"zoo"),1:5);
59 if execstr("L.x.b=null()","errcatch")==0 then pause,end
60 %0_i_A=%0_i_a;
61 if execstr("L.x.b=null()","errcatch")<>0 then pause,end
62 if or(L<>tlist(["foo","x","y"],mlist(["A","c"],"zoo"),1:5)) then pause,end
63
64 //sublist null assigment indexed by a number
65 clear %0_i_A
66 L=mlist(["foo","x","y"],tlist(["A","b","c"],10,"zoo"),1:5);
67 if execstr("L.x(2)=null()","errcatch")<>0 then pause,end
68 if or(L<>mlist(["foo","x","y"],tlist(["A","b","c"],"zoo"),1:5)) then pause,end
69
70 //try a more complex context
71 L=tlist(["foo","x","y"],list(33,mlist(["A","b","c"],10,"zoo")),1:5);
72 %0_i_A=%0_i_a;
73 if execstr("L.x(2).b=null()","errcatch")<>0 then pause,end
74
75 if or(L<>tlist(["foo","x","y"],list(33,mlist(["A","c"],"zoo")),1:5)) then pause,end