Skip to content

Commit 89c842f

Browse files
authored
Merge pull request #381 from ali-ince/1.4-char-should-encoded-as-string
char values should be encoded as strings
2 parents 22ad745 + 1a8907b commit 89c842f

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

driver/src/main/java/org/neo4j/driver/internal/packstream/PackStream.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ public void pack( boolean value ) throws IOException
177177
out.writeByte( value ? TRUE : FALSE );
178178
}
179179

180+
public void pack( char value ) throws IOException
181+
{
182+
pack( String.valueOf(value) );
183+
}
184+
180185
public void pack( long value ) throws IOException
181186
{
182187
if ( value >= MINUS_2_TO_THE_4 && value < PLUS_2_TO_THE_7)

driver/src/main/java/org/neo4j/driver/v1/Values.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,17 @@ public static Value value( boolean... input )
141141
}
142142
return new ListValue( values );
143143
}
144+
145+
public static Value value( char... input )
146+
{
147+
Value[] values = new Value[input.length];
148+
for ( int i = 0; i < input.length; i++ )
149+
{
150+
values[i] = value( input[i] );
151+
}
152+
return new ListValue( values );
153+
}
154+
144155
public static Value value( long... input )
145156
{
146157
Value[] values = new Value[input.length];
@@ -207,6 +218,8 @@ public static Value value( Iterator<Object> val )
207218
return new ListValue( values.toArray( new Value[values.size()] ) );
208219
}
209220

221+
public static Value value (final char val ) { return new StringValue( String.valueOf( val ) ); }
222+
210223
public static Value value( final String val )
211224
{
212225
return new StringValue( val );

driver/src/test/java/org/neo4j/driver/internal/ValuesTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ public void shouldConvertPrimitiveArrays() throws Throwable
8080
assertThat( value( new boolean[]{true, false, true} ),
8181
equalTo( (Value) new ListValue( values( true, false, true ) ) ) );
8282

83+
assertThat( value( new char[]{'a', 'b', 'c'} ),
84+
equalTo( (Value) new ListValue( values( 'a', 'b', 'c' ) ) ) );
85+
8386
assertThat( value( new String[]{"a", "b", "c"} ),
8487
equalTo( (Value) new ListValue( values( "a", "b", "c" ) ) ) );
8588
}
@@ -118,6 +121,9 @@ public void equalityRules() throws Throwable
118121
assertNotEquals( value( "Hello" ), value( "hello" ) );
119122
assertNotEquals( value( "This åäö string ?? contains strange " ),
120123
value( "This åäö string ?? contains strange Ü" ) );
124+
125+
assertEquals( value ( 'A' ), value( 'A' ));
126+
assertEquals( value ( 'A' ), value( "A" ));
121127
}
122128

123129
@Test

driver/src/test/java/org/neo4j/driver/internal/packstream/PackStreamTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,26 @@ public void testCanPackAndUnpackBytes() throws Throwable
395395

396396
}
397397

398+
@Test
399+
public void testCanPackAndUnpackChar() throws Throwable
400+
{
401+
// Given
402+
Machine machine = new Machine();
403+
404+
// When
405+
PackStream.Packer packer = machine.packer();
406+
packer.pack( 'A' );
407+
packer.flush();
408+
409+
// Then
410+
PackStream.Unpacker unpacker = newUnpacker( machine.output() );
411+
PackType packType = unpacker.peekNextType();
412+
413+
// Then
414+
assertThat( packType, equalTo( PackType.STRING ) );
415+
assertThat( unpacker.unpackString(), equalTo( "A" ));
416+
}
417+
398418
@Test
399419
public void testCanPackAndUnpackString() throws Throwable
400420
{

0 commit comments

Comments
 (0)