1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
// =============================================================================
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2007-2008 - INRIA
// Copyright (C) 2009 - DIGITEO - Allan CORNET
// This file is distributed under the same license as the Scilab package.
// =============================================================================
// <-- JVM NOT MANDATORY -->
//===============================
// unit tests strsplit
//===============================
STR_SPLITED = ['strsplit splits';'a string';'into';'a vector of strings'];
STR = 'strsplit splits a string into a vector of strings';
INDICES = [15 25 30];
R = stripblanks(strsplit(STR,INDICES));
if R <> STR_SPLITED then pause,end
//===============================
if strsplit([],[1 1 1]) <> [] then pause,end
//===============================
// Scilab 4.x
//if execstr('strsplit([],[3 2 1])','errcatch') <> 99 then pause,end
// Scilab 5.x
if strsplit([],[3 2 1]) <> [] then pause,end
//===============================
if execstr('strsplit('',[0 1])','errcatch') <> 31 then pause,end
// Scilab 4.x
//if execstr('strsplit([])','errcatch') <> 39 then pause,end
// Scilab 5.1
//if execstr('strsplit([])','errcatch') <> 77 then pause,end
// Scilab 5.2
if execstr('strsplit([])','errcatch') <> 0 then pause,end
if (strsplit([]) <> []) then pause,end
//===============================
ref_1 = ["toto"];
ref_2 = [];
[r_1, r_2] = strsplit("toto","a");
if ~and(ref_1 == r_1) then pause,end
if ~and(ref_2 == r_2) then pause,end
//===============================
// request 663
ref_1 = ["a";"b";"c";"d";"e";"f"];
ref_2 = ["";"";"";"";"";""];
[r_1, r_2] = strsplit("abcdef");
if ~and(ref_1 == r_1) then pause,end
if ~and(ref_2 == r_2) then pause,end
if strcat(r_1,"") <> "abcdef" then pause,end
//===============================
[r_1, r_2] = strsplit("abcdef","");
[r_3, r_4] = strsplit("abcdef");
if ~and(r_1 == r_3) then pause,end
if ~and(r_2 == r_4) then pause,end
//===============================
ref_1 = ["a";"bcdef"];
ref_2 = [""];
[r_1, r_2] = strsplit("abcdef","",1);
if ~and(ref_1 == r_1) then pause,end
if ~and(ref_2 == r_2) then pause,end
if strcat(r_1,"") <> "abcdef" then pause,end
//===============================
ref_1 = ["abcdef";"ghijkl";"mnopqr";"stuvw";"xyz"];
ref_2 = [",";",";",";","];
[r_1, r_2] = strsplit("abcdef,ghijkl,mnopqr,stuvw,xyz",",");
if ~and(ref_1 == r_1) then pause,end
if ~and(ref_2 == r_2) then pause,end
if strcat(r_1,",") <> "abcdef,ghijkl,mnopqr,stuvw,xyz" then pause,end
//===============================
ref_1 = ["abc";"";"";"def";"";"ghijkl";"";"mno"];
ref_2 = [":";":";":";":";":";":";":"];
[r_1, r_2] = strsplit("abc:::def::ghijkl::mno",":");
if ~and(ref_1 == r_1) then pause,end
if ~and(ref_2 == r_2) then pause,end
if strcat(r_1,":") <> "abc:::def::ghijkl::mno" then pause,end
//===============================
ref_1 = ["abcdef";"ghijkl";"mnopqr";"stuvw";"xyz"];
ref_2 = ["~~~";"~~~";"~~~";"~~~"] ;
[r_1, r_2] = strsplit("abcdef~~~ghijkl~~~mnopqr~~~stuvw~~~xyz","~~~");
if ~and(ref_1 == r_1) then pause,end
if ~and(ref_2 == r_2) then pause,end
if strcat(r_1,"~~~") <> "abcdef~~~ghijkl~~~mnopqr~~~stuvw~~~xyz" then pause,end
//===============================
ref_1 = ["abcdef";"ghijkl";"mnopqr";"stuvw";"xyz"];
ref_2 = ["2";"3";"6";"7"];
[r_1, r_2] = strsplit("abcdef2ghijkl3mnopqr6stuvw7xyz","/\d+/");
if ~and(ref_1 == r_1) then pause,end
if ~and(ref_2 == r_2) then pause,end
//===============================
ref_2 = ["scilab";"scilab"];
ref_1 = ["";" a numerical tools ";"oraty"];
[r_1, r_2] = strsplit("scilab a numerical tools scilaboraty","/scilab/");
if ~and(ref_1 == r_1) then pause,end
if ~and(ref_2 == r_2) then pause,end
//===============================
ref_1 = ["abcdef";"ghijkl";"mnopqr";"stuvw";"xyz"];
ref_2 = [ascii(9);ascii(9);ascii(9);ascii(9)];
[r_1, r_2] = strsplit("abcdef"+ascii(9)+"ghijkl" + ascii(9)+"mnopqr"+ascii(9)+"stuvw" + ascii(9)+"xyz","/\t/") ;
if ~and(ref_1 == r_1) then pause,end
if ~and(ref_2 == r_2) then pause,end
if strcat(r_1,ascii(9)) <> "abcdef"+ascii(9)+"ghijkl" + ascii(9)+"mnopqr"+ascii(9)+"stuvw" + ascii(9)+"xyz" then pause,end
//===============================
ref_1 = ["server.name";"scilab.org"];
ref_2 = " = ";
linestr = "server.name = scilab.org";
[r_1, r_2] = strsplit(linestr, "/\s*=\s*/");
if ~and(ref_1 == r_1) then pause,end
if ~and(ref_2 == r_2) then pause,end
if strcat(r_1,r_2) <> "server.name = scilab.org" then pause,end
//===============================
ierr = execstr("strsplit(''root:x:0:0:root:/root:/bin/bash'','':'',0)","errcatch");
if ierr <> 999 then pause,end
//===============================
ref_1 = ["root";"x:0:0:root:/root:/bin/bash"];
ref_2 = ":";
[r_1, r_2] = strsplit("root:x:0:0:root:/root:/bin/bash",":",1);
if ~and(ref_1 == r_1) then pause,end
if ~and(ref_2 == r_2) then pause,end
//===============================
ref_1 = ["root";"x";"0";"0";"root";"/root:/bin/bash"];
ref_2 = [":";":";":";":";":"];
[r_1, r_2] = strsplit("root:x:0:0:root:/root:/bin/bash",":",5);
if ~and(ref_1 == r_1) then pause,end
if ~and(ref_2 == r_2) then pause,end
//===============================
[r_1, r_2] = strsplit("root:x:0:0:root:/root:/bin/bash",":",7);
[r_3, r_4] = strsplit("root:x:0:0:root:/root:/bin/bash",":",50);
if ~and(r_1 == r_3) then pause,end
if ~and(r_2 == r_4) then pause,end
//===============================
ref_1 = ["abc";""];
ref_2 = ',';
[r_1, r_2] = strsplit("abc,",",");
if ~and(ref_1 == r_1) then pause,end
if ~and(ref_2 == r_2) then pause,end
//===============================
ref_1 = ["abc";""];
ref_2 = ',';
[r_1, r_2] = strsplit("abc,",",",1);
if ~and(ref_1 == r_1) then pause,end
if ~and(ref_2 == r_2) then pause,end
//===============================
[r_1, r_2] = strsplit("abc,",",",1);
[r_3, r_4] = strsplit("abc,",",",10);
if ~and(r_1 == r_3) then pause,end
if ~and(r_2 == r_4) then pause,end
//===============================
ref_1 = ["abc";"def";"ijk";"";"lmo"];
ref_2 = [",";":";",";":"];
[r_1, r_2] = strsplit("abc,def:ijk,:lmo","/:|,/");
if ~and(ref_1 == r_1) then pause,end
if ~and(ref_2 == r_2) then pause,end
//===============================
ref_1 = ["abc";"def";"ijk";"";"lmo"];
ref_2 = [",";":";",";":"];
[r_1, r_2] = strsplit("abc,def:ijk,:lmo",[":";","]);
if ~and(ref_1 == r_1) then pause,end
if ~and(ref_2 == r_2) then pause,end
//===============================
ref_1 = ["abc";"def";"ijk,:lmo"];
ref_2 = [",";":"];
[r_1, r_2] = strsplit("abc,def:ijk,:lmo",[":";","],2);
if ~and(ref_1 == r_1) then pause,end
if ~and(ref_2 == r_2) then pause,end
//===============================
v = "世界您好";
c = "您";
[r_1,r_2] = strsplit(v,c);
if strcat(r_1,r_2) <> v then pause,end
//===============================
v = "азеаея";
c = "з";
[r_1,r_2] = strsplit(v,c);
if strcat(r_1,r_2) <> v then pause,end
//===============================
v = "ድቅስድስግ";
c = "ቅ";
[r_1,r_2] = strsplit(v,c);
if strcat(r_1,r_2) <> v then pause,end
//===============================
v = "ハロー・ワールド";
c = "ド";
[r_1,r_2] = strsplit(v,c);
if strcat(r_1,r_2) <> v then pause,end
//===============================
v = "תוכנית";
c = "י";
[r_1,r_2] = strsplit(v,c);
if strcat(r_1,r_2) <> v then pause,end
//===============================
|