1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # This file is free software, which comes along with NIT. This software is
4 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
5 # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6 # PARTICULAR PURPOSE. You can modify it is you want, provided this header
7 # is kept unaltered, and a notification of the changes is added.
8 # You are allowed to redistribute it and sell it, alone or is a part of
11 module test_abstract_text
is test_suite
20 private var factories
: Collection[TextFactory] = [
22 new RopeBufferFactory,
26 fun test_escape_to_c
do
28 assert f
.create
("abAB12<>&").escape_to_c
== "abAB12<>&"
29 assert f
.create
("\n\"'\\").escape_to_c == "\\n\\\"\\'\\\\
"
30 assert f.create("allo
???!").escape_to_c == "allo
??\\
?!"
31 assert f.create("??=??/??'??(??)").escape_to_c == "?\\?=?\\?/??\\'?\\
?(?\\
?)"
32 assert f.create("??!??<??>??-").escape_to_c == "?\\
?!?\\
?<?\\
?>?\\
?-"
37 # A factory that creates instances of a particular implementation of `Text`
40 # Create a `Text` instance from the specified string
41 fun create(s: String): Text is abstract
48 redef fun create(s) do return new Concat("", s)
51 class RopeBufferFactory
54 redef fun create(s) do return new RopeBuffer.from(s)
57 class FlatBufferFactory
60 redef fun create(s) do return new FlatBuffer.from(s)