Permalink
Browse files

Convert the test script into an automated unit test.

  • Loading branch information...
1 parent 770a69b commit a48d43a45a2e78eb3e68f45ebea9b4a9a4435d01 @creationix committed Jan 1, 2010
Showing with 63 additions and 23 deletions.
  1. 0 test/{test.haml → standard.haml}
  2. +19 −0 test/standard.html
  3. +12 −0 test/standard.js
  4. +32 −23 test/test.js
File renamed without changes.
View
@@ -0,0 +1,19 @@
+<?xml version='1.0' encoding='utf-8' ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<title>Sample haml template</title>
+</head>
+<body>
+<div class="profile">
+<div class="left column">
+<div id="date">January 1, 2009</div>
+<div id="address">Richardson, TX</div>
+</div>
+<div class="right column">
+<div id="email">tim@creationix.com</div>
+<div id="bio">Experienced software professional...</div>
+</div>
+</div>
+</body>
+</html>
View
@@ -0,0 +1,12 @@
+{
+ locals: {
+ print_date: function () {
+ return 'January 1, 2009';
+ },
+ current_user: {
+ address: "Richardson, TX",
+ email: "tim@creationix.com",
+ bio: "Experienced software professional..."
+ }
+ }
+}
View
@@ -1,28 +1,37 @@
-// Requires nodeJS 0.1.13 or greater to run <http://nodejs.org/>
-// just type `node test.js` on the command line
-
-// Load the haml-js library from the current directory
-var Haml = require("./haml");
var file = require('file');
-var sys = require('sys');
+var posix = require('posix');
+var assert = require('assert');
+process.mixin(require('sys'));
+
+var Haml = require("../lib/haml");
-// Set up a scope for our view to render in
-var scope = {
- print_date: function () {
- return (new Date()).toDateString();
- },
- current_user: {
- address: "Richardson, TX",
- email: "tim@creationix.com",
- bio: "Experienced software professional..."
- }
-};
+posix.readdir('.').addCallback(function (files) {
+ files.forEach(function (haml_file) {
+ var m = haml_file.match(/^(.*)\.haml/),
+ base;
+ if (!m) {
+ return;
+ }
+ base = m[1];
-// Load, parse, and render the html. The result it passed to the callback puts
-// which prints it to the terminal.
-file.read('test.haml').addCallback(function (source) {
- sys.puts(Haml.render(source, {
- locals: scope
- }));
+ function load_haml(scope) {
+ file.read(haml_file).addCallback(function (haml) {
+ file.read(base + ".html").addCallback(function (expected) {
+ var actual = Haml.render(haml, scope);
+ assert.equal(actual, expected);
+ });
+ });
+ }
+
+ // Load scope
+ if (files.indexOf(base + ".js") >= 0) {
+ file.read(base + ".js").addCallback(function (js) {
+ load_haml(eval("(" + js + ")"));
+ });
+ } else {
+ load_haml({});
+ }
+ });
});
+

0 comments on commit a48d43a

Please sign in to comment.