Skip to content

char values should be encoded as strings #381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ public void pack( boolean value ) throws IOException
out.writeByte( value ? TRUE : FALSE );
}

public void pack( char value ) throws IOException
{
pack( String.valueOf(value) );
}

public void pack( long value ) throws IOException
{
if ( value >= MINUS_2_TO_THE_4 && value < PLUS_2_TO_THE_7)
Expand Down
13 changes: 13 additions & 0 deletions driver/src/main/java/org/neo4j/driver/v1/Values.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ public static Value value( boolean... input )
}
return new ListValue( values );
}

public static Value value( char... input )
{
Value[] values = new Value[input.length];
for ( int i = 0; i < input.length; i++ )
{
values[i] = value( input[i] );
}
return new ListValue( values );
}

public static Value value( long... input )
{
Value[] values = new Value[input.length];
Expand Down Expand Up @@ -207,6 +218,8 @@ public static Value value( Iterator<Object> val )
return new ListValue( values.toArray( new Value[values.size()] ) );
}

public static Value value (final char val ) { return new StringValue( String.valueOf( val ) ); }

public static Value value( final String val )
{
return new StringValue( val );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public void shouldConvertPrimitiveArrays() throws Throwable
assertThat( value( new boolean[]{true, false, true} ),
equalTo( (Value) new ListValue( values( true, false, true ) ) ) );

assertThat( value( new char[]{'a', 'b', 'c'} ),
equalTo( (Value) new ListValue( values( 'a', 'b', 'c' ) ) ) );

assertThat( value( new String[]{"a", "b", "c"} ),
equalTo( (Value) new ListValue( values( "a", "b", "c" ) ) ) );
}
Expand Down Expand Up @@ -118,6 +121,9 @@ public void equalityRules() throws Throwable
assertNotEquals( value( "Hello" ), value( "hello" ) );
assertNotEquals( value( "This åäö string ?? contains strange " ),
value( "This åäö string ?? contains strange Ü" ) );

assertEquals( value ( 'A' ), value( 'A' ));
assertEquals( value ( 'A' ), value( "A" ));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,26 @@ public void testCanPackAndUnpackBytes() throws Throwable

}

@Test
public void testCanPackAndUnpackChar() throws Throwable
{
// Given
Machine machine = new Machine();

// When
PackStream.Packer packer = machine.packer();
packer.pack( 'A' );
packer.flush();

// Then
PackStream.Unpacker unpacker = newUnpacker( machine.output() );
PackType packType = unpacker.peekNextType();

// Then
assertThat( packType, equalTo( PackType.STRING ) );
assertThat( unpacker.unpackString(), equalTo( "A" ));
}

@Test
public void testCanPackAndUnpackString() throws Throwable
{
Expand Down