summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2015-04-07 11:44:18 +0200
committerFlorian Pritz <bluewind@xinu.at>2015-04-07 11:44:18 +0200
commitd191251243863015f70f758d95c2dd02a9270484 (patch)
treecdc28d6ed5053939f8d7d7bc7369ee95f7307070 /application
parent312701cba9bf40d0699aec44752a9aec7cc1e9d5 (diff)
Test: Add pygments tests
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application')
-rw-r--r--application/tests/test_libraries_pygments.php82
1 files changed, 82 insertions, 0 deletions
diff --git a/application/tests/test_libraries_pygments.php b/application/tests/test_libraries_pygments.php
new file mode 100644
index 000000000..ba2103e50
--- /dev/null
+++ b/application/tests/test_libraries_pygments.php
@@ -0,0 +1,82 @@
+<?php
+/*
+ * Copyright 2015 Florian "Bluewind" Pritz <bluewind@server-speed.net>
+ *
+ * Licensed under AGPLv3
+ * (see COPYING for full license text)
+ *
+ */
+
+namespace tests;
+
+class test_libraries_pygments extends Test {
+
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+ public function init()
+ {
+ }
+
+ public function cleanup()
+ {
+ }
+
+ public function test_autodetect_lexer_normalCase()
+ {
+ $p = new \libraries\Pygments('/invalid/filepath', 'text/plain', 'stdin');
+ $this->t->is($p->autodetect_lexer(), 'text', "text/plain should be text");
+
+ $p = new \libraries\Pygments('/invalid/filepath', 'application/x-php', 'stdin');
+ $this->t->is($p->autodetect_lexer(), 'php', "application/php should be php");
+
+ $p = new \libraries\Pygments('/invalid/filepath', 'application/octet-stream', 'stdin');
+ $this->t->is($p->autodetect_lexer(), false, "application/octet-stream should return false");
+ }
+
+ public function test_autodetect_lexer_specialFilenames()
+ {
+ $p = new \libraries\Pygments('/invalid/filepath', 'text/plain', 'foo.c');
+ $this->t->is($p->autodetect_lexer(), 'c', "foo.c should be c");
+
+ $p = new \libraries\Pygments('/invalid/filepath', 'text/plain', 'PKGBUILD');
+ $this->t->is($p->autodetect_lexer(), 'bash', "PKGBUILD should be bash");
+ }
+
+ public function test_autodetect_lexer_specialFilenamesBinaryShouldNotHighlight()
+ {
+ $p = new \libraries\Pygments('/invalid/filepath', 'application/octet-stream', 'foo.c');
+ $this->t->is($p->autodetect_lexer(), false, "foo.c should not highlight if binary");
+
+ $p = new \libraries\Pygments('/invalid/filepath', 'application/octet-stream', 'PKGBUILD');
+ $this->t->is($p->autodetect_lexer(), false, "PKGBUILD should not highlight if binary");
+ }
+
+ public function test_can_highlight_normalCase()
+ {
+ $p = new \libraries\Pygments('/invalid/filepath', 'text/plain', 'stdin');
+ $this->t->is($p->can_highlight(), true, "text/plain can highlight");
+
+ $p = new \libraries\Pygments('/invalid/filepath', 'application/x-php', 'stdin');
+ $this->t->is($p->can_highlight(), true, "application/x-php can highlight");
+
+ $p = new \libraries\Pygments('/invalid/filepath', 'application/octet-stream', 'stdin');
+ $this->t->is($p->can_highlight(), false, "application/octet-stream can not highlight");
+ }
+
+ public function test_autodetect_lexer_canButShouldntHighlight()
+ {
+ $p = new \libraries\Pygments('/invalid/filepath', 'image/svg+xml', 'foo.svg');
+ $this->t->is($p->autodetect_lexer(), false, "image/svg+xml should return false");
+ }
+
+ public function test_can_highlight_canButShouldntHighlight()
+ {
+ $p = new \libraries\Pygments('/invalid/filepath', 'image/svg+xml', 'foo.svg');
+ $this->t->is($p->can_highlight(), true, "image/svg+xml can highlight");
+ }
+
+}
+