1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
$:.unshift File.join(File.dirname(__FILE__),"..","lib")
require 'minitest/autorun'
require 'rgen/template_language/output_handler'
class MetamodelBuilderTest < Minitest::Test
def test_direct_nl
h = RGen::TemplateLanguage::OutputHandler.new
h.mode = :direct
h << "Test"
h.ignoreNextNL
h << "\nContent"
assert_equal "TestContent", h.to_s
end
def test_direct_ws
h = RGen::TemplateLanguage::OutputHandler.new
h.mode = :direct
h << "Test"
h.ignoreNextWS
h << " \n Content"
assert_equal "TestContent", h.to_s
end
def test_explicit_indent
h = RGen::TemplateLanguage::OutputHandler.new
h.mode = :explicit
h.indent = 1
h << "Start"
h << " \n "
h << "Test"
h << " \n \n Content"
assert_equal " Start\n Test\n Content", h.to_s
end
def test_explicit_endswithws
h = RGen::TemplateLanguage::OutputHandler.new
h.mode = :explicit
h.indent = 1
h << "Start \n\n"
assert_equal " Start\n", h.to_s
end
def test_performance
h = RGen::TemplateLanguage::OutputHandler.new
h.mode = :explicit
h.indent = 1
line = (1..50).collect{|w| "someword"}.join(" ")+"\n"
# repeat more often to make performance differences visible
20.times do
h << line
end
end
def test_indent_string
h = RGen::TemplateLanguage::OutputHandler.new(1, "\t", :explicit)
h << "Start"
h << " \n "
h << "Test"
h << " \n \n Content"
assert_equal "\tStart\n\tTest\n\tContent", h.to_s
end
end
|