summaryrefslogtreecommitdiff
path: root/ext/pspell/tests
diff options
context:
space:
mode:
Diffstat (limited to 'ext/pspell/tests')
-rw-r--r--ext/pspell/tests/001.phpt116
-rw-r--r--ext/pspell/tests/002.phpt42
-rw-r--r--ext/pspell/tests/003.phpt39
-rw-r--r--ext/pspell/tests/004.phpt35
-rw-r--r--ext/pspell/tests/005.phpt46
-rw-r--r--ext/pspell/tests/wordlist.txt5
6 files changed, 283 insertions, 0 deletions
diff --git a/ext/pspell/tests/001.phpt b/ext/pspell/tests/001.phpt
new file mode 100644
index 0000000..0a22352
--- /dev/null
+++ b/ext/pspell/tests/001.phpt
@@ -0,0 +1,116 @@
+--TEST--
+pspell basic tests (warning: may fail with pspell/aspell < GNU Aspell 0.50.3)
+--SKIPIF--
+<?php
+if (!extension_loaded("pspell")) die("skip");
+if (!@pspell_new ("en", "", "", "", (PSPELL_FAST|PSPELL_RUN_TOGETHER))) {
+ die("skip English dictionary is not available");
+}
+?>
+--FILE--
+<?php // $Id$
+
+error_reporting(E_ALL);
+$string = "";
+$string .= "I will not buy this record, it is scratched. ";
+$string .= "Sorry ";
+$string .= "I will not buy this record, it is scratched. ";
+$string .= "Uh, no, no, no. This is a tobacconist's ";
+$string .= "Ah! I will not buy this tobacconist's, it is scratched. ";
+$string .= "No, no, no, no. Tobacco... um... cigarettes (holds up a pack). ";
+$string .= "Ya! See-gar-ets! Ya! Uh... My hovercraft is full of eels. ";
+$string .= "Sorry? ";
+$string .= "My hovercraft (pantomimes puffing a cigarette)... is full of eels (pretends to strike a match). ";
+$string .= "Ahh, matches!";
+
+$pspell = pspell_new ("en", "", "", "", (PSPELL_FAST|PSPELL_RUN_TOGETHER));
+$array = explode(' ',preg_replace('/[^a-zA-Z0-9 ]/','',$string));
+for($i=0,$u=count($array);$i<$u;++$i) {
+ echo $array[$i].' : ';
+ if (!pspell_check($pspell, $array[$i])) {
+ echo "..false\n";
+ echo "Possible spellings: " . join(',',pspell_suggest ($pspell, $array[$i])) . "\n";
+ } else {
+ echo "true\n";
+ }
+}
+?>
+--EXPECTF--
+I : true
+will : true
+not : true
+buy : true
+this : true
+record : true
+it : true
+is : true
+scratched : true
+Sorry : true
+I : true
+will : true
+not : true
+buy : true
+this : true
+record : true
+it : true
+is : true
+scratched : true
+Uh : true
+no : true
+no : true
+no : true
+This : true
+is : true
+a : true
+tobacconists : true
+Ah : true
+I : true
+will : true
+not : true
+buy : true
+this : true
+tobacconists : true
+it : true
+is : true
+scratched : true
+No : true
+no : true
+no : true
+no : true
+Tobacco : true
+um : true
+cigarettes : true
+holds : true
+up : true
+a : true
+pack : true
+Ya : true
+Seegarets : ..false
+Possible spellings:%s,Regrets,%s,Cigarettes,%s
+Ya : true
+Uh : true
+My : true
+hovercraft : true
+is : true
+full : true
+of : true
+eels : true
+Sorry : true
+My : true
+hovercraft : true
+pantomimes : true
+puffing : true
+a : true
+cigarette : true
+is : true
+full : true
+of : true
+eels : true
+pretends : true
+to : true
+strike : true
+a : true
+match : true
+Ahh : ..false
+Possible spellings:%sAh,Aha,%s
+matches : true
diff --git a/ext/pspell/tests/002.phpt b/ext/pspell/tests/002.phpt
new file mode 100644
index 0000000..e6aff66
--- /dev/null
+++ b/ext/pspell/tests/002.phpt
@@ -0,0 +1,42 @@
+--TEST--
+pspell session
+--SKIPIF--
+<?php
+if (!extension_loaded('pspell')) die('skip');
+if (!@pspell_new('en')) die('skip English dictionary is not available');
+?>
+--FILE--
+<?php
+
+$p = pspell_new('en');
+
+var_dump(pspell_check('a'));
+var_dump(pspell_check($p, 'somebogusword'));
+
+var_dump(pspell_add_to_session($p, ''));
+var_dump(pspell_add_to_session($p, 'somebogusword'));
+var_dump(pspell_check($p, 'somebogusword'));
+
+var_dump(pspell_clear_session(new stdclass));
+
+$res = @pspell_clear_session($p);
+if ($res) {
+ var_dump($res);
+ var_dump(pspell_check($p, 'somebogusword'));
+} else {
+ echo "bool(true)\n";
+ echo "bool(false)\n";
+}
+?>
+--EXPECTF--
+Warning: pspell_check() expects exactly 2 parameters, 1 given in %s on line %d
+NULL
+bool(false)
+bool(false)
+bool(true)
+bool(true)
+
+Warning: pspell_clear_session() expects parameter 1 to be long, object given in %s on line %d
+NULL
+bool(true)
+bool(false)
diff --git a/ext/pspell/tests/003.phpt b/ext/pspell/tests/003.phpt
new file mode 100644
index 0000000..4fc34bf
--- /dev/null
+++ b/ext/pspell/tests/003.phpt
@@ -0,0 +1,39 @@
+--TEST--
+pspell_config_ignore
+--SKIPIF--
+<?php
+if (!extension_loaded('pspell')) die('skip');
+if (!@pspell_new('en')) die('skip English dictionary is not available');
+?>
+--FILE--
+<?php
+
+$cfg = pspell_config_create('en', 'british', '', 'iso8859-1');
+$cfg2 = pspell_config_create('en', 'british', '', 'b0rked');
+
+$p = pspell_new_config($cfg);
+var_dump(pspell_check($p, 'yy'));
+
+$p2 = pspell_new_config($cfg2);
+var_dump(pspell_check($p2, 'yy'));
+
+echo "---\n";
+var_dump(pspell_config_ignore($cfg, 2));
+$p = pspell_new_config($cfg);
+var_dump(pspell_check($p, 'yy'));
+
+// segfault it?
+var_dump(pspell_config_ignore($cfg, PHP_INT_MAX));
+
+?>
+--EXPECTF--
+bool(false)
+
+Warning: pspell_new_config(): PSPELL couldn't open the dictionary. reason: The encoding "b0rked" is not known. This could also mean that the file "%sb0rked.%s" could not be opened for reading or does not exist. in %s003.php on line 9
+
+Warning: pspell_check(): 0 is not a PSPELL result index in %s003.php on line 10
+bool(false)
+---
+bool(true)
+bool(true)
+bool(true)
diff --git a/ext/pspell/tests/004.phpt b/ext/pspell/tests/004.phpt
new file mode 100644
index 0000000..80602bc
--- /dev/null
+++ b/ext/pspell/tests/004.phpt
@@ -0,0 +1,35 @@
+--TEST--
+pspell configs
+--SKIPIF--
+<?php
+if (!extension_loaded('pspell')) die('skip');
+if (!@pspell_new('en')) die('skip English dictionary is not available');
+?>
+--FILE--
+<?php
+
+$cfg = pspell_config_create('en', 'british', '', 'iso8859-1');
+var_dump(pspell_config_mode($cfg, PSPELL_BAD_SPELLERS));
+
+var_dump(pspell_config_runtogether($cfg, false));
+$p = pspell_new_config($cfg);
+var_dump(pspell_check($p, 'theoasis'));
+
+echo "---\n";
+
+// now it should pass
+var_dump(pspell_config_runtogether($cfg, true));
+$p = pspell_new_config($cfg);
+var_dump(pspell_check($p, 'theoasis'));
+
+var_dump(pspell_config_runtogether($cfg, NULL))
+
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(false)
+---
+bool(true)
+bool(true)
+bool(true)
diff --git a/ext/pspell/tests/005.phpt b/ext/pspell/tests/005.phpt
new file mode 100644
index 0000000..17ed190
--- /dev/null
+++ b/ext/pspell/tests/005.phpt
@@ -0,0 +1,46 @@
+--TEST--
+pspell configs
+--SKIPIF--
+<?php
+if (!extension_loaded('pspell')) die('skip');
+if (!@pspell_new('en')) die('skip English dictionary is not available');
+?>
+--FILE--
+<?php
+
+$wordlist = dirname(__FILE__).'/wordlist.txt';
+
+var_dump(pspell_new_personal(__FILE__, 'en'));
+$p = pspell_new_personal($wordlist, 'en');
+
+var_dump(pspell_check($p, 'dfnvnsafksfksf'));
+
+echo "--\n";
+$cfg = pspell_config_create('en');
+var_dump(pspell_config_personal($cfg, "$wordlist.tmp"));
+$p = pspell_new_config($cfg);
+
+copy($wordlist, "$wordlist.tmp");
+
+var_dump(pspell_check($p, 'ola'));
+var_dump(pspell_add_to_personal($p, 'ola'));
+var_dump(pspell_check($p, 'ola'));
+
+echo "--\n";
+var_dump(pspell_save_wordlist($p));
+var_dump(strpos(file_get_contents("$wordlist.tmp"), 'ola') !== FALSE);
+
+unlink("$wordlist.tmp");
+?>
+--EXPECTF--
+Warning: pspell_new_personal(): PSPELL couldn't open the dictionary. reason: The file "%s005.php" is not in the proper format. in %s005.php on line 5
+bool(false)
+bool(true)
+--
+bool(true)
+bool(false)
+bool(true)
+bool(true)
+--
+bool(true)
+bool(true)
diff --git a/ext/pspell/tests/wordlist.txt b/ext/pspell/tests/wordlist.txt
new file mode 100644
index 0000000..e9d8da7
--- /dev/null
+++ b/ext/pspell/tests/wordlist.txt
@@ -0,0 +1,5 @@
+personal_ws-1.1 en 4
+dfnvnsafksfksf
+fg
+iufrsn
+jsksjfsjf