Limited Test Set

1 view
Skip to first unread message

David

unread,
Aug 9, 2009, 12:41:15 PM8/9/09
to Haml Dev
What I use so far, template and expected, may be recognized as from
the HAML code set:

$template = "%one\n %two\n %three Hey there";
$expected = "<?xml version=\"1.0\"?>\n<one>\n <two>\n <three>Hey
there</three>\n </two>\n</one>\n";

$template = "%ul\n %li a\n %li b\n %li c\n %li d\n %li e\n %li
f\n %li g\n %li h\n %li i";
$expected = "<?xml version=\"1.0\"?>\n<ul>\n <li>a</li>\n <li>b</
li>\n <li>c</li>\n <li>d</li>\n <li>e</li>\n <li>f</li>\n <li>g</
li>\n <li>h</li>\n <li>i</li>\n</ul>\n";

$template = "%html\n %head\n %title Stop. haml time\n #content
\n %h1 This is a title!\n %p Lorem ipsum dolor sit amet,
consectetur adipisicing elit\n %p{ \"class\" = 'foo' } Cigarettes!
\n %h2 Man alive!\n %ul.things\n %li Slippers
\n %li Shoes\n %li Bathrobe\n %li Coffee\n
%pre\n This is some text that's in a pre block!\n Let's
see what happens when it's rendered! What about now, since we're on a
new line?\n";

$expected = "<?xml version=\"1.0\"?>\n<html>\n <head>\n
<title>Stop. haml time</title>\n <div id=\"content\">\n
<h1>This is a title!</h1>\n <p>Lorem ipsum dolor sit amet,
consectetur adipisicing elit</p>\n <p class=\"foo\"> Cigarettes!</
p>\n <h2>Man alive!</h2>\n <ul class=\"things\">\n
<li>Slippers</li>\n <li>Shoes</li>\n <li>Bathrobe</li>
\n <li>Coffee</li>\n </ul>\n <pre>This is some text
that's in a pre block!Let's see what happens when it's rendered! What
about now, since we're on a new line?</pre>\n </div>\n </head>\n</
html>\n";

$template = "%div.tags\n %foo 1\n %FOO 2\n %fooBAR 3\n %fooBar
4\n %foo_bar 5\n %foo-bar 6\n %foo:bar 7\n %foo.bar 8\n
%fooBAr_baz:boom_bar 9\n %foo13 10\n %foo2u 11\n%div.classes\n
%p.foo.bar#baz#boom\n .fooBar a\n .foo-bar b\n .foo_bar c
\n .FOOBAR d\n .foo16 e\n .123 f\n .foo2u g\n";
$expected = "<?xml version=\"1.0\"?>\n<div class=\"tags\">\n
<foo>1</foo>\n <FOO>2</FOO>\n <fooBAR>3</fooBAR>\n <fooBar>4</
fooBar>\n <foo_bar>5</foo_bar>\n <foo-bar>6</foo-bar>\n <foo:bar>7</
foo:bar>\n <foo class=\"bar\">8</foo>\n <fooBAr_baz:boom_bar>9</
fooBAr_baz:boom_bar>\n <foo13>10</foo13>\n <foo2u>11</foo2u>\n</div>
\n<div class=\"classes\">\n <p class=\"foo bar\" id=\"boom\"/>\n
<div class=\"fooBar\">a</div>\n <div class=\"foo-bar\">b</div>\n
<div class=\"foo_bar\">c</div>\n <div class=\"FOOBAR\">d</div>\n
<div class=\"foo16\">e</div>\n <div class=\"123\">f</div>\n <div
class=\"foo2u\">g</div>\n</div>\n";

Norman Clarke

unread,
Aug 9, 2009, 12:54:33 PM8/9/09
to haml...@googlegroups.com
On Sun, Aug 9, 2009 at 1:41 PM, David<david.appli...@gmail.com> wrote:
>
> What I use so far, template and expected, may be recognized as from
> the HAML code set:
>
>                $template = "%one\n  %two\n    %three Hey there";
>                $expected = "<?xml version=\"1.0\"?>\n<one>\n  <two>\n    <three>Hey
> there</three>\n  </two>\n</one>\n";
>
>                $template = "%ul\n  %li a\n  %li b\n  %li c\n  %li d\n  %li e\n  %li
> f\n  %li g\n  %li h\n  %li i";
>                $expected = "<?xml version=\"1.0\"?>\n<ul>\n  <li>a</li>\n  <li>b</
> li>\n  <li>c</li>\n  <li>d</li>\n  <li>e</li>\n  <li>f</li>\n  <li>g</
> li>\n  <li>h</li>\n  <li>i</li>\n</ul>\n";

Very exciting news to hear about Haml possibly being adopted by Zend framework!

I think ideally we would have unit tests or specs that demonstrate
much smaller units of the Haml language, in order to provide a guide
from a development standpoint, of what the language is and isn't.

The examples you provided here (and the tests that are already in
Haml) are useful more as functional tests to make sure your
parser/precompiler/renderer are all working well together.

What would have helped me in developing Lua haml would be something
like a list of really small, lower-level specifications like:

%p => "<p></p>
%p.class1 => <p class='class1'></p>
%p hello => <p>hello</p>
%p:p => <p:p></p:p>

etc.

With good commenting I think this would be a more effective guide for
developers as to what the Haml language is supposed to be.

Regards,

Norm

Nathan Weizenbaum

unread,
Aug 9, 2009, 2:51:21 PM8/9/09
to haml...@googlegroups.com
Again, check out test/haml/engine_test.rb for a large set of unit tests for small bits of Haml (including error cases). That might be worth looking at. It may not have great coverage of really simple cases, though... for a while, we tended to go with larger functional tests, so some behavior may only be tested there, and not in the unit tests.

Also, David, a comment on your output: Haml shouldn't automatically generate the XML header. That should be explicitly added with "!!! XML".

David

unread,
Aug 9, 2009, 5:30:39 PM8/9/09
to Haml Dev
!!!XML: Caught that as well. What I was using the PHP DOMDocument
class for output--that way, everything produced is compliant XML. But
it looks that I will have to give that up to put this where it needs
to go. In the ZF, I was writing the pHAML as a Zend_View object, but
to make it more usable, I think that it should be able to be used as a
Zend_View_Helper. Short for, do not worry, it is going away...

On Tests: I also see the need from a series of small tests--so I will
create some, I will try to make them universal, I will announce them
on this list when they are ready.

--d

On Aug 9, 1:51 pm, Nathan Weizenbaum <nex...@gmail.com> wrote:
> Again, check out test/haml/engine_test.rb for a large set of unit tests for
> small bits of Haml (including error cases). That might be worth looking at.
> It may not have great coverage of really simple cases, though... for a
> while, we tended to go with larger functional tests, so some behavior may
> only be tested there, and not in the unit tests.
>
> Also, David, a comment on your output: Haml shouldn't automatically generate
> the XML header. That should be explicitly added with "!!! XML".
>
> On Sun, Aug 9, 2009 at 9:54 AM, Norman Clarke <com...@gmail.com> wrote:
>
> > On Sun, Aug 9, 2009 at 1:41 PM, David<david.appliedautonom...@gmail.com>
Reply all
Reply to author
Forward
0 new messages