Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/source/BytesSourceSectionTest.java @ 18988:cca166aa28c0
Truffle/Tools: unit tests for new framework and tool instances
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Tue, 27 Jan 2015 20:27:25 -0800 |
parents | 174f78c24747 |
children |
rev | line source |
---|---|
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
1 /* |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
4 * |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
8 * |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
14 * |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
18 * |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
21 * questions. |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
22 */ |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.test.source; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
24 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
25 import static org.junit.Assert.*; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
26 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
27 import java.nio.charset.*; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
28 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
29 import org.junit.*; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
30 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
31 import com.oracle.truffle.api.source.*; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
32 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
33 public class BytesSourceSectionTest { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
34 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
35 @Test |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
36 public void testSectionsFromLineNumberASCII() { |
17095
174f78c24747
Truffle: simplify byte section tests.
Chris Seaton <chris.seaton@oracle.com>
parents:
17066
diff
changeset
|
37 final byte[] bytes = "foo\nbar\nbaz\n".getBytes(StandardCharsets.US_ASCII); |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
38 final Source source = Source.fromBytes(bytes, "description", new BytesDecoder.UTF8BytesDecoder()); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
39 assertEquals("foo", source.createSection("identifier", 1).getCode()); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
40 assertEquals("bar", source.createSection("identifier", 2).getCode()); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
41 assertEquals("baz", source.createSection("identifier", 3).getCode()); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
42 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
43 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
44 @Test |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
45 public void testSectionsFromOffsetsASCII() { |
17095
174f78c24747
Truffle: simplify byte section tests.
Chris Seaton <chris.seaton@oracle.com>
parents:
17066
diff
changeset
|
46 final byte[] bytes = "foo\nbar\nbaz\n".getBytes(StandardCharsets.US_ASCII); |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
47 final Source source = Source.fromBytes(bytes, "description", new BytesDecoder.UTF8BytesDecoder()); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
48 assertEquals("foo", source.createSection("identifier", 0, 3).getCode()); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
49 assertEquals("bar", source.createSection("identifier", 4, 3).getCode()); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
50 assertEquals("baz", source.createSection("identifier", 8, 3).getCode()); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
51 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
52 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
53 @Test |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
54 public void testOffset() { |
17095
174f78c24747
Truffle: simplify byte section tests.
Chris Seaton <chris.seaton@oracle.com>
parents:
17066
diff
changeset
|
55 final byte[] bytes = "xxxfoo\nbar\nbaz\nxxx".getBytes(StandardCharsets.US_ASCII); |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
56 final Source source = Source.fromBytes(bytes, 3, bytes.length - 6, "description", new BytesDecoder.UTF8BytesDecoder()); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
57 assertEquals("foo", source.createSection("identifier", 0, 3).getCode()); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
58 assertEquals("bar", source.createSection("identifier", 4, 3).getCode()); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
59 assertEquals("baz", source.createSection("identifier", 8, 3).getCode()); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
60 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
61 } |