forked from helidon-io/helidon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix handling of optional whitespace at the beginning of headers. (hel…
- Loading branch information
1 parent
4e78028
commit f2d018d
Showing
5 changed files
with
138 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
common/buffers/src/test/java/io/helidon/common/buffers/LazyStringTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (c) 2022 Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.helidon.common.buffers; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import static java.nio.charset.StandardCharsets.US_ASCII; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
class LazyStringTest { | ||
@ParameterizedTest | ||
@MethodSource("owsData") | ||
void testOwsHandling(OwsTestData data) { | ||
assertThat(data.string().stripOws(), is(data.expected())); | ||
} | ||
|
||
private static Stream<OwsTestData> owsData() { | ||
return Stream.of( | ||
new OwsTestData(new LazyString("some-value".getBytes(US_ASCII), US_ASCII), "some-value"), | ||
new OwsTestData(new LazyString(" some-value".getBytes(US_ASCII), US_ASCII), "some-value"), | ||
new OwsTestData(new LazyString("\tsome-value".getBytes(US_ASCII), US_ASCII), "some-value"), | ||
new OwsTestData(new LazyString(" some-value".getBytes(US_ASCII), US_ASCII), "some-value"), | ||
new OwsTestData(new LazyString("\t\tsome-value".getBytes(US_ASCII), US_ASCII), "some-value"), | ||
new OwsTestData(new LazyString(" \tsome-value".getBytes(US_ASCII), US_ASCII), "some-value"), | ||
new OwsTestData(new LazyString("some-value ".getBytes(US_ASCII), US_ASCII), "some-value"), | ||
new OwsTestData(new LazyString("some-value\t".getBytes(US_ASCII), US_ASCII), "some-value"), | ||
new OwsTestData(new LazyString("some-value ".getBytes(US_ASCII), US_ASCII), "some-value"), | ||
new OwsTestData(new LazyString("some-value\t\t".getBytes(US_ASCII), US_ASCII), "some-value"), | ||
new OwsTestData(new LazyString("some-value \t".getBytes(US_ASCII), US_ASCII), "some-value"), | ||
new OwsTestData(new LazyString(" some-value ".getBytes(US_ASCII), US_ASCII), "some-value"), | ||
new OwsTestData(new LazyString("\tsome-value\t".getBytes(US_ASCII), US_ASCII), "some-value"), | ||
new OwsTestData(new LazyString(" some-value ".getBytes(US_ASCII), US_ASCII), "some-value"), | ||
new OwsTestData(new LazyString("\t\tsome-value\t\t".getBytes(US_ASCII), US_ASCII), "some-value"), | ||
new OwsTestData(new LazyString(" \tsome-value\t ".getBytes(US_ASCII), US_ASCII), "some-value"), | ||
new OwsTestData(new LazyString(" \t\t ".getBytes(US_ASCII), US_ASCII), ""), | ||
new OwsTestData(new LazyString(" \t\r\t ".getBytes(US_ASCII), US_ASCII), "\r") | ||
); | ||
} | ||
|
||
record OwsTestData(LazyString string, String expected) { | ||
@Override | ||
public String toString() { | ||
StringBuilder result = new StringBuilder(); | ||
|
||
for (char c : string().toString().toCharArray()) { | ||
switch (c) { | ||
case '\t' -> result.append("\\t"); | ||
case '\r' -> result.append("\\r"); | ||
default -> result.append(c); | ||
} | ||
} | ||
|
||
return "\"" + result + "\""; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters