From ea7ca9b64fd38e2a3023b4e8568e6025d37f78bf Mon Sep 17 00:00:00 2001 From: Lloyd Hilaiel Date: Sat, 28 May 2011 16:36:39 -0600 Subject: [PATCH] move from in-tree tests to using them from the JSONSelectTests submodule. closes #16. --- .gitmodules | 3 + src/Makefile | 20 ++++++- src/test/run.js | 25 +++++---- src/test/tests | 2 +- tests/README.md | 14 ----- tests/alltests.txt | 31 ----------- tests/basic.json | 31 ----------- tests/basic_first-child.output | 2 - tests/basic_first-child.selector | 2 - tests/basic_grouping.output | 4 -- tests/basic_grouping.selector | 1 - tests/basic_id.output | 1 - tests/basic_id.selector | 1 - tests/basic_id_multiple.output | 3 - tests/basic_id_multiple.selector | 1 - tests/basic_id_quotes.output | 2 - tests/basic_id_quotes.selector | 1 - tests/basic_id_with_type.output | 1 - tests/basic_id_with_type.selector | 1 - tests/basic_last-child.output | 2 - tests/basic_last-child.selector | 2 - tests/basic_nth-child-2.output | 4 -- tests/basic_nth-child-2.selector | 1 - tests/basic_nth-child.output | 3 - tests/basic_nth-child.selector | 1 - tests/basic_nth-last-child.output | 2 - tests/basic_nth-last-child.selector | 1 - tests/basic_root_pseudo.output | 31 ----------- tests/basic_root_pseudo.selector | 1 - tests/basic_type.output | 14 ----- tests/basic_type.selector | 1 - tests/basic_type2.output | 1 - tests/basic_type2.selector | 1 - tests/basic_type3.output | 47 ---------------- tests/basic_type3.selector | 1 - tests/basic_universal.output | 85 ----------------------------- tests/basic_universal.selector | 1 - 37 files changed, 37 insertions(+), 308 deletions(-) create mode 100644 .gitmodules mode change 120000 => 160000 src/test/tests delete mode 100644 tests/README.md delete mode 100644 tests/alltests.txt delete mode 100644 tests/basic.json delete mode 100644 tests/basic_first-child.output delete mode 100644 tests/basic_first-child.selector delete mode 100644 tests/basic_grouping.output delete mode 100644 tests/basic_grouping.selector delete mode 100644 tests/basic_id.output delete mode 100644 tests/basic_id.selector delete mode 100644 tests/basic_id_multiple.output delete mode 100644 tests/basic_id_multiple.selector delete mode 100644 tests/basic_id_quotes.output delete mode 100644 tests/basic_id_quotes.selector delete mode 100644 tests/basic_id_with_type.output delete mode 100644 tests/basic_id_with_type.selector delete mode 100644 tests/basic_last-child.output delete mode 100644 tests/basic_last-child.selector delete mode 100644 tests/basic_nth-child-2.output delete mode 100644 tests/basic_nth-child-2.selector delete mode 100644 tests/basic_nth-child.output delete mode 100644 tests/basic_nth-child.selector delete mode 100644 tests/basic_nth-last-child.output delete mode 100644 tests/basic_nth-last-child.selector delete mode 100644 tests/basic_root_pseudo.output delete mode 100644 tests/basic_root_pseudo.selector delete mode 100644 tests/basic_type.output delete mode 100644 tests/basic_type.selector delete mode 100644 tests/basic_type2.output delete mode 100644 tests/basic_type2.selector delete mode 100644 tests/basic_type3.output delete mode 100644 tests/basic_type3.selector delete mode 100644 tests/basic_universal.output delete mode 100644 tests/basic_universal.selector diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..15339d4 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "src/test/tests"] + path = src/test/tests + url = git://github.com/lloyd/JSONSelectTests diff --git a/src/Makefile b/src/Makefile index d620532..ed07610 100644 --- a/src/Makefile +++ b/src/Makefile @@ -13,7 +13,7 @@ SRC = ${SRC_DIR}/jsonselect.js DIST = ${DIST_DIR}/jsonselect.js DIST_MIN = ${DIST_DIR}/jsonselect.min.js -all: hint project min +all: hint project min tests @@echo "Project build complete." ${DIST_DIR}: @@ -49,9 +49,25 @@ hint: fi +test/tests/README.md: + @@cd .. && git submodule init + @@cd .. && git submodule update + + +tests: test/tests/README.md + @@if test ! -z ${JS_ENGINE}; then \ + echo "Testing Project"; \ + ${JS_ENGINE} test/run.js; \ + else \ + echo "nodejs is missing"; \ + fi + + clean: @@echo "Removing Distribution directory:" ${DIST_DIR} @@rm -rf ${DIST_DIR} -.PHONY: all project hint min + + +.PHONY: all project hint min tests diff --git a/src/test/run.js b/src/test/run.js index 3a5498b..6fdda4e 100644 --- a/src/test/run.js +++ b/src/test/run.js @@ -16,9 +16,9 @@ var numTests = 0; var numPassed = 0; var tests = {}; -function runOneSync(name, selname) { - var testDocPath = path.join(pathToTests, name + ".json"); - var selDocPath = path.join(pathToTests, name + '_' + +function runOneSync(name, selname, p) { + var testDocPath = path.join(p, name + ".json"); + var selDocPath = path.join(p, name + '_' + selname + ".selector"); var outputDocPath = selDocPath.replace(/selector$/, "output"); @@ -35,14 +35,14 @@ function runOneSync(name, selname) { } - function runTests() { - console.log("Running Tests:"); +function runTests() { + console.log("Running Tests:"); for (var d in tests) { console.log(" tests against '" + d + ".json`:"); for (var i = 0; i < tests[d].length; i++) { - sys.print(" " + tests[d][i] + ": "); + sys.print(" " + tests[d][i][0] + ": "); try { - runOneSync(d, tests[d][i]); + runOneSync(d, tests[d][i][0], tests[d][i][1]); numPassed++; console.log("pass"); } catch (e) { @@ -55,15 +55,20 @@ function runOneSync(name, selname) { } // discover all tests -fs.readdir(pathToTests, function(e, files) { +var pathToTests = path.join(__dirname, "tests"); + +fs.readdirSync(pathToTests).forEach(function(subdir) { + var p = path.join(pathToTests, subdir); + if (!fs.statSync(p).isDirectory()) return; + var files = fs.readdirSync(p); for (var i = 0; i < files.length; i++) { var f = files[i]; var m = /^([A-Za-z]+)_(.+)\.selector$/.exec(f); if (m) { if (!tests.hasOwnProperty(m[1])) tests[m[1]] = []; numTests++; - tests[m[1]].push(m[2]); + tests[m[1]].push([m[2], p]); } } - runTests(); }); +runTests(); diff --git a/src/test/tests b/src/test/tests deleted file mode 120000 index eddac70..0000000 --- a/src/test/tests +++ /dev/null @@ -1 +0,0 @@ -../../tests/ \ No newline at end of file diff --git a/src/test/tests b/src/test/tests new file mode 160000 index 0000000..728372e --- /dev/null +++ b/src/test/tests @@ -0,0 +1 @@ +Subproject commit 728372ef0674c8b37fb63d876de0ebfb5c0af61b diff --git a/tests/README.md b/tests/README.md deleted file mode 100644 index 4c4552a..0000000 --- a/tests/README.md +++ /dev/null @@ -1,14 +0,0 @@ -## JSONSelect Conformance Tests. - -Test documents have a suffix of `.json`, like `basic.json`. - -Selectors to be applied to test documents have the document name, -followed by an underbar, followed by a description of the test, with -a `.selector` file name suffix, like `basic_grouping.selector`. - -Expected output files have the same name as the `.selector` file, -but have a `.output` suffix, like `basic_grouping.output`. - -Expected output files contain a stream of JSON objects that are what -is expected to be produced when a given selector is applied to a given -document. diff --git a/tests/alltests.txt b/tests/alltests.txt deleted file mode 100644 index 1f70e2c..0000000 --- a/tests/alltests.txt +++ /dev/null @@ -1,31 +0,0 @@ -basic.json -basic_first-child.output -basic_first-child.selector -basic_grouping.output -basic_grouping.selector -basic_id.output -basic_id.selector -basic_id_multiple.output -basic_id_multiple.selector -basic_id_quotes.output -basic_id_quotes.selector -basic_id_with_type.output -basic_id_with_type.selector -basic_last-child.output -basic_last-child.selector -basic_nth-child-2.output -basic_nth-child-2.selector -basic_nth-child.output -basic_nth-child.selector -basic_nth-last-child.output -basic_nth-last-child.selector -basic_root_pseudo.output -basic_root_pseudo.selector -basic_type.output -basic_type.selector -basic_type2.output -basic_type2.selector -basic_type3.output -basic_type3.selector -basic_universal.output -basic_universal.selector diff --git a/tests/basic.json b/tests/basic.json deleted file mode 100644 index 83c3769..0000000 --- a/tests/basic.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": { - "first": "Lloyd", - "last": "Hilaiel" - }, - "favoriteColor": "yellow", - "languagesSpoken": [ - { - "language": "Bulgarian", - "level": "advanced" - }, - { - "language": "English", - "level": "native" - }, - { - "language": "Spanish", - "level": "beginner" - } - ], - "seatingPreference": [ - "window", - "aisle" - ], - "drinkPreference": [ - "beer", - "whiskey", - "wine" - ], - "weight": 172 -} diff --git a/tests/basic_first-child.output b/tests/basic_first-child.output deleted file mode 100644 index ba6c81a..0000000 --- a/tests/basic_first-child.output +++ /dev/null @@ -1,2 +0,0 @@ -"window" -"beer" diff --git a/tests/basic_first-child.selector b/tests/basic_first-child.selector deleted file mode 100644 index 8288dac..0000000 --- a/tests/basic_first-child.selector +++ /dev/null @@ -1,2 +0,0 @@ -string:first-child - diff --git a/tests/basic_grouping.output b/tests/basic_grouping.output deleted file mode 100644 index ebbc034..0000000 --- a/tests/basic_grouping.output +++ /dev/null @@ -1,4 +0,0 @@ -"advanced" -"native" -"beginner" -172 diff --git a/tests/basic_grouping.selector b/tests/basic_grouping.selector deleted file mode 100644 index b8d0d79..0000000 --- a/tests/basic_grouping.selector +++ /dev/null @@ -1 +0,0 @@ -string.level,number diff --git a/tests/basic_id.output b/tests/basic_id.output deleted file mode 100644 index 1511f18..0000000 --- a/tests/basic_id.output +++ /dev/null @@ -1 +0,0 @@ -"yellow" diff --git a/tests/basic_id.selector b/tests/basic_id.selector deleted file mode 100644 index 7a3e32b..0000000 --- a/tests/basic_id.selector +++ /dev/null @@ -1 +0,0 @@ -.favoriteColor diff --git a/tests/basic_id_multiple.output b/tests/basic_id_multiple.output deleted file mode 100644 index 9021aaa..0000000 --- a/tests/basic_id_multiple.output +++ /dev/null @@ -1,3 +0,0 @@ -"Bulgarian" -"English" -"Spanish" diff --git a/tests/basic_id_multiple.selector b/tests/basic_id_multiple.selector deleted file mode 100644 index 24170a9..0000000 --- a/tests/basic_id_multiple.selector +++ /dev/null @@ -1 +0,0 @@ -.language diff --git a/tests/basic_id_quotes.output b/tests/basic_id_quotes.output deleted file mode 100644 index 1912273..0000000 --- a/tests/basic_id_quotes.output +++ /dev/null @@ -1,2 +0,0 @@ -172 - diff --git a/tests/basic_id_quotes.selector b/tests/basic_id_quotes.selector deleted file mode 100644 index 1adaed0..0000000 --- a/tests/basic_id_quotes.selector +++ /dev/null @@ -1 +0,0 @@ -."weight" diff --git a/tests/basic_id_with_type.output b/tests/basic_id_with_type.output deleted file mode 100644 index 1511f18..0000000 --- a/tests/basic_id_with_type.output +++ /dev/null @@ -1 +0,0 @@ -"yellow" diff --git a/tests/basic_id_with_type.selector b/tests/basic_id_with_type.selector deleted file mode 100644 index 48c2619..0000000 --- a/tests/basic_id_with_type.selector +++ /dev/null @@ -1 +0,0 @@ -string.favoriteColor diff --git a/tests/basic_last-child.output b/tests/basic_last-child.output deleted file mode 100644 index 9a334d0..0000000 --- a/tests/basic_last-child.output +++ /dev/null @@ -1,2 +0,0 @@ -"aisle" -"wine" diff --git a/tests/basic_last-child.selector b/tests/basic_last-child.selector deleted file mode 100644 index 8591de0..0000000 --- a/tests/basic_last-child.selector +++ /dev/null @@ -1,2 +0,0 @@ -string:last-child - diff --git a/tests/basic_nth-child-2.output b/tests/basic_nth-child-2.output deleted file mode 100644 index b55a882..0000000 --- a/tests/basic_nth-child-2.output +++ /dev/null @@ -1,4 +0,0 @@ -"window" -"aisle" -"beer" -"whiskey" diff --git a/tests/basic_nth-child-2.selector b/tests/basic_nth-child-2.selector deleted file mode 100644 index 6418a97..0000000 --- a/tests/basic_nth-child-2.selector +++ /dev/null @@ -1 +0,0 @@ -string:nth-child(-n+2) diff --git a/tests/basic_nth-child.output b/tests/basic_nth-child.output deleted file mode 100644 index 196d836..0000000 --- a/tests/basic_nth-child.output +++ /dev/null @@ -1,3 +0,0 @@ -"window" -"beer" -"wine" diff --git a/tests/basic_nth-child.selector b/tests/basic_nth-child.selector deleted file mode 100644 index 9bd4c5f..0000000 --- a/tests/basic_nth-child.selector +++ /dev/null @@ -1 +0,0 @@ -string:nth-child(odd) diff --git a/tests/basic_nth-last-child.output b/tests/basic_nth-last-child.output deleted file mode 100644 index 9a334d0..0000000 --- a/tests/basic_nth-last-child.output +++ /dev/null @@ -1,2 +0,0 @@ -"aisle" -"wine" diff --git a/tests/basic_nth-last-child.selector b/tests/basic_nth-last-child.selector deleted file mode 100644 index bc100d5..0000000 --- a/tests/basic_nth-last-child.selector +++ /dev/null @@ -1 +0,0 @@ -string:nth-last-child(1) diff --git a/tests/basic_root_pseudo.output b/tests/basic_root_pseudo.output deleted file mode 100644 index 83c3769..0000000 --- a/tests/basic_root_pseudo.output +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": { - "first": "Lloyd", - "last": "Hilaiel" - }, - "favoriteColor": "yellow", - "languagesSpoken": [ - { - "language": "Bulgarian", - "level": "advanced" - }, - { - "language": "English", - "level": "native" - }, - { - "language": "Spanish", - "level": "beginner" - } - ], - "seatingPreference": [ - "window", - "aisle" - ], - "drinkPreference": [ - "beer", - "whiskey", - "wine" - ], - "weight": 172 -} diff --git a/tests/basic_root_pseudo.selector b/tests/basic_root_pseudo.selector deleted file mode 100644 index 4035e80..0000000 --- a/tests/basic_root_pseudo.selector +++ /dev/null @@ -1 +0,0 @@ -:root diff --git a/tests/basic_type.output b/tests/basic_type.output deleted file mode 100644 index 332db77..0000000 --- a/tests/basic_type.output +++ /dev/null @@ -1,14 +0,0 @@ -"Lloyd" -"Hilaiel" -"yellow" -"Bulgarian" -"advanced" -"English" -"native" -"Spanish" -"beginner" -"window" -"aisle" -"beer" -"whiskey" -"wine" diff --git a/tests/basic_type.selector b/tests/basic_type.selector deleted file mode 100644 index ec186f1..0000000 --- a/tests/basic_type.selector +++ /dev/null @@ -1 +0,0 @@ -string \ No newline at end of file diff --git a/tests/basic_type2.output b/tests/basic_type2.output deleted file mode 100644 index 730a054..0000000 --- a/tests/basic_type2.output +++ /dev/null @@ -1 +0,0 @@ -172 diff --git a/tests/basic_type2.selector b/tests/basic_type2.selector deleted file mode 100644 index 0dfad6f..0000000 --- a/tests/basic_type2.selector +++ /dev/null @@ -1 +0,0 @@ -number \ No newline at end of file diff --git a/tests/basic_type3.output b/tests/basic_type3.output deleted file mode 100644 index 8394ec8..0000000 --- a/tests/basic_type3.output +++ /dev/null @@ -1,47 +0,0 @@ -{ - "first": "Lloyd", - "last": "Hilaiel" -} -{ - "language": "Bulgarian", - "level": "advanced" -} -{ - "language": "English", - "level": "native" -} -{ - "language": "Spanish", - "level": "beginner" -} -{ - "name": { - "first": "Lloyd", - "last": "Hilaiel" - }, - "favoriteColor": "yellow", - "languagesSpoken": [ - { - "language": "Bulgarian", - "level": "advanced" - }, - { - "language": "English", - "level": "native" - }, - { - "language": "Spanish", - "level": "beginner" - } - ], - "seatingPreference": [ - "window", - "aisle" - ], - "drinkPreference": [ - "beer", - "whiskey", - "wine" - ], - "weight": 172 -} diff --git a/tests/basic_type3.selector b/tests/basic_type3.selector deleted file mode 100644 index e2f6b77..0000000 --- a/tests/basic_type3.selector +++ /dev/null @@ -1 +0,0 @@ -object diff --git a/tests/basic_universal.output b/tests/basic_universal.output deleted file mode 100644 index cfbf20a..0000000 --- a/tests/basic_universal.output +++ /dev/null @@ -1,85 +0,0 @@ -"Lloyd" -"Hilaiel" -{ - "first": "Lloyd", - "last": "Hilaiel" -} -"yellow" -"Bulgarian" -"advanced" -{ - "language": "Bulgarian", - "level": "advanced" -} -"English" -"native" -{ - "language": "English", - "level": "native" -} -"Spanish" -"beginner" -{ - "language": "Spanish", - "level": "beginner" -} -[ - { - "language": "Bulgarian", - "level": "advanced" - }, - { - "language": "English", - "level": "native" - }, - { - "language": "Spanish", - "level": "beginner" - } -] -"window" -"aisle" -[ - "window", - "aisle" -] -"beer" -"whiskey" -"wine" -[ - "beer", - "whiskey", - "wine" -] -172 -{ - "name": { - "first": "Lloyd", - "last": "Hilaiel" - }, - "favoriteColor": "yellow", - "languagesSpoken": [ - { - "language": "Bulgarian", - "level": "advanced" - }, - { - "language": "English", - "level": "native" - }, - { - "language": "Spanish", - "level": "beginner" - } - ], - "seatingPreference": [ - "window", - "aisle" - ], - "drinkPreference": [ - "beer", - "whiskey", - "wine" - ], - "weight": 172 -} \ No newline at end of file diff --git a/tests/basic_universal.selector b/tests/basic_universal.selector deleted file mode 100644 index 72e8ffc..0000000 --- a/tests/basic_universal.selector +++ /dev/null @@ -1 +0,0 @@ -*