private TextValue nextTextValue( int minLength, int maxLength, CodePointFactory codePointFactory ) { // todo should we generate UTF8StringValue or StringValue? Or maybe both? Randomly? int length = intBetween( minLength, maxLength ); UTF8StringValueBuilder builder = new UTF8StringValueBuilder( nextPowerOf2( length ) ); for ( int i = 0; i < length; i++ ) { builder.addCodePoint( codePointFactory.generate() ); } return builder.build(); }
@Test void shouldHandleThreeByteCodePoints() { // Given UTF8StringValueBuilder builder = new UTF8StringValueBuilder(); int codepoint = "€".codePointAt( 0 ); // When builder.addCodePoint( codepoint ); builder.addCodePoint( codepoint ); builder.addCodePoint( codepoint ); // Then TextValue textValue = builder.build(); assertThat( textValue.stringValue(), equalTo("€€€")); }
@Test void shouldHandleTwoByteCodePoints() { // Given UTF8StringValueBuilder builder = new UTF8StringValueBuilder(); int codepoint = "¢".codePointAt( 0 ); // When builder.addCodePoint( codepoint ); builder.addCodePoint( codepoint ); builder.addCodePoint( codepoint ); // Then TextValue textValue = builder.build(); assertThat( textValue.stringValue(), equalTo("¢¢¢")); }
@Test void shouldHandleSingleByteCodePoints() { // Given UTF8StringValueBuilder builder = new UTF8StringValueBuilder(); int codepoint = "$".codePointAt( 0 ); // When builder.addCodePoint( codepoint ); builder.addCodePoint( codepoint ); builder.addCodePoint( codepoint ); // Then TextValue textValue = builder.build(); assertThat( textValue.stringValue(), equalTo("$$$")); }
@Test void shouldHandleFourByteCodePoints() { // Given UTF8StringValueBuilder builder = new UTF8StringValueBuilder(); int codepoint = "\uD800\uDF48".codePointAt( 0 ); // When builder.addCodePoint( codepoint ); builder.addCodePoint( codepoint ); builder.addCodePoint( codepoint ); // Then TextValue textValue = builder.build(); assertThat( textValue.stringValue(), equalTo("\uD800\uDF48\uD800\uDF48\uD800\uDF48")); } }
private TextValue nextTextValue( int minLength, int maxLength, CodePointFactory codePointFactory ) { // todo should we generate UTF8StringValue or StringValue? Or maybe both? Randomly? int length = intBetween( minLength, maxLength ); UTF8StringValueBuilder builder = new UTF8StringValueBuilder( nextPowerOf2( length ) ); for ( int i = 0; i < length; i++ ) { builder.addCodePoint( codePointFactory.generate() ); } return builder.build(); }