void () { myFixture.configureByFile(getTestName(true) + ".yml"); final int offset = myFixture.getCaretOffset(); final PsiElement elementAtCaret = myFixture.getFile().findElementAt(offset); final YAMLScalar scalarElement = PsiTreeUtil.getNonStrictParentOfType(elementAtCaret, YAMLScalar.class); assertNotNull(scalarElement); final LiteralTextEscaper<? extends PsiLanguageInjectionHost> elementLiteralEscaper = scalarElement.createLiteralTextEscaper(); assertNotNull(elementLiteralEscaper); final StringBuilder builder = new StringBuilder(); assertTrue(elementLiteralEscaper.decode(ElementManipulators.getValueTextRange(scalarElement), builder)); int[] offsets = new int[builder.length() + 1]; for (int i = 0; i < builder.length() + 1; ++i) { offsets[i] = elementLiteralEscaper.getOffsetInHost(i, TextRange.from(0, scalarElement.getTextLength())); } final String elementText = scalarElement.getText(); StringBuilder description = new StringBuilder(); for (int i = 0; i < builder.length(); ++i) { description.append(StringUtil.escapeLineBreak(Character.toString(builder.charAt(i)))) .append("->") .append(StringUtil.escapeLineBreak(elementText.subSequence(offsets[i], offsets[i + 1]).toString())) .append('\n'); } assertSameLinesWithFile(getTestDataPath() + getTestName(true) + ".positions.txt", Arrays.toString(offsets) + "\n" + description, false); String decodedText = builder.toString(); YAMLScalar scalar = WriteCommandAction.runWriteCommandAction( getProject(), (Computable<? extends YAMLScalar>)() -> CodeStyleManager.getInstance(getProject()) .performActionWithFormatterDisabled(() -> ElementManipulators.handleContentChange(scalarElement, decodedText)) ); //assertEquals("element text should be the same after re-decoding", elementText, scalar.getText()); final StringBuilder decodedOnceAgain = new StringBuilder(); assertTrue(scalar.createLiteralTextEscaper().decode(ElementManipulators.getValueTextRange(scalar), decodedOnceAgain)); assertEquals("should decode to the same content after content change with previously decoded content", decodedText, decodedOnceAgain.toString()); }