return Change.ofTextPatch(path, node.get("content").textValue());
return Change.ofTextPatch(path, node.get("content").textValue());
return Change.ofTextPatch(path, node.get("content").textValue());
break; case APPLY_TEXT_PATCH: result = Change.ofTextPatch(path, content.asText()); break; default:
break; case APPLY_TEXT_PATCH: result = Change.ofTextPatch(path, content.asText()); break; default:
break; case APPLY_TEXT_PATCH: result = Change.ofTextPatch(path, content.asText()); break; default:
final Change<String> textChange = Change.ofTextPatch(textNodePath, oldTextString, newTextString);
return Change.ofJsonPatch(path, (JsonNode) fromContent, (JsonNode) toContent); case TEXT: return Change.ofTextPatch(path, (String) fromContent, (String) toContent); default: throw new Error();
return Change.ofJsonPatch(path, (JsonNode) fromContent, (JsonNode) toContent); case TEXT: return Change.ofTextPatch(path, (String) fromContent, (String) toContent); default: throw new Error();
return Change.ofJsonPatch(path, (JsonNode) fromContent, (JsonNode) toContent); case TEXT: return Change.ofTextPatch(path, (String) fromContent, (String) toContent); default: throw new Error();
@Override protected com.linecorp.centraldogma.common.Change<?> doBackward(Change c) { switch (c.getType()) { case UPSERT_JSON: return com.linecorp.centraldogma.common.Change.ofJsonUpsert(c.getPath(), c.getContent()); case UPSERT_TEXT: return com.linecorp.centraldogma.common.Change.ofTextUpsert(c.getPath(), c.getContent()); case REMOVE: return com.linecorp.centraldogma.common.Change.ofRemoval(c.getPath()); case RENAME: return com.linecorp.centraldogma.common.Change.ofRename(c.getPath(), c.getContent()); case APPLY_JSON_PATCH: return com.linecorp.centraldogma.common.Change.ofJsonPatch(c.getPath(), c.getContent()); case APPLY_TEXT_PATCH: return com.linecorp.centraldogma.common.Change.ofTextPatch(c.getPath(), c.getContent()); } throw new Error(); }
@Override protected com.linecorp.centraldogma.common.Change<?> doBackward(Change c) { switch (c.getType()) { case UPSERT_JSON: return com.linecorp.centraldogma.common.Change.ofJsonUpsert(c.getPath(), c.getContent()); case UPSERT_TEXT: return com.linecorp.centraldogma.common.Change.ofTextUpsert(c.getPath(), c.getContent()); case REMOVE: return com.linecorp.centraldogma.common.Change.ofRemoval(c.getPath()); case RENAME: return com.linecorp.centraldogma.common.Change.ofRename(c.getPath(), c.getContent()); case APPLY_JSON_PATCH: return com.linecorp.centraldogma.common.Change.ofJsonPatch(c.getPath(), c.getContent()); case APPLY_TEXT_PATCH: return com.linecorp.centraldogma.common.Change.ofTextPatch(c.getPath(), c.getContent()); } throw new Error(); }
@Before public void setUp() throws Exception { prefix = '/' + testName.getMethodName() + '/'; allPattern = prefix + "**"; for (int i = 0; i < NUM_ITERATIONS; i++) { final String jsonPath = prefix + i + ".json"; final String textPath = prefix + i + ".txt"; jsonPaths[i] = jsonPath; textPaths[i] = textPath; jsonUpserts[i] = Change.ofJsonUpsert(jsonPath, "{ \"" + i + "\": " + i + " }"); textUpserts[i] = Change.ofTextUpsert(textPath, "value:\n" + i); } jsonPatches[0] = Change.ofJsonPatch(jsonPaths[0], null, jsonUpserts[0].content()); textPatches[0] = Change.ofTextPatch(textPaths[0], null, textUpserts[0].content()); for (int i = 1; i < NUM_ITERATIONS; i++) { jsonPatches[i] = Change.ofJsonPatch(jsonPaths[0], jsonUpserts[i - 1].content(), jsonUpserts[i].content()); textPatches[i] = Change.ofTextPatch(textPaths[0], textUpserts[i - 1].content(), textUpserts[i].content()); } watchConsumer = null; }
putChange(changeMap, newPath, Change.ofTextPatch(newPath, oldText, newText));
@Test public void testTextPatches() throws PatchFailedException { final String oriStr = "1\n2\n3\n4\n5\n6\n7\n8\n9"; final String newStr = "1a\n2\n3\n4\n5\n6\n7\n8\n9a"; final String expectedUnifiedDiff = "--- /text_file.txt\n" + "+++ /text_file.txt\n" + "@@ -1,4 +1,4 @@\n" + "-1\n" + "+1a\n" + " 2\n" + " 3\n" + " 4\n" + "@@ -6,4 +6,4 @@\n" + " 6\n" + " 7\n" + " 8\n" + "-9\n" + "+9a"; final Change<String> change = Change.ofTextPatch("/text_file.txt", oriStr, newStr); assertEquals(expectedUnifiedDiff, change.content()); final Patch<String> patch = DiffUtils.parseUnifiedDiff(Util.stringToLines(change.content())); final String patchedStr = String.join("\n", patch.applyTo(Util.stringToLines(oriStr))); assertEquals(newStr, patchedStr); }
putChange(changeMap, newPath, Change.ofTextPatch(newPath, oldText, newText));
break; case APPLY_TEXT_PATCH: converted = unsafeCast(Change.ofTextPatch(query.path(), r.getContent())); break; default:
break; case APPLY_TEXT_PATCH: converted = unsafeCast(Change.ofTextPatch(query.path(), r.getContent())); break; default:
break; case APPLY_TEXT_PATCH: converted = unsafeCast(Change.ofTextPatch(query.path(), r.getContent())); break; default:
'}'); TestUtil.assertJsonConversion(Change.ofTextPatch("/4", "foo", "bar"), Change.class, '{' + " \"type\": \"APPLY_TEXT_PATCH\"," +