Diffs
Acme_BrainPhack/trunk/test/MemoryStack_TestCase.php
@@ -0,0 +1,180 @@
+<?php
+/*
+ * Copyright (c) 2010 msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.*
+ */
+
+/**
+ * @package Acme_BrainPhack
+ * @author msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ * @version $Id$
+ */
+
+/**
+ * requires
+ */
+require_once('Acme/BrainPhack/MemoryStack.php');
+
+class MemoryStack_TestCase extends UnitTestCase
+{
+
+ function testConstructorAndPointerIncDec()
+ {
+ // create 3 sized memory stack
+ $bpms =& new Acme_BrainPhack_MemoryStack(3);
+
+ // decrement -> lesser than 0, return false
+ $r = $bpms->ptr_dec();
+ $this->assertIdentical(false, $r);
+
+ list($old, $new) = $bpms->ptr_inc();
+ $this->assertIdentical(0, $old);
+ $this->assertIdentical(1, $new);
+
+ list($old, $new) = $bpms->ptr_inc();
+ $this->assertIdentical(1, $old);
+ $this->assertIdentical(2, $new);
+
+ list($old, $new) = $bpms->ptr_inc();
+ $this->assertIdentical(2, $old);
+ $this->assertIdentical(3, $new);
+
+ // increment -> size over, return false
+ $r = $bpms->ptr_inc();
+ $this->assertIdentical(false, $r);
+
+ list($old, $new) = $bpms->ptr_dec();
+ $this->assertIdentical(3, $old);
+ $this->assertIdentical(2, $new);
+
+ list($old, $new) = $bpms->ptr_dec();
+ $this->assertIdentical(2, $old);
+ $this->assertIdentical(1, $new);
+
+ list($old, $new) = $bpms->ptr_dec();
+ $this->assertIdentical(1, $old);
+ $this->assertIdentical(0, $new);
+ }
+
+ function testGetterSetterAndMemoryInitialize()
+ {
+ // default, initialized by 0
+ $bpms =& new Acme_BrainPhack_MemoryStack(3);
+ $r = $bpms->get();
+ $this->assertIdentical(0, $r);
+ $bpms->ptr_inc();
+ $r = $bpms->get();
+ $this->assertIdentical(0, $r);
+ $bpms->ptr_inc();
+ $r = $bpms->get();
+ $this->assertIdentical(0, $r);
+
+ // initialized by 1
+ $bpms =& new Acme_BrainPhack_MemoryStack(3, 1);
+ $r = $bpms->get();
+ $this->assertIdentical(1, $r);
+ $bpms->ptr_inc();
+ $r = $bpms->get();
+ $this->assertIdentical(1, $r);
+ $bpms->ptr_inc();
+ $r = $bpms->get();
+ $this->assertIdentical(1, $r);
+
+ // initialized by 'A'
+ $bpms =& new Acme_BrainPhack_MemoryStack(3, 'A');
+ $r = $bpms->get();
+ $this->assertIdentical('A', $r);
+ $bpms->ptr_inc();
+ $r = $bpms->get();
+ $this->assertIdentical('A', $r);
+ $bpms->ptr_inc();
+ $r = $bpms->get();
+ $this->assertIdentical('A', $r);
+
+ // setter test
+ $old = $bpms->set('B');
+ $this->assertIdentical('A', $r);
+ $r = $bpms->get();
+ $this->assertIdentical('B', $r);
+
+ // get/set with pointer address
+ $r = $bpms->get(1);
+ $this->assertIdentical('A', $r);
+ $old = $bpms->set('C', 1);
+ $this->assertIdentical('A', $r);
+ $r = $bpms->get(1);
+ $this->assertIdentical('C', $r);
+ $r = $bpms->get(2);
+ $this->assertIdentical('B', $r);
+ }
+
+ function testGetterSetterNearBorder()
+ {
+ // size = 3, address range = 0 - 2.
+ $bpms =& new Acme_BrainPhack_MemoryStack(3);
+
+ // < 0
+ $r = $bpms->get(-1);
+ $this->assertIdentical(false, $r);
+ $r = $bpms->get(-2);
+ $this->assertIdentical(false, $r);
+ $r = $bpms->set(100, -1);
+ $this->assertIdentical(false, $r);
+ $r = $bpms->set(100, -2);
+ $this->assertIdentical(false, $r);
+
+ // > 3
+ $r = $bpms->get(3);
+ $this->assertIdentical(false, $r);
+ $r = $bpms->get(4);
+ $this->assertIdentical(false, $r);
+ $r = $bpms->set(100, 3);
+ $this->assertIdentical(false, $r);
+ $r = $bpms->set(100, 4);
+ $this->assertIdentical(false, $r);
+
+
+ }
+
+ function testClearReset()
+ {
+ $INIT = 2;
+ // init value = 2
+ $bpms =& new Acme_BrainPhack_MemoryStack(3, $INIT);
+ $bpms->set(9); $bpms->ptr_inc();
+ $bpms->set(8); $bpms->ptr_inc();
+ $bpms->set(7); $bpms->ptr_inc();
+ $bpms->clear_reset();
+ // test memory stack is initialized.
+ for ($i = 0; false !== ($r = $bpms->get($i)); $i++) {
+ $this->assertIdentical($INIT, $r);
+ }
+ // test pointer is reset.
+ list($old, $new) = $bpms->ptr_inc();
+ $this->assertIdentical(0, $old);
+ $this->assertIdentical(1, $new);
+ }
+}
+
+/**
+ * Local Variables:
+ * mode: php
+ * coding: iso-8859-1
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * indent-tabs-mode: nil
+ * End:
+ * vim: set expandtab tabstop=4 shiftwidth=4:
+ */
属性に変更があったパス: Acme_BrainPhack/trunk/test/MemoryStack_TestCase.php
___________________________________________________________________
名前: svn:keywords
+ Id
Acme_BrainPhack/trunk/test/Interpreter_TestCase.php
@@ -0,0 +1,390 @@
+<?php
+/*
+ * Copyright (c) 2010 msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.*
+ */
+
+/**
+ * @package Acme_BrainPhack
+ * @author msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ * @version $Id$
+ */
+
+/**
+ * requires
+ */
+require_once('PEAR/ErrorStack.php');
+require_once('Acme/BrainPhack/MemoryStack.php');
+require_once('Acme/BrainPhack/Interpreter.php');
+
+class Interpreter_TestCase extends UnitTestCase
+{
+ // {{{ testConstructorAndSomeShortIllegalSrc()
+
+ function testConstructorAndSomeShortIllegalSrc()
+ {
+ $MEMORY_STACK_SZ = 5;
+ $INIT = '0';
+ $bpms =& new Acme_BrainPhack_MemoryStack($MEMORY_STACK_SZ, $INIT);
+ $es =& new PEAR_ErrorStack('test');
+
+ $bpi =& new Acme_BrainPhack_Interpreter($bpms, $es);
+
+ $this->assertIdentical($bpi->isStdinReady(), true);
+ $bpi->disableStdin();
+ $this->assertIdentical($bpi->isStdinReady(), false);
+ $bpi->enableStdin();
+ $this->assertIdentical($bpi->isStdinReady(), true);
+
+ // empty source code
+ $s = '';
+ $r = $bpi->run($s);
+ $this->assertIdentical($r, true);
+ for ($i = 0; $i < $MEMORY_STACK_SZ; $i++) {
+ $this->assertIdentical($bpms->get($i), $INIT);
+ }
+ $errors = $es->getErrors(true);
+ $this->assertIdentical(count($errors), 0);
+
+ // only illegal character
+ $s = '*';
+ $r = $bpi->run($s);
+ $this->assertIdentical($r, true);
+ $r = $es->pop();
+ $this->assertEqual($r['code'], ACME_BRAINPHACK_EC_ILLEGAL_CHAR);
+ $this->assertEqual($r['level'], ACME_BRAINPHACK_EL_INFO);
+ $this->assertEqual($r['params'][0], 0);
+ $this->assertEqual($r['params'][1], '*');
+ $this->assertEqual($r['message'], 'Illegal Character.');
+ // there're no other errors
+ $errors = $es->getErrors(true);
+ $this->assertIdentical(count($errors), 0);
+
+ // only some illegal character
+ $s = '12345';
+ $r = $bpi->run($s);
+ $this->assertIdentical($r, true);
+ for ($i = 5; $i >= 1; $i--) {
+ $r = $es->pop();
+ $this->assertEqual($r['code'], ACME_BRAINPHACK_EC_ILLEGAL_CHAR);
+ $this->assertEqual($r['level'], ACME_BRAINPHACK_EL_INFO);
+ $this->assertEqual($r['params'][0], $i - 1);
+ $this->assertEqual($r['params'][1], $i);
+ $this->assertEqual($r['message'], 'Illegal Character.');
+ }
+ // there're no other errors
+ $errors = $es->getErrors(true);
+ $this->assertIdentical(count($errors), 0);
+ }
+
+ // }}}
+ // {{{ testIncDecAndPrintOps()
+
+ function testIncDecAndPrintOps()
+ {
+ $MEMORY_STACK_SZ = 5;
+ $INIT = 0;
+ $bpms =& new Acme_BrainPhack_MemoryStack($MEMORY_STACK_SZ, $INIT);
+ $es =& new PEAR_ErrorStack('test');
+
+ $bpi =& new Acme_BrainPhack_Interpreter($bpms, $es);
+
+ $s = '+>++++->+++++--<-<.>.>.';
+ $expected = sprintf('%c%c%c', 1, 2, 3);
+ ob_start();
+ $r = $bpi->run($s);
+ $r = ob_get_clean();
+ $this->assertIdentical($r, $expected);
+ // no errors
+ $errors = $es->getErrors(true);
+ $this->assertIdentical(count($errors), 0);
+ // check memory stack
+ $this->assertIdentical($bpms->get(0), 1);
+ $this->assertIdentical($bpms->get(1), 2);
+ $this->assertIdentical($bpms->get(2), 3);
+ $this->assertIdentical($bpms->get(3), $INIT);
+ $this->assertIdentical($bpms->get(4), $INIT);
+
+ $bpms->clear_reset();
+
+ // include some illegal characters
+ $s = '+>/++++->*+++?++--<-<.>.>.';
+ $expected = sprintf('%c%c%c', 1, 2, 3);
+ ob_start();
+ $r = $bpi->run($s);
+ $r = ob_get_clean();
+ $this->assertIdentical($r, $expected);
+ // no errors
+ $r = $es->pop();
+ $this->assertEqual($r['code'], ACME_BRAINPHACK_EC_ILLEGAL_CHAR);
+ $this->assertEqual($r['level'], ACME_BRAINPHACK_EL_INFO);
+ $this->assertEqual($r['params'][0], 13);
+ $this->assertEqual($r['params'][1], '?');
+ $r = $es->pop();
+ $this->assertEqual($r['code'], ACME_BRAINPHACK_EC_ILLEGAL_CHAR);
+ $this->assertEqual($r['level'], ACME_BRAINPHACK_EL_INFO);
+ $this->assertEqual($r['params'][0], 9);
+ $this->assertEqual($r['params'][1], '*');
+ $r = $es->pop();
+ $this->assertEqual($r['code'], ACME_BRAINPHACK_EC_ILLEGAL_CHAR);
+ $this->assertEqual($r['level'], ACME_BRAINPHACK_EL_INFO);
+ $this->assertEqual($r['params'][0], 2);
+ $this->assertEqual($r['params'][1], '/');
+ // there're no other errors
+ $errors = $es->getErrors(true);
+ $this->assertIdentical(count($errors), 0);
+ // check memory stack
+ $this->assertIdentical($bpms->get(0), 1);
+ $this->assertIdentical($bpms->get(1), 2);
+ $this->assertIdentical($bpms->get(2), 3);
+ $this->assertIdentical($bpms->get(3), $INIT);
+ $this->assertIdentical($bpms->get(4), $INIT);
+ }
+
+ // }}}
+ // {{{ testAddressIncDecRangeError()
+
+ function testAddressIncDecRangeError()
+ {
+ $MEMORY_STACK_SZ = 3;
+ $INIT = 0;
+ $bpms =& new Acme_BrainPhack_MemoryStack($MEMORY_STACK_SZ, $INIT);
+ $es =& new PEAR_ErrorStack('test');
+
+ $bpi =& new Acme_BrainPhack_Interpreter($bpms, $es);
+
+ $s = '<';
+ $r = $bpi->run($s);
+ $this->assertIdentical($r, false);
+ $r = $es->pop();
+ $this->assertEqual($r['code'], ACME_BRAINPHACK_EC_PTR_DEC);
+ $this->assertEqual($r['level'], ACME_BRAINPHACK_EL_ERROR);
+ $this->assertEqual($r['params'][0], 0);
+
+ // there're no other errors
+ $errors = $es->getErrors(true);
+ $this->assertIdentical(count($errors), 0);
+
+ $bpms->clear_reset();
+
+ $s = '>>>>';
+ $r = $bpi->run($s);
+ $this->assertIdentical($r, false);
+ $r = $es->pop();
+ $this->assertEqual($r['code'], ACME_BRAINPHACK_EC_PTR_INC);
+ $this->assertEqual($r['level'], ACME_BRAINPHACK_EL_ERROR);
+ $this->assertEqual($r['params'][0], 3);
+
+ // there're no other errors
+ $errors = $es->getErrors(true);
+ $this->assertIdentical(count($errors), 0);
+ }
+
+ // }}}
+ // {{{ testBracket()
+
+ function testBracket()
+ {
+ $MEMORY_STACK_SZ = 5;
+ $INIT = 0;
+ $bpms =& new Acme_BrainPhack_MemoryStack($MEMORY_STACK_SZ, $INIT);
+ $es =& new PEAR_ErrorStack('test');
+
+ $bpi =& new Acme_BrainPhack_Interpreter($bpms, $es);
+
+ $s = '+++[>+<-]>.';
+ $expected = sprintf('%c', 3);
+ ob_start();
+ $r = $bpi->run($s);
+ $r = ob_get_clean();
+ $this->assertIdentical($r, $expected);
+ // no errors
+ $errors = $es->getErrors(true);
+ $this->assertIdentical(count($errors), 0);
+ // check memory stack
+ $this->assertIdentical($bpms->get(0), $INIT);
+ $this->assertIdentical($bpms->get(1), 3);
+ $this->assertIdentical($bpms->get(2), $INIT);
+ $this->assertIdentical($bpms->get(3), $INIT);
+ $this->assertIdentical($bpms->get(4), $INIT);
+ }
+
+ // }}}
+ // {{{ testBracketLackError()
+
+ function testBracketLackError()
+ {
+ $MEMORY_STACK_SZ = 3;
+ $INIT = 0;
+ $bpms =& new Acme_BrainPhack_MemoryStack($MEMORY_STACK_SZ, $INIT);
+ $es =& new PEAR_ErrorStack('test');
+
+ $bpi =& new Acme_BrainPhack_Interpreter($bpms, $es);
+
+ // #1
+ $s = '[';
+ $r = $bpi->run($s);
+ $this->assertIdentical($r, false);
+ $r = $es->pop();
+ $this->assertEqual($r['code'], ACME_BRAINPHACK_EC_LACK_RBRACKET);
+ $this->assertEqual($r['level'], ACME_BRAINPHACK_EL_ERROR);
+ $this->assertEqual($r['params'][0], 0);
+ // there're no other errors
+ $errors = $es->getErrors(true);
+ $this->assertIdentical(count($errors), 0);
+
+ $bpms->clear_reset();
+
+ // #2
+ $s = '+]';
+ $r = $bpi->run($s);
+ $this->assertIdentical($r, false);
+ $r = $es->pop();
+ $this->assertEqual($r['code'], ACME_BRAINPHACK_EC_LACK_LBRACKET);
+ $this->assertEqual($r['level'], ACME_BRAINPHACK_EL_ERROR);
+ $this->assertEqual($r['params'][0], 1);
+ // there're no other errors
+ $errors = $es->getErrors(true);
+ $this->assertIdentical(count($errors), 0);
+
+ $bpms->clear_reset();
+
+ // #3
+ $s = '+++---[';
+ $r = $bpi->run($s);
+ $this->assertIdentical($r, false);
+ $r = $es->pop();
+ $this->assertEqual($r['code'], ACME_BRAINPHACK_EC_LACK_RBRACKET);
+ $this->assertEqual($r['level'], ACME_BRAINPHACK_EL_ERROR);
+ $this->assertEqual($r['params'][0], 6);
+ $this->assertEqual($r['message'], "']' not found for '[' at 6");
+ // there're no other errors
+ $errors = $es->getErrors(true);
+ $this->assertIdentical(count($errors), 0);
+
+ $bpms->clear_reset();
+
+ // #4
+ $s = '+++]';
+ $r = $bpi->run($s);
+ $this->assertIdentical($r, false);
+ $r = $es->pop();
+ $this->assertEqual($r['code'], ACME_BRAINPHACK_EC_LACK_LBRACKET);
+ $this->assertEqual($r['level'], ACME_BRAINPHACK_EL_ERROR);
+ $this->assertEqual($r['params'][0], 3);
+ $this->assertEqual($r['message'], "'[' not found for ']' at 3");
+ // there're no other errors
+ $errors = $es->getErrors(true);
+ $this->assertIdentical(count($errors), 0);
+
+ }
+
+ // }}}
+ // {{{ testHelloWorld1()
+
+ function testHelloWorld1()
+ {
+ $MEMORY_STACK_SZ = 1024;
+ $INIT = 0;
+ $bpms =& new Acme_BrainPhack_MemoryStack($MEMORY_STACK_SZ, $INIT);
+ $es =& new PEAR_ErrorStack('test');
+
+ $bpi =& new Acme_BrainPhack_Interpreter($bpms, $es);
+
+ // stupid BrainF*ck "Hello, World!"
+ $s =
+ '++++++++[>++++++++<-]>++++++++.>'. // 'H' = 72
+ '++++++++++[>++++++++++<-]>+.>'. // 'e' = 101
+ '++++++++++[>+++++++++++<-]>--..>'. // 'l' = 108 x 2
+ '++++++++++[>+++++++++++<-]>+.>'. // 'o' = 111
+ '++++++++++[>++++<-]>++++.>'. // ',' = 44
+ '++++++++++[>+++<-]>++.>'. // ' ' = 32
+ '++++++++++[>++++++++<-]>+++++++.>'. // 'W' = 72
+ '++++++++++[>+++++++++++<-]>+.>'. // 'o' = 111
+ '++++++++++[>+++++++++++<-]>++++.>'. // 'r' = 114
+ '++++++++++[>+++++++++++<-]>--.>'. // 'l' = 108
+ '++++++++++[>++++++++++<-]>.>'. // 'd' = 100
+ '++++++++++[>+++<-]>+++.>'; // '!' = 33
+ ob_start();
+ $r = $bpi->run($s);
+ $r = ob_get_clean();
+ $this->assertIdentical($r, 'Hello, World!');
+ // no errors
+ $errors = $es->getErrors(true);
+ $this->assertIdentical(count($errors), 0);
+ }
+
+ // }}}
+ // {{{ testHelloWorld2()
+
+ function testHelloWorld2()
+ {
+ $MEMORY_STACK_SZ = 1024;
+ $INIT = 0;
+ $bpms =& new Acme_BrainPhack_MemoryStack($MEMORY_STACK_SZ, $INIT);
+ $es =& new PEAR_ErrorStack('test');
+
+ $bpi =& new Acme_BrainPhack_Interpreter($bpms, $es);
+
+ // from ja.wikipedia.org
+ $s =
+ '+++++++++[>++++++++>+++++++++++>+++++<<<-]>.'.
+ '>++.+++++++..+++.>-.------------.<++++++++.'.
+ '--------.+++.------.--------.>+.';
+ ob_start();
+ $r = $bpi->run($s);
+ $r = ob_get_clean();
+ $this->assertIdentical($r, 'Hello, world!');
+ // no errors
+ $errors = $es->getErrors(true);
+ $this->assertIdentical(count($errors), 0);
+ }
+
+ // }}}
+ // {{{ testIgnoresInputWhenStdinNotReady()
+
+ function testIgnoresInputWhenStdinNotReady()
+ {
+ $MEMORY_STACK_SZ = 5;
+ $INIT = 0;
+ $bpms =& new Acme_BrainPhack_MemoryStack($MEMORY_STACK_SZ, $INIT);
+ $es =& new PEAR_ErrorStack('test');
+
+ $bpi =& new Acme_BrainPhack_Interpreter($bpms, $es);
+
+ $bpi->disableStdin();
+
+ $s = '+++,+++';
+ $r = $bpi->run($s);
+ $this->assertIdentical($r, true);
+ $this->assertIdentical($bpms->get(0), 6);
+ // no errors
+ $errors = $es->getErrors(true);
+ $this->assertIdentical(count($errors), 0);
+ }
+
+ // }}}
+}
+
+/**
+ * Local Variables:
+ * mode: php
+ * coding: iso-8859-1
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * indent-tabs-mode: nil
+ * End:
+ * vim: set expandtab tabstop=4 shiftwidth=4:
+ */
属性に変更があったパス: Acme_BrainPhack/trunk/test/Interpreter_TestCase.php
___________________________________________________________________
名前: svn:keywords
+ Id
Acme_BrainPhack/trunk/test/stdin_test.php
@@ -0,0 +1,59 @@
+<?php
+/*
+ * Copyright (c) 2010 msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.*
+ */
+
+/**
+ * @package Acme_BrainPhack
+ * @author msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ * @version $Id$
+ */
+
+$include_path = ini_get('include_path');
+//$__pear_src_dir = realpath(dirname(__FILE__).'/../');
+$__pear_src_dir = realpath(dirname(__FILE__).'/../../../'); // TODO
+ini_set('include_path', $__pear_src_dir.PATH_SEPARATOR.$include_path);
+
+require_once('PEAR/ErrorStack.php');
+require_once('Acme/BrainPhack/MemoryStack.php');
+require_once('Acme/BrainPhack/Interpreter.php');
+
+// ACME_BRAINPHACK_OP_INPUT(',') manual test from php-cli
+
+$MEMORY_STACK_SZ = 5;
+$INIT = 0;
+$bpms =& new Acme_BrainPhack_MemoryStack($MEMORY_STACK_SZ, $INIT);
+$es =& new PEAR_ErrorStack('test');
+
+$bpi =& new Acme_BrainPhack_Interpreter($bpms, $es);
+
+echo "input one char:";
+$s = ',.';
+ob_start();
+$r = $bpi->run($s);
+$o = ob_get_clean();
+echo "\nconfirm: your input is [" . $o . "]\n";
+
+/**
+ * Local Variables:
+ * mode: php
+ * coding: iso-8859-1
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * indent-tabs-mode: nil
+ * End:
+ * vim: set expandtab tabstop=4 shiftwidth=4:
+ */
属性に変更があったパス: Acme_BrainPhack/trunk/test/stdin_test.php
___________________________________________________________________
名前: svn:keywords
+ Id
Acme_BrainPhack/trunk/test/testsrc/HelloWorld_Jojo_Dio.txt
表示できません: バイナリ形式としてマークされたファイルです。
svn:mime-type = application/octet-stream
属性に変更があったパス: Acme_BrainPhack/trunk/test/testsrc/HelloWorld_Jojo_Dio.txt
___________________________________________________________________
名前: svn:mime-type
+ application/octet-stream
Acme_BrainPhack/trunk/test/testsrc/HelloWorld_None.txt
@@ -0,0 +1,5 @@
+# default mapping HelloWorld and input & output a character
++++++++++[>++++++++>+++++++++++>+++++<<<-]>.
+>++.+++++++..+++.>-.------------.<++++++++.
+--------.+++.------.--------.>+.
+,.
\ ファイルの末尾に改行がありません
Acme_BrainPhack/trunk/test/testsrc/HelloWorld_Yaruo_Detteiu.txt
@@ -0,0 +1,80 @@
+# default mapping HelloWorld and input & output a character
+PHPでっていう
+今更っていう
+しかもBrainF*ckでっていう
+遅すぎっていう
+ネタ狙いすぎっていう
+何様っていう
+所詮自己満足っていう
+でも楽しんでくれたらラッキーっていう
+ででででっていう。
+
+ギロッ
+
+しかもパッケージが"Acme"系列ワロスっていう。
+ジョークPEARかっていう。
+折角だから草生やしてみるっていうwwwww
+半角なら問題ないっていうwwwwwww
+でででっていうでっていう
+でででででっていう
+
+でっていう大杉テラワロス。
+これでもHelloWorldかっていうwwww
+
+そうはいってもっていう
+結構難しいっていう
+"+"の数大杉っていう
+うまくつなげるのがムズイっていう
+いつまで "っていう" が続くのかっていうwwww
+でっていうマジウゼェ言われるのも納得っていうwwww
+でででっていうででっていう
+
+まだ続くワロスっていう。
+「でででっていうででっていう」で稼ぐしかないっていう。
+笑ってみるしかないっていう。
+
+ニヤニヤニヤニヤニヤニヤwww
+
+キリッ
+ワロス
+ププッ
+
+真面目顔ワロスっていうwww
+ででででっていう。
+ププッ
+でっていう。
+
+Translatorのアイデア自体は悪くないかもっていう。
+でもTranslatorの調整がめんどいっていう。
+どうしても"+"が多くなるっていう。
+"+"と"-"のバランスも難しいっていう。
+下手に「っていう」みたいな語尾を"+"にするとマジウザイっていうププッ。
+
+ププッ ザマァっていう。
+
+ででででっていうでっていう
+
+マジウゼェ ププッ テラワロスwww
+
+しかも"-"の数もププッ出てくる時は大量に出過ぎwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwププッ
+ニヤニヤ
+どんだけ草生やす気っていうででででっていう。
+調整ムズスギっていう。
+ででででっていうでっていう。
+少し手抜きさせてほしいっていう。
+もう少しっていう。
+マジHelloWorldだけでウザっていう。ププッ
+wwwwwwwwwwwwwwwwwwwwwwww
+ププッ 草生やすのも大変っていう。
+でっていうででででっていう
+ププッ
+ステガノグラフィにしても手間かかりスギwwwwwwwwwwwwwwwwww
+ププッwwwwwwwwwwwwwwwwwwwwwwww
+ププッワロス
+あと少しっていう。
+ププッ
+
+以下、1文字入力して1文字表示。
+
+「や ら な い か」
+「ププッ」
Acme_BrainPhack/trunk/test/Translator_TestCase.php
@@ -0,0 +1,330 @@
+<?php
+/*
+ * Copyright (c) 2010 msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.*
+ */
+
+/**
+ * @package Acme_BrainPhack
+ * @author msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ * @version $Id$
+ */
+
+/**
+ * requires
+ */
+require_once('Acme/BrainPhack/Translator.php');
+
+class Translator_TestCase extends UnitTestCase
+{
+
+ function setUp()
+ {
+ mb_internal_encoding('UTF-8');
+ }
+
+ // {{{ testOriginalBrainFuck()
+
+ function testOriginalBrainFuck()
+ {
+ $bpt =& new Acme_BrainPhack_Translator();
+
+ $map = array(
+ '+' => '+',
+ '-' => '-',
+ '>' => '>',
+ '<' => '<',
+ '.' => '.',
+ ',' => ',',
+ '[' => '[',
+ ']' => ']',
+ );
+ $src = '';
+ $r = $bpt->translate($map, $src);
+ $this->assertIdentical($r, '');
+
+ $src = '?';
+ $r = $bpt->translate($map, $src);
+ $this->assertIdentical($r, '');
+
+ $src = '][,.<>-+';
+ $r = $bpt->translate($map, $src);
+ $this->assertIdentical($r, $src);
+
+ $src = '+-><.,[]';
+ $r = $bpt->translate($map, $src);
+ $this->assertIdentical($r, $src);
+ }
+
+ // }}}
+ // {{{ testSimpleAlphabetTable()
+
+ function testSimpleAlphabetTable()
+ {
+ $bpt =& new Acme_BrainPhack_Translator();
+
+ $map = array(
+ '+' => 'A',
+ '-' => 'B',
+ );
+ $r = $bpt->translate($map, 'A');
+ $this->assertIdentical($r, '+');
+ $r = $bpt->translate($map, 'B');
+ $this->assertIdentical($r, '-');
+ $r = $bpt->translate($map, 'AB');
+ $this->assertIdentical($r, '+-');
+ $r = $bpt->translate($map, 'BA');
+ $this->assertIdentical($r, '-+');
+
+ $map = array(
+ '+' => 'ABC',
+ '-' => 'DEF',
+ );
+ $src = '';
+ $r = $bpt->translate($map, $src);
+ $this->assertIdentical($r, '');
+
+ $src = '?';
+ $r = $bpt->translate($map, $src);
+ $this->assertIdentical($r, '');
+
+ $src = 'ABC';
+ $r = $bpt->translate($map, $src);
+ $this->assertIdentical($r, '+');
+
+ $src = 'DEF';
+ $r = $bpt->translate($map, $src);
+ $this->assertIdentical($r, '-');
+
+ $src = 'ABCDEF';
+ $r = $bpt->translate($map, $src);
+ $this->assertIdentical($r, '+-');
+
+ $src = 'DEFABC';
+ $r = $bpt->translate($map, $src);
+ $this->assertIdentical($r, '-+');
+
+ $src = '? ABC - DEF //---';
+ $r = $bpt->translate($map, $src);
+ $this->assertIdentical($r, '+-');
+
+ $src = ' ABC - CDE - DEF DEF FABC';
+ $r = $bpt->translate($map, $src);
+ $this->assertIdentical($r, '+--+');
+ }
+
+ // }}}
+ // {{{ testMultibyte()
+
+ function testMultibyte()
+ {
+ $bpt =& new Acme_BrainPhack_Translator();
+
+ $map = array(
+ '+' => 'あ',
+ '-' => 'い',
+ );
+ $src = '';
+ $r = $bpt->translate($map, $src);
+ $this->assertIdentical($r, '');
+
+ $src = '?';
+ $r = $bpt->translate($map, $src);
+ $this->assertIdentical($r, '');
+
+ $src = 'あ';
+ $r = $bpt->translate($map, $src);
+ $this->assertIdentical($r, '+');
+
+ $src = 'い';
+ $r = $bpt->translate($map, $src);
+ $this->assertIdentical($r, '-');
+
+ $src = 'あい';
+ $r = $bpt->translate($map, $src);
+ $this->assertIdentical($r, '+-');
+
+ $src = 'いあ';
+ $r = $bpt->translate($map, $src);
+ $this->assertIdentical($r, '-+');
+
+ $src = '? あ - い //---';
+ $r = $bpt->translate($map, $src);
+ $this->assertIdentical($r, '+-');
+
+ $src = ' あ - い い かあ';
+ $r = $bpt->translate($map, $src);
+ $this->assertIdentical($r, '+--+');
+ }
+
+ // }}}
+ // {{{ testMultiWords()
+
+ function testMultiWords()
+ {
+ $bpt =& new Acme_BrainPhack_Translator();
+
+ $map = array(
+ '+' => array('A', 'B'),
+ '-' => 'C',
+ );
+ $r = $bpt->translate($map, '');
+ $this->assertIdentical($r, '');
+ $r = $bpt->translate($map, 'A');
+ $this->assertIdentical($r, '+');
+ $r = $bpt->translate($map, 'B');
+ $this->assertIdentical($r, '+');
+ $r = $bpt->translate($map, 'AB');
+ $this->assertIdentical($r, '++');
+ $r = $bpt->translate($map, 'BA');
+ $this->assertIdentical($r, '++');
+ $r = $bpt->translate($map, 'C');
+ $this->assertIdentical($r, '-');
+ $r = $bpt->translate($map, 'AC');
+ $this->assertIdentical($r, '+-');
+ $r = $bpt->translate($map, 'BC');
+ $this->assertIdentical($r, '+-');
+ $r = $bpt->translate($map, 'CA');
+ $this->assertIdentical($r, '-+');
+ $r = $bpt->translate($map, 'CB');
+ $this->assertIdentical($r, '-+');
+ $r = $bpt->translate($map, 'CC');
+ $this->assertIdentical($r, '--');
+ $r = $bpt->translate($map, 'ABC');
+ $this->assertIdentical($r, '++-');
+ $r = $bpt->translate($map, 'CBA');
+ $this->assertIdentical($r, '-++');
+
+ $map = array(
+ '+' => array('AB', 'CD'),
+ '-' => array('EF', 'GH'),
+ );
+ $r = $bpt->translate($map, '? EF - A - AB .. GH G H CD /');
+ $this->assertIdentical($r, '-+-+');
+ }
+
+ // }}}
+ // {{{ testMultiWordsByMultibyte()
+
+ function testMultiWordsByMultibyte()
+ {
+ $bpt =& new Acme_BrainPhack_Translator();
+
+ $map = array(
+ '+' => array('あ', 'い'),
+ '-' => 'う',
+ );
+ $r = $bpt->translate($map, '');
+ $this->assertIdentical($r, '');
+ $r = $bpt->translate($map, 'あ');
+ $this->assertIdentical($r, '+');
+ $r = $bpt->translate($map, 'い');
+ $this->assertIdentical($r, '+');
+ $r = $bpt->translate($map, 'あい');
+ $this->assertIdentical($r, '++');
+ $r = $bpt->translate($map, 'いあ');
+ $this->assertIdentical($r, '++');
+ $r = $bpt->translate($map, 'う');
+ $this->assertIdentical($r, '-');
+ $r = $bpt->translate($map, 'あう');
+ $this->assertIdentical($r, '+-');
+ $r = $bpt->translate($map, 'いう');
+ $this->assertIdentical($r, '+-');
+ $r = $bpt->translate($map, 'うあ');
+ $this->assertIdentical($r, '-+');
+ $r = $bpt->translate($map, 'うい');
+ $this->assertIdentical($r, '-+');
+ $r = $bpt->translate($map, 'うう');
+ $this->assertIdentical($r, '--');
+ $r = $bpt->translate($map, 'あいう');
+ $this->assertIdentical($r, '++-');
+ $r = $bpt->translate($map, 'ういあ');
+ $this->assertIdentical($r, '-++');
+
+ $map = array(
+ '+' => array('あい', 'うえ'),
+ '-' => array('かき', 'くけ'),
+ );
+ $r = $bpt->translate($map, '? かき - あ - あい .. くけ く け うえ');
+ $this->assertIdentical($r, '-+-+');
+ }
+
+ // }}}
+ // {{{ testMisa()
+
+ /**
+ * @see http://homepage2.nifty.com/kujira_niku/okayu/misa.html
+ */
+ function testMisa()
+ {
+ $bpt =& new Acme_BrainPhack_Translator();
+
+ $map = array(
+ '>' => array('>', '→', '~', 'ー'),
+ '>' => array('<', '←', '★', '☆'),
+ '+' => array('+', 'あ', 'ぁ', 'お', 'ぉ'),
+ '-' => array('-', 'っ', 'ッ'),
+ '.' => array('.', '!'),
+ ',' => array(',', '?'),
+ '[' => array('[', '「', '『'),
+ ']' => array(']', '」', '』'),
+ );
+
+ $src =<<<TEXT
+あおあおあお「~ああぁおおぉ☆っ」
+ここまでで6x8=48=アスキーコードとすれば文字列0!
+あ!あ!あ!あ!あ!あ!あ!あ!あ!
+TEXT;
+ $r = $bpt->translate($map, $src);
+ $this->assertIdentical($r, '++++++[++++++>-].+.+.+.+.+.+.+.+.+.');
+ }
+
+ // }}}
+ // {{{ testGetMapping()
+
+ function testGetMapping()
+ {
+ $bpt =& new Acme_BrainPhack_Translator();
+
+ // default
+ $bptm =& $bpt->getMapper();
+ $r = $bptm->getName();
+ $this->assertIdentical($r, 'Default BrainF*ck Translator mapping');
+
+ // JOJO's DIO
+ $bptm =& $bpt->getMapper('JOJO_Dio');
+ $r = $bptm->getName();
+ $this->assertIdentical($r, "JOJO's DIO mapping");
+
+ // Yaruo's Detteiu
+ $bptm =& $bpt->getMapper('Yaruo_Detteiu');
+ $r = $bptm->getName();
+ $this->assertIdentical($r, "Yaruo's 'でっていう' mapping");
+
+ }
+
+ // }}}
+}
+
+/**
+ * Local Variables:
+ * mode: php
+ * coding: iso-8859-1
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * indent-tabs-mode: nil
+ * End:
+ * vim: set expandtab tabstop=4 shiftwidth=4:
+ */
属性に変更があったパス: Acme_BrainPhack/trunk/test/Translator_TestCase.php
___________________________________________________________________
名前: svn:keywords
+ Id
Acme_BrainPhack/trunk/test/scripts_test.php
@@ -0,0 +1,48 @@
+<?php
+/*
+ * Copyright (c) 2010 msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.*
+ */
+
+/**
+ * @package Acme_BrainPhack
+ * @author msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ * @version $Id$
+ */
+
+// script file manual test bootstrap
+
+$include_path = ini_get('include_path');
+$__base_dir = realpath(dirname(__FILE__));
+//$__pear_src_dir = realpath($__base_dir.'/../');
+$__pear_src_dir = realpath($__base_dir.'/../../../'); // TODO
+ini_set('include_path',
+ $__base_dir.PATH_SEPARATOR.$__pear_src_dir.PATH_SEPARATOR.$include_path);
+
+// load and invoke script file
+$_script = realpath($__base_dir.'/../../../scripts/brainphack.sh');
+require_once($_script);
+
+/**
+ * Local Variables:
+ * mode: php
+ * coding: iso-8859-1
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * indent-tabs-mode: nil
+ * End:
+ * vim: set expandtab tabstop=4 shiftwidth=4:
+ */
+
属性に変更があったパス: Acme_BrainPhack/trunk/test/scripts_test.php
___________________________________________________________________
名前: svn:keywords
+ Id
Acme_BrainPhack/trunk/test/README
@@ -0,0 +1,18 @@
+* Acme_BrainPhack test code README
+
+Acme_BrainPhack test codes require "simpletest" php unit test library.
+see: http://simpletest.sourceforge.net/
+
+- all_test.php : Run unit tests for all Acme_BrainPhack classes,
+ except ","(read a char from stdin) instruction.
+
+- stdin_test.php : Run only "," instruction. Confirm input and output by hand..
+
+- scripts_test.php : Run scripts/brainphack.sh wrapper.
+ Try sample helloworlds in "testsrc" directory.
+
+For more details, read source codes.
+
+Thank you.
+
+Copyright 2010 sakamoto-gsyc-3s@glamenv-septzen.net
Acme_BrainPhack/trunk/test/all_test.php
@@ -0,0 +1,52 @@
+<?php
+/*
+ * Copyright (c) 2010 msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.*
+ */
+
+/**
+ * @package Acme_BrainPhack
+ * @author msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ * @version $Id$
+ */
+
+require_once('simpletest/unit_tester.php');
+require_once('simpletest/reporter.php');
+
+$include_path = ini_get('include_path');
+$__base_dir = realpath(dirname(__FILE__));
+//$__pear_src_dir = realpath($__base_dir.'/../');
+$__pear_src_dir = realpath($__base_dir.'/../../../'); // TODO
+ini_set('include_path',
+ $__base_dir.PATH_SEPARATOR.$__pear_src_dir.PATH_SEPARATOR.$include_path);
+
+$test = &new TestSuite('All tests');
+$test->addTestFile('MemoryStack_TestCase.php');
+$test->addTestFile('Interpreter_TestCase.php');
+$test->addTestFile('Translator_TestCase.php');
+$test->run(new TextReporter());
+
+
+/**
+ * Local Variables:
+ * mode: php
+ * coding: iso-8859-1
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * indent-tabs-mode: nil
+ * End:
+ * vim: set expandtab tabstop=4 shiftwidth=4:
+ */
+
属性に変更があったパス: Acme_BrainPhack/trunk/test/all_test.php
___________________________________________________________________
名前: svn:keywords
+ Id