Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/source/BytesSourceSectionTest.java @ 17095:174f78c24747
Truffle: simplify byte section tests.
author | Chris Seaton <chris.seaton@oracle.com> |
---|---|
date | Wed, 10 Sep 2014 21:38:26 +0100 |
parents | 0bcefb0f8488 |
children |
comparison
equal
deleted
inserted
replaced
17094:86888df288ec | 17095:174f78c24747 |
---|---|
32 | 32 |
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.UTF_8); | 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", new BytesDecoder.UTF8BytesDecoder()); |
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.UTF_8); | 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", new BytesDecoder.UTF8BytesDecoder()); |
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 testSectionsFromLineNumberUTF8() { | |
55 // ☃ is three bytes in UTF8 | |
56 final byte[] bytes = "foo\n☃\nbaz\n".getBytes(StandardCharsets.UTF_8); | |
57 final Source source = Source.fromBytes(bytes, "description", new BytesDecoder.UTF8BytesDecoder()); | |
58 assertEquals("foo", source.createSection("identifier", 1).getCode()); | |
59 assertEquals("☃", source.createSection("identifier", 2).getCode()); | |
60 assertEquals("baz", source.createSection("identifier", 3).getCode()); | |
61 } | |
62 | |
63 @Test | |
64 public void testSectionsFromOffsetsUTF8() { | |
65 // ☃ is three bytes in UTF8 | |
66 final byte[] bytes = "foo\n☃\nbaz\n".getBytes(StandardCharsets.UTF_8); | |
67 final Source source = Source.fromBytes(bytes, "description", new BytesDecoder.UTF8BytesDecoder()); | |
68 assertEquals("foo", source.createSection("identifier", 0, 3).getCode()); | |
69 assertEquals("☃", source.createSection("identifier", 4, 3).getCode()); | |
70 assertEquals("baz", source.createSection("identifier", 8, 3).getCode()); | |
71 } | |
72 | |
73 @Test | |
74 public void testOffset() { | 54 public void testOffset() { |
75 final byte[] bytes = "xxxfoo\nbar\nbaz\nxxx".getBytes(StandardCharsets.UTF_8); | 55 final byte[] bytes = "xxxfoo\nbar\nbaz\nxxx".getBytes(StandardCharsets.US_ASCII); |
76 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", new BytesDecoder.UTF8BytesDecoder()); |
77 assertEquals("foo", source.createSection("identifier", 0, 3).getCode()); | 57 assertEquals("foo", source.createSection("identifier", 0, 3).getCode()); |
78 assertEquals("bar", source.createSection("identifier", 4, 3).getCode()); | 58 assertEquals("bar", source.createSection("identifier", 4, 3).getCode()); |
79 assertEquals("baz", source.createSection("identifier", 8, 3).getCode()); | 59 assertEquals("baz", source.createSection("identifier", 8, 3).getCode()); |
80 } | 60 } |