Merge: doc: fixed some typos and other misc. corrections
[nit.git] / lib / core / text / test_abstract_text.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
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
9 # another product.
10
11 module test_abstract_text is test
12
13 import text
14 intrude import ropes
15
16 class TestText
17 test
18
19 private var factories: Collection[TextFactory] = [
20 new ConcatFactory,
21 new FlatBufferFactory
22 : TextFactory]
23
24 fun test_escape_to_c is test do
25 for f in factories do
26 assert f.create("abAB12<>&").escape_to_c == "abAB12<>&"
27 assert f.create("\n\"'\\").escape_to_c == "\\n\\\"\\'\\\\"
28 assert f.create("allo???!").escape_to_c == "allo??\\?!"
29 assert f.create("??=??/??'??(??)").escape_to_c == "?\\?=?\\?/??\\'?\\?(?\\?)"
30 assert f.create("??!??<??>??-").escape_to_c == "?\\?!?\\?<?\\?>?\\?-"
31 end
32 end
33 end
34
35 # A factory that creates instances of a particular implementation of `Text`
36 interface TextFactory
37
38 # Create a `Text` instance from the specified string
39 fun create(s: String): Text is abstract
40 end
41
42
43 class ConcatFactory
44 super TextFactory
45
46 redef fun create(s) do return new Concat("", s)
47 end
48 class FlatBufferFactory
49 super TextFactory
50
51 redef fun create(s) do return new FlatBuffer.from(s)
52 end