lib/standard/string: Fixed substring, could produce strings with a negative length
[nit.git] / tests / sav / nitpretty_args25.res
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 class Foo
16         fun bar: Bool do return true
17
18         fun foo(other: Foo): Foo do
19                 if other.bar then
20                         return other
21                 else
22                         return self
23                 end
24         end
25
26         fun baz: Int do
27                 var nb = 0
28
29                 while nb < 10 do
30                         print nb
31                         nb += 1
32                 end # 1
33
34                 return nb
35         end
36
37         fun gaz: Int do
38                 if bar then # 3
39                         return 1
40                 else
41                         return -1 # 4
42                 end
43         end
44 end
45
46 class Test[E]
47         var heap: ArrayHeap[E]
48         init to(comparator: Comparator[E]) do heap = new ArrayHeap[E](comparator)
49
50         init from(comparator: Comparator[E], items: Collection[E]) do
51                 heap = new ArrayHeap[E].from(comparator, items.to_a)
52         end
53
54         fun count(k: E): Int do
55                 if heap.has(k) then
56                         return 1
57                 else
58                         return 0
59                 end
60         end
61
62         fun node_at_idx(i: Int, k: E) do
63                 while heap != null do
64                         if heap.is_empty or i == k then # FIXME prefilter because the compiler is not smart enought yet
65                                 break
66                         end
67                 end
68         end
69
70         fun save_those_nodes(nodes: Collection[Object]) do for node in nodes do count(node)
71 end
72
73 fun foo do
74         if last_slash > 0 then
75                 return substring(last_slash + 1, length)
76         else
77                 return null
78         end
79 end
80
81 print "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam tincidun" +
82         "t sapien et velit fringilla varius at non eros. Nunc ut ultricies metus, sit a" +
83         "met lacinia felis. Donec in facilisis neque, non laoreet nibh. Etiam nec purus" +
84         " eu orci congue iaculis eu quis lorem. Ut et blandit erat. Cras fermentum pell" +
85         "entesque ante, ut dapibus ipsum placerat sit amet. Vivamus pharetra, sem vitae" +
86         " consequat venenatis, diam risus placerat est, sed hendrerit purus justo vitae" +
87         " lectus. In id quam mattis, rutrum augue eu, vehicula ipsum. Nulla nec egestas" +
88         " turpis, nec ullamcorper odio. Pellentesque vitae arcu justo. Aliquam sed phar" +
89         "etra lacus."
90
91 var lorem = "lorem"
92 var ipsum = "ipsum" # for fun
93
94 print "We also need to handle super strings: {lorem} {ipsum} dolor sit amet, con" +
95         "sectetur adipiscing elit. Aliquam tincidunt sapien et velit fringilla varius a" +
96         "t non eros. Nunc ut ultricies metus, sit amet lacinia felis. Donec in facilisi" +
97         "s neque, non laoreet nibh. Etiam nec purus eu orci congue iaculis eu quis {lorem}" +
98         ". Ut et blandit erat. Cras fermentum pellentesque ante, ut dapibus {ipsum} pla" +
99         "cerat sit amet. Vivamus pharetra, sem vitae consequat venenatis, diam risus pl" +
100         "acerat est, sed hendrerit purus justo vitae lectus. In id quam mattis, rutrum " +
101         "augue eu, vehicula ipsum. Nulla nec egestas turpis, nec ullamcorper odio. Pell" +
102         "entesque vitae arcu justo. Aliquam sed pharetra lacus." # ending
103
104 var title = "title"
105 var links = new Array[String] # why not?
106
107 var body = """
108 <!DOCTYPE html>
109 <head>
110         <meta charset="utf-8">
111         <meta http-equiv="X-UA-Compatible" content="IE=edge">
112         <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
113         <title>{{{title}}}</title>
114 </head>
115 <body>
116         <div class="container">
117                 <h1>{{{title}}}</h1>
118                 <ul>
119                         <li>{{{links.join("</li>\n\t\t\t<li>")}}}</li>
120                 </ul>
121         </div>
122 </body>
123 </html>"""