comparison truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/source/SourceTextTest.java @ 21951:9c8c0937da41

Moving all sources into truffle subdirectory
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 17 Jun 2015 10:58:08 +0200
parents graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/source/SourceTextTest.java@acd822f17ef5
children fb6c6070b64d
comparison
equal deleted inserted replaced
21950:2a5011c7e641 21951:9c8c0937da41
1 /*
2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.oracle.truffle.api.test.source;
24
25 import static org.junit.Assert.*;
26
27 import org.junit.*;
28
29 import com.oracle.truffle.api.source.*;
30
31 public class SourceTextTest {
32
33 private final Source emptySource = Source.fromText("", null);
34
35 private final Source emptyLineSource = Source.fromText("\n", null);
36
37 private final Source shortSource = Source.fromText("01", null);
38
39 private final Source longSource = Source.fromText("01234\n67\n9\n", null);
40
41 @Test
42 public void emptyTextTest0() {
43 assertEquals(emptySource.getLineCount(), 0);
44 }
45
46 @Test(expected = IllegalArgumentException.class)
47 public void emptyTextTest1() {
48 emptySource.getLineNumber(0);
49 }
50
51 @Test(expected = IllegalArgumentException.class)
52 public void emptyTextTest2() {
53 emptySource.getColumnNumber(0);
54 }
55
56 @Test(expected = IllegalArgumentException.class)
57 public void emptyTextTest3() {
58 emptySource.getLineNumber(-1);
59 }
60
61 @Test(expected = IllegalArgumentException.class)
62 public void emptyTextTest4() {
63 emptySource.getLineStartOffset(0);
64 }
65
66 @Test(expected = IllegalArgumentException.class)
67 public void emptyTextTest5() {
68 emptySource.getLineStartOffset(1);
69 }
70
71 @Test(expected = IllegalArgumentException.class)
72 public void emptyTextTest6() {
73 emptySource.getLineLength(1);
74 }
75
76 @Test
77 public void emptyLineTest0() {
78 assertEquals(emptyLineSource.getLineCount(), 1);
79 assertEquals(emptyLineSource.getLineNumber(0), 1);
80 assertEquals(emptyLineSource.getLineStartOffset(1), 0);
81 assertEquals(emptyLineSource.getColumnNumber(0), 1);
82 assertEquals(emptyLineSource.getLineLength(1), 0);
83 }
84
85 @Test(expected = IllegalArgumentException.class)
86 public void emptyLineTest1() {
87 emptyLineSource.getLineNumber(1);
88 }
89
90 @Test(expected = IllegalArgumentException.class)
91 public void emptyLineTest2() {
92 emptyLineSource.getLineStartOffset(2);
93 }
94
95 @Test(expected = IllegalArgumentException.class)
96 public void emptyLineTest3() {
97 emptyLineSource.getColumnNumber(1);
98 }
99
100 @Test(expected = IllegalArgumentException.class)
101 public void emptyLineTest4() {
102 emptyLineSource.getLineLength(2);
103 }
104
105 @Test
106 public void shortTextTest0() {
107
108 assertEquals(shortSource.getLineCount(), 1);
109
110 assertEquals(shortSource.getLineNumber(0), 1);
111 assertEquals(shortSource.getLineStartOffset(1), 0);
112 assertEquals(shortSource.getColumnNumber(0), 1);
113
114 assertEquals(shortSource.getLineNumber(1), 1);
115 assertEquals(shortSource.getColumnNumber(1), 2);
116
117 assertEquals(shortSource.getLineLength(1), 2);
118 }
119
120 @Test(expected = IllegalArgumentException.class)
121 public void shortTextTest1() {
122 shortSource.getLineNumber(-1);
123 }
124
125 @Test(expected = IllegalArgumentException.class)
126 public void shortTextTest2() {
127 shortSource.getColumnNumber(-1);
128 }
129
130 @Test(expected = IllegalArgumentException.class)
131 public void shortTextTest3() {
132 shortSource.getLineNumber(2);
133 }
134
135 @Test(expected = IllegalArgumentException.class)
136 public void shortTextTest4() {
137 shortSource.getColumnNumber(2);
138 }
139
140 @Test(expected = IllegalArgumentException.class)
141 public void shortTextTest5() {
142 shortSource.getLineLength(2);
143 }
144
145 @Test(expected = IllegalArgumentException.class)
146 public void shortTextTest6() {
147 shortSource.getLineLength(2);
148 }
149
150 @Test
151 public void longTextTest0() {
152
153 assertEquals(longSource.getLineCount(), 3);
154
155 assertEquals(longSource.getLineNumber(0), 1);
156 assertEquals(longSource.getLineStartOffset(1), 0);
157 assertEquals(longSource.getColumnNumber(0), 1);
158
159 assertEquals(longSource.getLineNumber(4), 1);
160 assertEquals(longSource.getColumnNumber(4), 5);
161
162 assertEquals(longSource.getLineNumber(5), 1); // newline
163 assertEquals(longSource.getColumnNumber(5), 6); // newline
164 assertEquals(longSource.getLineLength(1), 5);
165
166 assertEquals(longSource.getLineNumber(6), 2);
167 assertEquals(longSource.getLineStartOffset(2), 6);
168 assertEquals(longSource.getColumnNumber(6), 1);
169
170 assertEquals(longSource.getLineNumber(7), 2);
171 assertEquals(longSource.getColumnNumber(7), 2);
172
173 assertEquals(longSource.getLineNumber(8), 2); // newline
174 assertEquals(longSource.getLineNumber(8), 2); // newline
175 assertEquals(longSource.getLineLength(2), 2);
176
177 assertEquals(longSource.getLineNumber(9), 3);
178 assertEquals(longSource.getLineStartOffset(3), 9);
179 assertEquals(longSource.getColumnNumber(9), 1);
180
181 assertEquals(longSource.getLineNumber(10), 3); // newline
182 assertEquals(longSource.getColumnNumber(10), 2); // newline
183 assertEquals(longSource.getLineLength(3), 1);
184
185 }
186
187 @Test(expected = IllegalArgumentException.class)
188 public void longTextTest1() {
189 longSource.getLineNumber(11);
190 }
191
192 @Test(expected = IllegalArgumentException.class)
193 public void longTextTest2() {
194 longSource.getColumnNumber(11);
195 }
196
197 @Test(expected = IllegalArgumentException.class)
198 public void longTextTest3() {
199 longSource.getLineStartOffset(4);
200 }
201
202 }