Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/source/BytesSourceSectionTest.java @ 22157:dc83cc1f94f2
Using fully qualified imports
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Wed, 16 Sep 2015 11:33:22 +0200 |
parents | b2d1c8ff592a |
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 |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21987
diff
changeset
|
25 import com.oracle.truffle.api.source.Source; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21987
diff
changeset
|
26 import java.nio.charset.StandardCharsets; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21987
diff
changeset
|
27 import static org.junit.Assert.assertEquals; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21987
diff
changeset
|
28 import org.junit.Test; |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
29 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
30 public class BytesSourceSectionTest { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
31 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
32 @Test |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
33 public void testSectionsFromLineNumberASCII() { |
17095
174f78c24747
Truffle: simplify byte section tests.
Chris Seaton <chris.seaton@oracle.com>
parents:
17066
diff
changeset
|
34 final byte[] bytes = "foo\nbar\nbaz\n".getBytes(StandardCharsets.US_ASCII); |
21987
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
35 final Source source = Source.fromBytes(bytes, "description", StandardCharsets.US_ASCII); |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
36 assertEquals("foo", source.createSection("identifier", 1).getCode()); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
37 assertEquals("bar", source.createSection("identifier", 2).getCode()); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
38 assertEquals("baz", source.createSection("identifier", 3).getCode()); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
39 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
40 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
41 @Test |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
42 public void testSectionsFromOffsetsASCII() { |
17095
174f78c24747
Truffle: simplify byte section tests.
Chris Seaton <chris.seaton@oracle.com>
parents:
17066
diff
changeset
|
43 final byte[] bytes = "foo\nbar\nbaz\n".getBytes(StandardCharsets.US_ASCII); |
21987
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
44 final Source source = Source.fromBytes(bytes, "description", StandardCharsets.US_ASCII); |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
45 assertEquals("foo", source.createSection("identifier", 0, 3).getCode()); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
46 assertEquals("bar", source.createSection("identifier", 4, 3).getCode()); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
47 assertEquals("baz", source.createSection("identifier", 8, 3).getCode()); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
48 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
49 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
50 @Test |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
51 public void testOffset() { |
17095
174f78c24747
Truffle: simplify byte section tests.
Chris Seaton <chris.seaton@oracle.com>
parents:
17066
diff
changeset
|
52 final byte[] bytes = "xxxfoo\nbar\nbaz\nxxx".getBytes(StandardCharsets.US_ASCII); |
21987
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
53 final Source source = Source.fromBytes(bytes, 3, bytes.length - 6, "description", StandardCharsets.US_ASCII); |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
54 assertEquals("foo", source.createSection("identifier", 0, 3).getCode()); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
55 assertEquals("bar", source.createSection("identifier", 4, 3).getCode()); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
56 assertEquals("baz", source.createSection("identifier", 8, 3).getCode()); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
57 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
diff
changeset
|
58 } |