Permalink
Browse files

tweaked and made easy to switch testing between nwmatcher full versio…

…n and modular version
  • Loading branch information...
1 parent df3bea5 commit 259558f9851534a0eb4cdb614149aa8c5d87a63e @dperini committed Dec 28, 2011
@@ -225,9 +225,11 @@
<script>
document.querySelector = document.querySelectorAll = null;
</script>
+ <script type="text/javascript" src="../../src/nwmatcher.js"></script>
+<!--
<script type="text/javascript" src="../../src/nwmatcher-base.js"></script>
- <script type="text/javascript" src="../../src/modules/nwmatcher-cache.js"></script>
<script type="text/javascript" src="../../src/modules/nwmatcher-pseudos.js"></script>
+-->
<script>
window.onload = function(){
document.getElementById("toggle").onclick = function(){
View
@@ -4,11 +4,17 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>NWMatcher HTML5 elements selection test</title>
<!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
-<script type="text/javascript" src="http://s3.amazonaws.com/nwapi/nwmatcher/nwmatcher.js"></script>
+<script type="text/javascript" src="../../src/nwmatcher.js"></script>
+<!--
+<script type="text/javascript" src="../../src/nwmatcher-base.js"></script>
+<script type="text/javascript" src="../../src/modules/nwmatcher-pseudos.js"></script>
+-->
<style type="text/css">
abbr { Helvetica, sans-serif; font-weight: bold; }
mark { background-color: yellow; }
span { background-color: lime; }
+.pass { background-color: lime; }
+.fail { background-color: red; }
</style>
</head>
@@ -19,46 +25,56 @@ <h1>NWMatcher HTML5 elements selection test</h1>
<p>Usual nonsense content...</p>
<p>
-<abbr title="International Barbershop Association">IBA</abbr>
-Located at <mark>116</mark> Messina Avenue, London NW6 4LD
-<abbr title="United Kingdom">UK</abbr>
+<abbr id="IBA" title="International Barbershop Association">IBA</abbr>
+Located at <mark id="NUM">116</mark> Messina Avenue, London NW6 4LD
+<abbr id="UK" title="United Kingdom">UK</abbr>
</p>
-<hr>
+<section>
+ <ul>
+ <li id="first">First</li>
+ <li id="second">Second</li>
+ <li id="last">Last</li>
+ </ul>
+</section>
-<p>Selection test start here...</p>
+<hr>
<script type="text/javascript">
window.onload = function() {
function log(msg) {
- document.body.appendChild(document.createElement('p')).innerHTML = msg;
+ document.body.appendChild(document.createElement('div')).innerHTML = msg;
}
- log(NW.Dom.select("abbr:first-of-type")[0].innerHTML + ' <span>abbr:first-of-type</span>');
- log(NW.Dom.select("abbr:last-of-type")[0].innerHTML + ' <span>abbr:last-of-type</span>');
- log(NW.Dom.select("mark:only-of-type")[0].innerHTML + ' <span>mark:only-of-type</span>');
-
- log(NW.Dom.select("abbr:nth-of-type(1)")[0].innerHTML + ' <span>abbr:nth-of-type(1)</span>');
- log(NW.Dom.select("abbr:nth-of-type(2)")[0].innerHTML + ' <span>abbr:nth-of-type(2)</span>');
-
- log(NW.Dom.select("abbr:nth-last-of-type(1)")[0].innerHTML + ' <span>abbr:nth-last-of-type(1)</span>');
- log(NW.Dom.select("abbr:nth-last-of-type(2)")[0].innerHTML + ' <span>abbr:nth-last-of-type(2)</span>');
-
- /*
-
- log(document.querySelectorAll("abbr:first-of-type")[0].innerHTML + ' <span>abbr:first-of-type</span>');
- log(document.querySelectorAll("abbr:last-of-type")[0].innerHTML + ' <span>abbr:last-of-type</span>');
- log(document.querySelectorAll("mark:only-of-type")[0].innerHTML + ' <span>mark:only-of-type</span>');
-
- log(document.querySelectorAll("abbr:nth-of-type(1)")[0].innerHTML + ' <span>abbr:nth-of-type(1)</span>');
- log(document.querySelectorAll("abbr:nth-of-type(2)")[0].innerHTML + ' <span>abbr:nth-of-type(2)</span>');
+ var i, temp, test, selectors = {
+ 'abbr:first-of-type': 'IBA',
+ 'abbr:last-of-type': 'UK',
+ 'mark:only-of-type': 'NUM',
+ 'abbr:nth-of-type(1)': 'IBA',
+ 'abbr:nth-of-type(2)': 'UK',
+ 'abbr:nth-last-of-type(1)': 'UK',
+ 'abbr:nth-last-of-type(2)': 'IBA',
+ 'section li:first-of-type': 'first',
+ 'section li:last-of-type': 'last'
+ };
+
+ log('--- TEST USING NW.Dom.select ---');
+
+ for (i in selectors) {
+ temp = NW.Dom.select(i)[0];
+ test = temp && temp.id == selectors[i];
+ log((test ? temp.innerHTML : 'FAIL') + ' <span class="' + (test ? 'pass' : 'fail') + '">' + i + '</span>');
+ }
- log(document.querySelectorAll("abbr:nth-last-of-type(1)")[0].innerHTML + ' <span>abbr:nth-last-of-type(1)</span>');
- log(document.querySelectorAll("abbr:nth-last-of-type(2)")[0].innerHTML + ' <span>abbr:nth-last-of-type(2)</span>');
+ log('--- TEST USING document.querySelectorAll ---');
- */
+ for (i in selectors) {
+ temp = document.querySelectorAll(i)[0];
+ test = temp && temp.id == selectors[i];
+ log((test ? temp.innerHTML : 'FAIL') + ' <span class="' + (test ? 'pass' : 'fail') + '">' + i + '</span>');
+ }
};
View
@@ -8,10 +8,12 @@
ol#empty { opacity: 0; filter:Alpha(opacity=0); } /* for testing opacity set in styles in IE */
</style>
<!-- Includes -->
-
<script type="text/javascript" src="../../src/nwmatcher.js"></script>
+<!--
+ <script type="text/javascript" src="../../src/nwmatcher-base.js"></script>
+ <script type="text/javascript" src="../../src/modules/nwmatcher-pseudos.js"></script>
+-->
<script type="text/javascript" src="../../src/modules/nwmatcher-jquery.js"></script>
-
<script type="text/javascript" src="qunit/testrunner.js"></script>
<script type="text/javascript" src="unit/selector.js"></script>
</head>
@@ -5,8 +5,11 @@
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>NWMatcher Unit Test</title>
<link rel="stylesheet" href="test.css" type="text/css" media="screen" charset="utf-8" />
+ <script src="../../src/nwmatcher.js" type="text/javascript" charset="utf-8"></script>
+<!--
<script src="../../src/nwmatcher-base.js" type="text/javascript" charset="utf-8"></script>
<script src="../../src/modules/nwmatcher-pseudos.js" type="text/javascript" charset="utf-8"></script>
+-->
<script src="assets/prototype.js" type="text/javascript" charset="utf-8"></script>
<script src="lib_assets/unittest.js" type="text/javascript" charset="utf-8"></script>
</head>
@@ -11,9 +11,11 @@
<script src="assets/prototype.js?1267715612" type="text/javascript" charset="utf-8"></script>
<script src="lib_assets/unittest.js?1267715612" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" href="lib_assets/unittest.css?1267715612" type="text/css" />
-
-
<script src="../../src/nwmatcher.js" type="text/javascript" charset="utf-8"></script>
+<!--
+ <script src="../../src/nwmatcher-base.js" type="text/javascript" charset="utf-8"></script>
+ <script src="../../src/modules/nwmatcher-pseudos.js" type="text/javascript" charset="utf-8"></script>
+-->
<script src="tests/nwmatcher-test.js" type="text/javascript" charset="utf-8"></script>
<script src="tests/selector_engine_test.js?1267715612" type="text/javascript" charset="utf-8"></script>
</head>
@@ -11,10 +11,11 @@
<script src="assets/prototype.js?1267715612" type="text/javascript" charset="utf-8"></script>
<script src="lib_assets/unittest.js?1267715612" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" href="lib_assets/unittest.css?1267715612" type="text/css" />
-
-
+ <script src="../../src/nwmatcher.js" type="text/javascript" charset="utf-8"></script>
+<!--
<script src="../../src/nwmatcher-base.js" type="text/javascript" charset="utf-8"></script>
<script src="../../src/modules/nwmatcher-pseudos.js" type="text/javascript" charset="utf-8"></script>
+-->
<script src="tests/nwmatcher-test.js" type="text/javascript" charset="utf-8"></script>
<script src="tests/selector_test.js?1267715612" type="text/javascript" charset="utf-8"></script>
</head>

0 comments on commit 259558f

Please sign in to comment.