79 def set_literal_and_get_newline_delta(self, literal_value: LiteralValue) -> int:
80 encoded = literal_value.format.encode(
81 literal_value.actual,
82 self.__language,
83 self.__escape_leading_whitespace,
84 )
85 if not isinstance(literal_value.format, LiteralRepr):
86
87 round_tripped = literal_value.format.parse(encoded, self.__language)
88 if round_tripped != literal_value.actual:
89 raise ValueError(
90 f"There is an error in {literal_value.format.__class__.__name__}, "
91 "the following value isn't round tripping.\n"
92 f"Please report this error and the data below at "
93 "https://github.com/diffplug/selfie/issues/new\n"
94 f"```\n"
95 f"ORIGINAL\n{literal_value.actual}\n"
96 f"ROUNDTRIPPED\n{round_tripped}\n"
97 f"ENCODED ORIGINAL\n{encoded}\n"
98 f"```\n"
99 )
100 existing_newlines = self.__function_call_plus_arg.count("\n")
101 new_newlines = encoded.count("\n")
102 self.__parent._content_slice = Slice(
103 self.__function_call_plus_arg.replaceSelfWith(
104 f"{self.__dot_fun_open_paren}{encoded})"
105 )
106 )
107
108 return new_newlines - existing_newlines
109