completion: fix completion and completeline unit tests 63/10563/4
Simon Marchetto [Mon, 25 Feb 2013 09:40:30 +0000 (10:40 +0100)]
Change-Id: I7d0f1ed6a20428681d8b3ab85204d575e337f73b

scilab/modules/completion/tests/unit_tests/completeline.dia.ref
scilab/modules/completion/tests/unit_tests/completeline.tst
scilab/modules/completion/tests/unit_tests/completion.dia.ref
scilab/modules/completion/tests/unit_tests/completion.tst

index d61ef4d..df674e4 100644 (file)
@@ -1,18 +1,51 @@
 // =============================================================================
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2009 - DIGITEO - Allan CORNET
+// Copyright (C) 2013 - Scilab Enterprises - Simon MARCHETTO
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
 // <-- CLI SHELL MODE -->
 ilib_verbose(0);
-ierr = exec(SCI+"/modules/completion/tests/utilities/build_primitives.sce","errcatch",-1);
-if ierr<>0 then bugmes();quit;end
-ierr = exec(TMPDIR + "/completion/loader.sce","errcatch",-1);
-if ierr<>0 then bugmes();quit;end
-currentline = 'cd /home/sy';
-r = completeline(currentline,'sylvestre',getfilepartlevel(currentline),getpartlevel(currentline),%t);
-if r <> 'cd /home/sylvestre' then bugmes();quit;end
-currentline = 'cd d:\GIT-scilab-';
-r = completeline(currentline,'d:\GIT-scilab-branch',getpartlevel(currentline),getfilepartlevel(currentline),%t);
-if r <> 'cd d:\GIT-scilab-branch' then bugmes();quit;end
+exec(SCI+"/modules/completion/tests/utilities/build_primitives.sce","errcatch",-1);
+exec(TMPDIR + "/completion/loader.sce","errcatch",-1);
+currentline = 'cd /t';
+r = completeline(currentline,'/tmp',getfilepartlevel(currentline),getpartlevel(currentline),%t);
+assert_checkequal(r, 'cd /tmp');
+r = completeline('cd /home/sy','sylvestre',getfilepartlevel(currentline),getpartlevel(currentline),%t);
+assert_checkequal(r, 'cd /home/sylvestre');
+r = completeline('cd d:\GIT-scilab-','d:\GIT-scilab-branch',getpartlevel(currentline),getfilepartlevel(currentline),%t);
+assert_checkequal(r, 'cd d:\GIT-scilab-branch');
+currentline = 'cd C:\ProgramD';
+r = completeline(currentline,'ProgramData',getpartlevel(currentline),getfilepartlevel(currentline),%t);
+assert_checkequal(r, 'cd C:\ProgramData');
+currentline = 'cd C:\Program F';
+r = completeline(currentline,'Program Files',getpartlevel(currentline),getfilepartlevel(currentline),%t);
+assert_checkequal(r, 'cd C:\Program Files');
+currentline = 'cd C:\Windows\Sys';
+r = completeline(currentline,'System32',getpartlevel(currentline),getfilepartlevel(currentline),%t);
+assert_checkequal(r, 'cd C:\Windows\System32');
+currentline = 'ho';
+r = completeline(currentline,'home',getfilepartlevel(currentline),getpartlevel(currentline),%t);
+assert_checkequal(r, 'home');
+currentline = 'TMP';
+r = completeline(currentline,'TMPDIR',getfilepartlevel(currentline),getpartlevel(currentline),%t);
+assert_checkequal(r, 'TMPDIR');
+currentline = 'disp(TMP';
+r = completeline(currentline,'TMPDIR',getfilepartlevel(currentline),getpartlevel(currentline),%t);
+assert_checkequal(r, 'disp(TMPDIR');
+currentline = '1 + ab';
+r = completeline(currentline,'abs',getfilepartlevel(currentline),getpartlevel(currentline),%t);
+assert_checkequal(r, '1 + abs');
+currentline = 'tmpStr = ""TMP = "" + TMP';
+r = completeline(currentline,'TMPDIR',getfilepartlevel(currentline),getpartlevel(currentline),%t);
+assert_checkequal(r, 'tmpStr = ""TMP = "" + TMPDIR');
+currentline = 'mytab = ab';
+r = completeline(currentline,'abs',getfilepartlevel(currentline),getpartlevel(currentline),%t);
+assert_checkequal(r, 'mytab = abs');
+currentline = 't.fie';
+r = completeline(currentline,'field1',getfilepartlevel(currentline),getpartlevel(currentline),%t);
+assert_checkequal(r, 't.field1');
+currentline = 't.field1 = t.fie';
+r = completeline(currentline,'field2',getfilepartlevel(currentline),getpartlevel(currentline),%t);
+assert_checkequal(r, 't.field1 = t.field2');
\ No newline at end of file
index 6f633c1..841ff62 100644 (file)
@@ -1,6 +1,7 @@
 // =============================================================================
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2009 - DIGITEO - Allan CORNET
+// Copyright (C) 2013 - Scilab Enterprises - Simon MARCHETTO
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
@@ -8,15 +9,59 @@
 // <-- CLI SHELL MODE -->
 
 ilib_verbose(0);
-ierr = exec(SCI+"/modules/completion/tests/utilities/build_primitives.sce","errcatch",-1);
-if ierr<>0 then pause, end
-ierr = exec(TMPDIR + "/completion/loader.sce","errcatch",-1);
-if ierr<>0 then pause, end
-
-currentline = 'cd /home/sy';
-r = completeline(currentline,'sylvestre',getfilepartlevel(currentline),getpartlevel(currentline),%t);
-if r <> 'cd /home/sylvestre' then pause,end
-
-currentline = 'cd d:\GIT-scilab-';
-r = completeline(currentline,'d:\GIT-scilab-branch',getpartlevel(currentline),getfilepartlevel(currentline),%t);
-if r <> 'cd d:\GIT-scilab-branch' then pause,end
+exec(SCI+"/modules/completion/tests/utilities/build_primitives.sce","errcatch",-1);
+exec(TMPDIR + "/completion/loader.sce","errcatch",-1);
+
+currentline = 'cd /t';
+r = completeline(currentline,'/tmp',getfilepartlevel(currentline),getpartlevel(currentline),%t);
+assert_checkequal(r, 'cd /tmp');
+
+r = completeline('cd /home/sy','sylvestre',getfilepartlevel(currentline),getpartlevel(currentline),%t);
+assert_checkequal(r, 'cd /home/sylvestre');
+
+r = completeline('cd d:\GIT-scilab-','d:\GIT-scilab-branch',getpartlevel(currentline),getfilepartlevel(currentline),%t);
+assert_checkequal(r, 'cd d:\GIT-scilab-branch');
+
+currentline = 'cd C:\ProgramD';
+r = completeline(currentline,'ProgramData',getpartlevel(currentline),getfilepartlevel(currentline),%t);
+assert_checkequal(r, 'cd C:\ProgramData');
+
+currentline = 'cd C:\Program F';
+r = completeline(currentline,'Program Files',getpartlevel(currentline),getfilepartlevel(currentline),%t);
+assert_checkequal(r, 'cd C:\Program Files');
+
+currentline = 'cd C:\Windows\Sys';
+r = completeline(currentline,'System32',getpartlevel(currentline),getfilepartlevel(currentline),%t);
+assert_checkequal(r, 'cd C:\Windows\System32');
+
+currentline = 'ho';
+r = completeline(currentline,'home',getfilepartlevel(currentline),getpartlevel(currentline),%t);
+assert_checkequal(r, 'home');
+
+currentline = 'TMP';
+r = completeline(currentline,'TMPDIR',getfilepartlevel(currentline),getpartlevel(currentline),%t);
+assert_checkequal(r, 'TMPDIR');
+
+currentline = 'disp(TMP';
+r = completeline(currentline,'TMPDIR',getfilepartlevel(currentline),getpartlevel(currentline),%t);
+assert_checkequal(r, 'disp(TMPDIR');
+
+currentline = '1 + ab';
+r = completeline(currentline,'abs',getfilepartlevel(currentline),getpartlevel(currentline),%t);
+assert_checkequal(r, '1 + abs');
+
+currentline = 'tmpStr = ""TMP = "" + TMP';
+r = completeline(currentline,'TMPDIR',getfilepartlevel(currentline),getpartlevel(currentline),%t);
+assert_checkequal(r, 'tmpStr = ""TMP = "" + TMPDIR');
+
+currentline = 'mytab = ab';
+r = completeline(currentline,'abs',getfilepartlevel(currentline),getpartlevel(currentline),%t);
+assert_checkequal(r, 'mytab = abs');
+
+currentline = 't.fie';
+r = completeline(currentline,'field1',getfilepartlevel(currentline),getpartlevel(currentline),%t);
+assert_checkequal(r, 't.field1');
+
+currentline = 't.field1 = t.fie';
+r = completeline(currentline,'field2',getfilepartlevel(currentline),getpartlevel(currentline),%t);
+assert_checkequal(r, 't.field1 = t.field2');
index f201804..3c575fe 100644 (file)
 // =============================================================================
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2007-2008 - INRIA
+// Copyright (C) 2013 - Scilab Enterprises - Simon MARCHETTO
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
-// <-- CLI SHELL MODE -->
 //===============================
 // unit tests completion
 //===============================
-// parameters tests
-r = completion('%');
-s = size(r,'*');
-if s < 748 then bugmes();quit;end
-//===============================
-functions1 = completion('%','functions');
-s = size(functions1,'*');
-if s < 17 then bugmes();quit;end
-//===============================
-commands1 = completion('%','commands');
-s = size(commands1,'*');
-if s <> 0 then bugmes();quit;end
-//===============================
-variables1 = completion('%','variables');
-s = size(variables1,'*');
-if s < 10 then bugmes();quit;end
-//===============================
-macros1 = completion('%','macros');
-s = size(macros1,'*');
-if s < 705 then bugmes();quit;end
-//===============================
-graphic_properties1 = completion('%','graphic_properties');
-s = size(graphic_properties1,'*');
-if s <> 0 then bugmes();quit;end
-//===============================
-files1 = completion('%','files');
-s = size(files1,'*');
-if s <> 0 then bugmes();quit;end
-//===============================
-[functions2,commands2,variables2,macros2,graphic_properties2,files2] = completion('%');
-if functions2 <> functions1 then bugmes();quit;end
-if commands2 <> commands1 then bugmes();quit;end
-if variables2 <> variables1 then bugmes();quit;end
-if macros2 <> macros1 then bugmes();quit;end
-if graphic_properties2 <> graphic_properties1 then bugmes();quit;end
-if files2 <> files1 then bugmes();quit;end
-//===============================
-[functions3,commands3,variables3,macros3,graphic_properties3] = completion('%');
-if functions3 <> functions1 then bugmes();quit;end
-if commands3 <> commands1 then bugmes();quit;end
-if variables3 <> variables1 then bugmes();quit;end
-if macros3 <> macros1 then bugmes();quit;end
-if graphic_properties3 <> graphic_properties1 then bugmes();quit;end
-//===============================
-[functions4,commands4,variables4,macros4] = completion('%');
-if functions4 <> functions1 then bugmes();quit;end
-if commands4 <> commands1 then bugmes();quit;end
-if variables4 <> variables1 then bugmes();quit;end
-if macros4 <> macros1 then bugmes();quit;end
-//===============================
-[functions5,commands5,variables5] = completion('%');
-if functions5 <> functions1 then bugmes();quit;end
-if commands5 <> commands1 then bugmes();quit;end
-if variables5 <> variables1 then bugmes();quit;end
-//===============================
-[functions6,commands6] = completion('%');
-if functions6 <> functions1 then bugmes();quit;end
-if commands6 <> commands1 then bugmes();quit;end
-//===============================
-// check memory leak
-//for i=1:1000000,a=completion('w');end;
-//for i=1:1000000,a=completion('w',"functions");end;
-//for i=1:1000000,a=completion('w',"commands");end;
-//for i=1:1000000,a=completion('w',"variables");end;
-//for i=1:1000000,a=completion('w',"macros");end;
-//for i=1:1000000,a=completion('w',"graphic_properties");end;
-//for i=1:1000000,a=completion('w',"files");end;
-//===============================
+// File paths
+if (getos() == "Windows") then;
+    r = completion('C:\Documents and');
+    assert_checkequal(r, 'Documents and Settings\');
+else
+    r = completion('/tm');
+    assert_checkequal(r, 'tmp/');
+end
+r = completion(SCI+'/to');
+if (getos() == "Windows") then;
+   assert_checkequal(r, ['tools\']);
+else;
+   assert_checkequal(r, ['tools/']);
+end
+// Predefined variables
+r = completion('ho', 'variables');
+assert_checkequal(r, 'home');
+r = completion('%na');
+assert_checkequal(r, '%nan');
+r = completion('TMP');
+assert_checkequal(r, 'TMPDIR');
+r = completion('%', 'variables');
+rexpected = ['%F'; '%T'; '%e'; '%eps'; '%f'; '%fftw'; '%gui'; '%i';'%inf'; '%io';
+  '%modalWarning'; '%nan'; '%pi'; '%s'; '%t'; '%tk'; '%toolboxes'; '%toolboxes_dir'; '%z'];
+assert_checkequal(r, rexpected);
+// User variables
+variable_completion1 = 1;
+variable_completion2 = 2;
+r = completion('variable_comp');
+assert_checkequal(r, ['variable_completion1'; 'variable_completion2']);
+// Predefined functions, macros and commands
+r = completion('floo');
+assert_checkequal(r, 'floor');
+r = completion('abort');
+assert_checkequal(r, 'abort');
+// User functions, macros, commands
+function [] = function_completion(x);
+endfunction;
+r = completion('function_comp');
+assert_checkequal(r, 'function_completion');
+// Filter argument
+r = completion('ho');
+assert_checkequal(r, ['home'; 'horizontalalignment'; 'horner'; 'host'; 'hotcolormap'; 'householder']);
+r = completion('ho', 'functions');
+assert_checkequal(r, 'host');
+r = completion('ho', 'commands');
+assert_checkequal(r, []);
+r = completion('ho', 'macros');
+assert_checkequal(r, ['horner'; 'hotcolormap'; 'householder']);
+r = completion('ho', 'variables');
+assert_checkequal(r, 'home');
+r = completion('ho', 'graphic_properties');
+assert_checkequal(r, 'horizontalalignment');
+r = completion('ho', 'files');
+assert_checkequal(r, []);
+r = completion('abo');
+assert_checkequal(r, ['abort'; 'about']);
+r = completion('abo', 'functions');
+assert_checkequal(r, 'about');
+r = completion('abo', 'commands');
+assert_checkequal(r, 'abort');
+r = completion('abo', 'variables');
+assert_checkequal(r, []);
+r = completion('abo', 'macros');
+assert_checkequal(r, []);
+r = completion('abo', 'graphic_properties');
+assert_checkequal(r, []);
+r = completion('abo', 'files');
+assert_checkequal(r, []);
+// Output arguments
+[functions,commands,variables,macros,graphic_properties,files] = completion('ho');
+assert_checkequal(functions, ['host']);
+assert_checkequal(commands, []);
+assert_checkequal(variables, ['home']);
+assert_checkequal(macros, ['horner'; 'hotcolormap'; 'householder']);
+assert_checkequal(graphic_properties, ['horizontalalignment']);
+assert_checkequal(files, []);
+[functions,commands,variables,macros,graphic_properties,files] = completion('abo');
+assert_checkequal(functions, ['about']);
+assert_checkequal(commands, ['abort']);
+assert_checkequal(variables, []);
+assert_checkequal(macros, []);
+assert_checkequal(graphic_properties, []);
+assert_checkequal(files, []);
+if (getos() == "Windows") then;
+    [functions,commands,variables,macros,graphic_properties,files] = completion('C:\Documents and');
+    assert_checkequal(files, ['Documents and Settings\']);
+else
+    [functions,commands,variables,macros,graphic_properties,files] = completion('/tm');
+    assert_checkequal(files, ['tmp/']);
+end
index 4c97bf3..9e4a855 100644 (file)
 // =============================================================================
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2007-2008 - INRIA
+// Copyright (C) 2013 - Scilab Enterprises - Simon MARCHETTO
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
 
-// <-- CLI SHELL MODE -->
-
 //===============================
 // unit tests completion
 //===============================
 
-// parameters tests
-r = completion('%');
-s = size(r,'*');
-if s < 748 then pause,end
-//===============================
-functions1 = completion('%','functions');
-s = size(functions1,'*');
-if s < 17 then pause,end
-//===============================
-commands1 = completion('%','commands');
-s = size(commands1,'*');
-if s <> 0 then pause,end
-//===============================
-variables1 = completion('%','variables');
-s = size(variables1,'*');
-if s < 10 then pause,end
-//===============================
-macros1 = completion('%','macros');
-s = size(macros1,'*');
-if s < 705 then pause,end
-//===============================
-graphic_properties1 = completion('%','graphic_properties');
-s = size(graphic_properties1,'*');
-if s <> 0 then pause,end
-//===============================
-files1 = completion('%','files');
-s = size(files1,'*');
-if s <> 0 then pause,end
-//===============================
-[functions2,commands2,variables2,macros2,graphic_properties2,files2] = completion('%');
-if functions2 <> functions1 then pause,end
-if commands2 <> commands1 then pause,end
-if variables2 <> variables1 then pause,end
-if macros2 <> macros1 then pause,end
-if graphic_properties2 <> graphic_properties1 then pause,end
-if files2 <> files1 then pause,end
-//===============================
-[functions3,commands3,variables3,macros3,graphic_properties3] = completion('%');
-if functions3 <> functions1 then pause,end
-if commands3 <> commands1 then pause,end
-if variables3 <> variables1 then pause,end
-if macros3 <> macros1 then pause,end
-if graphic_properties3 <> graphic_properties1 then pause,end
-//===============================
-[functions4,commands4,variables4,macros4] = completion('%');
-if functions4 <> functions1 then pause,end
-if commands4 <> commands1 then pause,end
-if variables4 <> variables1 then pause,end
-if macros4 <> macros1 then pause,end
-//===============================
-[functions5,commands5,variables5] = completion('%');
-if functions5 <> functions1 then pause,end
-if commands5 <> commands1 then pause,end
-if variables5 <> variables1 then pause,end
-//===============================
-[functions6,commands6] = completion('%');
-if functions6 <> functions1 then pause,end
-if commands6 <> commands1 then pause,end
-//===============================
-// check memory leak
-//for i=1:1000000,a=completion('w');end;
-//for i=1:1000000,a=completion('w',"functions");end;
-//for i=1:1000000,a=completion('w',"commands");end;
-//for i=1:1000000,a=completion('w',"variables");end;
-//for i=1:1000000,a=completion('w',"macros");end;
-//for i=1:1000000,a=completion('w',"graphic_properties");end;
-//for i=1:1000000,a=completion('w',"files");end;
-//===============================
+// File paths
+
+if (getos() == "Windows") then;
+    r = completion('C:\Documents and');
+    assert_checkequal(r, 'Documents and Settings\');
+else
+    r = completion('/tm');
+    assert_checkequal(r, 'tmp/');
+end
+
+r = completion(SCI+'/to');
+if (getos() == "Windows") then;
+   assert_checkequal(r, ['tools\']);
+else;
+   assert_checkequal(r, ['tools/']);
+end
+
+// Predefined variables
+
+r = completion('ho', 'variables');
+assert_checkequal(r, 'home');
+
+r = completion('%na');
+assert_checkequal(r, '%nan');
+
+r = completion('TMP');
+assert_checkequal(r, 'TMPDIR');
+
+r = completion('%', 'variables');
+rexpected = ['%F'; '%T'; '%e'; '%eps'; '%f'; '%fftw'; '%gui'; '%i';'%inf'; '%io';
+  '%modalWarning'; '%nan'; '%pi'; '%s'; '%t'; '%tk'; '%toolboxes'; '%toolboxes_dir'; '%z'];
+assert_checkequal(r, rexpected);
+
+
+// User variables
+
+variable_completion1 = 1;
+variable_completion2 = 2;
+r = completion('variable_comp');
+assert_checkequal(r, ['variable_completion1'; 'variable_completion2']);
+
+
+// Predefined functions, macros and commands
+
+r = completion('floo');
+assert_checkequal(r, 'floor');
+
+r = completion('abort');
+assert_checkequal(r, 'abort');
+
+
+// User functions, macros, commands
+function [] = function_completion(x);
+endfunction;
+r = completion('function_comp');
+assert_checkequal(r, 'function_completion');
+
+
+// Filter argument
+
+r = completion('ho');
+assert_checkequal(r, ['home'; 'horizontalalignment'; 'horner'; 'host'; 'hotcolormap'; 'householder']);
+
+r = completion('ho', 'functions');
+assert_checkequal(r, 'host');
+
+r = completion('ho', 'commands');
+assert_checkequal(r, []);
+
+r = completion('ho', 'macros');
+assert_checkequal(r, ['horner'; 'hotcolormap'; 'householder']);
+
+r = completion('ho', 'variables');
+assert_checkequal(r, 'home');
+
+r = completion('ho', 'graphic_properties');
+assert_checkequal(r, 'horizontalalignment');
+
+r = completion('ho', 'files');
+assert_checkequal(r, []);
+
+r = completion('abo');
+assert_checkequal(r, ['abort'; 'about']);
+
+r = completion('abo', 'functions');
+assert_checkequal(r, 'about');
+
+r = completion('abo', 'commands');
+assert_checkequal(r, 'abort');
+
+r = completion('abo', 'variables');
+assert_checkequal(r, []);
+
+r = completion('abo', 'macros');
+assert_checkequal(r, []);
+
+r = completion('abo', 'graphic_properties');
+assert_checkequal(r, []);
+
+r = completion('abo', 'files');
+assert_checkequal(r, []);
+
+
+// Output arguments
+
+[functions,commands,variables,macros,graphic_properties,files] = completion('ho');
+assert_checkequal(functions, ['host']);
+assert_checkequal(commands, []);
+assert_checkequal(variables, ['home']);
+assert_checkequal(macros, ['horner'; 'hotcolormap'; 'householder']);
+assert_checkequal(graphic_properties, ['horizontalalignment']);
+assert_checkequal(files, []);
+
+[functions,commands,variables,macros,graphic_properties,files] = completion('abo');
+assert_checkequal(functions, ['about']);
+assert_checkequal(commands, ['abort']);
+assert_checkequal(variables, []);
+assert_checkequal(macros, []);
+assert_checkequal(graphic_properties, []);
+assert_checkequal(files, []);
+
+if (getos() == "Windows") then;
+    [functions,commands,variables,macros,graphic_properties,files] = completion('C:\Documents and');
+    assert_checkequal(files, ['Documents and Settings\']);
+else
+    [functions,commands,variables,macros,graphic_properties,files] = completion('/tm');
+    assert_checkequal(files, ['tmp/']);
+end