lib/standard/text: Added global test on all the API of Text and subclasses.
authorLucas Bajolet <r4pass@hotmail.com>
Thu, 5 Jun 2014 15:28:17 +0000 (11:28 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Mon, 9 Jun 2014 15:58:51 +0000 (11:58 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

tests/sav/test_text.res [new file with mode: 0644]
tests/sav/test_text_alt1.res [new file with mode: 0644]
tests/sav/test_text_alt2.res [new file with mode: 0644]
tests/test_text.nit [new file with mode: 0644]

diff --git a/tests/sav/test_text.res b/tests/sav/test_text.res
new file mode 100644 (file)
index 0000000..fc9283b
--- /dev/null
@@ -0,0 +1,15 @@
+WOE TO YOU, OH EARTH AND SEA FOR THE DEVIL SENDS THE BEAST WITH WRATH BECAUSE HE KNOWS THE TIME IS SHORT. LET HIM WHO HATH UNDERSTANDING RECKON THE NUMBER OF THE BEAST, FOR IT IS A HUMAN NUMBER, ITS NUMBER IS SIX HUNDRED AND SIXTY-SIX.
+woe to you, oh earth and sea for the devil sends the beast with wrath because he knows the time is short. let him who hath understanding reckon the number of the beast, for it is a human number, its number is six hundred and sixty-six.
+Woe to you, oh earth and sea for the Devil sends the beast with wrath because he knows the time is short.
+Let him who hath understanding reckon the number of the beast, for it is a human number, its number is Six Hundred and Sixty-Six.
+.xiS-ytxiS dna derdnuH xiS si rebmun sti ,rebmun namuh a si ti rof ,tsaeb eht fo rebmun eht nokcer gnidnatsrednu htah ohw mih teL .trohs si emit eht swonk eh esuaceb htarw htiw tsaeb eht sdnes liveD eht rof aes dna htrae ho ,uoy ot eoW
+235
+13
+110
+-1
+106
+37
+true
+true
+Woe to you, oh earth and sea for the Devil sends the beast with wrath because he knows the time is short. Let him who hath understanding reckon the number of the beast, for it is a human number, its number is Six Hundred and Sixty-Six.
+W o e   t o   y o u ,   o h   e a r t h   a n d   s e a   f o r   t h e   D e v i l   s e n d s   t h e   b e a s t   w i t h   w r a t h   b e c a u s e   h e   k n o w s   t h e   t i m e   i s   s h o r t .   L e t   h i m   w h o   h a t h   u n d e r s t a n d i n g   r e c k o n   t h e   n u m b e r   o f   t h e   b e a s t ,   f o r   i t   i s   a   h u m a n   n u m b e r ,   i t s   n u m b e r   i s   S i x   H u n d r e d   a n d   S i x t y - S i x .
diff --git a/tests/sav/test_text_alt1.res b/tests/sav/test_text_alt1.res
new file mode 100644 (file)
index 0000000..fc9283b
--- /dev/null
@@ -0,0 +1,15 @@
+WOE TO YOU, OH EARTH AND SEA FOR THE DEVIL SENDS THE BEAST WITH WRATH BECAUSE HE KNOWS THE TIME IS SHORT. LET HIM WHO HATH UNDERSTANDING RECKON THE NUMBER OF THE BEAST, FOR IT IS A HUMAN NUMBER, ITS NUMBER IS SIX HUNDRED AND SIXTY-SIX.
+woe to you, oh earth and sea for the devil sends the beast with wrath because he knows the time is short. let him who hath understanding reckon the number of the beast, for it is a human number, its number is six hundred and sixty-six.
+Woe to you, oh earth and sea for the Devil sends the beast with wrath because he knows the time is short.
+Let him who hath understanding reckon the number of the beast, for it is a human number, its number is Six Hundred and Sixty-Six.
+.xiS-ytxiS dna derdnuH xiS si rebmun sti ,rebmun namuh a si ti rof ,tsaeb eht fo rebmun eht nokcer gnidnatsrednu htah ohw mih teL .trohs si emit eht swonk eh esuaceb htarw htiw tsaeb eht sdnes liveD eht rof aes dna htrae ho ,uoy ot eoW
+235
+13
+110
+-1
+106
+37
+true
+true
+Woe to you, oh earth and sea for the Devil sends the beast with wrath because he knows the time is short. Let him who hath understanding reckon the number of the beast, for it is a human number, its number is Six Hundred and Sixty-Six.
+W o e   t o   y o u ,   o h   e a r t h   a n d   s e a   f o r   t h e   D e v i l   s e n d s   t h e   b e a s t   w i t h   w r a t h   b e c a u s e   h e   k n o w s   t h e   t i m e   i s   s h o r t .   L e t   h i m   w h o   h a t h   u n d e r s t a n d i n g   r e c k o n   t h e   n u m b e r   o f   t h e   b e a s t ,   f o r   i t   i s   a   h u m a n   n u m b e r ,   i t s   n u m b e r   i s   S i x   H u n d r e d   a n d   S i x t y - S i x .
diff --git a/tests/sav/test_text_alt2.res b/tests/sav/test_text_alt2.res
new file mode 100644 (file)
index 0000000..fc9283b
--- /dev/null
@@ -0,0 +1,15 @@
+WOE TO YOU, OH EARTH AND SEA FOR THE DEVIL SENDS THE BEAST WITH WRATH BECAUSE HE KNOWS THE TIME IS SHORT. LET HIM WHO HATH UNDERSTANDING RECKON THE NUMBER OF THE BEAST, FOR IT IS A HUMAN NUMBER, ITS NUMBER IS SIX HUNDRED AND SIXTY-SIX.
+woe to you, oh earth and sea for the devil sends the beast with wrath because he knows the time is short. let him who hath understanding reckon the number of the beast, for it is a human number, its number is six hundred and sixty-six.
+Woe to you, oh earth and sea for the Devil sends the beast with wrath because he knows the time is short.
+Let him who hath understanding reckon the number of the beast, for it is a human number, its number is Six Hundred and Sixty-Six.
+.xiS-ytxiS dna derdnuH xiS si rebmun sti ,rebmun namuh a si ti rof ,tsaeb eht fo rebmun eht nokcer gnidnatsrednu htah ohw mih teL .trohs si emit eht swonk eh esuaceb htarw htiw tsaeb eht sdnes liveD eht rof aes dna htrae ho ,uoy ot eoW
+235
+13
+110
+-1
+106
+37
+true
+true
+Woe to you, oh earth and sea for the Devil sends the beast with wrath because he knows the time is short. Let him who hath understanding reckon the number of the beast, for it is a human number, its number is Six Hundred and Sixty-Six.
+W o e   t o   y o u ,   o h   e a r t h   a n d   s e a   f o r   t h e   D e v i l   s e n d s   t h e   b e a s t   w i t h   w r a t h   b e c a u s e   h e   k n o w s   t h e   t i m e   i s   s h o r t .   L e t   h i m   w h o   h a t h   u n d e r s t a n d i n g   r e c k o n   t h e   n u m b e r   o f   t h e   b e a s t ,   f o r   i t   i s   a   h u m a n   n u m b e r ,   i t s   n u m b e r   i s   S i x   H u n d r e d   a n d   S i x t y - S i x .
diff --git a/tests/test_text.nit b/tests/test_text.nit
new file mode 100644 (file)
index 0000000..4a27158
--- /dev/null
@@ -0,0 +1,99 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+var str = "Woe to you, oh earth and sea for the Devil sends the beast with wrath because he knows the time is short. Let him who hath understanding reckon the number of the beast, for it is a human number, its number is Six Hundred and Sixty-Six."
+var spaces = "           "
+var numstr = "1001"
+
+var txt: Text
+var trimable: Text
+var num: Text
+
+txt = str
+trimable = spaces + str + spaces
+num = numstr
+
+#alt1 txt = new FlatBuffer.from(str)
+#alt1 trimable = new FlatBuffer.from(spaces)
+#alt1 trimable.append(str)
+#alt1 trimable.append(spaces)
+#alt1 num = new FlatBuffer.from(numstr)
+
+#alt2 txt = new RopeString.from(str)
+#alt2 trimable = new RopeString.from(spaces)
+#alt2 trimable = trimable + str
+#alt2 trimable = trimable + spaces
+#alt2 num = new RopeString.from(numstr)
+
+# Test Text methods on all types of receivers
+
+print txt.to_upper
+print txt.to_lower
+assert txt * 2 == txt + txt
+print txt.substring(0, 105)
+print txt.substring_from(106)
+print txt.reversed
+print txt.length
+assert not txt.is_empty
+print txt.index_of('h')
+print txt.index_of_from('h', 105)
+print txt.index_of('Z')
+print txt.last_index_of('L')
+print txt.last_index_of_from('D', 105)
+print txt.has_substring("Woe", 0)
+print txt.has_substring("Let", 106)
+assert trimable != txt
+assert trimable.trim == txt
+assert num.is_numeric
+assert txt.has_prefix("Woe")
+assert txt.has_suffix("Six.")
+assert txt.hash == trimable.trim.hash
+
+# Test Text.chars (SequenceRead[Char]) methods on all receivers
+
+var chars = txt.chars
+
+assert chars != txt.substring_from(106).chars
+assert (txt.substring(0,105) + txt.substring_from(105)).chars == txt.chars
+assert chars[0] == 'W'
+assert chars.count('o') == 11
+assert chars.first == chars[0]
+assert chars.has('L')
+assert spaces.chars.has_only(' ')
+assert chars.index_of('D') == 37
+assert not chars.is_empty
+var count = 0
+for i in chars do
+       assert i != '!'
+       printn i
+       count += 1
+end
+printn "\n"
+assert count == txt.length
+var iter_from = txt.substring_from(105).chars.iterator
+var txt_iter_from = chars.iterator_from(105)
+while iter_from.is_ok do
+       assert iter_from.item == txt_iter_from.item
+       iter_from.next
+       txt_iter_from.next
+end
+assert not iter_from.is_ok and not txt_iter_from.is_ok
+var txt_reviter = chars.reverse_iterator_from(104)
+var sub_reviter = txt.substring(0,105).chars.reverse_iterator
+while txt_reviter.is_ok do
+       assert txt_reviter.item == sub_reviter.item
+       txt_reviter.next
+       sub_reviter.next
+end
+print chars.join(" ")