check.php
43 lines
| 1 | <?php |
| 2 | require_once __DIR__ . '/../src/MultiStringMatcher.php'; |
| 3 | require_once __DIR__ . '/../src/MultiStringReplacer.php'; |
| 4 | |
| 5 | use AhoCorasick\MultiStringReplacer; |
| 6 | |
| 7 | if ( !file_exists( __DIR__ . '/23835-0.txt' ) ) { |
| 8 | die( 'Please download http://www.gutenberg.org/files/23835/23835-0.txt' ); |
| 9 | } |
| 10 | |
| 11 | if ( !file_exists( __DIR__ . '/ZhConversion.php' ) ) { |
| 12 | die( 'You need ZhConversion.php, from http://git.io/vIMst' ); |
| 13 | } |
| 14 | |
| 15 | require_once __DIR__ . '/ZhConversion.php'; |
| 16 | |
| 17 | $text = file_get_contents( __DIR__ . '/23835-0.txt' ); |
| 18 | |
| 19 | $status = 0; |
| 20 | $expected = strtr( $text, $zh2Hant ); |
| 21 | |
| 22 | echo "MultiStringReplacer::searchAndReplace(): "; |
| 23 | $replacer = new MultiStringReplacer( $zh2Hant ); |
| 24 | if ( $replacer->searchAndReplace( $text ) !== $expected ) { |
| 25 | echo "ERROR\n"; |
| 26 | $status = 1; |
| 27 | } else { |
| 28 | echo "OK\n"; |
| 29 | } |
| 30 | |
| 31 | if ( function_exists( 'fss_exec_replace' ) ) { |
| 32 | echo "fss_exec_replace(): "; |
| 33 | $fss = fss_prep_replace( $zh2Hant ); |
| 34 | if ( fss_exec_replace( $fss, $text ) !== $expected ) { |
| 35 | echo "ERROR\n"; |
| 36 | $status = 1; |
| 37 | } else { |
| 38 | echo "OK\n"; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | exit( $status ); |
| 43 |