comparison truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/source/BytesSourceSectionTest.java @ 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.
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 01 Jul 2015 10:23:36 +0200
parents 9c8c0937da41
children dc83cc1f94f2
comparison
equal deleted inserted replaced
21986:67ea94a23074 21987:b2d1c8ff592a
33 public class BytesSourceSectionTest { 33 public class BytesSourceSectionTest {
34 34
35 @Test 35 @Test
36 public void testSectionsFromLineNumberASCII() { 36 public void testSectionsFromLineNumberASCII() {
37 final byte[] bytes = "foo\nbar\nbaz\n".getBytes(StandardCharsets.US_ASCII); 37 final byte[] bytes = "foo\nbar\nbaz\n".getBytes(StandardCharsets.US_ASCII);
38 final Source source = Source.fromBytes(bytes, "description", new BytesDecoder.UTF8BytesDecoder()); 38 final Source source = Source.fromBytes(bytes, "description", StandardCharsets.US_ASCII);
39 assertEquals("foo", source.createSection("identifier", 1).getCode()); 39 assertEquals("foo", source.createSection("identifier", 1).getCode());
40 assertEquals("bar", source.createSection("identifier", 2).getCode()); 40 assertEquals("bar", source.createSection("identifier", 2).getCode());
41 assertEquals("baz", source.createSection("identifier", 3).getCode()); 41 assertEquals("baz", source.createSection("identifier", 3).getCode());
42 } 42 }
43 43
44 @Test 44 @Test
45 public void testSectionsFromOffsetsASCII() { 45 public void testSectionsFromOffsetsASCII() {
46 final byte[] bytes = "foo\nbar\nbaz\n".getBytes(StandardCharsets.US_ASCII); 46 final byte[] bytes = "foo\nbar\nbaz\n".getBytes(StandardCharsets.US_ASCII);
47 final Source source = Source.fromBytes(bytes, "description", new BytesDecoder.UTF8BytesDecoder()); 47 final Source source = Source.fromBytes(bytes, "description", StandardCharsets.US_ASCII);
48 assertEquals("foo", source.createSection("identifier", 0, 3).getCode()); 48 assertEquals("foo", source.createSection("identifier", 0, 3).getCode());
49 assertEquals("bar", source.createSection("identifier", 4, 3).getCode()); 49 assertEquals("bar", source.createSection("identifier", 4, 3).getCode());
50 assertEquals("baz", source.createSection("identifier", 8, 3).getCode()); 50 assertEquals("baz", source.createSection("identifier", 8, 3).getCode());
51 } 51 }
52 52
53 @Test 53 @Test
54 public void testOffset() { 54 public void testOffset() {
55 final byte[] bytes = "xxxfoo\nbar\nbaz\nxxx".getBytes(StandardCharsets.US_ASCII); 55 final byte[] bytes = "xxxfoo\nbar\nbaz\nxxx".getBytes(StandardCharsets.US_ASCII);
56 final Source source = Source.fromBytes(bytes, 3, bytes.length - 6, "description", new BytesDecoder.UTF8BytesDecoder()); 56 final Source source = Source.fromBytes(bytes, 3, bytes.length - 6, "description", StandardCharsets.US_ASCII);
57 assertEquals("foo", source.createSection("identifier", 0, 3).getCode()); 57 assertEquals("foo", source.createSection("identifier", 0, 3).getCode());
58 assertEquals("bar", source.createSection("identifier", 4, 3).getCode()); 58 assertEquals("bar", source.createSection("identifier", 4, 3).getCode());
59 assertEquals("baz", source.createSection("identifier", 8, 3).getCode()); 59 assertEquals("baz", source.createSection("identifier", 8, 3).getCode());
60 } 60 }
61 } 61 }