From fdf3424f783f3a1bd1cf8a935204286c463d4886 Mon Sep 17 00:00:00 2001
From: Tobie Langel <tobie.langel@gmail.com>
Date: Sun, 25 Oct 2009 00:40:48 +0200
Subject: [PATCH] Add unit tests.

---
 test/unit/fixtures/selector_engine.html |  4 ++
 test/unit/selector_engine_test.js       | 53 +++++++++++++++++++++++++
 2 files changed, 57 insertions(+)
 create mode 100644 test/unit/fixtures/selector_engine.html
 create mode 100644 test/unit/selector_engine_test.js

diff --git a/test/unit/fixtures/selector_engine.html b/test/unit/fixtures/selector_engine.html
new file mode 100644
index 0000000..5b1acd2
--- /dev/null
+++ b/test/unit/fixtures/selector_engine.html
@@ -0,0 +1,4 @@
+<div id="test_div_parent" class="test_class">
+  <div id="test_div_child" class="test_class">
+  </div>
+</div>
\ No newline at end of file
diff --git a/test/unit/selector_engine_test.js b/test/unit/selector_engine_test.js
new file mode 100644
index 0000000..dec966f
--- /dev/null
+++ b/test/unit/selector_engine_test.js
@@ -0,0 +1,53 @@
+/*
+<div id="test_div_parent" class="test_class">
+  <div id="test_div_child" class="test_class">
+  </div>
+</div>
+*/
+
+new Test.Unit.Runner({
+  testEngine: function() {
+    this.assert(Prototype.Selector.engine);
+  },
+  
+  testSelect: function() {
+    var elements = Prototype.Selector.select('.test_class');
+    
+    this.assert(Object.isArray(elements));
+    this.assertEqual(2, elements.length);
+    this.assertEqual('test_div_parent', elements[0].id);
+    this.assertEqual('test_div_child', elements[1].id);
+  },
+  
+  testSelectWithContext: function() {
+    var elements = Prototype.Selector.select('.test_class', $('test_div_parent'));
+    
+    this.assert(Object.isArray(elements));
+    this.assertEqual(1, elements.length);
+    this.assertEqual('test_div_child', elements[0].id);
+  },
+  
+  testSelectWithEmptyResult: function() {
+    var elements = Prototype.Selector.select('.non_existent');
+    
+    this.assert(Object.isArray(elements));
+    this.assertEqual(0, elements.length);
+  },
+  
+  testMatch: function() {
+    var element = $('test_div_parent');
+    
+    this.assertEqual(true, Prototype.Selector.match(element, '.test_class'));
+    this.assertEqual(false, Prototype.Selector.match(element, '.non_existent'));
+  },
+  
+  testFilter: function() {
+    var elements = document.getElementsByTagName('*'),
+        filtered = Prototype.Selector.filter(elements, '.test_class');
+        
+    this.assert(Object.isArray(filtered));
+    this.assertEqual(2, filtered.length);
+    this.assertEqual('test_div_parent', filtered[0].id);
+    this.assertEqual('test_div_child', filtered[1].id);
+  }
+});
\ No newline at end of file