forked from tada/pljava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharsetTest.java
More file actions
59 lines (43 loc) · 1.36 KB
/
Copy pathCharsetTest.java
File metadata and controls
59 lines (43 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* Copyright (c) 2020 Tada AB and other contributors, as listed below.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the The BSD 3-Clause License
* which accompanies this distribution, and is available at
* http://opensource.org/licenses/BSD-3-Clause
*
* Contributors:
* Chapman Flack
*/
package org.postgresql.pljava.internal;
import junit.framework.TestCase;
import static org.junit.Assert.*;
import org.junit.Ignore;
import static org.hamcrest.CoreMatchers.*;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import static java.nio.charset.StandardCharsets.US_ASCII;
import static java.util.regex.Pattern.matches;
public class CharsetTest extends TestCase
{
public CharsetTest(String name) { super(name); }
public void testSQL_ASCII() throws Exception
{
Charset sqa = Charset.forName("SQL_ASCII");
assertNotNull(sqa);
assertTrue(sqa.contains(sqa));
assertTrue(sqa.contains(US_ASCII));
ByteBuffer bb = ByteBuffer.allocate(256);
while ( bb.hasRemaining() )
bb.put((byte)bb.position());
bb.flip();
CharBuffer cb = sqa.decode(bb);
assertTrue(matches("[\\u0000-\\u007f]{128}+" +
"(?:[\\ufdd8-\\ufddf][\\ufde0-\\ufdef]){128}+", cb));
cb.rewind();
ByteBuffer bb2 = sqa.encode(cb);
bb.rewind();
assertTrue(bb2.equals(bb));
}
}