summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Lexer/LexerTest.php1
-rw-r--r--tests/Misc/UtfStringTest.php88
-rw-r--r--tests/data/lexUtf8.in1
-rw-r--r--tests/data/lexUtf8.out1
4 files changed, 91 insertions, 0 deletions
diff --git a/tests/Lexer/LexerTest.php b/tests/Lexer/LexerTest.php
index dabe64d..cd8718c 100644
--- a/tests/Lexer/LexerTest.php
+++ b/tests/Lexer/LexerTest.php
@@ -51,6 +51,7 @@ class LexerTest extends TestCase
{
return array(
array('lex'),
+ array('lexUtf8'),
array('lexBool'),
array('lexComment'),
array('lexDelimiter'),
diff --git a/tests/Misc/UtfStringTest.php b/tests/Misc/UtfStringTest.php
new file mode 100644
index 0000000..0d1ff78
--- /dev/null
+++ b/tests/Misc/UtfStringTest.php
@@ -0,0 +1,88 @@
+<?php
+
+namespace SqlParser\Tests\Misc;
+
+use SqlParser\UtfString;
+
+use SqlParser\Tests\TestCase;
+
+class UtfStringTest extends TestCase
+{
+
+ /**
+ * Sample phrase in French.
+ *
+ * @var UtfString
+ */
+ const TEST_PHRASE = 'Les naïfs ægithales hâtifs pondant à Noël où il ' .
+ 'gèle sont sûrs d\'être déçus en voyant leurs drôles d\'œufs abîmés.';
+
+ /**
+ * The length of the sample phrase.
+ *
+ * @var int
+ */
+ const TEST_PHRASE_LEN = 113;
+
+ public function testArrayAccess()
+ {
+ $str = new UtfString(static::TEST_PHRASE);
+
+ // offsetExists
+ $this->assertTrue(isset($str[static::TEST_PHRASE_LEN - 1]));
+ $this->assertFalse(isset($str[-1]));
+ $this->assertFalse(isset($str[static::TEST_PHRASE_LEN]));
+
+ // offsetGet
+ $this->assertEquals('.', $str[static::TEST_PHRASE_LEN - 1]);
+ $this->assertEquals(null, $str[-1]);
+ $this->assertEquals(null, $str[static::TEST_PHRASE_LEN]);
+ }
+
+ /**
+ * @expectedException \Exception
+ * @expectedExceptionMessage Not implemented.
+ */
+ public function testSet()
+ {
+ $str = new UtfString('');
+ $str[0] = 'a';
+ }
+
+ /**
+ * @expectedException \Exception
+ * @expectedExceptionMessage Not implemented.
+ */
+ public function testUnset()
+ {
+ $str = new UtfString('');
+ unset($str[0]);
+ }
+
+ public function testGetCharLength()
+ {
+ $this->assertEquals(1, UtfString::getCharLength(chr(0x00))); // 00000000
+ $this->assertEquals(1, UtfString::getCharLength(chr(0x7F))); // 01111111
+
+ $this->assertEquals(2, UtfString::getCharLength(chr(0xC0))); // 11000000
+ $this->assertEquals(2, UtfString::getCharLength(chr(0xDF))); // 11011111
+
+ $this->assertEquals(3, UtfString::getCharLength(chr(0xE0))); // 11100000
+ $this->assertEquals(3, UtfString::getCharLength(chr(0xEF))); // 11101111
+
+ $this->assertEquals(4, UtfString::getCharLength(chr(0xF0))); // 11110000
+ $this->assertEquals(4, UtfString::getCharLength(chr(0xF7))); // 11110111
+
+ $this->assertEquals(5, UtfString::getCharLength(chr(0xF8))); // 11111000
+ $this->assertEquals(5, UtfString::getCharLength(chr(0xFB))); // 11111011
+
+ $this->assertEquals(6, UtfString::getCharLength(chr(0xFC))); // 11111100
+ $this->assertEquals(6, UtfString::getCharLength(chr(0xFD))); // 11111101
+ }
+
+ public function testToString()
+ {
+ $str = new UtfString(static::TEST_PHRASE);
+ $this->assertEquals(static::TEST_PHRASE, (string) $str);
+ }
+}
diff --git a/tests/data/lexUtf8.in b/tests/data/lexUtf8.in
new file mode 100644
index 0000000..9cf478e
--- /dev/null
+++ b/tests/data/lexUtf8.in
@@ -0,0 +1 @@
+select * from école \ No newline at end of file
diff --git a/tests/data/lexUtf8.out b/tests/data/lexUtf8.out
new file mode 100644
index 0000000..a930264
--- /dev/null
+++ b/tests/data/lexUtf8.out
@@ -0,0 +1 @@
+a:2:{s:5:"lexer";O:15:"SqlParser\Lexer":8:{s:6:"strict";b:0;s:3:"str";O:19:"SqlParser\UtfString":5:{s:3:"str";s:20:"select * from école";s:7:"byteIdx";i:19;s:7:"charIdx";i:18;s:7:"byteLen";i:20;s:7:"charLen";i:19;}s:3:"len";i:19;s:4:"last";i:19;s:4:"list";O:20:"SqlParser\TokensList":3:{s:6:"tokens";a:8:{i:0;O:15:"SqlParser\Token":5:{s:5:"token";s:6:"select";s:5:"value";s:6:"SELECT";s:4:"type";i:1;s:5:"flags";i:3;s:8:"position";i:0;}i:1;O:15:"SqlParser\Token":5:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:6;}i:2;O:15:"SqlParser\Token":5:{s:5:"token";s:1:"*";s:5:"value";s:1:"*";s:4:"type";i:2;s:5:"flags";i:1;s:8:"position";i:7;}i:3;O:15:"SqlParser\Token":5:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:8;}i:4;O:15:"SqlParser\Token":5:{s:5:"token";s:4:"from";s:5:"value";s:4:"FROM";s:4:"type";i:1;s:5:"flags";i:3;s:8:"position";i:9;}i:5;O:15:"SqlParser\Token":5:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:13;}i:6;O:15:"SqlParser\Token":5:{s:5:"token";s:6:"école";s:5:"value";s:6:"école";s:4:"type";i:0;s:5:"flags";i:0;s:8:"position";i:14;}i:7;O:15:"SqlParser\Token":5:{s:5:"token";N;s:5:"value";N;s:4:"type";i:9;s:5:"flags";i:0;s:8:"position";N;}}s:5:"count";i:8;s:3:"idx";i:0;}s:9:"delimiter";s:1:";";s:12:"delimiterLen";i:1;s:6:"errors";a:0:{}}s:6:"errors";a:0:{}} \ No newline at end of file