diff options
author | makoto kuwata <kwa@kuwata-lab.com> | 2006-08-02 08:20:20 +0000 |
---|---|---|
committer | makoto kuwata <kwa@kuwata-lab.com> | 2006-08-02 08:20:20 +0000 |
commit | 9058fefd0b905bc4fac9f681fe76624e042330e8 (patch) | |
tree | 9a1513532f85bceed7ffcc8fed998248dd7cd329 /test/test-main.rb | |
parent | 749ac6327f2bc2aabb32acd2f7299b8216f571da (diff) | |
download | erubis-9058fefd0b905bc4fac9f681fe76624e042330e8.tar.gz |
- [refactor] divide Engine class into Converter, Generator, and Evaluator
- [refactor] merge 'pi/enhancer.rb' into 'engine.rb'
- [refacotr] remove 'pi/*.rb'
- [enhance] add PI::TinyEruby
- [change] property ':escape' is renamed to ':escapefunc'
- [enhance] new property '--escape={true|false}'
Diffstat (limited to 'test/test-main.rb')
-rw-r--r-- | test/test-main.rb | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/test/test-main.rb b/test/test-main.rb index a486a54..2910d60 100644 --- a/test/test-main.rb +++ b/test/test-main.rb @@ -75,6 +75,62 @@ user: (none) END + PI_INPUT = <<'END' +<ul> + <?rb @list = ['<aaa>', 'b&b', '"ccc"'] + for item in @list ?> + <li>${item} / $!{item} + <%= item %> / <%== item %></li> + <?rb end ?> +<ul> +END + + PI_SRC = <<'END' +_buf = []; _buf << '<ul> +'; @list = ['<aaa>', 'b&b', '"ccc"'] + for item in @list + _buf << ' <li>'; _buf << Erubis::XmlHelper.escape_xml(item); _buf << ' / '; _buf << (item).to_s; _buf << ' + '; _buf << ( item ).to_s; _buf << ' / '; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << '</li> +'; end + _buf << '<ul> +'; +_buf.join +END + + PI_ESCAPED_SRC = <<'END' +_buf = []; _buf << '<ul> +'; @list = ['<aaa>', 'b&b', '"ccc"'] + for item in @list + _buf << ' <li>'; _buf << (item).to_s; _buf << ' / '; _buf << Erubis::XmlHelper.escape_xml(item); _buf << ' + '; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << ' / '; _buf << ( item ).to_s; _buf << '</li> +'; end + _buf << '<ul> +'; +_buf.join +END + + PI_OUTPUT = <<'END' +<ul> + <li><aaa> / <aaa> + <aaa> / <aaa></li> + <li>b&b / b&b + b&b / b&b</li> + <li>"ccc" / "ccc" + "ccc" / "ccc"</li> +<ul> +END + + PI_ESCAPED_OUTPUT = <<'END' +<ul> + <li><aaa> / <aaa> + <aaa> / <aaa></li> + <li>b&b / b&b + b&b / b&b</li> + <li>"ccc" / "ccc" + "ccc" / "ccc"</li> +<ul> +END + def _test() if $target name = (caller()[0] =~ /in `test_(.*?)'/) && $1 @@ -397,4 +453,56 @@ END end + def test_pi1 # --pi -x + @input = PI_INPUT + @expected = PI_SRC + @options = '-x --pi' + _test() + end + + def test_pi2 # --pi -x --escape=false + @input = PI_INPUT + @expected = PI_ESCAPED_SRC + @options = '-x --pi --escape=false' + _test() + end + + def test_pi3 # --pi + @input = PI_INPUT + @expected = PI_OUTPUT + @options = '--pi' + _test() + end + + def test_pi4 # --pi --escape=false + @input = PI_INPUT + @expected = PI_ESCAPED_OUTPUT + @options = '--pi --escape=false' + _test() + end + + def test_pi5 # --pi=ruby -x + @input = PI_INPUT.gsub(/<\?rb/, '<?ruby') + @expected = PI_SRC + @options = '--pi=ruby -x' + _test() + end + + def test_pi6 # --pi -xl java + @input = <<'END' +<?java for (int i = 0; i < arr.length; i++) { ?> + - ${arr[i]} / $!{arr[i]} +<?java } ?> +END + @expected = <<'END' +StringBuffer _buf = new StringBuffer(); for (int i = 0; i < arr.length; i++) { +_buf.append(" - "); _buf.append(escape(arr[i])); _buf.append(" / "); _buf.append(arr[i]); _buf.append("\n"); + } +return _buf.toString(); +END + @options = '--pi -xl java' + _test() + end + + end |