Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generalize test suite and add better documentation
- Loading branch information
Dave Pacheco
committed
Jul 30, 2012
1 parent
445a5b3
commit aefbc95
Showing
10 changed files
with
187 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env node | ||
|
||
var mod_fs = require('fs'); | ||
|
||
var strsplit = require('../lib/strsplit'); | ||
var buffer = ''; | ||
|
||
process.stdin.resume(); | ||
process.stdin.on('data', function (chunk) { | ||
var i, line; | ||
|
||
buffer += chunk.toString('utf8'); | ||
|
||
i = buffer.indexOf('\n'); | ||
while (i != -1) { | ||
line = buffer.substr(0, i); | ||
buffer = buffer.substr(i + 1); | ||
i = buffer.indexOf('\n'); | ||
processLine(line); | ||
} | ||
}); | ||
|
||
function processLine(line) | ||
{ | ||
var parts, rv; | ||
|
||
if (line.length === 0 || line[0] == '#') { | ||
console.log(line); | ||
return; | ||
} | ||
|
||
parts = line.split(';'); | ||
if (parts.length != 3) { | ||
console.log('line garbled: %s', line); | ||
return; | ||
} | ||
|
||
rv = strsplit(parts[2], new RegExp(parts[1]), Math.floor(parts[0])); | ||
console.log(rv.join(';')); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env node | ||
|
||
/* | ||
* JavaScript-special test cases. These are required to test string patterns | ||
* rather than regular expressions. | ||
*/ | ||
|
||
var mod_assert = require('assert'); | ||
var strsplit = require('../lib/strsplit'); | ||
|
||
/* basic case with string pattern (uses String.split) */ | ||
mod_assert.deepEqual([ 'one', 'two', 'three' ], | ||
strsplit('one two three', ' ')); | ||
|
||
/* limit ineffective, simple cases */ | ||
mod_assert.deepEqual([ 'one', 'two', 'three', 'four', 'five' ], | ||
strsplit('one two three four five', ' ', 10)); | ||
mod_assert.deepEqual([ 'one', 'two three', 'four', 'five' ], | ||
strsplit('one two three four five', ' ', 10)); | ||
|
||
/* limit ineffective, empty fields */ | ||
mod_assert.deepEqual([ 'one', 'two', '', 'three' ], | ||
strsplit('one two three', ' ', 10)); | ||
|
||
/* regexp escaping for string patterns */ | ||
mod_assert.deepEqual([ 'one', 'two', 'three' ], | ||
strsplit('one.two.three', '.', 10)); | ||
mod_assert.deepEqual([ '', '', '', '', 'two.three' ], | ||
strsplit('one.two.three', /./, 5)); | ||
|
||
/* limit effective */ | ||
mod_assert.deepEqual([ 'one', 'two three' ], | ||
strsplit('one two three', ' ', 2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# The main test suite for strsplit is to run the body of test cases in | ||
# ../survey/ and compare the output to that of Java and Perl, whose | ||
# implementations we intend to mirror exactly. errexit will cause this script | ||
# to exit with failure if any of these operations fail. | ||
# | ||
set -o errexit | ||
|
||
surveydir=$(dirname $0)/../survey | ||
|
||
set -o xtrace | ||
make -C $surveydir perl.csv java.csv js-strsplit.csv | ||
diff $surveydir/js-strsplit.csv $surveydir/perl.csv > /dev/null | ||
diff $surveydir/js-strsplit.csv $surveydir/java.csv > /dev/null | ||
set +o xtrace | ||
|
||
echo "Test PASSED" |