core: implement Float::to_precision in C without callbacks
[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_suite
12
13 import test_suite
14 import text
15 intrude import ropes
16
17 class TestText
18 super TestSuite
19
20 private var factories: Collection[TextFactory] = [
21 new ConcatFactory,
22 new FlatBufferFactory
23 : TextFactory]
24
25 fun test_escape_to_c do
26 for f in factories do
27 assert f.create("abAB12<>&").escape_to_c == "abAB12<>&"
28 assert f.create("\n\"'\\").escape_to_c == "\\n\\\"\\'\\\\"
29 assert f.create("allo???!").escape_to_c == "allo??\\?!"
30 assert f.create("??=??/??'??(??)").escape_to_c == "?\\?=?\\?/??\\'?\\?(?\\?)"
31 assert f.create("??!??<??>??-").escape_to_c == "?\\?!?\\?<?\\?>?\\?-"
32 end
33 end
34 end
35
36 # A factory that creates instances of a particular implementation of `Text`
37 interface TextFactory
38
39 # Create a `Text` instance from the specified string
40 fun create(s: String): Text is abstract
41 end
42
43
44 class ConcatFactory
45 super TextFactory
46
47 redef fun create(s) do return new Concat("", s)
48 end
49 class FlatBufferFactory
50 super TextFactory
51
52 redef fun create(s) do return new FlatBuffer.from(s)
53 end