|
90 | 90 | import static org.mockito.Mockito.when;
|
91 | 91 | import static org.opengrok.indexer.condition.RepositoryInstalled.Type.MERCURIAL;
|
92 | 92 | import static org.opengrok.indexer.history.LatestRevisionUtil.getLatestRevision;
|
| 93 | +import static org.opengrok.indexer.web.Util.fixPathIfWindows; |
93 | 94 |
|
94 | 95 | /**
|
95 | 96 | * Unit tests for the {@code PageConfig} class.
|
@@ -1091,4 +1092,52 @@ public String getPathInfo() {
|
1091 | 1092 | // cleanup
|
1092 | 1093 | assertTrue(file.setReadable(true, false));
|
1093 | 1094 | }
|
| 1095 | + |
| 1096 | + @Test |
| 1097 | + void testEvaluateMatchOffsetNoParam() { |
| 1098 | + final String relativePath = Path.of("mercurial", "main.c").toString(); |
| 1099 | + HttpServletRequest req = new DummyHttpServletRequest() { |
| 1100 | + @Override |
| 1101 | + public String getPathInfo() { |
| 1102 | + return fixPathIfWindows(relativePath); |
| 1103 | + } |
| 1104 | + }; |
| 1105 | + |
| 1106 | + final File file = new File(RuntimeEnvironment.getInstance().getSourceRootPath(), relativePath); |
| 1107 | + assertTrue(file.exists()); |
| 1108 | + PageConfig cfg = PageConfig.get(req); |
| 1109 | + assertFalse(cfg.evaluateMatchOffset()); |
| 1110 | + assertNull(cfg.getFragmentIdentifier()); |
| 1111 | + } |
| 1112 | + |
| 1113 | + private static Stream<Pair<String, String>> getParamsForTestEvaluateMatchOffset() { |
| 1114 | + return Stream.of(Pair.of("0", "1"), |
| 1115 | + Pair.of("42", "3")); |
| 1116 | + } |
| 1117 | + |
| 1118 | + @ParameterizedTest |
| 1119 | + @MethodSource("getParamsForTestEvaluateMatchOffset") |
| 1120 | + void testEvaluateMatchOffset(Pair<String, String> offsetPair) { |
| 1121 | + final String relativePath = Path.of("mercurial", "main.c").toString(); |
| 1122 | + HttpServletRequest req = new DummyHttpServletRequest() { |
| 1123 | + @Override |
| 1124 | + public String getPathInfo() { |
| 1125 | + return fixPathIfWindows(relativePath); |
| 1126 | + } |
| 1127 | + |
| 1128 | + @Override |
| 1129 | + public String getParameter(String name) { |
| 1130 | + if (name.equals(QueryParameters.MATCH_OFFSET_PARAM)) { |
| 1131 | + return offsetPair.getLeft(); |
| 1132 | + } |
| 1133 | + return null; |
| 1134 | + } |
| 1135 | + }; |
| 1136 | + |
| 1137 | + final File file = new File(RuntimeEnvironment.getInstance().getSourceRootPath(), relativePath); |
| 1138 | + assertTrue(file.exists()); |
| 1139 | + PageConfig cfg = PageConfig.get(req); |
| 1140 | + assertTrue(cfg.evaluateMatchOffset()); |
| 1141 | + assertEquals(offsetPair.getRight(), cfg.getFragmentIdentifier()); |
| 1142 | + } |
1094 | 1143 | }
|
0 commit comments